| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 { | 115 { |
| 116 } | 116 } |
| 117 | 117 |
| 118 void fire() | 118 void fire() |
| 119 { | 119 { |
| 120 this->Timer<ImageQualityController>::fired(); | 120 this->Timer<ImageQualityController>::fired(); |
| 121 stop(); | 121 stop(); |
| 122 } | 122 } |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 TEST_F(ImageQualityControllerTest, LowQualityFilterForLiveResize) | |
| 126 { | |
| 127 MockTimer* mockTimer = new MockTimer(controller(), &ImageQualityController::
highQualityRepaintTimerFired); | |
| 128 controller()->setTimer(mockTimer); | |
| 129 setBodyInnerHTML("<img src='myimage'></img>"); | |
| 130 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje
ct()); | |
| 131 | |
| 132 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); | |
| 133 | |
| 134 // Start a resize | |
| 135 document().frame()->view()->willStartLiveResize(); | |
| 136 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t
estImage.get(), testImage.get(), LayoutSize(2, 2))); | |
| 137 | |
| 138 document().frame()->view()->willEndLiveResize(); | |
| 139 | |
| 140 // End of live resize, but timer has not fired. Therefore paint at non-low q
uality. | |
| 141 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img
, testImage.get(), testImage.get(), LayoutSize(3, 3))); | |
| 142 | |
| 143 // Start another resize | |
| 144 document().frame()->view()->willStartLiveResize(); | |
| 145 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t
estImage.get(), testImage.get(), LayoutSize(3, 3))); | |
| 146 | |
| 147 // While still in resize, expire the timer. | |
| 148 document().frame()->view()->willEndLiveResize(); | |
| 149 | |
| 150 mockTimer->fire(); | |
| 151 // End of live resize, and timer has fired. Therefore paint at non-low quali
ty, even though the size has changed. | |
| 152 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img
, testImage.get(), testImage.get(), LayoutSize(4, 4))); | |
| 153 } | |
| 154 | |
| 155 TEST_F(ImageQualityControllerTest, LowQualityFilterForResizingImage) | 125 TEST_F(ImageQualityControllerTest, LowQualityFilterForResizingImage) |
| 156 { | 126 { |
| 157 MockTimer* mockTimer = new MockTimer(controller(), &ImageQualityController::
highQualityRepaintTimerFired); | 127 MockTimer* mockTimer = new MockTimer(controller(), &ImageQualityController::
highQualityRepaintTimerFired); |
| 158 controller()->setTimer(mockTimer); | 128 controller()->setTimer(mockTimer); |
| 159 setBodyInnerHTML("<img src='myimage'></img>"); | 129 setBodyInnerHTML("<img src='myimage'></img>"); |
| 160 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje
ct()); | 130 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje
ct()); |
| 161 | 131 |
| 162 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); | 132 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); |
| 163 OwnPtr<PaintController> paintController = PaintController::create(); | 133 OwnPtr<PaintController> paintController = PaintController::create(); |
| 164 GraphicsContext context(*paintController); | 134 GraphicsContext context(*paintController); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 EXPECT_FALSE(mockTimer->isActive()); | 199 EXPECT_FALSE(mockTimer->isActive()); |
| 230 // Painted at the same size, so even though timer is still executing, don't
go to low quality. | 200 // Painted at the same size, so even though timer is still executing, don't
go to low quality. |
| 231 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t
estImage.get(), testImage.get(), LayoutSize(4, 4))); | 201 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t
estImage.get(), testImage.get(), LayoutSize(4, 4))); |
| 232 // 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. | 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. |
| 233 EXPECT_FALSE(mockTimer->isActive()); | 203 EXPECT_FALSE(mockTimer->isActive()); |
| 234 } | 204 } |
| 235 | 205 |
| 236 #endif | 206 #endif |
| 237 | 207 |
| 238 } // namespace blink | 208 } // namespace blink |
| OLD | NEW |