OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 void didDraw(const Image*) override { } | 59 void didDraw(const Image*) override { } |
60 bool shouldPauseAnimation(const Image*) override { return false; } | 60 bool shouldPauseAnimation(const Image*) override { return false; } |
61 void animationAdvanced(const Image*) override { } | 61 void animationAdvanced(const Image*) override { } |
62 | 62 |
63 virtual void changedInRect(const Image*, const IntRect&) { } | 63 virtual void changedInRect(const Image*, const IntRect&) { } |
64 | 64 |
65 size_t m_lastDecodedSize; | 65 size_t m_lastDecodedSize; |
66 int m_lastDecodedSizeChangedDelta; | 66 int m_lastDecodedSizeChangedDelta; |
67 }; | 67 }; |
68 | 68 |
69 BitmapImageTest() : BitmapImageTest(false) { } | |
70 BitmapImageTest(bool enableDeferredDecoding) : m_enableDeferredDecoding(enab leDeferredDecoding) { } | |
71 | |
72 static PassRefPtr<SharedBuffer> readFile(const char* fileName) | 69 static PassRefPtr<SharedBuffer> readFile(const char* fileName) |
73 { | 70 { |
74 String filePath = testing::blinkRootDir(); | 71 String filePath = testing::blinkRootDir(); |
75 filePath.append(fileName); | 72 filePath.append(fileName); |
76 return testing::readFromFile(filePath); | 73 return testing::readFromFile(filePath); |
77 } | 74 } |
78 | 75 |
79 // Accessors to BitmapImage's protected methods. | 76 // Accessors to BitmapImage's protected methods. |
80 void destroyDecodedData() { m_image->destroyDecodedData(); } | 77 void destroyDecodedData() { m_image->destroyDecodedData(); } |
81 size_t frameCount() { return m_image->frameCount(); } | 78 size_t frameCount() { return m_image->frameCount(); } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 } | 136 } |
140 | 137 |
141 int lastDecodedSizeChange() | 138 int lastDecodedSizeChange() |
142 { | 139 { |
143 return m_imageObserver->m_lastDecodedSizeChangedDelta; | 140 return m_imageObserver->m_lastDecodedSizeChangedDelta; |
144 } | 141 } |
145 | 142 |
146 protected: | 143 protected: |
147 void SetUp() override | 144 void SetUp() override |
148 { | 145 { |
149 DeferredImageDecoder::setEnabled(m_enableDeferredDecoding); | |
150 m_imageObserver = new FakeImageObserver; | 146 m_imageObserver = new FakeImageObserver; |
151 m_image = BitmapImage::create(m_imageObserver.get()); | 147 m_image = BitmapImage::create(m_imageObserver.get()); |
152 } | 148 } |
153 | 149 |
154 Persistent<FakeImageObserver> m_imageObserver; | 150 Persistent<FakeImageObserver> m_imageObserver; |
155 RefPtr<BitmapImage> m_image; | 151 RefPtr<BitmapImage> m_image; |
156 | |
157 private: | |
158 bool m_enableDeferredDecoding; | |
159 }; | 152 }; |
160 | 153 |
161 TEST_F(BitmapImageTest, destroyDecodedData) | 154 TEST_F(BitmapImageTest, destroyDecodedData) |
162 { | 155 { |
163 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); | 156 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); |
164 size_t totalSize = decodedSize(); | 157 size_t totalSize = decodedSize(); |
165 EXPECT_GT(totalSize, 0u); | 158 EXPECT_GT(totalSize, 0u); |
166 destroyDecodedData(); | 159 destroyDecodedData(); |
167 EXPECT_EQ(-static_cast<int>(totalSize), lastDecodedSizeChange()); | 160 EXPECT_EQ(-static_cast<int>(totalSize), lastDecodedSizeChange()); |
168 EXPECT_EQ(0u, decodedSize()); | 161 EXPECT_EQ(0u, decodedSize()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 | 246 |
254 TEST_F(BitmapImageTest, icoHasWrongFrameDimensions) | 247 TEST_F(BitmapImageTest, icoHasWrongFrameDimensions) |
255 { | 248 { |
256 loadImage("/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico"); | 249 loadImage("/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico"); |
257 // This call would cause crash without fix for 408026 | 250 // This call would cause crash without fix for 408026 |
258 imageForDefaultFrame(); | 251 imageForDefaultFrame(); |
259 } | 252 } |
260 | 253 |
261 TEST_F(BitmapImageTest, correctDecodedDataSize) | 254 TEST_F(BitmapImageTest, correctDecodedDataSize) |
262 { | 255 { |
263 // When requesting a frame of a multi-frame GIF causes another frame to be | 256 // Requesting any one frame shouldn't result in decoding any other frames. |
264 // decoded as well, both frames' sizes should be reported by the source and | |
265 // thus included in the decoded size changed notification. | |
266 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); | 257 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); |
267 frameAtIndex(1); | 258 frameAtIndex(1); |
268 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame: :PixelData)); | 259 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame: :PixelData)); |
269 EXPECT_EQ(frameSize * 2, lastDecodedSizeChange()); | 260 EXPECT_EQ(frameSize, lastDecodedSizeChange()); |
chrishtr
2016/06/08 20:02:12
Why did this change?
hajimehoshi
2016/06/09 04:02:38
It's because the original test assumed that Deferr
| |
270 } | 261 } |
271 | 262 |
272 TEST_F(BitmapImageTest, recachingFrameAfterDataChanged) | 263 TEST_F(BitmapImageTest, recachingFrameAfterDataChanged) |
273 { | 264 { |
274 loadImage("/LayoutTests/fast/images/resources/green.jpg"); | 265 loadImage("/LayoutTests/fast/images/resources/green.jpg"); |
275 setFirstFrameNotComplete(); | 266 setFirstFrameNotComplete(); |
276 EXPECT_GT(lastDecodedSizeChange(), 0); | 267 EXPECT_GT(lastDecodedSizeChange(), 0); |
277 m_imageObserver->m_lastDecodedSizeChangedDelta = 0; | 268 m_imageObserver->m_lastDecodedSizeChangedDelta = 0; |
278 | 269 |
279 // Calling dataChanged causes the cache to flush, but doesn't affect the | 270 // Calling dataChanged causes the cache to flush, but doesn't affect the |
280 // source's decoded frames. It shouldn't affect decoded size. | 271 // source's decoded frames. It shouldn't affect decoded size. |
281 m_image->dataChanged(true); | 272 m_image->dataChanged(true); |
282 EXPECT_EQ(0, lastDecodedSizeChange()); | 273 EXPECT_EQ(0, lastDecodedSizeChange()); |
283 // Recaching the first frame also shouldn't affect decoded size. | 274 // Recaching the first frame also shouldn't affect decoded size. |
284 m_image->imageForCurrentFrame(); | 275 m_image->imageForCurrentFrame(); |
285 EXPECT_EQ(0, lastDecodedSizeChange()); | 276 EXPECT_EQ(0, lastDecodedSizeChange()); |
286 } | 277 } |
287 | 278 |
288 class BitmapImageDeferredDecodingTest : public BitmapImageTest { | |
289 public: | |
290 BitmapImageDeferredDecodingTest() : BitmapImageTest(true) { } | |
291 }; | |
292 | |
293 TEST_F(BitmapImageDeferredDecodingTest, correctDecodedDataSize) | |
294 { | |
295 // When deferred decoding is enabled, requesting any one frame shouldn't | |
296 // result in decoding any other frames. | |
297 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); | |
298 frameAtIndex(1); | |
299 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame: :PixelData)); | |
300 EXPECT_EQ(frameSize, lastDecodedSizeChange()); | |
301 } | |
302 | |
303 template <typename HistogramEnumType> | 279 template <typename HistogramEnumType> |
304 struct HistogramTestParams { | 280 struct HistogramTestParams { |
305 const char* filename; | 281 const char* filename; |
306 HistogramEnumType type; | 282 HistogramEnumType type; |
307 }; | 283 }; |
308 | 284 |
309 template <typename HistogramEnumType> | 285 template <typename HistogramEnumType> |
310 class BitmapHistogramTest | 286 class BitmapHistogramTest |
311 : public BitmapImageTest | 287 : public BitmapImageTest |
312 , public ::testing::WithParamInterface<HistogramTestParams<HistogramEnumType >> { | 288 , public ::testing::WithParamInterface<HistogramTestParams<HistogramEnumType >> { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 {"/LayoutTests/fast/images/resources/exif-orientation-5-lu.jpg", OriginLeftT op}, | 329 {"/LayoutTests/fast/images/resources/exif-orientation-5-lu.jpg", OriginLeftT op}, |
354 {"/LayoutTests/fast/images/resources/exif-orientation-6-ru.jpg", OriginRight Top}, | 330 {"/LayoutTests/fast/images/resources/exif-orientation-6-ru.jpg", OriginRight Top}, |
355 {"/LayoutTests/fast/images/resources/exif-orientation-7-rl.jpg", OriginRight Bottom}, | 331 {"/LayoutTests/fast/images/resources/exif-orientation-7-rl.jpg", OriginRight Bottom}, |
356 {"/LayoutTests/fast/images/resources/exif-orientation-8-llo.jpg", OriginLeft Bottom} | 332 {"/LayoutTests/fast/images/resources/exif-orientation-8-llo.jpg", OriginLeft Bottom} |
357 }; | 333 }; |
358 | 334 |
359 INSTANTIATE_TEST_CASE_P(DecodedImageOrientationHistogramTest, DecodedImageOrient ationHistogramTest, | 335 INSTANTIATE_TEST_CASE_P(DecodedImageOrientationHistogramTest, DecodedImageOrient ationHistogramTest, |
360 ::testing::ValuesIn(kDecodedImageOrientationHistogramTestParams)); | 336 ::testing::ValuesIn(kDecodedImageOrientationHistogramTestParams)); |
361 | 337 |
362 } // namespace blink | 338 } // namespace blink |
OLD | NEW |