-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
main_thread_debugger_test.cc
90 lines (74 loc) · 3.24 KB
/
main_thread_debugger_test.cc
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/inspector/main_thread_debugger.h"
#include <memory>
#include "base/test/scoped_feature_list.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
namespace blink {
class MainThreadDebuggerTest : public PageTestBase {
};
TEST_F(MainThreadDebuggerTest, HitBreakPointDuringLifecycle) {
Document& document = GetDocument();
std::unique_ptr<DocumentLifecycle::PostponeTransitionScope>
postponed_transition_scope =
std::make_unique<DocumentLifecycle::PostponeTransitionScope>(
document.Lifecycle());
EXPECT_TRUE(document.Lifecycle().LifecyclePostponed());
// The following steps would cause either style update or layout, it should
// never crash.
document.View()->ViewportSizeChanged(true, true);
document.View()->UpdateAllLifecyclePhases(DocumentUpdateReason::kTest);
document.UpdateStyleAndLayout(DocumentUpdateReason::kTest);
document.UpdateStyleAndLayoutTree();
postponed_transition_scope.reset();
EXPECT_FALSE(document.Lifecycle().LifecyclePostponed());
}
class MainThreadDebuggerMultipleMainFramesTest
: public MainThreadDebuggerTest,
public testing::WithParamInterface<bool> {
public:
MainThreadDebuggerMultipleMainFramesTest() {
if (IsDebuggerAllowed()) {
scoped_feature_list_.InitAndEnableFeature(
features::kAllowDevToolsMainThreadDebuggerForMultipleMainFrames);
} else {
scoped_feature_list_.InitAndDisableFeature(
features::kAllowDevToolsMainThreadDebuggerForMultipleMainFrames);
}
}
~MainThreadDebuggerMultipleMainFramesTest() override = default;
void SetUp() override {
second_dummy_page_holder_ = std::make_unique<DummyPageHolder>();
MainThreadDebuggerTest::SetUp();
}
Page& GetSecondPage() { return second_dummy_page_holder_->GetPage(); }
bool IsDebuggerAllowed() { return GetParam(); }
private:
base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<DummyPageHolder> second_dummy_page_holder_;
};
INSTANTIATE_TEST_SUITE_P(All,
MainThreadDebuggerMultipleMainFramesTest,
testing::Bool());
TEST_P(MainThreadDebuggerMultipleMainFramesTest, Allow) {
Page::InsertOrdinaryPageForTesting(&GetPage());
Page::InsertOrdinaryPageForTesting(&GetSecondPage());
GetFrame().GetSettings()->SetScriptEnabled(true);
auto* debugger = MainThreadDebugger::Instance();
int context_group_id = debugger->ContextGroupId(&GetFrame());
if (IsDebuggerAllowed()) {
ASSERT_TRUE(debugger->canExecuteScripts(context_group_id));
} else {
ASSERT_FALSE(debugger->canExecuteScripts(context_group_id));
}
}
} // namespace blink