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

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

Issue 2484213003: Convert performance monitor to the subscription model. (Closed)
Patch Set: core export 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/frame/PerformanceMonitor.h" 7 #include "core/frame/PerformanceMonitor.h"
8 #include "core/testing/DummyPageHolder.h" 8 #include "core/testing/DummyPageHolder.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 class PerformanceTest : public ::testing::Test { 13 class PerformanceTest : public ::testing::Test {
14 protected: 14 protected:
15 void SetUp() override { 15 void SetUp() override {
16 m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); 16 m_pageHolder = DummyPageHolder::create(IntSize(800, 600));
17 m_pageHolder->document().setURL(KURL(KURL(), "https://example.com")); 17 m_pageHolder->document().setURL(KURL(KURL(), "https://example.com"));
18 m_performance = Performance::create(&m_pageHolder->frame()); 18 m_performance = Performance::create(&m_pageHolder->frame());
19
20 // Create another dummy page holder and pretend this is the iframe.
21 m_anotherPageHolder = DummyPageHolder::create(IntSize(400, 300));
22 m_anotherPageHolder->document().setURL(
23 KURL(KURL(), "https://iframed.com/bar"));
19 } 24 }
20 25
21 bool observingLongTasks() { 26 bool observingLongTasks() {
22 return PerformanceMonitor::instrumentingMonitor( 27 return PerformanceMonitor::instrumentingMonitor(
23 m_performance->getExecutionContext()); 28 m_performance->getExecutionContext());
24 } 29 }
25 30
26 void addLongTaskObserver() { 31 void addLongTaskObserver() {
27 // simulate with filter options. 32 // simulate with filter options.
28 m_performance->m_observerFilterOptions |= PerformanceEntry::LongTask; 33 m_performance->m_observerFilterOptions |= PerformanceEntry::LongTask;
29 } 34 }
30 35
31 void removeLongTaskObserver() { 36 void removeLongTaskObserver() {
32 // simulate with filter options. 37 // simulate with filter options.
33 m_performance->m_observerFilterOptions = PerformanceEntry::Invalid; 38 m_performance->m_observerFilterOptions = PerformanceEntry::Invalid;
34 } 39 }
35 40
41 LocalFrame* frame() const { return m_pageHolder->document().frame(); }
42
43 LocalFrame* anotherFrame() const {
44 return m_anotherPageHolder->document().frame();
45 }
46
47 String sanitizedAttribution(const HeapHashSet<Member<Frame>>& frames,
48 Frame* observerFrame) {
49 return Performance::sanitizedAttribution(frames, observerFrame).first;
50 }
51
36 Persistent<Performance> m_performance; 52 Persistent<Performance> m_performance;
37 std::unique_ptr<DummyPageHolder> m_pageHolder; 53 std::unique_ptr<DummyPageHolder> m_pageHolder;
54 std::unique_ptr<DummyPageHolder> m_anotherPageHolder;
38 }; 55 };
39 56
40 TEST_F(PerformanceTest, LongTaskObserverInstrumentation) { 57 TEST_F(PerformanceTest, LongTaskObserverInstrumentation) {
41 m_performance->updateLongTaskInstrumentation(); 58 m_performance->updateLongTaskInstrumentation();
42 EXPECT_FALSE(observingLongTasks()); 59 EXPECT_FALSE(observingLongTasks());
43 60
44 // Adding LongTask observer (with filer option) enables instrumentation. 61 // Adding LongTask observer (with filer option) enables instrumentation.
45 addLongTaskObserver(); 62 addLongTaskObserver();
46 m_performance->updateLongTaskInstrumentation(); 63 m_performance->updateLongTaskInstrumentation();
47 EXPECT_TRUE(observingLongTasks()); 64 EXPECT_TRUE(observingLongTasks());
48 65
49 // Removing LongTask observer disables instrumentation. 66 // Removing LongTask observer disables instrumentation.
50 removeLongTaskObserver(); 67 removeLongTaskObserver();
51 m_performance->updateLongTaskInstrumentation(); 68 m_performance->updateLongTaskInstrumentation();
52 EXPECT_FALSE(observingLongTasks()); 69 EXPECT_FALSE(observingLongTasks());
53 } 70 }
71
72 TEST_F(PerformanceTest, SanitizedLongTaskName) {
73 HeapHashSet<Member<Frame>> frameContexts;
74 // Unable to attribute, when no execution contents are available.
75 EXPECT_EQ("unknown", sanitizedAttribution(frameContexts, frame()));
76
77 // Attribute for same context (and same origin).
78 frameContexts.add(frame());
79 EXPECT_EQ("same-origin", sanitizedAttribution(frameContexts, frame()));
80
81 // Unable to attribute, when multiple script execution contents are involved.
82 frameContexts.add(anotherFrame());
83 EXPECT_EQ("multiple-contexts", sanitizedAttribution(frameContexts, frame()));
54 } 84 }
85
86 TEST_F(PerformanceTest, SanitizedLongTaskName_CrossOrigin) {
87 HeapHashSet<Member<Frame>> frameContexts;
88 // Unable to attribute, when no execution contents are available.
89 EXPECT_EQ("unknown", sanitizedAttribution(frameContexts, frame()));
90
91 // Attribute for same context (and same origin).
92 frameContexts.add(anotherFrame());
93 EXPECT_EQ("cross-origin-unreachable",
94 sanitizedAttribution(frameContexts, frame()));
95 }
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698