Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ico/ICOImageDecoderTest.cpp

Issue 2930513004: [WIP] Move ImageDecoders to SkCodec
Patch Set: Adding check for decoder creation Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "platform/image-decoders/ico/ICOImageDecoder.h"
6
7 #include <memory>
8 #include "platform/image-decoders/ImageDecoderTestHelpers.h"
9 #include "platform/wtf/PtrUtil.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace blink {
13
14 namespace {
15
16 std::unique_ptr<ImageDecoder> CreateDecoder() {
17 return WTF::WrapUnique(
18 new ICOImageDecoder(ImageDecoder::kAlphaNotPremultiplied,
19 ColorBehavior::TransformToTargetForTesting(),
20 ImageDecoder::kNoDecodedImageByteLimit));
21 }
22 }
23
24 TEST(ICOImageDecoderTests, trunctedIco) {
25 RefPtr<SharedBuffer> data =
26 ReadFile("/LayoutTests/images/resources/png-in-ico.ico");
27 ASSERT_FALSE(data->IsEmpty());
28
29 RefPtr<SharedBuffer> truncated_data =
30 SharedBuffer::Create(data->Data(), data->size() / 2);
31 auto decoder = CreateDecoder();
32
33 decoder->SetData(truncated_data.Get(), false);
34 decoder->FrameBufferAtIndex(0);
35 EXPECT_FALSE(decoder->Failed());
36
37 decoder->SetData(truncated_data.Get(), true);
38 decoder->FrameBufferAtIndex(0);
39 EXPECT_TRUE(decoder->Failed());
40 }
41
42 TEST(ICOImageDecoderTests, errorInPngInIco) {
43 RefPtr<SharedBuffer> data =
44 ReadFile("/LayoutTests/images/resources/png-in-ico.ico");
45 ASSERT_FALSE(data->IsEmpty());
46
47 // Modify the file to have a broken CRC in IHDR.
48 constexpr size_t kCrcOffset = 22 + 29;
49 constexpr size_t kCrcSize = 4;
50 RefPtr<SharedBuffer> modified_data =
51 SharedBuffer::Create(data->Data(), kCrcOffset);
52 Vector<char> bad_crc(kCrcSize, 0);
53 modified_data->Append(bad_crc);
54 modified_data->Append(data->Data() + kCrcOffset + kCrcSize,
55 data->size() - kCrcOffset - kCrcSize);
56
57 auto decoder = CreateDecoder();
58 decoder->SetData(modified_data.Get(), true);
59
60 // ICOImageDecoder reports the frame count based on whether enough data has
61 // been received according to the icon directory. So even though the
62 // embedded PNG is broken, there is enough data to include it in the frame
63 // count.
64 EXPECT_EQ(1u, decoder->FrameCount());
65
66 decoder->FrameBufferAtIndex(0);
67 EXPECT_TRUE(decoder->Failed());
68 }
69
70 TEST(ICOImageDecoderTests, parseAndDecodeByteByByte) {
71 TestByteByByteDecode(&CreateDecoder,
72 "/LayoutTests/images/resources/png-in-ico.ico", 1u,
73 kAnimationNone);
74 TestByteByByteDecode(&CreateDecoder,
75 "/LayoutTests/images/resources/2entries.ico", 2u,
76 kAnimationNone);
77 TestByteByByteDecode(&CreateDecoder,
78 "/LayoutTests/images/resources/greenbox-3frames.cur", 3u,
79 kAnimationNone);
80 TestByteByByteDecode(
81 &CreateDecoder,
82 "/LayoutTests/images/resources/icon-without-and-bitmap.ico", 1u,
83 kAnimationNone);
84 TestByteByByteDecode(&CreateDecoder, "/LayoutTests/images/resources/1bit.ico",
85 1u, kAnimationNone);
86 TestByteByByteDecode(&CreateDecoder,
87 "/LayoutTests/images/resources/bug653075.ico", 2u,
88 kAnimationNone);
89 }
90
91 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698