diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 10:22:43 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 12:36:28 +0000 |
commit | 271a6c3487a14599023a9106329505597638d793 (patch) | |
tree | e040d58ffc86c1480b79ca8528020ca9ec919bf8 /chromium/third_party/blink/renderer/core/paint/first_meaningful_paint_detector_test.cc | |
parent | 7b2ffa587235a47d4094787d72f38102089f402a (diff) | |
download | qtwebengine-chromium-271a6c3487a14599023a9106329505597638d793.tar.gz |
BASELINE: Update Chromium to 77.0.3865.59
Change-Id: I1e89a5f3b009a9519a6705102ad65c92fe736f21
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/core/paint/first_meaningful_paint_detector_test.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/core/paint/first_meaningful_paint_detector_test.cc | 174 |
1 files changed, 67 insertions, 107 deletions
diff --git a/chromium/third_party/blink/renderer/core/paint/first_meaningful_paint_detector_test.cc b/chromium/third_party/blink/renderer/core/paint/first_meaningful_paint_detector_test.cc index aa4923c6a28..19483295968 100644 --- a/chromium/third_party/blink/renderer/core/paint/first_meaningful_paint_detector_test.cc +++ b/chromium/third_party/blink/renderer/core/paint/first_meaningful_paint_detector_test.cc @@ -9,7 +9,6 @@ #include "third_party/blink/renderer/core/paint/paint_event.h" #include "third_party/blink/renderer/core/paint/paint_timing.h" #include "third_party/blink/renderer/core/testing/page_test_base.h" -#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/time.h" @@ -18,13 +17,27 @@ namespace blink { class FirstMeaningfulPaintDetectorTest : public PageTestBase { protected: void SetUp() override { - platform_->AdvanceClock(TimeDelta::FromSeconds(1)); + EnablePlatform(); + platform()->AdvanceClock(base::TimeDelta::FromSeconds(1)); + const base::TickClock* test_clock = + platform()->test_task_runner()->GetMockTickClock(); + FirstMeaningfulPaintDetector::SetTickClockForTesting(test_clock); PageTestBase::SetUp(); + GetPaintTiming().SetTickClockForTesting(test_clock); } - TimeTicks AdvanceClockAndGetTime() { - platform_->AdvanceClock(TimeDelta::FromSeconds(1)); - return CurrentTimeTicks(); + void TearDown() override { + const base::TickClock* clock = base::DefaultTickClock::GetInstance(); + GetPaintTiming().SetTickClockForTesting(clock); + PageTestBase::TearDown(); + FirstMeaningfulPaintDetector::SetTickClockForTesting(clock); + } + + base::TimeTicks Now() { return platform()->test_task_runner()->NowTicks(); } + + base::TimeTicks AdvanceClockAndGetTime() { + platform()->AdvanceClock(base::TimeDelta::FromSeconds(1)); + return Now(); } PaintTiming& GetPaintTiming() { return PaintTiming::From(GetDocument()); } @@ -33,7 +46,7 @@ class FirstMeaningfulPaintDetectorTest : public PageTestBase { } void SimulateLayoutAndPaint(int new_elements) { - platform_->AdvanceClock(TimeDelta::FromMilliseconds(1)); + platform()->AdvanceClock(base::TimeDelta::FromMilliseconds(1)); StringBuilder builder; for (int i = 0; i < new_elements; i++) builder.Append("<span>a</span>"); @@ -44,39 +57,27 @@ class FirstMeaningfulPaintDetectorTest : public PageTestBase { void SimulateNetworkStable() { GetDocument().SetParsingState(Document::kFinishedParsing); - Detector().OnNetwork0Quiet(); - Detector().OnNetwork2Quiet(); - } - - void SimulateNetwork0Quiet() { - GetDocument().SetParsingState(Document::kFinishedParsing); - Detector().OnNetwork0Quiet(); - } - - void SimulateNetwork2Quiet() { - GetDocument().SetParsingState(Document::kFinishedParsing); Detector().OnNetwork2Quiet(); } void SimulateUserInput() { Detector().NotifyInputEvent(); } void ClearFirstPaintSwapPromise() { - platform_->AdvanceClock(TimeDelta::FromMilliseconds(1)); - GetPaintTiming().ReportSwapTime(PaintEvent::kFirstPaint, - WebWidgetClient::SwapResult::kDidSwap, - CurrentTimeTicks()); + platform()->AdvanceClock(base::TimeDelta::FromMilliseconds(1)); + GetPaintTiming().ReportSwapTime( + PaintEvent::kFirstPaint, WebWidgetClient::SwapResult::kDidSwap, Now()); } void ClearFirstContentfulPaintSwapPromise() { - platform_->AdvanceClock(TimeDelta::FromMilliseconds(1)); + platform()->AdvanceClock(base::TimeDelta::FromMilliseconds(1)); GetPaintTiming().ReportSwapTime(PaintEvent::kFirstContentfulPaint, WebWidgetClient::SwapResult::kDidSwap, - CurrentTimeTicks()); + Now()); } void ClearProvisionalFirstMeaningfulPaintSwapPromise() { - platform_->AdvanceClock(TimeDelta::FromMilliseconds(1)); - ClearProvisionalFirstMeaningfulPaintSwapPromise(CurrentTimeTicks()); + platform()->AdvanceClock(base::TimeDelta::FromMilliseconds(1)); + ClearProvisionalFirstMeaningfulPaintSwapPromise(Now()); } void ClearProvisionalFirstMeaningfulPaintSwapPromise( @@ -98,17 +99,13 @@ class FirstMeaningfulPaintDetectorTest : public PageTestBase { GetPaintTiming().MarkFirstPaint(); ClearFirstPaintSwapPromise(); } - - protected: - ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> - platform_; }; TEST_F(FirstMeaningfulPaintDetectorTest, NoFirstPaint) { SimulateLayoutAndPaint(1); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 0U); SimulateNetworkStable(); - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); } TEST_F(FirstMeaningfulPaintDetectorTest, OneLayout) { @@ -116,8 +113,8 @@ TEST_F(FirstMeaningfulPaintDetectorTest, OneLayout) { SimulateLayoutAndPaint(1); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); - TimeTicks after_paint = AdvanceClockAndGetTime(); - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + base::TimeTicks after_paint = AdvanceClockAndGetTime(); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); SimulateNetworkStable(); EXPECT_LT(GetPaintTiming().FirstMeaningfulPaint(), after_paint); } @@ -127,11 +124,11 @@ TEST_F(FirstMeaningfulPaintDetectorTest, TwoLayoutsSignificantSecond) { SimulateLayoutAndPaint(1); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); - TimeTicks after_layout1 = AdvanceClockAndGetTime(); + base::TimeTicks after_layout1 = AdvanceClockAndGetTime(); SimulateLayoutAndPaint(10); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); - TimeTicks after_layout2 = AdvanceClockAndGetTime(); + base::TimeTicks after_layout2 = AdvanceClockAndGetTime(); SimulateNetworkStable(); EXPECT_GT(GetPaintTiming().FirstMeaningfulPaint(), after_layout1); EXPECT_LT(GetPaintTiming().FirstMeaningfulPaint(), after_layout2); @@ -142,7 +139,7 @@ TEST_F(FirstMeaningfulPaintDetectorTest, TwoLayoutsSignificantFirst) { SimulateLayoutAndPaint(10); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); - TimeTicks after_layout1 = AdvanceClockAndGetTime(); + base::TimeTicks after_layout1 = AdvanceClockAndGetTime(); SimulateLayoutAndPaint(1); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 0U); SimulateNetworkStable(); @@ -153,19 +150,21 @@ TEST_F(FirstMeaningfulPaintDetectorTest, TwoLayoutsSignificantFirst) { TEST_F(FirstMeaningfulPaintDetectorTest, FirstMeaningfulPaintCandidate) { MarkFirstContentfulPaintAndClearSwapPromise(); - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaintCandidate(), TimeTicks()); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaintCandidate(), + base::TimeTicks()); SimulateLayoutAndPaint(1); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); - TimeTicks after_paint = AdvanceClockAndGetTime(); + base::TimeTicks after_paint = AdvanceClockAndGetTime(); // The first candidate gets ignored. - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaintCandidate(), TimeTicks()); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaintCandidate(), + base::TimeTicks()); SimulateLayoutAndPaint(10); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); // The second candidate gets reported. EXPECT_GT(GetPaintTiming().FirstMeaningfulPaintCandidate(), after_paint); - TimeTicks candidate = GetPaintTiming().FirstMeaningfulPaintCandidate(); + base::TimeTicks candidate = GetPaintTiming().FirstMeaningfulPaintCandidate(); // The third candidate gets ignored since we already saw the first candidate. SimulateLayoutAndPaint(20); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); @@ -176,17 +175,19 @@ TEST_F(FirstMeaningfulPaintDetectorTest, FirstMeaningfulPaintCandidate) { TEST_F(FirstMeaningfulPaintDetectorTest, OnlyOneFirstMeaningfulPaintCandidateBeforeNetworkStable) { MarkFirstContentfulPaintAndClearSwapPromise(); - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaintCandidate(), TimeTicks()); - TimeTicks before_paint = AdvanceClockAndGetTime(); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaintCandidate(), + base::TimeTicks()); + base::TimeTicks before_paint = AdvanceClockAndGetTime(); SimulateLayoutAndPaint(1); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); // The first candidate is initially ignored. - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaintCandidate(), TimeTicks()); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaintCandidate(), + base::TimeTicks()); SimulateNetworkStable(); // The networkStable then promotes the first candidate. EXPECT_GT(GetPaintTiming().FirstMeaningfulPaintCandidate(), before_paint); - TimeTicks candidate = GetPaintTiming().FirstMeaningfulPaintCandidate(); + base::TimeTicks candidate = GetPaintTiming().FirstMeaningfulPaintCandidate(); // The second candidate is then ignored. SimulateLayoutAndPaint(10); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 0U); @@ -200,10 +201,10 @@ TEST_F(FirstMeaningfulPaintDetectorTest, EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); SimulateNetworkStable(); - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); MarkFirstContentfulPaintAndClearSwapPromise(); SimulateNetworkStable(); - EXPECT_NE(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_NE(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); } TEST_F(FirstMeaningfulPaintDetectorTest, @@ -212,53 +213,13 @@ TEST_F(FirstMeaningfulPaintDetectorTest, SimulateLayoutAndPaint(10); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); - platform_->AdvanceClock(TimeDelta::FromMilliseconds(1)); + platform()->AdvanceClock(base::TimeDelta::FromMilliseconds(1)); MarkFirstContentfulPaintAndClearSwapPromise(); SimulateNetworkStable(); EXPECT_GE(GetPaintTiming().FirstMeaningfulPaint(), GetPaintTiming().FirstContentfulPaint()); } -TEST_F(FirstMeaningfulPaintDetectorTest, Network2QuietThen0Quiet) { - MarkFirstContentfulPaintAndClearSwapPromise(); - - SimulateLayoutAndPaint(1); - EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); - TimeTicks after_first_paint = AdvanceClockAndGetTime(); - ClearProvisionalFirstMeaningfulPaintSwapPromise(); - TimeTicks after_first_paint_swap = AdvanceClockAndGetTime(); - SimulateNetwork2Quiet(); - - SimulateLayoutAndPaint(10); - EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 0U); - SimulateNetwork0Quiet(); - - // The first paint is FirstMeaningfulPaint. - EXPECT_GT(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); - EXPECT_GT(GetPaintTiming().FirstMeaningfulPaint(), after_first_paint); - EXPECT_LT(GetPaintTiming().FirstMeaningfulPaint(), after_first_paint_swap); -} - -TEST_F(FirstMeaningfulPaintDetectorTest, Network0QuietThen2Quiet) { - MarkFirstContentfulPaintAndClearSwapPromise(); - - SimulateLayoutAndPaint(1); - EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); - ClearProvisionalFirstMeaningfulPaintSwapPromise(); - TimeTicks after_first_paint = AdvanceClockAndGetTime(); - SimulateNetwork0Quiet(); - - SimulateLayoutAndPaint(10); - EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); - ClearProvisionalFirstMeaningfulPaintSwapPromise(); - TimeTicks after_second_paint = AdvanceClockAndGetTime(); - SimulateNetwork2Quiet(); - - // The second paint is FirstMeaningfulPaint. - EXPECT_GT(GetPaintTiming().FirstMeaningfulPaint(), after_first_paint); - EXPECT_LT(GetPaintTiming().FirstMeaningfulPaint(), after_second_paint); -} - TEST_F(FirstMeaningfulPaintDetectorTest, FirstMeaningfulPaintAfterUserInteraction) { MarkFirstContentfulPaintAndClearSwapPromise(); @@ -267,7 +228,7 @@ TEST_F(FirstMeaningfulPaintDetectorTest, EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); SimulateNetworkStable(); - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); } TEST_F(FirstMeaningfulPaintDetectorTest, UserInteractionBeforeFirstPaint) { @@ -277,7 +238,7 @@ TEST_F(FirstMeaningfulPaintDetectorTest, UserInteractionBeforeFirstPaint) { EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); SimulateNetworkStable(); - EXPECT_NE(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_NE(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); } TEST_F(FirstMeaningfulPaintDetectorTest, @@ -286,9 +247,9 @@ TEST_F(FirstMeaningfulPaintDetectorTest, SimulateLayoutAndPaint(10); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); SimulateNetworkStable(); - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); ClearProvisionalFirstMeaningfulPaintSwapPromise(); - EXPECT_NE(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_NE(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); } TEST_F(FirstMeaningfulPaintDetectorTest, @@ -296,21 +257,21 @@ TEST_F(FirstMeaningfulPaintDetectorTest, MarkFirstContentfulPaintAndClearSwapPromise(); SimulateLayoutAndPaint(1); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); - platform_->AdvanceClock(TimeDelta::FromMilliseconds(1)); + platform()->AdvanceClock(base::TimeDelta::FromMilliseconds(1)); SimulateLayoutAndPaint(10); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 2U); // Having outstanding swap promises should defer setting FMP. SimulateNetworkStable(); - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); // Clearing the first swap promise should have no effect on FMP. ClearProvisionalFirstMeaningfulPaintSwapPromise(); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); - TimeTicks after_first_swap = AdvanceClockAndGetTime(); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); + base::TimeTicks after_first_swap = AdvanceClockAndGetTime(); // Clearing the last outstanding swap promise should set FMP. ClearProvisionalFirstMeaningfulPaintSwapPromise(); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 0U); - EXPECT_GT(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_GT(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); EXPECT_GT(GetPaintTiming().FirstMeaningfulPaint(), after_first_swap); } @@ -320,14 +281,14 @@ TEST_F(FirstMeaningfulPaintDetectorTest, SimulateLayoutAndPaint(10); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); ClearProvisionalFirstMeaningfulPaintSwapPromise(); - platform_->AdvanceClock(TimeDelta::FromMilliseconds(1)); + platform()->AdvanceClock(base::TimeDelta::FromMilliseconds(1)); GetPaintTiming().MarkFirstContentfulPaint(); // FCP > FMP candidate, but still waiting for FCP swap. SimulateNetworkStable(); - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); // Trigger notifying the detector about the FCP swap. ClearFirstContentfulPaintSwapPromise(); - EXPECT_GT(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_GT(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), GetPaintTiming().FirstContentfulPaint()); } @@ -338,16 +299,15 @@ TEST_F(FirstMeaningfulPaintDetectorTest, SimulateLayoutAndPaint(1); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); - // Simulate only network 2-quiet so provisional FMP will be set on next - // layout. - TimeTicks pre_stable_timestamp = AdvanceClockAndGetTime(); - platform_->AdvanceClock(TimeDelta::FromMilliseconds(1)); - SimulateNetwork2Quiet(); - EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + // Simulate network stable so provisional FMP will be set on next layout. + base::TimeTicks pre_stable_timestamp = AdvanceClockAndGetTime(); + platform()->AdvanceClock(base::TimeDelta::FromMilliseconds(1)); + SimulateNetworkStable(); + EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); // Force another FMP candidate while there is a pending swap promise and the - // network 2-quiet FMP non-swap timestamp is set. - platform_->AdvanceClock(TimeDelta::FromMilliseconds(1)); + // FMP non-swap timestamp is set. + platform()->AdvanceClock(base::TimeDelta::FromMilliseconds(1)); SimulateLayoutAndPaint(10); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 1U); @@ -356,7 +316,7 @@ TEST_F(FirstMeaningfulPaintDetectorTest, // non-swap timestamp is used. ClearProvisionalFirstMeaningfulPaintSwapPromise(pre_stable_timestamp); EXPECT_EQ(OutstandingDetectorSwapPromiseCount(), 0U); - EXPECT_GT(GetPaintTiming().FirstMeaningfulPaint(), TimeTicks()); + EXPECT_GT(GetPaintTiming().FirstMeaningfulPaint(), base::TimeTicks()); EXPECT_EQ(GetPaintTiming().FirstMeaningfulPaint(), pre_stable_timestamp); } |