| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 double FirstMeaningfulPaintDetectorTest::s_timeElapsed; | 53 double FirstMeaningfulPaintDetectorTest::s_timeElapsed; |
| 54 | 54 |
| 55 TEST_F(FirstMeaningfulPaintDetectorTest, NoFirstPaint) { | 55 TEST_F(FirstMeaningfulPaintDetectorTest, NoFirstPaint) { |
| 56 simulateLayoutAndPaint(1); | 56 simulateLayoutAndPaint(1); |
| 57 simulateNetworkStable(); | 57 simulateNetworkStable(); |
| 58 EXPECT_EQ(paintTiming().firstMeaningfulPaint(), 0.0); | 58 EXPECT_EQ(paintTiming().firstMeaningfulPaint(), 0.0); |
| 59 } | 59 } |
| 60 | 60 |
| 61 TEST_F(FirstMeaningfulPaintDetectorTest, OneLayout) { | 61 TEST_F(FirstMeaningfulPaintDetectorTest, OneLayout) { |
| 62 paintTiming().markFirstPaint(); | 62 paintTiming().markFirstContentfulPaint(); |
| 63 simulateLayoutAndPaint(1); | 63 simulateLayoutAndPaint(1); |
| 64 double afterPaint = monotonicallyIncreasingTime(); | 64 double afterPaint = monotonicallyIncreasingTime(); |
| 65 EXPECT_EQ(paintTiming().firstMeaningfulPaint(), 0.0); | 65 EXPECT_EQ(paintTiming().firstMeaningfulPaint(), 0.0); |
| 66 simulateNetworkStable(); | 66 simulateNetworkStable(); |
| 67 EXPECT_GT(paintTiming().firstMeaningfulPaint(), paintTiming().firstPaint()); | 67 EXPECT_GT(paintTiming().firstMeaningfulPaint(), paintTiming().firstPaint()); |
| 68 EXPECT_LT(paintTiming().firstMeaningfulPaint(), afterPaint); | 68 EXPECT_LT(paintTiming().firstMeaningfulPaint(), afterPaint); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST_F(FirstMeaningfulPaintDetectorTest, TwoLayoutsSignificantSecond) { | 71 TEST_F(FirstMeaningfulPaintDetectorTest, TwoLayoutsSignificantSecond) { |
| 72 paintTiming().markFirstPaint(); | 72 paintTiming().markFirstContentfulPaint(); |
| 73 simulateLayoutAndPaint(1); | 73 simulateLayoutAndPaint(1); |
| 74 double afterLayout1 = monotonicallyIncreasingTime(); | 74 double afterLayout1 = monotonicallyIncreasingTime(); |
| 75 simulateLayoutAndPaint(10); | 75 simulateLayoutAndPaint(10); |
| 76 double afterLayout2 = monotonicallyIncreasingTime(); | 76 double afterLayout2 = monotonicallyIncreasingTime(); |
| 77 simulateNetworkStable(); | 77 simulateNetworkStable(); |
| 78 EXPECT_GT(paintTiming().firstMeaningfulPaint(), afterLayout1); | 78 EXPECT_GT(paintTiming().firstMeaningfulPaint(), afterLayout1); |
| 79 EXPECT_LT(paintTiming().firstMeaningfulPaint(), afterLayout2); | 79 EXPECT_LT(paintTiming().firstMeaningfulPaint(), afterLayout2); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST_F(FirstMeaningfulPaintDetectorTest, TwoLayoutsSignificantFirst) { | 82 TEST_F(FirstMeaningfulPaintDetectorTest, TwoLayoutsSignificantFirst) { |
| 83 paintTiming().markFirstPaint(); | 83 paintTiming().markFirstContentfulPaint(); |
| 84 simulateLayoutAndPaint(10); | 84 simulateLayoutAndPaint(10); |
| 85 double afterLayout1 = monotonicallyIncreasingTime(); | 85 double afterLayout1 = monotonicallyIncreasingTime(); |
| 86 simulateLayoutAndPaint(1); | 86 simulateLayoutAndPaint(1); |
| 87 simulateNetworkStable(); | 87 simulateNetworkStable(); |
| 88 EXPECT_GT(paintTiming().firstMeaningfulPaint(), paintTiming().firstPaint()); | 88 EXPECT_GT(paintTiming().firstMeaningfulPaint(), paintTiming().firstPaint()); |
| 89 EXPECT_LT(paintTiming().firstMeaningfulPaint(), afterLayout1); | 89 EXPECT_LT(paintTiming().firstMeaningfulPaint(), afterLayout1); |
| 90 } | 90 } |
| 91 | 91 |
| 92 TEST_F(FirstMeaningfulPaintDetectorTest, FirstMeaningfulPaintCandidate) { | 92 TEST_F(FirstMeaningfulPaintDetectorTest, FirstMeaningfulPaintCandidate) { |
| 93 paintTiming().markFirstPaint(); | 93 paintTiming().markFirstContentfulPaint(); |
| 94 EXPECT_EQ(paintTiming().firstMeaningfulPaintCandidate(), 0.0); | 94 EXPECT_EQ(paintTiming().firstMeaningfulPaintCandidate(), 0.0); |
| 95 simulateLayoutAndPaint(1); | 95 simulateLayoutAndPaint(1); |
| 96 double afterPaint = monotonicallyIncreasingTime(); | 96 double afterPaint = monotonicallyIncreasingTime(); |
| 97 // The first candidate gets ignored. | 97 // The first candidate gets ignored. |
| 98 EXPECT_EQ(paintTiming().firstMeaningfulPaintCandidate(), 0.0); | 98 EXPECT_EQ(paintTiming().firstMeaningfulPaintCandidate(), 0.0); |
| 99 simulateLayoutAndPaint(10); | 99 simulateLayoutAndPaint(10); |
| 100 // The second candidate gets reported. | 100 // The second candidate gets reported. |
| 101 EXPECT_GT(paintTiming().firstMeaningfulPaintCandidate(), afterPaint); | 101 EXPECT_GT(paintTiming().firstMeaningfulPaintCandidate(), afterPaint); |
| 102 double candidate = paintTiming().firstMeaningfulPaintCandidate(); | 102 double candidate = paintTiming().firstMeaningfulPaintCandidate(); |
| 103 // The third candidate gets ignored since we already saw the first candidate. | 103 // The third candidate gets ignored since we already saw the first candidate. |
| 104 simulateLayoutAndPaint(10); | 104 simulateLayoutAndPaint(10); |
| 105 EXPECT_EQ(paintTiming().firstMeaningfulPaintCandidate(), candidate); | 105 EXPECT_EQ(paintTiming().firstMeaningfulPaintCandidate(), candidate); |
| 106 } | 106 } |
| 107 | 107 |
| 108 TEST_F(FirstMeaningfulPaintDetectorTest, |
| 109 NetworkStableBeforeFirstContentfulPaint) { |
| 110 paintTiming().markFirstPaint(); |
| 111 simulateLayoutAndPaint(1); |
| 112 simulateNetworkStable(); |
| 113 EXPECT_EQ(paintTiming().firstMeaningfulPaint(), 0.0); |
| 114 paintTiming().markFirstContentfulPaint(); |
| 115 simulateNetworkStable(); |
| 116 EXPECT_NE(paintTiming().firstMeaningfulPaint(), 0.0); |
| 117 } |
| 118 |
| 108 } // namespace blink | 119 } // namespace blink |
| OLD | NEW |