| 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/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 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 m_performance->m_observerFilterOptions |= PerformanceEntry::LongTask; | 33 m_performance->m_observerFilterOptions |= PerformanceEntry::LongTask; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void removeLongTaskObserver() { | 36 void removeLongTaskObserver() { |
| 37 // simulate with filter options. | 37 // simulate with filter options. |
| 38 m_performance->m_observerFilterOptions = PerformanceEntry::Invalid; | 38 m_performance->m_observerFilterOptions = PerformanceEntry::Invalid; |
| 39 } | 39 } |
| 40 | 40 |
| 41 LocalFrame* frame() const { return m_pageHolder->document().frame(); } | 41 LocalFrame* frame() const { return m_pageHolder->document().frame(); } |
| 42 | 42 |
| 43 Document* document() const { return &m_pageHolder->document(); } |
| 44 |
| 43 LocalFrame* anotherFrame() const { | 45 LocalFrame* anotherFrame() const { |
| 44 return m_anotherPageHolder->document().frame(); | 46 return m_anotherPageHolder->document().frame(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 String sanitizedAttribution(const HeapHashSet<Member<Frame>>& frames, | 49 Document* anotherDocument() const { return &m_anotherPageHolder->document(); } |
| 50 |
| 51 String sanitizedAttribution(ExecutionContext* context, |
| 52 bool hasMultipleContexts, |
| 48 Frame* observerFrame) { | 53 Frame* observerFrame) { |
| 49 return Performance::sanitizedAttribution(frames, observerFrame).first; | 54 return Performance::sanitizedAttribution(context, hasMultipleContexts, |
| 55 observerFrame) |
| 56 .first; |
| 50 } | 57 } |
| 51 | 58 |
| 52 Persistent<Performance> m_performance; | 59 Persistent<Performance> m_performance; |
| 53 std::unique_ptr<DummyPageHolder> m_pageHolder; | 60 std::unique_ptr<DummyPageHolder> m_pageHolder; |
| 54 std::unique_ptr<DummyPageHolder> m_anotherPageHolder; | 61 std::unique_ptr<DummyPageHolder> m_anotherPageHolder; |
| 55 }; | 62 }; |
| 56 | 63 |
| 57 TEST_F(PerformanceTest, LongTaskObserverInstrumentation) { | 64 TEST_F(PerformanceTest, LongTaskObserverInstrumentation) { |
| 58 m_performance->updateLongTaskInstrumentation(); | 65 m_performance->updateLongTaskInstrumentation(); |
| 59 EXPECT_FALSE(observingLongTasks()); | 66 EXPECT_FALSE(observingLongTasks()); |
| 60 | 67 |
| 61 // Adding LongTask observer (with filer option) enables instrumentation. | 68 // Adding LongTask observer (with filer option) enables instrumentation. |
| 62 addLongTaskObserver(); | 69 addLongTaskObserver(); |
| 63 m_performance->updateLongTaskInstrumentation(); | 70 m_performance->updateLongTaskInstrumentation(); |
| 64 EXPECT_TRUE(observingLongTasks()); | 71 EXPECT_TRUE(observingLongTasks()); |
| 65 | 72 |
| 66 // Removing LongTask observer disables instrumentation. | 73 // Removing LongTask observer disables instrumentation. |
| 67 removeLongTaskObserver(); | 74 removeLongTaskObserver(); |
| 68 m_performance->updateLongTaskInstrumentation(); | 75 m_performance->updateLongTaskInstrumentation(); |
| 69 EXPECT_FALSE(observingLongTasks()); | 76 EXPECT_FALSE(observingLongTasks()); |
| 70 } | 77 } |
| 71 | 78 |
| 72 TEST_F(PerformanceTest, SanitizedLongTaskName) { | 79 TEST_F(PerformanceTest, SanitizedLongTaskName) { |
| 73 HeapHashSet<Member<Frame>> frameContexts; | |
| 74 // Unable to attribute, when no execution contents are available. | 80 // Unable to attribute, when no execution contents are available. |
| 75 EXPECT_EQ("unknown", sanitizedAttribution(frameContexts, frame())); | 81 EXPECT_EQ("unknown", sanitizedAttribution(nullptr, false, frame())); |
| 76 | 82 |
| 77 // Attribute for same context (and same origin). | 83 // Attribute for same context (and same origin). |
| 78 frameContexts.add(frame()); | 84 EXPECT_EQ("same-origin", sanitizedAttribution(document(), false, frame())); |
| 79 EXPECT_EQ("same-origin", sanitizedAttribution(frameContexts, frame())); | |
| 80 | 85 |
| 81 // Unable to attribute, when multiple script execution contents are involved. | 86 // Unable to attribute, when multiple script execution contents are involved. |
| 82 frameContexts.add(anotherFrame()); | 87 EXPECT_EQ("multiple-contexts", |
| 83 EXPECT_EQ("multiple-contexts", sanitizedAttribution(frameContexts, frame())); | 88 sanitizedAttribution(document(), true, frame())); |
| 84 } | 89 } |
| 85 | 90 |
| 86 TEST_F(PerformanceTest, SanitizedLongTaskName_CrossOrigin) { | 91 TEST_F(PerformanceTest, SanitizedLongTaskName_CrossOrigin) { |
| 87 HeapHashSet<Member<Frame>> frameContexts; | |
| 88 // Unable to attribute, when no execution contents are available. | 92 // Unable to attribute, when no execution contents are available. |
| 89 EXPECT_EQ("unknown", sanitizedAttribution(frameContexts, frame())); | 93 EXPECT_EQ("unknown", sanitizedAttribution(nullptr, false, frame())); |
| 90 | 94 |
| 91 // Attribute for same context (and same origin). | 95 // Attribute for same context (and same origin). |
| 92 frameContexts.add(anotherFrame()); | |
| 93 EXPECT_EQ("cross-origin-unreachable", | 96 EXPECT_EQ("cross-origin-unreachable", |
| 94 sanitizedAttribution(frameContexts, frame())); | 97 sanitizedAttribution(anotherDocument(), false, frame())); |
| 95 } | 98 } |
| 96 } | 99 } |
| OLD | NEW |