Chromium Code Reviews| 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/paint/FirstMeaningfulPaintDetector.h" | 5 #include "core/paint/FirstMeaningfulPaintDetector.h" |
| 6 | 6 |
| 7 #include "core/paint/PaintTiming.h" | 7 #include "core/paint/PaintTiming.h" |
| 8 #include "core/testing/DummyPageHolder.h" | 8 #include "core/testing/DummyPageHolder.h" |
| 9 #include "core/timing/DOMWindowPerformance.h" | |
| 10 #include "core/timing/Performance.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 12 |
| 11 namespace blink { | 13 namespace blink { |
| 12 | 14 |
| 13 class FirstMeaningfulPaintDetectorTest : public testing::Test { | 15 class FirstMeaningfulPaintDetectorTest : public testing::Test { |
| 14 protected: | 16 protected: |
| 15 void SetUp() override { | 17 void SetUp() override { |
| 16 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 18 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| 17 s_timeElapsed = 0.0; | 19 s_timeElapsed = timeOrigin(); |
| 18 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime); | 20 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime); |
| 19 } | 21 } |
| 20 | 22 |
| 21 void TearDown() override { | 23 void TearDown() override { |
| 22 setTimeFunctionsForTesting(m_originalTimeFunction); | 24 setTimeFunctionsForTesting(m_originalTimeFunction); |
| 23 } | 25 } |
| 24 | 26 |
| 25 Document& document() { return m_dummyPageHolder->document(); } | 27 Document& document() { return m_dummyPageHolder->document(); } |
| 26 PaintTiming& paintTiming() { return PaintTiming::from(document()); } | 28 PaintTiming& paintTiming() { return PaintTiming::from(document()); } |
| 29 | |
| 27 FirstMeaningfulPaintDetector& detector() { | 30 FirstMeaningfulPaintDetector& detector() { |
| 28 return paintTiming().firstMeaningfulPaintDetector(); | 31 return paintTiming().firstMeaningfulPaintDetector(); |
| 29 } | 32 } |
| 30 | 33 |
| 31 void simulateLayoutAndPaint(int newElements) { | 34 void simulateLayoutAndPaint(int newElements) { |
| 32 StringBuilder builder; | 35 StringBuilder builder; |
| 33 for (int i = 0; i < newElements; i++) | 36 for (int i = 0; i < newElements; i++) |
| 34 builder.append("<span>a</span>"); | 37 builder.append("<span>a</span>"); |
| 35 document().write(builder.toString()); | 38 document().write(builder.toString()); |
| 36 document().updateStyleAndLayout(); | 39 document().updateStyleAndLayout(); |
| 37 detector().notifyPaint(); | 40 detector().notifyPaint(); |
| 38 } | 41 } |
| 39 | 42 |
| 40 void simulateNetworkStable() { detector().networkStableTimerFired(nullptr); } | 43 void simulateNetworkStable() { detector().networkStableTimerFired(nullptr); } |
| 41 | 44 |
| 42 private: | 45 private: |
| 43 static double returnMockTime() { | 46 static double returnMockTime() { |
| 44 s_timeElapsed += 1.0; | 47 s_timeElapsed += 1.0; |
| 45 return s_timeElapsed; | 48 return s_timeElapsed; |
| 46 } | 49 } |
| 47 | 50 |
| 51 double timeOrigin() { | |
|
panicker
2017/01/13 19:11:59
Update CL description mentioning why this file is
sunjian
2017/01/13 19:49:33
Done.
| |
| 52 Performance* performance = DOMWindowPerformance::performance(*m_dummyPageHol der->frame().domWindow()); | |
|
panicker
2017/01/13 19:11:59
Nit: did you run git cl format?
sunjian
2017/01/13 19:49:33
Done.
| |
| 53 if (!performance) | |
| 54 return 0.0; | |
| 55 return performance->timeOrigin(); | |
| 56 } | |
| 57 | |
| 48 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 58 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 49 TimeFunction m_originalTimeFunction; | 59 TimeFunction m_originalTimeFunction; |
| 50 static double s_timeElapsed; | 60 static double s_timeElapsed; |
| 51 }; | 61 }; |
| 52 | 62 |
| 53 double FirstMeaningfulPaintDetectorTest::s_timeElapsed; | 63 double FirstMeaningfulPaintDetectorTest::s_timeElapsed; |
| 54 | 64 |
| 55 TEST_F(FirstMeaningfulPaintDetectorTest, NoFirstPaint) { | 65 TEST_F(FirstMeaningfulPaintDetectorTest, NoFirstPaint) { |
| 56 simulateLayoutAndPaint(1); | 66 simulateLayoutAndPaint(1); |
| 57 simulateNetworkStable(); | 67 simulateNetworkStable(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 paintTiming().markFirstPaint(); | 120 paintTiming().markFirstPaint(); |
| 111 simulateLayoutAndPaint(1); | 121 simulateLayoutAndPaint(1); |
| 112 simulateNetworkStable(); | 122 simulateNetworkStable(); |
| 113 EXPECT_EQ(paintTiming().firstMeaningfulPaint(), 0.0); | 123 EXPECT_EQ(paintTiming().firstMeaningfulPaint(), 0.0); |
| 114 paintTiming().markFirstContentfulPaint(); | 124 paintTiming().markFirstContentfulPaint(); |
| 115 simulateNetworkStable(); | 125 simulateNetworkStable(); |
| 116 EXPECT_NE(paintTiming().firstMeaningfulPaint(), 0.0); | 126 EXPECT_NE(paintTiming().firstMeaningfulPaint(), 0.0); |
| 117 } | 127 } |
| 118 | 128 |
| 119 } // namespace blink | 129 } // namespace blink |
| OLD | NEW |