OLD | NEW |
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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 std::unique_ptr<scheduler::FakeWebTaskRunner> m_taskRunner; | 166 std::unique_ptr<scheduler::FakeWebTaskRunner> m_taskRunner; |
167 | 167 |
168 DISALLOW_COPY_AND_ASSIGN(MockTimer); | 168 DISALLOW_COPY_AND_ASSIGN(MockTimer); |
169 }; | 169 }; |
170 | 170 |
171 TEST_F(ImageQualityControllerTest, LowQualityFilterForResizingImage) { | 171 TEST_F(ImageQualityControllerTest, LowQualityFilterForResizingImage) { |
172 MockTimer* mockTimer = | 172 MockTimer* mockTimer = |
173 MockTimer::create(controller(), | 173 MockTimer::create(controller(), |
174 &ImageQualityController::highQualityRepaintTimerFired) | 174 &ImageQualityController::highQualityRepaintTimerFired) |
175 .release(); | 175 .release(); |
176 controller()->setTimer(wrapUnique(mockTimer)); | 176 controller()->setTimer(WTF::wrapUnique(mockTimer)); |
177 setBodyInnerHTML("<img src='myimage'></img>"); | 177 setBodyInnerHTML("<img src='myimage'></img>"); |
178 LayoutImage* img = | 178 LayoutImage* img = |
179 toLayoutImage(document().body()->firstChild()->layoutObject()); | 179 toLayoutImage(document().body()->firstChild()->layoutObject()); |
180 | 180 |
181 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); | 181 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); |
182 std::unique_ptr<PaintController> paintController = PaintController::create(); | 182 std::unique_ptr<PaintController> paintController = PaintController::create(); |
183 GraphicsContext context(*paintController); | 183 GraphicsContext context(*paintController); |
184 | 184 |
185 // Paint once. This will kick off a timer to see if we resize it during that | 185 // Paint once. This will kick off a timer to see if we resize it during that |
186 // timer's execution. | 186 // timer's execution. |
(...skipping 18 matching lines...) Expand all Loading... |
205 controller()->chooseInterpolationQuality( | 205 controller()->chooseInterpolationQuality( |
206 *img, testImage.get(), testImage.get(), LayoutSize(4, 4))); | 206 *img, testImage.get(), testImage.get(), LayoutSize(4, 4))); |
207 } | 207 } |
208 | 208 |
209 TEST_F(ImageQualityControllerTest, | 209 TEST_F(ImageQualityControllerTest, |
210 MediumQualityFilterForNotAnimatedWhileAnotherAnimates) { | 210 MediumQualityFilterForNotAnimatedWhileAnotherAnimates) { |
211 MockTimer* mockTimer = | 211 MockTimer* mockTimer = |
212 MockTimer::create(controller(), | 212 MockTimer::create(controller(), |
213 &ImageQualityController::highQualityRepaintTimerFired) | 213 &ImageQualityController::highQualityRepaintTimerFired) |
214 .release(); | 214 .release(); |
215 controller()->setTimer(wrapUnique(mockTimer)); | 215 controller()->setTimer(WTF::wrapUnique(mockTimer)); |
216 setBodyInnerHTML( | 216 setBodyInnerHTML( |
217 "<img id='myAnimatingImage' src='myimage'></img> <img " | 217 "<img id='myAnimatingImage' src='myimage'></img> <img " |
218 "id='myNonAnimatingImage' src='myimage2'></img>"); | 218 "id='myNonAnimatingImage' src='myimage2'></img>"); |
219 LayoutImage* animatingImage = toLayoutImage( | 219 LayoutImage* animatingImage = toLayoutImage( |
220 document().getElementById("myAnimatingImage")->layoutObject()); | 220 document().getElementById("myAnimatingImage")->layoutObject()); |
221 LayoutImage* nonAnimatingImage = toLayoutImage( | 221 LayoutImage* nonAnimatingImage = toLayoutImage( |
222 document().getElementById("myNonAnimatingImage")->layoutObject()); | 222 document().getElementById("myNonAnimatingImage")->layoutObject()); |
223 | 223 |
224 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); | 224 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); |
225 std::unique_ptr<PaintController> paintController = PaintController::create(); | 225 std::unique_ptr<PaintController> paintController = PaintController::create(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 *nonAnimatingImage, testImage.get(), | 258 *nonAnimatingImage, testImage.get(), |
259 testImage.get(), LayoutSize(4, 4))); | 259 testImage.get(), LayoutSize(4, 4))); |
260 } | 260 } |
261 | 261 |
262 TEST_F(ImageQualityControllerTest, | 262 TEST_F(ImageQualityControllerTest, |
263 DontKickTheAnimationTimerWhenPaintingAtTheSameSize) { | 263 DontKickTheAnimationTimerWhenPaintingAtTheSameSize) { |
264 MockTimer* mockTimer = | 264 MockTimer* mockTimer = |
265 MockTimer::create(controller(), | 265 MockTimer::create(controller(), |
266 &ImageQualityController::highQualityRepaintTimerFired) | 266 &ImageQualityController::highQualityRepaintTimerFired) |
267 .release(); | 267 .release(); |
268 controller()->setTimer(wrapUnique(mockTimer)); | 268 controller()->setTimer(WTF::wrapUnique(mockTimer)); |
269 setBodyInnerHTML("<img src='myimage'></img>"); | 269 setBodyInnerHTML("<img src='myimage'></img>"); |
270 LayoutImage* img = | 270 LayoutImage* img = |
271 toLayoutImage(document().body()->firstChild()->layoutObject()); | 271 toLayoutImage(document().body()->firstChild()->layoutObject()); |
272 | 272 |
273 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); | 273 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); |
274 | 274 |
275 // Paint once. This will kick off a timer to see if we resize it during that | 275 // Paint once. This will kick off a timer to see if we resize it during that |
276 // timer's execution. | 276 // timer's execution. |
277 EXPECT_EQ(InterpolationMedium, | 277 EXPECT_EQ(InterpolationMedium, |
278 controller()->chooseInterpolationQuality( | 278 controller()->chooseInterpolationQuality( |
(...skipping 19 matching lines...) Expand all Loading... |
298 // Check that the timer was not kicked. It should not have been, since the | 298 // Check that the timer was not kicked. It should not have been, since the |
299 // image was painted at the same size as last time. | 299 // image was painted at the same size as last time. |
300 EXPECT_FALSE(mockTimer->isActive()); | 300 EXPECT_FALSE(mockTimer->isActive()); |
301 } | 301 } |
302 | 302 |
303 TEST_F(ImageQualityControllerTest, DontRestartTimerUnlessAdvanced) { | 303 TEST_F(ImageQualityControllerTest, DontRestartTimerUnlessAdvanced) { |
304 MockTimer* mockTimer = | 304 MockTimer* mockTimer = |
305 MockTimer::create(controller(), | 305 MockTimer::create(controller(), |
306 &ImageQualityController::highQualityRepaintTimerFired) | 306 &ImageQualityController::highQualityRepaintTimerFired) |
307 .release(); | 307 .release(); |
308 controller()->setTimer(wrapUnique(mockTimer)); | 308 controller()->setTimer(WTF::wrapUnique(mockTimer)); |
309 setBodyInnerHTML("<img src='myimage'></img>"); | 309 setBodyInnerHTML("<img src='myimage'></img>"); |
310 LayoutImage* img = | 310 LayoutImage* img = |
311 toLayoutImage(document().body()->firstChild()->layoutObject()); | 311 toLayoutImage(document().body()->firstChild()->layoutObject()); |
312 | 312 |
313 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); | 313 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); |
314 | 314 |
315 // Paint once. This will kick off a timer to see if we resize it during that | 315 // Paint once. This will kick off a timer to see if we resize it during that |
316 // timer's execution. | 316 // timer's execution. |
317 mockTimer->setTime(0.1); | 317 mockTimer->setTime(0.1); |
318 EXPECT_FALSE(controller()->shouldPaintAtLowQuality( | 318 EXPECT_FALSE(controller()->shouldPaintAtLowQuality( |
(...skipping 19 matching lines...) Expand all Loading... |
338 *img, testImage.get(), testImage.get(), LayoutSize(4, 4), | 338 *img, testImage.get(), testImage.get(), LayoutSize(4, 4), |
339 nextTime)); | 339 nextTime)); |
340 // Now the timer has restarted, leading to a larger fire interval. | 340 // Now the timer has restarted, leading to a larger fire interval. |
341 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, | 341 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, |
342 mockTimer->nextFireInterval()); | 342 mockTimer->nextFireInterval()); |
343 } | 343 } |
344 | 344 |
345 #endif | 345 #endif |
346 | 346 |
347 } // namespace blink | 347 } // namespace blink |
OLD | NEW |