| 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 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/graphics/BitmapImage.h" | 31 #include "platform/graphics/BitmapImage.h" |
| 32 | 32 |
| 33 #include "platform/SharedBuffer.h" | 33 #include "platform/SharedBuffer.h" |
| 34 #include "platform/graphics/BitmapImageMetrics.h" | 34 #include "platform/graphics/BitmapImageMetrics.h" |
| 35 #include "platform/graphics/DeferredImageDecoder.h" | 35 #include "platform/graphics/DeferredImageDecoder.h" |
| 36 #include "platform/graphics/ImageObserver.h" | 36 #include "platform/graphics/ImageObserver.h" |
| 37 #include "platform/scheduler/test/fake_web_task_runner.h" |
| 37 #include "platform/testing/HistogramTester.h" | 38 #include "platform/testing/HistogramTester.h" |
| 38 #include "platform/testing/UnitTestHelpers.h" | 39 #include "platform/testing/UnitTestHelpers.h" |
| 39 #include "platform/wtf/StdLibExtras.h" | 40 #include "platform/wtf/StdLibExtras.h" |
| 40 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 41 #include "third_party/skia/include/core/SkImage.h" | 42 #include "third_party/skia/include/core/SkImage.h" |
| 42 | 43 |
| 43 namespace blink { | 44 namespace blink { |
| 44 | 45 |
| 45 class BitmapImageTest : public ::testing::Test { | 46 class BitmapImageTest : public ::testing::Test { |
| 46 public: | 47 public: |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 128 |
| 128 int LastDecodedSizeChange() { | 129 int LastDecodedSizeChange() { |
| 129 return image_observer_->last_decoded_size_changed_delta_; | 130 return image_observer_->last_decoded_size_changed_delta_; |
| 130 } | 131 } |
| 131 | 132 |
| 132 PassRefPtr<SharedBuffer> Data() { return image_->Data(); } | 133 PassRefPtr<SharedBuffer> Data() { return image_->Data(); } |
| 133 | 134 |
| 134 protected: | 135 protected: |
| 135 void SetUp() override { | 136 void SetUp() override { |
| 136 image_observer_ = new FakeImageObserver; | 137 image_observer_ = new FakeImageObserver; |
| 137 image_ = BitmapImage::Create(image_observer_.Get()); | 138 image_ = BitmapImage::Create(task_runner_, image_observer_.Get()); |
| 139 task_runner_ = AdoptRef(new scheduler::FakeWebTaskRunner); |
| 138 } | 140 } |
| 139 | 141 |
| 140 Persistent<FakeImageObserver> image_observer_; | 142 Persistent<FakeImageObserver> image_observer_; |
| 141 RefPtr<BitmapImage> image_; | 143 RefPtr<BitmapImage> image_; |
| 144 RefPtr<scheduler::FakeWebTaskRunner> task_runner_; |
| 142 }; | 145 }; |
| 143 | 146 |
| 144 TEST_F(BitmapImageTest, destroyDecodedData) { | 147 TEST_F(BitmapImageTest, destroyDecodedData) { |
| 145 LoadImage("/LayoutTests/images/resources/animated-10color.gif"); | 148 LoadImage("/LayoutTests/images/resources/animated-10color.gif"); |
| 146 size_t total_size = DecodedSize(); | 149 size_t total_size = DecodedSize(); |
| 147 EXPECT_GT(total_size, 0u); | 150 EXPECT_GT(total_size, 0u); |
| 148 DestroyDecodedData(); | 151 DestroyDecodedData(); |
| 149 EXPECT_EQ(-static_cast<int>(total_size), LastDecodedSizeChange()); | 152 EXPECT_EQ(-static_cast<int>(total_size), LastDecodedSizeChange()); |
| 150 EXPECT_EQ(0u, DecodedSize()); | 153 EXPECT_EQ(0u, DecodedSize()); |
| 151 } | 154 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 172 } | 175 } |
| 173 } | 176 } |
| 174 EXPECT_TRUE(AnimationFinished()); | 177 EXPECT_TRUE(AnimationFinished()); |
| 175 } | 178 } |
| 176 | 179 |
| 177 TEST_F(BitmapImageTest, isAllDataReceived) { | 180 TEST_F(BitmapImageTest, isAllDataReceived) { |
| 178 RefPtr<SharedBuffer> image_data = | 181 RefPtr<SharedBuffer> image_data = |
| 179 ReadFile("/LayoutTests/images/resources/green.jpg"); | 182 ReadFile("/LayoutTests/images/resources/green.jpg"); |
| 180 ASSERT_TRUE(image_data.Get()); | 183 ASSERT_TRUE(image_data.Get()); |
| 181 | 184 |
| 182 RefPtr<BitmapImage> image = BitmapImage::Create(); | 185 RefPtr<BitmapImage> image = |
| 186 BitmapImage::Create(BitmapImageTest::task_runner_); |
| 183 EXPECT_FALSE(image->IsAllDataReceived()); | 187 EXPECT_FALSE(image->IsAllDataReceived()); |
| 184 | 188 |
| 185 image->SetData(image_data, false); | 189 image->SetData(image_data, false); |
| 186 EXPECT_FALSE(image->IsAllDataReceived()); | 190 EXPECT_FALSE(image->IsAllDataReceived()); |
| 187 | 191 |
| 188 image->SetData(image_data, true); | 192 image->SetData(image_data, true); |
| 189 EXPECT_TRUE(image->IsAllDataReceived()); | 193 EXPECT_TRUE(image->IsAllDataReceived()); |
| 190 | 194 |
| 191 image->SetData(SharedBuffer::Create("data", sizeof("data")), false); | 195 image->SetData(SharedBuffer::Create("data", sizeof("data")), false); |
| 192 EXPECT_FALSE(image->IsAllDataReceived()); | 196 EXPECT_FALSE(image->IsAllDataReceived()); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 kOriginRightBottom}, | 331 kOriginRightBottom}, |
| 328 {"/LayoutTests/images/resources/exif-orientation-8-llo.jpg", | 332 {"/LayoutTests/images/resources/exif-orientation-8-llo.jpg", |
| 329 kOriginLeftBottom}}; | 333 kOriginLeftBottom}}; |
| 330 | 334 |
| 331 INSTANTIATE_TEST_CASE_P( | 335 INSTANTIATE_TEST_CASE_P( |
| 332 DecodedImageOrientationHistogramTest, | 336 DecodedImageOrientationHistogramTest, |
| 333 DecodedImageOrientationHistogramTest, | 337 DecodedImageOrientationHistogramTest, |
| 334 ::testing::ValuesIn(kDecodedImageOrientationHistogramTestParams)); | 338 ::testing::ValuesIn(kDecodedImageOrientationHistogramTestParams)); |
| 335 | 339 |
| 336 } // namespace blink | 340 } // namespace blink |
| OLD | NEW |