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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 TEST(DeferredImageDecoderTestWoPlatform, mixImagesBmp) | 73 TEST(DeferredImageDecoderTestWoPlatform, mixImagesBmp) |
74 { | 74 { |
75 mixImages("/LayoutTests/fast/images/resources/lenna.bmp", 122u, 0u); | 75 mixImages("/LayoutTests/fast/images/resources/lenna.bmp", 122u, 0u); |
76 } | 76 } |
77 | 77 |
78 TEST(DeferredImageDecoderTestWoPlatform, mixImagesIco) | 78 TEST(DeferredImageDecoderTestWoPlatform, mixImagesIco) |
79 { | 79 { |
80 mixImages("/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico", 1
376u, 1u); | 80 mixImages("/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico", 1
376u, 1u); |
81 } | 81 } |
82 | 82 |
| 83 TEST(DeferredImageDecoderTestWoPlatform, fragmentedSignature) |
| 84 { |
| 85 struct { |
| 86 const char* m_file; |
| 87 ImageDecoder::SniffResult m_expectedResult; |
| 88 } tests[] = { |
| 89 { "/LayoutTests/fast/images/resources/animated.gif", ImageDecoder::Sniff
Result::GIF }, |
| 90 { "/LayoutTests/fast/images/resources/mu.png", ImageDecoder::SniffResult
::PNG }, |
| 91 { "/LayoutTests/fast/images/resources/2-dht.jpg", ImageDecoder::SniffRes
ult::JPEG }, |
| 92 { "/LayoutTests/fast/images/resources/webp-animated.webp", ImageDecoder:
:SniffResult::WEBP }, |
| 93 { "/LayoutTests/fast/images/resources/lenna.bmp", ImageDecoder::SniffRes
ult::BMP }, |
| 94 { "/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico", Image
Decoder::SniffResult::ICO }, |
| 95 }; |
| 96 |
| 97 for (size_t i = 0; i < SK_ARRAY_COUNT(tests); ++i) { |
| 98 RefPtr<SharedBuffer> fileBuffer = readFile(tests[i].m_file); |
| 99 ASSERT_NE(fileBuffer, nullptr); |
| 100 // We need contiguous data, which SharedBuffer doesn't guarantee. |
| 101 sk_sp<SkData> skData = fileBuffer->getAsSkData(); |
| 102 ASSERT_EQ(skData->size(), fileBuffer->size()); |
| 103 const char* data = reinterpret_cast<const char*>(skData->bytes()); |
| 104 |
| 105 // Truncated signature (only 1 byte) |
| 106 RefPtr<SharedBuffer> buffer = SharedBuffer::create<size_t>(data, 1u); |
| 107 ASSERT_EQ(ImageDecoder::determineImageType(*buffer), ImageDecoder::Sniff
Result::InsufficientData); |
| 108 |
| 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); |
| 111 ASSERT_EQ(ImageDecoder::determineImageType(*buffer), tests[i].m_expected
Result); |
| 112 } |
| 113 } |
| 114 |
83 } // namespace blink | 115 } // namespace blink |
OLD | NEW |