| 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 "platform/scheduler/test/fake_web_task_runner.h" | 9 #include "platform/scheduler/test/fake_web_task_runner.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 simulateLayoutAndPaint(10); | 151 simulateLayoutAndPaint(10); |
| 152 // The second candidate gets reported. | 152 // The second candidate gets reported. |
| 153 EXPECT_GT(paintTiming().firstMeaningfulPaintCandidate(), afterPaint); | 153 EXPECT_GT(paintTiming().firstMeaningfulPaintCandidate(), afterPaint); |
| 154 double candidate = paintTiming().firstMeaningfulPaintCandidate(); | 154 double candidate = paintTiming().firstMeaningfulPaintCandidate(); |
| 155 // The third candidate gets ignored since we already saw the first candidate. | 155 // The third candidate gets ignored since we already saw the first candidate. |
| 156 simulateLayoutAndPaint(10); | 156 simulateLayoutAndPaint(10); |
| 157 EXPECT_EQ(paintTiming().firstMeaningfulPaintCandidate(), candidate); | 157 EXPECT_EQ(paintTiming().firstMeaningfulPaintCandidate(), candidate); |
| 158 } | 158 } |
| 159 | 159 |
| 160 TEST_F(FirstMeaningfulPaintDetectorTest, | 160 TEST_F(FirstMeaningfulPaintDetectorTest, |
| 161 OnlyOneFirstMeaningfulPaintCandidateBeforeNetworkStable) { |
| 162 paintTiming().markFirstContentfulPaint(); |
| 163 EXPECT_EQ(paintTiming().firstMeaningfulPaintCandidate(), 0.0); |
| 164 double beforePaint = monotonicallyIncreasingTime(); |
| 165 simulateLayoutAndPaint(1); |
| 166 // The first candidate is initially ignored. |
| 167 EXPECT_EQ(paintTiming().firstMeaningfulPaintCandidate(), 0.0); |
| 168 simulateNetworkStable(); |
| 169 // The networkStable then promotes the first candidate. |
| 170 EXPECT_GT(paintTiming().firstMeaningfulPaintCandidate(), beforePaint); |
| 171 double candidate = paintTiming().firstMeaningfulPaintCandidate(); |
| 172 // The second candidate is then ignored. |
| 173 simulateLayoutAndPaint(10); |
| 174 EXPECT_EQ(paintTiming().firstMeaningfulPaintCandidate(), candidate); |
| 175 } |
| 176 |
| 177 TEST_F(FirstMeaningfulPaintDetectorTest, |
| 161 NetworkStableBeforeFirstContentfulPaint) { | 178 NetworkStableBeforeFirstContentfulPaint) { |
| 162 paintTiming().markFirstPaint(); | 179 paintTiming().markFirstPaint(); |
| 163 simulateLayoutAndPaint(1); | 180 simulateLayoutAndPaint(1); |
| 164 simulateNetworkStable(); | 181 simulateNetworkStable(); |
| 165 EXPECT_EQ(paintTiming().firstMeaningfulPaint(), 0.0); | 182 EXPECT_EQ(paintTiming().firstMeaningfulPaint(), 0.0); |
| 166 paintTiming().markFirstContentfulPaint(); | 183 paintTiming().markFirstContentfulPaint(); |
| 167 simulateNetworkStable(); | 184 simulateNetworkStable(); |
| 168 EXPECT_NE(paintTiming().firstMeaningfulPaint(), 0.0); | 185 EXPECT_NE(paintTiming().firstMeaningfulPaint(), 0.0); |
| 169 } | 186 } |
| 170 | 187 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 EXPECT_FALSE(isNetwork2QuietTimerRestarted()); | 249 EXPECT_FALSE(isNetwork2QuietTimerRestarted()); |
| 233 | 250 |
| 234 setActiveConnections(0); | 251 setActiveConnections(0); |
| 235 EXPECT_TRUE(isNetwork0QuietTimerActive()); | 252 EXPECT_TRUE(isNetwork0QuietTimerActive()); |
| 236 EXPECT_TRUE(isNetwork0QuietTimerRestarted()); | 253 EXPECT_TRUE(isNetwork0QuietTimerRestarted()); |
| 237 EXPECT_TRUE(isNetwork2QuietTimerActive()); | 254 EXPECT_TRUE(isNetwork2QuietTimerActive()); |
| 238 EXPECT_FALSE(isNetwork2QuietTimerRestarted()); | 255 EXPECT_FALSE(isNetwork2QuietTimerRestarted()); |
| 239 } | 256 } |
| 240 | 257 |
| 241 } // namespace blink | 258 } // namespace blink |
| OLD | NEW |