Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: third_party/WebKit/Source/core/paint/FirstMeaningfulPaintDetectorTest.cpp

Issue 2655123002: Revert of Added DCHECK for monotonicTimeToDOMHighResTimeStamp in PerformanceBase (Closed)
Patch Set: sync Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/timing/PerformanceBase.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
12 10
13 namespace blink { 11 namespace blink {
14 12
15 class FirstMeaningfulPaintDetectorTest : public testing::Test { 13 class FirstMeaningfulPaintDetectorTest : public testing::Test {
16 protected: 14 protected:
17 void SetUp() override { 15 void SetUp() override {
18 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); 16 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
19 s_timeElapsed = timeOrigin(); 17 s_timeElapsed = 0.0;
20 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime); 18 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime);
21 } 19 }
22 20
23 void TearDown() override { 21 void TearDown() override {
24 setTimeFunctionsForTesting(m_originalTimeFunction); 22 setTimeFunctionsForTesting(m_originalTimeFunction);
25 } 23 }
26 24
27 Document& document() { return m_dummyPageHolder->document(); } 25 Document& document() { return m_dummyPageHolder->document(); }
28 PaintTiming& paintTiming() { return PaintTiming::from(document()); } 26 PaintTiming& paintTiming() { return PaintTiming::from(document()); }
29
30 FirstMeaningfulPaintDetector& detector() { 27 FirstMeaningfulPaintDetector& detector() {
31 return paintTiming().firstMeaningfulPaintDetector(); 28 return paintTiming().firstMeaningfulPaintDetector();
32 } 29 }
33 30
34 void simulateLayoutAndPaint(int newElements) { 31 void simulateLayoutAndPaint(int newElements) {
35 StringBuilder builder; 32 StringBuilder builder;
36 for (int i = 0; i < newElements; i++) 33 for (int i = 0; i < newElements; i++)
37 builder.append("<span>a</span>"); 34 builder.append("<span>a</span>");
38 document().write(builder.toString()); 35 document().write(builder.toString());
39 document().updateStyleAndLayout(); 36 document().updateStyleAndLayout();
40 detector().notifyPaint(); 37 detector().notifyPaint();
41 } 38 }
42 39
43 void simulateNetworkStable() { detector().networkStableTimerFired(nullptr); } 40 void simulateNetworkStable() { detector().networkStableTimerFired(nullptr); }
44 41
45 private: 42 private:
46 static double returnMockTime() { 43 static double returnMockTime() {
47 s_timeElapsed += 1.0; 44 s_timeElapsed += 1.0;
48 return s_timeElapsed; 45 return s_timeElapsed;
49 } 46 }
50 47
51 double timeOrigin() {
52 Performance* performance = DOMWindowPerformance::performance(
53 *m_dummyPageHolder->frame().domWindow());
54 if (!performance)
55 return 0.0;
56 return performance->timeOrigin();
57 }
58
59 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; 48 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
60 TimeFunction m_originalTimeFunction; 49 TimeFunction m_originalTimeFunction;
61 static double s_timeElapsed; 50 static double s_timeElapsed;
62 }; 51 };
63 52
64 double FirstMeaningfulPaintDetectorTest::s_timeElapsed; 53 double FirstMeaningfulPaintDetectorTest::s_timeElapsed;
65 54
66 TEST_F(FirstMeaningfulPaintDetectorTest, NoFirstPaint) { 55 TEST_F(FirstMeaningfulPaintDetectorTest, NoFirstPaint) {
67 simulateLayoutAndPaint(1); 56 simulateLayoutAndPaint(1);
68 simulateNetworkStable(); 57 simulateNetworkStable();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 paintTiming().markFirstPaint(); 110 paintTiming().markFirstPaint();
122 simulateLayoutAndPaint(1); 111 simulateLayoutAndPaint(1);
123 simulateNetworkStable(); 112 simulateNetworkStable();
124 EXPECT_EQ(paintTiming().firstMeaningfulPaint(), 0.0); 113 EXPECT_EQ(paintTiming().firstMeaningfulPaint(), 0.0);
125 paintTiming().markFirstContentfulPaint(); 114 paintTiming().markFirstContentfulPaint();
126 simulateNetworkStable(); 115 simulateNetworkStable();
127 EXPECT_NE(paintTiming().firstMeaningfulPaint(), 0.0); 116 EXPECT_NE(paintTiming().firstMeaningfulPaint(), 0.0);
128 } 117 }
129 118
130 } // namespace blink 119 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/timing/PerformanceBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698