OLD | NEW |
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/frame/PerformanceMonitor.h" | 5 #include "core/frame/PerformanceMonitor.h" |
6 | 6 |
7 #include "core/frame/LocalFrame.h" | 7 #include "core/frame/LocalFrame.h" |
8 #include "core/frame/Location.h" | 8 #include "core/frame/Location.h" |
9 #include "core/testing/DummyPageHolder.h" | 9 #include "core/testing/DummyPageHolder.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "wtf/PtrUtil.h" | 11 #include "wtf/PtrUtil.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 class PerformanceMonitorTest : public ::testing::Test { | 17 class PerformanceMonitorTest : public ::testing::Test { |
18 protected: | 18 protected: |
19 void SetUp() override; | 19 void SetUp() override; |
| 20 void TearDown() override; |
20 LocalFrame* frame() const { return m_pageHolder->document().frame(); } | 21 LocalFrame* frame() const { return m_pageHolder->document().frame(); } |
21 ExecutionContext* executionContext() const { | 22 ExecutionContext* executionContext() const { |
22 return &m_pageHolder->document(); | 23 return &m_pageHolder->document(); |
23 } | 24 } |
24 LocalFrame* anotherFrame() const { | 25 LocalFrame* anotherFrame() const { |
25 return m_anotherPageHolder->document().frame(); | 26 return m_anotherPageHolder->document().frame(); |
26 } | 27 } |
27 ExecutionContext* anotherExecutionContext() const { | 28 ExecutionContext* anotherExecutionContext() const { |
28 return &m_anotherPageHolder->document(); | 29 return &m_anotherPageHolder->document(); |
29 } | 30 } |
30 | 31 |
31 void willExecuteScript(ExecutionContext* executionContext) { | 32 void willExecuteScript(ExecutionContext* executionContext) { |
32 m_monitor->alwaysWillExecuteScript(executionContext); | 33 m_monitor->willExecuteScript(executionContext); |
33 } | 34 } |
34 | 35 |
35 // scheduler::TaskTimeObserver implementation | 36 // scheduler::TaskTimeObserver implementation |
36 void willProcessTask(scheduler::TaskQueue* queue, double startTime) { | 37 void willProcessTask(scheduler::TaskQueue* queue, double startTime) { |
37 m_monitor->willProcessTask(queue, startTime); | 38 m_monitor->willProcessTask(queue, startTime); |
38 } | 39 } |
39 | 40 |
40 void didProcessTask(scheduler::TaskQueue* queue, | 41 void didProcessTask(scheduler::TaskQueue* queue, |
41 double startTime, | 42 double startTime, |
42 double endTime) { | 43 double endTime) { |
(...skipping 12 matching lines...) Expand all Loading... |
55 m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); | 56 m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); |
56 m_pageHolder->document().setURL(KURL(KURL(), "https://example.com/foo")); | 57 m_pageHolder->document().setURL(KURL(KURL(), "https://example.com/foo")); |
57 m_monitor = new PerformanceMonitor(frame()); | 58 m_monitor = new PerformanceMonitor(frame()); |
58 | 59 |
59 // Create another dummy page holder and pretend this is the iframe. | 60 // Create another dummy page holder and pretend this is the iframe. |
60 m_anotherPageHolder = DummyPageHolder::create(IntSize(400, 300)); | 61 m_anotherPageHolder = DummyPageHolder::create(IntSize(400, 300)); |
61 m_anotherPageHolder->document().setURL( | 62 m_anotherPageHolder->document().setURL( |
62 KURL(KURL(), "https://iframed.com/bar")); | 63 KURL(KURL(), "https://iframed.com/bar")); |
63 } | 64 } |
64 | 65 |
| 66 void PerformanceMonitorTest::TearDown() { |
| 67 m_monitor->shutdown(); |
| 68 } |
| 69 |
65 String PerformanceMonitorTest::frameContextURL() { | 70 String PerformanceMonitorTest::frameContextURL() { |
66 // This is reported only if there is a single frameContext URL. | 71 // This is reported only if there is a single frameContext URL. |
67 if (m_monitor->m_taskHasMultipleContexts) | 72 if (m_monitor->m_taskHasMultipleContexts) |
68 return ""; | 73 return ""; |
69 Frame* frame = toDocument(m_monitor->m_taskExecutionContext)->frame(); | 74 Frame* frame = toDocument(m_monitor->m_taskExecutionContext)->frame(); |
70 return toLocalFrame(frame)->document()->location()->href(); | 75 return toLocalFrame(frame)->document()->location()->href(); |
71 } | 76 } |
72 | 77 |
73 int PerformanceMonitorTest::numUniqueFrameContextsSeen() { | 78 int PerformanceMonitorTest::numUniqueFrameContextsSeen() { |
74 if (!m_monitor->m_taskExecutionContext) | 79 if (!m_monitor->m_taskExecutionContext) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 willExecuteScript(executionContext()); | 126 willExecuteScript(executionContext()); |
122 didProcessTask(nullptr, 3719349.445172, 3719349.445182); | 127 didProcessTask(nullptr, 3719349.445172, 3719349.445182); |
123 | 128 |
124 willProcessTask(nullptr, 3719349.445172); | 129 willProcessTask(nullptr, 3719349.445172); |
125 didProcessTask(nullptr, 3719349.445172, 3719349.5561923); // Long task | 130 didProcessTask(nullptr, 3719349.445172, 3719349.5561923); // Long task |
126 // Without presence of Script, FrameContext URL is not available | 131 // Without presence of Script, FrameContext URL is not available |
127 EXPECT_EQ(0, numUniqueFrameContextsSeen()); | 132 EXPECT_EQ(0, numUniqueFrameContextsSeen()); |
128 } | 133 } |
129 | 134 |
130 } // namespace blink | 135 } // namespace blink |
OLD | NEW |