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

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

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

Powered by Google App Engine
This is Rietveld 408576698