Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 BitmapImageTest(bool enableDeferredDecoding) : m_enableDeferredDecoding(enab leDeferredDecoding) { } | 62 BitmapImageTest(bool enableDeferredDecoding) : m_enableDeferredDecoding(enab leDeferredDecoding) { } |
| 63 | 63 |
| 64 static PassRefPtr<SharedBuffer> readFile(const char* fileName) | 64 static PassRefPtr<SharedBuffer> readFile(const char* fileName) |
| 65 { | 65 { |
| 66 String filePath = testing::blinkRootDir(); | 66 String filePath = testing::blinkRootDir(); |
| 67 filePath.append(fileName); | 67 filePath.append(fileName); |
| 68 return testing::readFromFile(filePath); | 68 return testing::readFromFile(filePath); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Accessors to BitmapImage's protected methods. | 71 // Accessors to BitmapImage's protected methods. |
| 72 void destroyDecodedData(bool destroyAll) { m_image->destroyDecodedData(destr oyAll); } | 72 void destroyDecodedData() { m_image->destroyDecodedData(); } |
| 73 size_t frameCount() { return m_image->frameCount(); } | 73 size_t frameCount() { return m_image->frameCount(); } |
| 74 void frameAtIndex(size_t index) | 74 void frameAtIndex(size_t index) |
| 75 { | 75 { |
| 76 m_image->frameAtIndex(index); | 76 m_image->frameAtIndex(index); |
| 77 } | 77 } |
| 78 void setCurrentFrame(size_t frame) { m_image->m_currentFrame = frame; } | 78 void setCurrentFrame(size_t frame) { m_image->m_currentFrame = frame; } |
| 79 size_t frameDecodedSize(size_t frame) { return m_image->m_frames[frame].m_fr ameBytes; } | 79 size_t frameDecodedSize(size_t frame) { return m_image->m_frames[frame].m_fr ameBytes; } |
| 80 size_t decodedFramesCount() const { return m_image->m_frames.size(); } | 80 size_t decodedFramesCount() const { return m_image->m_frames.size(); } |
| 81 | 81 |
| 82 void setFirstFrameNotComplete() { m_image->m_frames[0].m_isComplete = false; } | 82 void setFirstFrameNotComplete() { m_image->m_frames[0].m_isComplete = false; } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 m_image = BitmapImage::create(m_imageObserver.get()); | 138 m_image = BitmapImage::create(m_imageObserver.get()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 OwnPtrWillBePersistent<FakeImageObserver> m_imageObserver; | 141 OwnPtrWillBePersistent<FakeImageObserver> m_imageObserver; |
| 142 RefPtr<BitmapImage> m_image; | 142 RefPtr<BitmapImage> m_image; |
| 143 | 143 |
| 144 private: | 144 private: |
| 145 bool m_enableDeferredDecoding; | 145 bool m_enableDeferredDecoding; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 TEST_F(BitmapImageTest, destroyDecodedDataExceptCurrentFrame) | |
| 149 { | |
| 150 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); | |
| 151 size_t totalSize = decodedSize(); | |
| 152 size_t frame = frameCount() / 2; | |
| 153 setCurrentFrame(frame); | |
| 154 size_t size = frameDecodedSize(frame); | |
| 155 destroyDecodedData(false); | |
| 156 EXPECT_LT(m_imageObserver->m_lastDecodedSizeChangedDelta, 0); | |
| 157 EXPECT_GE(m_imageObserver->m_lastDecodedSizeChangedDelta, -static_cast<int>( totalSize - size)); | |
| 158 } | |
| 159 | |
| 160 TEST_F(BitmapImageTest, destroyAllDecodedData) | 148 TEST_F(BitmapImageTest, destroyAllDecodedData) |
| 161 { | 149 { |
| 162 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); | 150 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); |
| 163 size_t totalSize = decodedSize(); | 151 size_t totalSize = decodedSize(); |
| 164 EXPECT_GT(totalSize, 0u); | 152 EXPECT_GT(totalSize, 0u); |
| 165 destroyDecodedData(true); | 153 destroyDecodedData(); |
| 166 EXPECT_EQ(-static_cast<int>(totalSize), m_imageObserver->m_lastDecodedSizeCh angedDelta); | 154 EXPECT_EQ(-static_cast<int>(totalSize), m_imageObserver->m_lastDecodedSizeCh angedDelta); |
| 167 EXPECT_EQ(0u, decodedSize()); | 155 EXPECT_EQ(0u, decodedSize()); |
| 168 } | 156 } |
| 169 | 157 |
| 170 TEST_F(BitmapImageTest, maybeAnimated) | 158 TEST_F(BitmapImageTest, maybeAnimated) |
| 171 { | 159 { |
| 172 loadImage("/LayoutTests/fast/images/resources/gif-loop-count.gif"); | 160 loadImage("/LayoutTests/fast/images/resources/gif-loop-count.gif"); |
| 173 for (size_t i = 0; i < frameCount(); ++i) { | 161 for (size_t i = 0; i < frameCount(); ++i) { |
| 174 EXPECT_TRUE(m_image->maybeAnimated()); | 162 EXPECT_TRUE(m_image->maybeAnimated()); |
| 175 advanceAnimation(); | 163 advanceAnimation(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 | 247 |
| 260 TEST_F(BitmapImageTest, correctDecodedDataSize) | 248 TEST_F(BitmapImageTest, correctDecodedDataSize) |
| 261 { | 249 { |
| 262 // When requesting a frame of a multi-frame GIF causes another frame to be | 250 // When requesting a frame of a multi-frame GIF causes another frame to be |
| 263 // decoded as well, both frames' sizes should be reported by the source and | 251 // decoded as well, both frames' sizes should be reported by the source and |
| 264 // thus included in the decoded size changed notification. | 252 // thus included in the decoded size changed notification. |
| 265 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); | 253 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); |
| 266 frameAtIndex(1); | 254 frameAtIndex(1); |
| 267 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame: :PixelData)); | 255 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame: :PixelData)); |
| 268 EXPECT_EQ(frameSize * 2, m_imageObserver->m_lastDecodedSizeChangedDelta); | 256 EXPECT_EQ(frameSize * 2, m_imageObserver->m_lastDecodedSizeChangedDelta); |
| 269 | |
| 270 // Trying to destroy all data except an undecoded frame should cause the | |
| 271 // decoder to seek backwards and preserve the most recent previous frame | |
| 272 // necessary to decode that undecoded frame, and destroy all other frames. | |
| 273 setCurrentFrame(2); | |
| 274 destroyDecodedData(false); | |
| 275 EXPECT_EQ(-frameSize, m_imageObserver->m_lastDecodedSizeChangedDelta); | |
| 276 } | 257 } |
| 277 | 258 |
| 278 TEST_F(BitmapImageTest, recachingFrameAfterDataChanged) | 259 TEST_F(BitmapImageTest, recachingFrameAfterDataChanged) |
| 279 { | 260 { |
| 280 loadImage("/LayoutTests/fast/images/resources/green.jpg"); | 261 loadImage("/LayoutTests/fast/images/resources/green.jpg"); |
| 281 setFirstFrameNotComplete(); | 262 setFirstFrameNotComplete(); |
| 282 EXPECT_GT(m_imageObserver->m_lastDecodedSizeChangedDelta, 0); | 263 EXPECT_GT(m_imageObserver->m_lastDecodedSizeChangedDelta, 0); |
| 283 m_imageObserver->m_lastDecodedSizeChangedDelta = 0; | 264 m_imageObserver->m_lastDecodedSizeChangedDelta = 0; |
| 284 | 265 |
| 285 // Calling dataChanged causes the cache to flush, but doesn't affect the | 266 // Calling dataChanged causes the cache to flush, but doesn't affect the |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 297 }; | 278 }; |
| 298 | 279 |
| 299 TEST_F(BitmapImageDeferredDecodingTest, correctDecodedDataSize) | 280 TEST_F(BitmapImageDeferredDecodingTest, correctDecodedDataSize) |
| 300 { | 281 { |
| 301 // When deferred decoding is enabled, requesting any one frame shouldn't | 282 // When deferred decoding is enabled, requesting any one frame shouldn't |
| 302 // result in decoding any other frames. | 283 // result in decoding any other frames. |
| 303 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); | 284 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); |
| 304 frameAtIndex(1); | 285 frameAtIndex(1); |
| 305 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame: :PixelData)); | 286 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame: :PixelData)); |
| 306 EXPECT_EQ(frameSize, m_imageObserver->m_lastDecodedSizeChangedDelta); | 287 EXPECT_EQ(frameSize, m_imageObserver->m_lastDecodedSizeChangedDelta); |
| 307 frameAtIndex(0); | 288 frameAtIndex(0); |
|
Peter Kasting
2016/04/05 01:55:58
This frameAtIndex() call should be removed as well
| |
| 308 | |
| 309 // Trying to destroy all data except an undecoded frame should go ahead and | |
| 310 // destroy all other frames. | |
| 311 setCurrentFrame(2); | |
| 312 destroyDecodedData(false); | |
| 313 EXPECT_EQ(-frameSize * 2, m_imageObserver->m_lastDecodedSizeChangedDelta); | |
| 314 } | 289 } |
| 315 | 290 |
| 316 } // namespace blink | 291 } // namespace blink |
| OLD | NEW |