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 <memory> | 7 #include <memory> |
8 #include "platform/SharedBuffer.h" | 8 #include "platform/SharedBuffer.h" |
9 #include "platform/image-decoders/ImageDecoderTestHelpers.h" | 9 #include "platform/image-decoders/ImageDecoderTestHelpers.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 RefPtr<SharedBuffer> fileBuffer = readFile(testFiles[i]); | 97 RefPtr<SharedBuffer> fileBuffer = readFile(testFiles[i]); |
98 ASSERT_NE(fileBuffer, nullptr); | 98 ASSERT_NE(fileBuffer, nullptr); |
99 // We need contiguous data, which SharedBuffer doesn't guarantee. | 99 // We need contiguous data, which SharedBuffer doesn't guarantee. |
100 sk_sp<SkData> skData = fileBuffer->getAsSkData(); | 100 sk_sp<SkData> skData = fileBuffer->getAsSkData(); |
101 EXPECT_EQ(skData->size(), fileBuffer->size()); | 101 EXPECT_EQ(skData->size(), fileBuffer->size()); |
102 const char* data = reinterpret_cast<const char*>(skData->bytes()); | 102 const char* data = reinterpret_cast<const char*>(skData->bytes()); |
103 | 103 |
104 // Truncated signature (only 1 byte). Decoder instantiation should fail. | 104 // Truncated signature (only 1 byte). Decoder instantiation should fail. |
105 RefPtr<SharedBuffer> buffer = SharedBuffer::create<size_t>(data, 1u); | 105 RefPtr<SharedBuffer> buffer = SharedBuffer::create<size_t>(data, 1u); |
106 EXPECT_FALSE(ImageDecoder::hasSufficientDataToSniffImageType(*buffer)); | 106 EXPECT_FALSE(ImageDecoder::hasSufficientDataToSniffImageType(*buffer)); |
107 EXPECT_EQ(nullptr, DeferredImageDecoder::create( | 107 EXPECT_EQ(nullptr, |
108 buffer, false, ImageDecoder::AlphaPremultiplied, | 108 DeferredImageDecoder::create(buffer, false, |
109 ColorBehavior::ignore())); | 109 ImageDecoder::AlphaPremultiplied, |
| 110 ColorBehavior::ignore())); |
110 | 111 |
111 // Append the rest of the data. We should be able to sniff the signature | 112 // Append the rest of the data. We should be able to sniff the signature |
112 // now, even if segmented. | 113 // now, even if segmented. |
113 buffer->append<size_t>(data + 1, skData->size() - 1); | 114 buffer->append<size_t>(data + 1, skData->size() - 1); |
114 EXPECT_TRUE(ImageDecoder::hasSufficientDataToSniffImageType(*buffer)); | 115 EXPECT_TRUE(ImageDecoder::hasSufficientDataToSniffImageType(*buffer)); |
115 std::unique_ptr<DeferredImageDecoder> decoder = | 116 std::unique_ptr<DeferredImageDecoder> decoder = |
116 DeferredImageDecoder::create(buffer, false, | 117 DeferredImageDecoder::create(buffer, false, |
117 ImageDecoder::AlphaPremultiplied, | 118 ImageDecoder::AlphaPremultiplied, |
118 ColorBehavior::ignore()); | 119 ColorBehavior::ignore()); |
119 ASSERT_NE(decoder, nullptr); | 120 ASSERT_NE(decoder, nullptr); |
120 EXPECT_TRUE(String(testFiles[i]).endsWith(decoder->filenameExtension())); | 121 EXPECT_TRUE(String(testFiles[i]).endsWith(decoder->filenameExtension())); |
121 } | 122 } |
122 } | 123 } |
123 | 124 |
124 } // namespace blink | 125 } // namespace blink |
OLD | NEW |