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

Side by Side Diff: third_party/WebKit/Source/core/layout/ImageQualityControllerTest.cpp

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 years, 6 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"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include <memory>
12 13
13 namespace blink { 14 namespace blink {
14 15
15 class ImageQualityControllerTest : public RenderingTest { 16 class ImageQualityControllerTest : public RenderingTest {
16 protected: 17 protected:
17 ImageQualityController* controller() { return m_controller; } 18 ImageQualityController* controller() { return m_controller; }
18 19
19 private: 20 private:
20 void SetUp() override 21 void SetUp() override
21 { 22 {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 }; 164 };
164 165
165 TEST_F(ImageQualityControllerTest, LowQualityFilterForResizingImage) 166 TEST_F(ImageQualityControllerTest, LowQualityFilterForResizingImage)
166 { 167 {
167 MockTimer* mockTimer = new MockTimer(controller(), &ImageQualityController:: highQualityRepaintTimerFired); 168 MockTimer* mockTimer = new MockTimer(controller(), &ImageQualityController:: highQualityRepaintTimerFired);
168 controller()->setTimer(mockTimer); 169 controller()->setTimer(mockTimer);
169 setBodyInnerHTML("<img src='myimage'></img>"); 170 setBodyInnerHTML("<img src='myimage'></img>");
170 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct()); 171 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
171 172
172 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); 173 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality);
173 OwnPtr<PaintController> paintController = PaintController::create(); 174 std::unique_ptr<PaintController> paintController = PaintController::create() ;
174 GraphicsContext context(*paintController); 175 GraphicsContext context(*paintController);
175 176
176 // Paint once. This will kick off a timer to see if we resize it during that timer's execution. 177 // Paint once. This will kick off a timer to see if we resize it during that timer's execution.
177 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), testImage.get(), LayoutSize(2, 2))); 178 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), testImage.get(), LayoutSize(2, 2)));
178 179
179 // Go into low-quality mode now that the size changed. 180 // Go into low-quality mode now that the size changed.
180 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize(3, 3))); 181 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize(3, 3)));
181 182
182 // Stay in low-quality mode since the size changed again. 183 // Stay in low-quality mode since the size changed again.
183 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize(4, 4))); 184 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize(4, 4)));
184 185
185 mockTimer->fire(); 186 mockTimer->fire();
186 // The timer fired before painting at another size, so this doesn't count as animation. Therefore not painting at low quality. 187 // The timer fired before painting at another size, so this doesn't count as animation. Therefore not painting at low quality.
187 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), testImage.get(), LayoutSize(4, 4))); 188 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), testImage.get(), LayoutSize(4, 4)));
188 } 189 }
189 190
190 TEST_F(ImageQualityControllerTest, MediumQualityFilterForNotAnimatedWhileAnother Animates) 191 TEST_F(ImageQualityControllerTest, MediumQualityFilterForNotAnimatedWhileAnother Animates)
191 { 192 {
192 MockTimer* mockTimer = new MockTimer(controller(), &ImageQualityController:: highQualityRepaintTimerFired); 193 MockTimer* mockTimer = new MockTimer(controller(), &ImageQualityController:: highQualityRepaintTimerFired);
193 controller()->setTimer(mockTimer); 194 controller()->setTimer(mockTimer);
194 setBodyInnerHTML("<img id='myAnimatingImage' src='myimage'></img> <img id='m yNonAnimatingImage' src='myimage2'></img>"); 195 setBodyInnerHTML("<img id='myAnimatingImage' src='myimage'></img> <img id='m yNonAnimatingImage' src='myimage2'></img>");
195 LayoutImage* animatingImage = toLayoutImage(document().getElementById("myAni matingImage")->layoutObject()); 196 LayoutImage* animatingImage = toLayoutImage(document().getElementById("myAni matingImage")->layoutObject());
196 LayoutImage* nonAnimatingImage = toLayoutImage(document().getElementById("my NonAnimatingImage")->layoutObject()); 197 LayoutImage* nonAnimatingImage = toLayoutImage(document().getElementById("my NonAnimatingImage")->layoutObject());
197 198
198 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); 199 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality);
199 OwnPtr<PaintController> paintController = PaintController::create(); 200 std::unique_ptr<PaintController> paintController = PaintController::create() ;
200 GraphicsContext context(*paintController); 201 GraphicsContext context(*paintController);
201 202
202 // Paint once. This will kick off a timer to see if we resize it during that timer's execution. 203 // Paint once. This will kick off a timer to see if we resize it during that timer's execution.
203 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*ani matingImage, testImage.get(), testImage.get(), LayoutSize(2, 2))); 204 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*ani matingImage, testImage.get(), testImage.get(), LayoutSize(2, 2)));
204 205
205 // Go into low-quality mode now that the size changed. 206 // Go into low-quality mode now that the size changed.
206 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*animat ingImage, testImage.get(), testImage.get(), LayoutSize(3, 3))); 207 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*animat ingImage, testImage.get(), testImage.get(), LayoutSize(3, 3)));
207 208
208 // The non-animating image receives a medium-quality filter, even though the other one is animating. 209 // The non-animating image receives a medium-quality filter, even though the other one is animating.
209 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*non AnimatingImage, testImage.get(), testImage.get(), LayoutSize(4, 4))); 210 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*non AnimatingImage, testImage.get(), testImage.get(), LayoutSize(4, 4)));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // This animation is far enough in the future to make the timer restart, sin ce it is half over. 268 // This animation is far enough in the future to make the timer restart, sin ce it is half over.
268 nextTime = 0.1 + ImageQualityController::cTimerRestartThreshold + 0.01; 269 nextTime = 0.1 + ImageQualityController::cTimerRestartThreshold + 0.01;
269 EXPECT_EQ(true, controller()->shouldPaintAtLowQuality(*img, testImage.get(), testImage.get(), LayoutSize(4, 4), nextTime)); 270 EXPECT_EQ(true, controller()->shouldPaintAtLowQuality(*img, testImage.get(), testImage.get(), LayoutSize(4, 4), nextTime));
270 // Now the timer has restarted, leading to a larger fire interval. 271 // Now the timer has restarted, leading to a larger fire interval.
271 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, mockTimer->nextF ireInterval()); 272 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, mockTimer->nextF ireInterval());
272 } 273 }
273 274
274 #endif 275 #endif
275 276
276 } // namespace blink 277 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698