summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/exported/web_disallow_transition_scope_test.cc
blob: 54d58c477942a116c6155e35203984847944fd9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/public/web/web_disallow_transition_scope.h"

#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"

namespace blink {

using blink::frame_test_helpers::WebViewHelper;

class WebDisallowTransitionScopeTest : public testing::Test {
 protected:
  Document* TopDocument() const;
  WebDocument TopWebDocument() const;

  WebViewHelper web_view_helper_;
};

Document* WebDisallowTransitionScopeTest::TopDocument() const {
  return To<LocalFrame>(web_view_helper_.GetWebView()->GetPage()->MainFrame())
      ->GetDocument();
}

WebDocument WebDisallowTransitionScopeTest::TopWebDocument() const {
  return web_view_helper_.LocalMainFrame()->GetDocument();
}

#if !defined(OS_ANDROID)
// TODO(crbug.com/1067036): the death test fails on Android.
TEST_F(WebDisallowTransitionScopeTest, TestDisallowTransition) {
  // Make the death test thread-safe. For more info, see:
  // https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#death-tests-and-threads
  ::testing::FLAGS_gtest_death_test_style = "threadsafe";

  web_view_helper_.InitializeAndLoad("about:blank");

  WebDocument web_doc = TopWebDocument();
  Document* core_doc = TopDocument();

  // Legal transition.
  core_doc->Lifecycle().AdvanceTo(DocumentLifecycle::kLayoutClean);

  {
    // Illegal transition.
    WebDisallowTransitionScope disallow(&web_doc);
    EXPECT_DEATH(core_doc->Lifecycle().EnsureStateAtMost(
                     DocumentLifecycle::kVisualUpdatePending),
                 "Cannot rewind document lifecycle");
  }

  // Legal transition.
  core_doc->Lifecycle().EnsureStateAtMost(
      DocumentLifecycle::kVisualUpdatePending);
}
#endif

}  // namespace blink