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/testing/TestingPlatformSupport.h" | 9 #include "platform/testing/TestingPlatformSupport.h" |
10 #include "platform/wtf/text/StringBuilder.h" | 10 #include "platform/wtf/text/StringBuilder.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 void SimulateNetwork0Quiet() { | 49 void SimulateNetwork0Quiet() { |
50 GetDocument().SetParsingState(Document::kFinishedParsing); | 50 GetDocument().SetParsingState(Document::kFinishedParsing); |
51 Detector().Network0QuietTimerFired(nullptr); | 51 Detector().Network0QuietTimerFired(nullptr); |
52 } | 52 } |
53 | 53 |
54 void SimulateNetwork2Quiet() { | 54 void SimulateNetwork2Quiet() { |
55 GetDocument().SetParsingState(Document::kFinishedParsing); | 55 GetDocument().SetParsingState(Document::kFinishedParsing); |
56 Detector().Network2QuietTimerFired(nullptr); | 56 Detector().Network2QuietTimerFired(nullptr); |
57 } | 57 } |
58 | 58 |
| 59 void SimulateUserInput() { Detector().NotifyInputEvent(); } |
| 60 |
59 void SetActiveConnections(int connections) { | 61 void SetActiveConnections(int connections) { |
60 Detector().SetNetworkQuietTimers(connections); | 62 Detector().SetNetworkQuietTimers(connections); |
61 } | 63 } |
62 | 64 |
63 bool IsNetwork0QuietTimerActive() { | 65 bool IsNetwork0QuietTimerActive() { |
64 return Detector().network0_quiet_timer_.IsActive(); | 66 return Detector().network0_quiet_timer_.IsActive(); |
65 } | 67 } |
66 | 68 |
67 bool IsNetwork2QuietTimerActive() { | 69 bool IsNetwork2QuietTimerActive() { |
68 return Detector().network2_quiet_timer_.IsActive(); | 70 return Detector().network2_quiet_timer_.IsActive(); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 SetActiveConnections(2); // This should reset the 2-quiet timer. | 244 SetActiveConnections(2); // This should reset the 2-quiet timer. |
243 platform_->RunForPeriodSeconds(kNetwork2QuietWindowSeconds - 0.1); | 245 platform_->RunForPeriodSeconds(kNetwork2QuietWindowSeconds - 0.1); |
244 EXPECT_TRUE(IsNetwork2QuietTimerActive()); | 246 EXPECT_TRUE(IsNetwork2QuietTimerActive()); |
245 EXPECT_FALSE(HadNetwork2Quiet()); | 247 EXPECT_FALSE(HadNetwork2Quiet()); |
246 | 248 |
247 SetActiveConnections(1); // This should not reset the 2-quiet timer. | 249 SetActiveConnections(1); // This should not reset the 2-quiet timer. |
248 platform_->RunForPeriodSeconds(0.1001); | 250 platform_->RunForPeriodSeconds(0.1001); |
249 EXPECT_TRUE(HadNetwork2Quiet()); | 251 EXPECT_TRUE(HadNetwork2Quiet()); |
250 } | 252 } |
251 | 253 |
| 254 TEST_F(FirstMeaningfulPaintDetectorTest, |
| 255 FirstMeaningfulPaintAfterUserInteraction) { |
| 256 GetPaintTiming().MarkFirstContentfulPaint(); |
| 257 SimulateUserInput(); |
| 258 SimulateLayoutAndPaint(10); |
| 259 SimulateNetworkStable(); |
| 260 EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), 0.0); |
| 261 } |
| 262 |
| 263 TEST_F(FirstMeaningfulPaintDetectorTest, UserInteractionBeforeFirstPaint) { |
| 264 SimulateUserInput(); |
| 265 GetPaintTiming().MarkFirstContentfulPaint(); |
| 266 SimulateLayoutAndPaint(10); |
| 267 SimulateNetworkStable(); |
| 268 EXPECT_NE(GetPaintTiming().FirstMeaningfulPaint(), 0.0); |
| 269 } |
| 270 |
252 } // namespace blink | 271 } // namespace blink |
OLD | NEW |