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

Unified Diff: third_party/WebKit/Source/core/layout/ImageQualityControllerTest.cpp

Issue 1911273002: Don't restart the ImageQualityController timer unless it is already half over. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/ImageQualityControllerTest.cpp
diff --git a/third_party/WebKit/Source/core/layout/ImageQualityControllerTest.cpp b/third_party/WebKit/Source/core/layout/ImageQualityControllerTest.cpp
index c9e585a53181716764b22aa3db8880a33067883f..a54ba3c47ced2536b32918117a09561eb4122361 100644
--- a/third_party/WebKit/Source/core/layout/ImageQualityControllerTest.cpp
+++ b/third_party/WebKit/Source/core/layout/ImageQualityControllerTest.cpp
@@ -112,6 +112,7 @@ class MockTimer : public Timer<ImageQualityController> {
public:
MockTimer(ImageQualityController* o, TimerFiredFunction f)
: Timer<ImageQualityController>(o, f)
+ , started(false)
Xianzhu 2016/04/22 19:39:17 Nit: Indent 4 more spaces.
{
}
@@ -120,6 +121,14 @@ public:
this->Timer<ImageQualityController>::fired();
stop();
}
+
+ void startOneShot(double interval, const WebTraceLocation& caller) override
Xianzhu 2016/04/22 18:14:59 Can you use Timer::isActive() and Timer::cancel()
chrishtr 2016/04/22 18:30:35 I'm not sure how to do that. Are you suggesting ca
Xianzhu 2016/04/22 19:39:17 I see Timer::cancel() would affect what we want to
Xianzhu 2016/04/22 19:49:51 Just noticed that you would have to mock the time.
+ {
+ Timer<ImageQualityController>::startOneShot(interval, caller);
+ started = true;
+ }
+
+ bool started;
};
TEST_F(ImageQualityControllerTest, LowQualityFilterForResizingImage)
@@ -203,6 +212,31 @@ TEST_F(ImageQualityControllerTest, DontKickTheAnimationTimerWhenPaintingAtTheSam
EXPECT_FALSE(mockTimer->isActive());
}
+TEST_F(ImageQualityControllerTest, DontRestartTimerUnlessAdvanced)
+{
+ MockTimer* mockTimer = new MockTimer(controller(), &ImageQualityController::highQualityRepaintTimerFired);
+ controller()->setTimer(mockTimer);
+ setBodyInnerHTML("<img src='myimage'></img>");
+ LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObject());
+
+ RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality);
+
+ // Paint once. This will kick off a timer to see if we resize it during that timer's execution.
+ EXPECT_FALSE(mockTimer->started);
+
+ EXPECT_EQ(false, controller()->shouldPaintAtLowQuality(*img, testImage.get(), testImage.get(), LayoutSize(2, 2), 0.1));
+ EXPECT_TRUE(mockTimer->started);
+
+ // Go into low-quality mode now that the size changed.
+ mockTimer->started = false;
+ EXPECT_EQ(true, controller()->shouldPaintAtLowQuality(*img, testImage.get(), testImage.get(), LayoutSize(3, 3), 0.1 + ImageQualityController::cTimerRestartThreshold / 2.0));
+ EXPECT_FALSE(mockTimer->started);
+
+ // This animation is far enough in the future to make the timer restart, since it is half over.
+ EXPECT_EQ(true, controller()->shouldPaintAtLowQuality(*img, testImage.get(), testImage.get(), LayoutSize(4, 4), 0.1 + ImageQualityController::cTimerRestartThreshold + 0.01));
+ EXPECT_TRUE(mockTimer->started);
+}
+
#endif
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/layout/ImageQualityController.cpp ('k') | third_party/WebKit/Source/core/page/ChromeClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698