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 "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 void simulateLayoutAndPaint(int newElements) { | 31 void simulateLayoutAndPaint(int newElements) { |
32 StringBuilder builder; | 32 StringBuilder builder; |
33 for (int i = 0; i < newElements; i++) | 33 for (int i = 0; i < newElements; i++) |
34 builder.append("<span>a</span>"); | 34 builder.append("<span>a</span>"); |
35 document().write(builder.toString()); | 35 document().write(builder.toString()); |
36 document().updateStyleAndLayout(); | 36 document().updateStyleAndLayout(); |
37 detector().notifyPaint(); | 37 detector().notifyPaint(); |
38 } | 38 } |
39 | 39 |
40 void simulateNetworkStable() { detector().networkStableTimerFired(nullptr); } | 40 void simulateNetworkStable() { |
| 41 document().setParsingState(Document::FinishedParsing); |
| 42 detector().network0QuietTimerFired(nullptr); |
| 43 detector().network2QuietTimerFired(nullptr); |
| 44 } |
| 45 |
| 46 void simulateNetwork0Quiet() { |
| 47 document().setParsingState(Document::FinishedParsing); |
| 48 detector().network0QuietTimerFired(nullptr); |
| 49 } |
| 50 |
| 51 void simulateNetwork2Quiet() { |
| 52 document().setParsingState(Document::FinishedParsing); |
| 53 detector().network2QuietTimerFired(nullptr); |
| 54 } |
41 | 55 |
42 private: | 56 private: |
43 static double returnMockTime() { | 57 static double returnMockTime() { |
44 s_timeElapsed += 1.0; | 58 s_timeElapsed += 1.0; |
45 return s_timeElapsed; | 59 return s_timeElapsed; |
46 } | 60 } |
47 | 61 |
48 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 62 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
49 TimeFunction m_originalTimeFunction; | 63 TimeFunction m_originalTimeFunction; |
50 static double s_timeElapsed; | 64 static double s_timeElapsed; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 TEST_F(FirstMeaningfulPaintDetectorTest, | 133 TEST_F(FirstMeaningfulPaintDetectorTest, |
120 FirstMeaningfulPaintShouldNotBeBeforeFirstContentfulPaint) { | 134 FirstMeaningfulPaintShouldNotBeBeforeFirstContentfulPaint) { |
121 paintTiming().markFirstPaint(); | 135 paintTiming().markFirstPaint(); |
122 simulateLayoutAndPaint(10); | 136 simulateLayoutAndPaint(10); |
123 paintTiming().markFirstContentfulPaint(); | 137 paintTiming().markFirstContentfulPaint(); |
124 simulateNetworkStable(); | 138 simulateNetworkStable(); |
125 EXPECT_GE(paintTiming().firstMeaningfulPaint(), | 139 EXPECT_GE(paintTiming().firstMeaningfulPaint(), |
126 paintTiming().firstContentfulPaint()); | 140 paintTiming().firstContentfulPaint()); |
127 } | 141 } |
128 | 142 |
| 143 TEST_F(FirstMeaningfulPaintDetectorTest, Network2QuietThen0Quiet) { |
| 144 paintTiming().markFirstContentfulPaint(); |
| 145 |
| 146 simulateLayoutAndPaint(1); |
| 147 double afterFirstPaint = monotonicallyIncreasingTime(); |
| 148 simulateNetwork2Quiet(); |
| 149 |
| 150 simulateLayoutAndPaint(10); |
| 151 simulateNetwork0Quiet(); |
| 152 |
| 153 // The first paint is FirstMeaningfulPaint. |
| 154 EXPECT_GT(paintTiming().firstMeaningfulPaint(), 0.0); |
| 155 EXPECT_LT(paintTiming().firstMeaningfulPaint(), afterFirstPaint); |
| 156 } |
| 157 |
| 158 TEST_F(FirstMeaningfulPaintDetectorTest, Network0QuietThen2Quiet) { |
| 159 paintTiming().markFirstContentfulPaint(); |
| 160 |
| 161 simulateLayoutAndPaint(1); |
| 162 double afterFirstPaint = monotonicallyIncreasingTime(); |
| 163 simulateNetwork0Quiet(); |
| 164 |
| 165 simulateLayoutAndPaint(10); |
| 166 double afterSecondPaint = monotonicallyIncreasingTime(); |
| 167 simulateNetwork2Quiet(); |
| 168 |
| 169 // The second paint is FirstMeaningfulPaint. |
| 170 EXPECT_GT(paintTiming().firstMeaningfulPaint(), afterFirstPaint); |
| 171 EXPECT_LT(paintTiming().firstMeaningfulPaint(), afterSecondPaint); |
| 172 } |
| 173 |
129 } // namespace blink | 174 } // namespace blink |
OLD | NEW |