Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: third_party/WebKit/Source/core/timing/PerformanceTest.cpp

Issue 2449673002: Refactor InspectorWebPerfAgent: update lifecycle management to be per Local Frame root; replace hea… (Closed)
Patch Set: Update unittests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/timing/Performance.h" 5 #include "core/timing/Performance.h"
6 6
7 #include "core/testing/DummyPageHolder.h" 7 #include "core/testing/DummyPageHolder.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 class PerformanceTest : public ::testing::Test { 12 class PerformanceTest : public ::testing::Test {
13 protected: 13 protected:
14 void SetUp() override { 14 void SetUp() override {
15 m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); 15 m_pageHolder = DummyPageHolder::create(IntSize(800, 600));
16 m_pageHolder->document().setURL(KURL(KURL(), "https://example.com")); 16 m_pageHolder->document().setURL(KURL(KURL(), "https://example.com"));
17 m_performance = Performance::create(&m_pageHolder->frame()); 17 m_performance = Performance::create(&m_pageHolder->frame());
18 } 18 }
19 19
20 bool hasLongTaskInspectorAgent() { 20 bool observingLongTasks() { return m_performance->observingLongTasks(); }
21 return m_performance->m_longTaskInspectorAgent; 21
22 bool hasLongTaskAgentObservers() {
23 return m_performance->frame()->webPerformanceObservers().size() > 0;
22 } 24 }
23 25
24 void addLongTaskObserver() { 26 void addLongTaskObserver() {
25 // simulate with filter options. 27 // simulate with filter options.
26 m_performance->m_observerFilterOptions |= PerformanceEntry::LongTask; 28 m_performance->m_observerFilterOptions |= PerformanceEntry::LongTask;
27 } 29 }
28 30
29 void removeLongTaskObserver() { 31 void removeLongTaskObserver() {
30 // simulate with filter options. 32 // simulate with filter options.
31 m_performance->m_observerFilterOptions = PerformanceEntry::Invalid; 33 m_performance->m_observerFilterOptions = PerformanceEntry::Invalid;
32 } 34 }
33 35
34 Persistent<Performance> m_performance; 36 Persistent<Performance> m_performance;
35 std::unique_ptr<DummyPageHolder> m_pageHolder; 37 std::unique_ptr<DummyPageHolder> m_pageHolder;
36 }; 38 };
37 39
38 TEST_F(PerformanceTest, LongTaskObserverInstrumentation) { 40 TEST_F(PerformanceTest, LongTaskObserverInstrumentation) {
39 m_performance->updateLongTaskInstrumentation(); 41 m_performance->updateLongTaskInstrumentation();
40 EXPECT_FALSE(hasLongTaskInspectorAgent()); 42 EXPECT_FALSE(hasLongTaskAgentObservers());
43 EXPECT_FALSE(observingLongTasks());
41 44
42 // Adding LongTask observer (with filer option) enables instrumentation. 45 // Adding LongTask observer (with filer option) enables instrumentation.
43 addLongTaskObserver(); 46 addLongTaskObserver();
44 m_performance->updateLongTaskInstrumentation(); 47 m_performance->updateLongTaskInstrumentation();
45 EXPECT_TRUE(hasLongTaskInspectorAgent()); 48 EXPECT_TRUE(hasLongTaskAgentObservers());
46 49 EXPECT_TRUE(observingLongTasks());
47 // While LongTask observer is present, updateLongTaskInstrumentation has no
48 // effect.
49 m_performance->updateLongTaskInstrumentation();
50 EXPECT_TRUE(hasLongTaskInspectorAgent());
51 50
52 // Removing LongTask observer disables instrumentation. 51 // Removing LongTask observer disables instrumentation.
53 removeLongTaskObserver(); 52 removeLongTaskObserver();
54 m_performance->updateLongTaskInstrumentation(); 53 m_performance->updateLongTaskInstrumentation();
55 EXPECT_FALSE(hasLongTaskInspectorAgent()); 54 EXPECT_FALSE(hasLongTaskAgentObservers());
55 EXPECT_FALSE(observingLongTasks());
56 } 56 }
57 } 57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698