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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/layout/ImageQualityController.h" 5 #include "core/layout/ImageQualityController.h"
6 6
7 #include "core/layout/LayoutImage.h" 7 #include "core/layout/LayoutImage.h"
8 #include "core/layout/LayoutTestHelper.h" 8 #include "core/layout/LayoutTestHelper.h"
9 #include "platform/graphics/GraphicsContext.h" 9 #include "platform/graphics/GraphicsContext.h"
10 #include "platform/graphics/paint/PaintController.h" 10 #include "platform/graphics/paint/PaintController.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); 106 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality);
107 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), testImage.get(), LayoutSize(1, 1))); 107 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), testImage.get(), LayoutSize(1, 1)));
108 } 108 }
109 109
110 class MockTimer : public Timer<ImageQualityController> { 110 class MockTimer : public Timer<ImageQualityController> {
111 typedef void (ImageQualityController::*TimerFiredFunction)(Timer*); 111 typedef void (ImageQualityController::*TimerFiredFunction)(Timer*);
112 public: 112 public:
113 MockTimer(ImageQualityController* o, TimerFiredFunction f) 113 MockTimer(ImageQualityController* o, TimerFiredFunction f)
114 : Timer<ImageQualityController>(o, f) 114 : Timer<ImageQualityController>(o, f)
115 , started(false)
Xianzhu 2016/04/22 19:39:17 Nit: Indent 4 more spaces.
115 { 116 {
116 } 117 }
117 118
118 void fire() 119 void fire()
119 { 120 {
120 this->Timer<ImageQualityController>::fired(); 121 this->Timer<ImageQualityController>::fired();
121 stop(); 122 stop();
122 } 123 }
124
125 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.
126 {
127 Timer<ImageQualityController>::startOneShot(interval, caller);
128 started = true;
129 }
130
131 bool started;
123 }; 132 };
124 133
125 TEST_F(ImageQualityControllerTest, LowQualityFilterForResizingImage) 134 TEST_F(ImageQualityControllerTest, LowQualityFilterForResizingImage)
126 { 135 {
127 MockTimer* mockTimer = new MockTimer(controller(), &ImageQualityController:: highQualityRepaintTimerFired); 136 MockTimer* mockTimer = new MockTimer(controller(), &ImageQualityController:: highQualityRepaintTimerFired);
128 controller()->setTimer(mockTimer); 137 controller()->setTimer(mockTimer);
129 setBodyInnerHTML("<img src='myimage'></img>"); 138 setBodyInnerHTML("<img src='myimage'></img>");
130 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct()); 139 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
131 140
132 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); 141 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize(4, 4))); 205 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize(4, 4)));
197 206
198 mockTimer->stop(); 207 mockTimer->stop();
199 EXPECT_FALSE(mockTimer->isActive()); 208 EXPECT_FALSE(mockTimer->isActive());
200 // Painted at the same size, so even though timer is still executing, don't go to low quality. 209 // Painted at the same size, so even though timer is still executing, don't go to low quality.
201 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize(4, 4))); 210 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize(4, 4)));
202 // Check that the timer was not kicked. It should not have been, since the i mage was painted at the same size as last time. 211 // Check that the timer was not kicked. It should not have been, since the i mage was painted at the same size as last time.
203 EXPECT_FALSE(mockTimer->isActive()); 212 EXPECT_FALSE(mockTimer->isActive());
204 } 213 }
205 214
215 TEST_F(ImageQualityControllerTest, DontRestartTimerUnlessAdvanced)
216 {
217 MockTimer* mockTimer = new MockTimer(controller(), &ImageQualityController:: highQualityRepaintTimerFired);
218 controller()->setTimer(mockTimer);
219 setBodyInnerHTML("<img src='myimage'></img>");
220 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
221
222 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality);
223
224 // Paint once. This will kick off a timer to see if we resize it during that timer's execution.
225 EXPECT_FALSE(mockTimer->started);
226
227 EXPECT_EQ(false, controller()->shouldPaintAtLowQuality(*img, testImage.get() , testImage.get(), LayoutSize(2, 2), 0.1));
228 EXPECT_TRUE(mockTimer->started);
229
230 // Go into low-quality mode now that the size changed.
231 mockTimer->started = false;
232 EXPECT_EQ(true, controller()->shouldPaintAtLowQuality(*img, testImage.get(), testImage.get(), LayoutSize(3, 3), 0.1 + ImageQualityController::cTimerRestartT hreshold / 2.0));
233 EXPECT_FALSE(mockTimer->started);
234
235 // This animation is far enough in the future to make the timer restart, sin ce it is half over.
236 EXPECT_EQ(true, controller()->shouldPaintAtLowQuality(*img, testImage.get(), testImage.get(), LayoutSize(4, 4), 0.1 + ImageQualityController::cTimerRestartT hreshold + 0.01));
237 EXPECT_TRUE(mockTimer->started);
238 }
239
206 #endif 240 #endif
207 241
208 } // namespace blink 242 } // namespace blink
OLDNEW
« 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