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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 String filePath = WebKit::Platform::current()->unitTestSupport()->webKit RootDir(); | 63 String filePath = WebKit::Platform::current()->unitTestSupport()->webKit RootDir(); |
64 filePath.append(fileName); | 64 filePath.append(fileName); |
65 return WebKit::Platform::current()->unitTestSupport()->readFromFile(file Path); | 65 return WebKit::Platform::current()->unitTestSupport()->readFromFile(file Path); |
66 } | 66 } |
67 | 67 |
68 // Accessors to BitmapImage's protected methods. | 68 // Accessors to BitmapImage's protected methods. |
69 void destroyDecodedData(bool destroyAll) { m_image->destroyDecodedData(destr oyAll); } | 69 void destroyDecodedData(bool destroyAll) { m_image->destroyDecodedData(destr oyAll); } |
70 size_t frameCount() { return m_image->frameCount(); } | 70 size_t frameCount() { return m_image->frameCount(); } |
71 void setCurrentFrame(size_t frame) { m_image->m_currentFrame = frame; } | 71 void setCurrentFrame(size_t frame) { m_image->m_currentFrame = frame; } |
72 size_t frameDecodedSize(size_t frame) { return m_image->m_frames[frame].m_fr ameBytes; } | 72 size_t frameDecodedSize(size_t frame) { return m_image->m_frames[frame].m_fr ameBytes; } |
73 size_t decodedFramesCount() const { return m_image->m_frames.size(); } | |
73 | 74 |
74 void loadImage(const char* fileName) | 75 void loadImage(const char* fileName) |
75 { | 76 { |
76 RefPtr<SharedBuffer> imageData = readFile("/LayoutTests/fast/images/reso urces/animated-10color.gif"); | 77 RefPtr<SharedBuffer> imageData = readFile("/LayoutTests/fast/images/reso urces/animated-10color.gif"); |
77 ASSERT_TRUE(imageData.get()); | 78 ASSERT_TRUE(imageData.get()); |
78 | 79 |
79 m_image->setData(imageData, true); | 80 m_image->setData(imageData, true); |
80 EXPECT_EQ(0u, m_image->decodedSize()); | 81 EXPECT_EQ(0u, decodedSize()); |
81 | 82 |
82 size_t frameCount = m_image->frameCount(); | 83 size_t frameCount = m_image->frameCount(); |
83 for (size_t i = 0; i < frameCount; ++i) | 84 for (size_t i = 0; i < frameCount; ++i) |
84 m_image->frameAtIndex(i); | 85 m_image->frameAtIndex(i); |
85 } | 86 } |
86 | 87 |
88 size_t decodedSize() | |
89 { | |
90 // In the context of this test, the following loop will give the correct result. But only because the test | |
Peter Kasting
2013/10/10 18:53:41
Nit: result. But -> result, but
| |
91 // forces all frames to be decoded in loadImage() above. There is no gen eral guarantee that frameDecodedSize() | |
92 // is up-to-date. Because of how multi frame images (like GIF) works, re questing one frame to be decoded may | |
Peter Kasting
2013/10/10 18:53:41
Nit: works -> work
| |
93 // require other previous frames to be decoded as well. In those cases f rameDecodedSize() wouldn't return the | |
94 // correct thing for the previous frame because the decoded size wouldn' t have propagated upwards to the | |
95 // BitmapImage frame cache. | |
96 size_t size = 0; | |
97 for (size_t i = 0; i < decodedFramesCount(); ++i) | |
98 size += frameDecodedSize(i); | |
99 return size; | |
100 } | |
101 | |
87 protected: | 102 protected: |
88 virtual void SetUp() OVERRIDE | 103 virtual void SetUp() OVERRIDE |
89 { | 104 { |
90 m_image = BitmapImage::create(&m_imageObserver); | 105 m_image = BitmapImage::create(&m_imageObserver); |
91 } | 106 } |
92 | 107 |
93 FakeImageObserver m_imageObserver; | 108 FakeImageObserver m_imageObserver; |
94 RefPtr<BitmapImage> m_image; | 109 RefPtr<BitmapImage> m_image; |
95 }; | 110 }; |
96 | 111 |
97 TEST_F(BitmapImageTest, destroyDecodedDataExceptCurrentFrame) | 112 TEST_F(BitmapImageTest, destroyDecodedDataExceptCurrentFrame) |
98 { | 113 { |
99 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); | 114 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); |
100 size_t totalSize = m_image->decodedSize(); | 115 size_t totalSize = decodedSize(); |
101 size_t frame = frameCount() / 2; | 116 size_t frame = frameCount() / 2; |
102 setCurrentFrame(frame); | 117 setCurrentFrame(frame); |
103 size_t size = frameDecodedSize(frame); | 118 size_t size = frameDecodedSize(frame); |
104 destroyDecodedData(false); | 119 destroyDecodedData(false); |
105 EXPECT_LT(m_imageObserver.m_lastDecodedSizeChangedDelta, 0); | 120 EXPECT_LT(m_imageObserver.m_lastDecodedSizeChangedDelta, 0); |
106 EXPECT_GE(m_imageObserver.m_lastDecodedSizeChangedDelta, -static_cast<int>(t otalSize - size)); | 121 EXPECT_GE(m_imageObserver.m_lastDecodedSizeChangedDelta, -static_cast<int>(t otalSize - size)); |
107 } | 122 } |
108 | 123 |
109 TEST_F(BitmapImageTest, destroyAllDecodedData) | 124 TEST_F(BitmapImageTest, destroyAllDecodedData) |
110 { | 125 { |
111 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); | 126 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); |
112 size_t decodedSize = m_image->decodedSize(); | 127 size_t totalSize = decodedSize(); |
113 EXPECT_GT(decodedSize, 0u); | 128 EXPECT_GT(totalSize, 0u); |
114 destroyDecodedData(true); | 129 destroyDecodedData(true); |
115 EXPECT_EQ(-static_cast<int>(decodedSize), m_imageObserver.m_lastDecodedSizeC hangedDelta); | 130 EXPECT_EQ(-static_cast<int>(totalSize), m_imageObserver.m_lastDecodedSizeCha ngedDelta); |
116 EXPECT_EQ(0u, m_image->decodedSize()); | 131 EXPECT_EQ(0u, decodedSize()); |
117 } | 132 } |
118 | 133 |
119 } // namespace | 134 } // namespace |
OLD | NEW |