OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/graphics/DeferredImageDecoder.h" | 5 #include "platform/graphics/DeferredImageDecoder.h" |
6 | 6 |
7 #include "platform/SharedBuffer.h" | 7 #include "platform/SharedBuffer.h" |
8 #include "platform/image-decoders/ImageDecoderTestHelpers.h" | 8 #include "platform/image-decoders/ImageDecoderTestHelpers.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/skia/include/core/SkImage.h" | 10 #include "third_party/skia/include/core/SkImage.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 * | 28 * |
29 * @param fileName File to decode | 29 * @param fileName File to decode |
30 * @param bytesForFirstFrame Number of bytes needed to return an SkImage | 30 * @param bytesForFirstFrame Number of bytes needed to return an SkImage |
31 * @param laterFrame Frame to decode with almost complete data. Can be 0. | 31 * @param laterFrame Frame to decode with almost complete data. Can be 0. |
32 */ | 32 */ |
33 static void mixImages(const char* fileName, size_t bytesForFirstFrame, size_t la terFrame) | 33 static void mixImages(const char* fileName, size_t bytesForFirstFrame, size_t la terFrame) |
34 { | 34 { |
35 RefPtr<SharedBuffer> file = readFile(fileName); | 35 RefPtr<SharedBuffer> file = readFile(fileName); |
36 ASSERT_NE(file, nullptr); | 36 ASSERT_NE(file, nullptr); |
37 | 37 |
38 std::unique_ptr<DeferredImageDecoder> decoder = DeferredImageDecoder::create (ImageDecoder::determineImageType(*file.get()), ImageDecoder::AlphaPremultiplied , ImageDecoder::GammaAndColorProfileIgnored); | |
39 ASSERT_TRUE(decoder.get()); | |
40 | |
41 RefPtr<SharedBuffer> partialFile = SharedBuffer::create(file->data(), bytesF orFirstFrame); | 38 RefPtr<SharedBuffer> partialFile = SharedBuffer::create(file->data(), bytesF orFirstFrame); |
42 decoder->setData(*partialFile.get(), false); | 39 std::unique_ptr<DeferredImageDecoder> decoder = DeferredImageDecoder::create (partialFile, false, |
40 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno red); | |
41 ASSERT_NE(decoder, nullptr); | |
43 RefPtr<SkImage> partialImage = decoder->createFrameAtIndex(0); | 42 RefPtr<SkImage> partialImage = decoder->createFrameAtIndex(0); |
44 | 43 |
45 RefPtr<SharedBuffer> almostCompleteFile = SharedBuffer::create(file->data(), file->size() - 1); | 44 RefPtr<SharedBuffer> almostCompleteFile = SharedBuffer::create(file->data(), file->size() - 1); |
46 decoder->setData(*almostCompleteFile.get(), false); | 45 decoder->setData(almostCompleteFile, false); |
47 RefPtr<SkImage> imageWithMoreData = decoder->createFrameAtIndex(laterFrame); | 46 RefPtr<SkImage> imageWithMoreData = decoder->createFrameAtIndex(laterFrame); |
48 | 47 |
49 imageWithMoreData->preroll(); | 48 imageWithMoreData->preroll(); |
50 partialImage->preroll(); | 49 partialImage->preroll(); |
51 } | 50 } |
52 | 51 |
53 TEST(DeferredImageDecoderTestWoPlatform, mixImagesGif) | 52 TEST(DeferredImageDecoderTestWoPlatform, mixImagesGif) |
54 { | 53 { |
55 mixImages("/LayoutTests/fast/images/resources/animated.gif", 818u, 1u); | 54 mixImages("/LayoutTests/fast/images/resources/animated.gif", 818u, 1u); |
56 } | 55 } |
(...skipping 20 matching lines...) Expand all Loading... | |
77 | 76 |
78 TEST(DeferredImageDecoderTestWoPlatform, mixImagesIco) | 77 TEST(DeferredImageDecoderTestWoPlatform, mixImagesIco) |
79 { | 78 { |
80 mixImages("/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico", 1 376u, 1u); | 79 mixImages("/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico", 1 376u, 1u); |
81 } | 80 } |
82 | 81 |
83 TEST(DeferredImageDecoderTestWoPlatform, fragmentedSignature) | 82 TEST(DeferredImageDecoderTestWoPlatform, fragmentedSignature) |
84 { | 83 { |
85 struct { | 84 struct { |
86 const char* m_file; | 85 const char* m_file; |
87 ImageDecoder::SniffResult m_expectedResult; | |
Peter Kasting
2016/08/19 23:04:58
It seems like we've lost the functionality of chec
f(malita)
2016/08/22 01:51:15
Indeed. I would hope we have other tests to verif
| |
88 } tests[] = { | 86 } tests[] = { |
89 { "/LayoutTests/fast/images/resources/animated.gif", ImageDecoder::Sniff Result::GIF }, | 87 { "/LayoutTests/fast/images/resources/animated.gif" }, |
90 { "/LayoutTests/fast/images/resources/mu.png", ImageDecoder::SniffResult ::PNG }, | 88 { "/LayoutTests/fast/images/resources/mu.png" }, |
91 { "/LayoutTests/fast/images/resources/2-dht.jpg", ImageDecoder::SniffRes ult::JPEG }, | 89 { "/LayoutTests/fast/images/resources/2-dht.jpg" }, |
92 { "/LayoutTests/fast/images/resources/webp-animated.webp", ImageDecoder: :SniffResult::WEBP }, | 90 { "/LayoutTests/fast/images/resources/webp-animated.webp" }, |
93 { "/LayoutTests/fast/images/resources/lenna.bmp", ImageDecoder::SniffRes ult::BMP }, | 91 { "/LayoutTests/fast/images/resources/lenna.bmp" }, |
94 { "/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico", Image Decoder::SniffResult::ICO }, | 92 { "/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico" }, |
95 }; | 93 }; |
96 | 94 |
97 for (size_t i = 0; i < SK_ARRAY_COUNT(tests); ++i) { | 95 for (size_t i = 0; i < SK_ARRAY_COUNT(tests); ++i) { |
98 RefPtr<SharedBuffer> fileBuffer = readFile(tests[i].m_file); | 96 RefPtr<SharedBuffer> fileBuffer = readFile(tests[i].m_file); |
99 ASSERT_NE(fileBuffer, nullptr); | 97 ASSERT_NE(fileBuffer, nullptr); |
100 // We need contiguous data, which SharedBuffer doesn't guarantee. | 98 // We need contiguous data, which SharedBuffer doesn't guarantee. |
101 sk_sp<SkData> skData = fileBuffer->getAsSkData(); | 99 sk_sp<SkData> skData = fileBuffer->getAsSkData(); |
102 ASSERT_EQ(skData->size(), fileBuffer->size()); | 100 ASSERT_EQ(skData->size(), fileBuffer->size()); |
103 const char* data = reinterpret_cast<const char*>(skData->bytes()); | 101 const char* data = reinterpret_cast<const char*>(skData->bytes()); |
104 | 102 |
105 // Truncated signature (only 1 byte) | 103 // Truncated signature (only 1 byte). Decoder instantiation should fail . |
106 RefPtr<SharedBuffer> buffer = SharedBuffer::create<size_t>(data, 1u); | 104 RefPtr<SharedBuffer> buffer = SharedBuffer::create<size_t>(data, 1u); |
107 ASSERT_EQ(ImageDecoder::determineImageType(*buffer), ImageDecoder::Sniff Result::InsufficientData); | 105 ASSERT_FALSE(ImageDecoder::isSufficientData(*buffer)); |
106 ASSERT_EQ(nullptr, DeferredImageDecoder::create(buffer, false, | |
107 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfile Ignored)); | |
108 | 108 |
109 // Append the rest of the data. We should be able to sniff the signatur e now, even if segmented. | 109 // Append the rest of the data. We should be able to sniff the signatur e now, even if segmented. |
110 buffer->append<size_t>(data + 1, skData->size() - 1); | 110 buffer->append<size_t>(data + 1, skData->size() - 1); |
111 ASSERT_EQ(ImageDecoder::determineImageType(*buffer), tests[i].m_expected Result); | 111 ASSERT_TRUE(ImageDecoder::isSufficientData(*buffer)); |
112 ASSERT_NE(nullptr, DeferredImageDecoder::create(buffer, false, | |
113 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfile Ignored)); | |
112 } | 114 } |
113 } | 115 } |
114 | 116 |
115 } // namespace blink | 117 } // namespace blink |
OLD | NEW |