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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp

Issue 2878363003: Revert of Fix ImageAnimation constant names after Blink renaming (Closed)
Patch Set: Created 3 years, 7 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
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 ImageDecoder::kNoDecodedImageByteLimit)); 52 ImageDecoder::kNoDecodedImageByteLimit));
53 } 53 }
54 54
55 void TestRepetitionCount(const char* dir, 55 void TestRepetitionCount(const char* dir,
56 const char* file, 56 const char* file,
57 int expected_repetition_count) { 57 int expected_repetition_count) {
58 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); 58 std::unique_ptr<ImageDecoder> decoder = CreateDecoder();
59 RefPtr<SharedBuffer> data = ReadFile(dir, file); 59 RefPtr<SharedBuffer> data = ReadFile(dir, file);
60 ASSERT_TRUE(data.Get()); 60 ASSERT_TRUE(data.Get());
61 decoder->SetData(data.Get(), true); 61 decoder->SetData(data.Get(), true);
62 EXPECT_EQ(kAnimationLoopOnce, 62 EXPECT_EQ(kCAnimationLoopOnce,
63 decoder->RepetitionCount()); // Default value before decode. 63 decoder->RepetitionCount()); // Default value before decode.
64 64
65 for (size_t i = 0; i < decoder->FrameCount(); ++i) { 65 for (size_t i = 0; i < decoder->FrameCount(); ++i) {
66 ImageFrame* frame = decoder->FrameBufferAtIndex(i); 66 ImageFrame* frame = decoder->FrameBufferAtIndex(i);
67 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus()); 67 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus());
68 } 68 }
69 69
70 EXPECT_EQ(expected_repetition_count, 70 EXPECT_EQ(expected_repetition_count,
71 decoder->RepetitionCount()); // Expected value after decode. 71 decoder->RepetitionCount()); // Expected value after decode.
72 } 72 }
73 73
74 } // anonymous namespace 74 } // anonymous namespace
75 75
76 TEST(GIFImageDecoderTest, decodeTwoFrames) { 76 TEST(GIFImageDecoderTest, decodeTwoFrames) {
77 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); 77 std::unique_ptr<ImageDecoder> decoder = CreateDecoder();
78 78
79 RefPtr<SharedBuffer> data = ReadFile(kLayoutTestResourcesDir, "animated.gif"); 79 RefPtr<SharedBuffer> data = ReadFile(kLayoutTestResourcesDir, "animated.gif");
80 ASSERT_TRUE(data.Get()); 80 ASSERT_TRUE(data.Get());
81 decoder->SetData(data.Get(), true); 81 decoder->SetData(data.Get(), true);
82 EXPECT_EQ(kAnimationLoopOnce, decoder->RepetitionCount()); 82 EXPECT_EQ(kCAnimationLoopOnce, decoder->RepetitionCount());
83 83
84 ImageFrame* frame = decoder->FrameBufferAtIndex(0); 84 ImageFrame* frame = decoder->FrameBufferAtIndex(0);
85 uint32_t generation_id0 = frame->Bitmap().getGenerationID(); 85 uint32_t generation_id0 = frame->Bitmap().getGenerationID();
86 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus()); 86 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus());
87 EXPECT_EQ(16, frame->Bitmap().width()); 87 EXPECT_EQ(16, frame->Bitmap().width());
88 EXPECT_EQ(16, frame->Bitmap().height()); 88 EXPECT_EQ(16, frame->Bitmap().height());
89 89
90 frame = decoder->FrameBufferAtIndex(1); 90 frame = decoder->FrameBufferAtIndex(1);
91 uint32_t generation_id1 = frame->Bitmap().getGenerationID(); 91 uint32_t generation_id1 = frame->Bitmap().getGenerationID();
92 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus()); 92 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus());
93 EXPECT_EQ(16, frame->Bitmap().width()); 93 EXPECT_EQ(16, frame->Bitmap().width());
94 EXPECT_EQ(16, frame->Bitmap().height()); 94 EXPECT_EQ(16, frame->Bitmap().height());
95 EXPECT_TRUE(generation_id0 != generation_id1); 95 EXPECT_TRUE(generation_id0 != generation_id1);
96 96
97 EXPECT_EQ(2u, decoder->FrameCount()); 97 EXPECT_EQ(2u, decoder->FrameCount());
98 EXPECT_EQ(kAnimationLoopInfinite, decoder->RepetitionCount()); 98 EXPECT_EQ(kCAnimationLoopInfinite, decoder->RepetitionCount());
99 } 99 }
100 100
101 TEST(GIFImageDecoderTest, parseAndDecode) { 101 TEST(GIFImageDecoderTest, parseAndDecode) {
102 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); 102 std::unique_ptr<ImageDecoder> decoder = CreateDecoder();
103 103
104 RefPtr<SharedBuffer> data = ReadFile(kLayoutTestResourcesDir, "animated.gif"); 104 RefPtr<SharedBuffer> data = ReadFile(kLayoutTestResourcesDir, "animated.gif");
105 ASSERT_TRUE(data.Get()); 105 ASSERT_TRUE(data.Get());
106 decoder->SetData(data.Get(), true); 106 decoder->SetData(data.Get(), true);
107 EXPECT_EQ(kAnimationLoopOnce, decoder->RepetitionCount()); 107 EXPECT_EQ(kCAnimationLoopOnce, decoder->RepetitionCount());
108 108
109 // This call will parse the entire file. 109 // This call will parse the entire file.
110 EXPECT_EQ(2u, decoder->FrameCount()); 110 EXPECT_EQ(2u, decoder->FrameCount());
111 111
112 ImageFrame* frame = decoder->FrameBufferAtIndex(0); 112 ImageFrame* frame = decoder->FrameBufferAtIndex(0);
113 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus()); 113 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus());
114 EXPECT_EQ(16, frame->Bitmap().width()); 114 EXPECT_EQ(16, frame->Bitmap().width());
115 EXPECT_EQ(16, frame->Bitmap().height()); 115 EXPECT_EQ(16, frame->Bitmap().height());
116 116
117 frame = decoder->FrameBufferAtIndex(1); 117 frame = decoder->FrameBufferAtIndex(1);
118 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus()); 118 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus());
119 EXPECT_EQ(16, frame->Bitmap().width()); 119 EXPECT_EQ(16, frame->Bitmap().width());
120 EXPECT_EQ(16, frame->Bitmap().height()); 120 EXPECT_EQ(16, frame->Bitmap().height());
121 EXPECT_EQ(kAnimationLoopInfinite, decoder->RepetitionCount()); 121 EXPECT_EQ(kCAnimationLoopInfinite, decoder->RepetitionCount());
122 } 122 }
123 123
124 TEST(GIFImageDecoderTest, parseByteByByte) { 124 TEST(GIFImageDecoderTest, parseByteByByte) {
125 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); 125 std::unique_ptr<ImageDecoder> decoder = CreateDecoder();
126 126
127 RefPtr<SharedBuffer> data = ReadFile(kLayoutTestResourcesDir, "animated.gif"); 127 RefPtr<SharedBuffer> data = ReadFile(kLayoutTestResourcesDir, "animated.gif");
128 ASSERT_TRUE(data.Get()); 128 ASSERT_TRUE(data.Get());
129 129
130 size_t frame_count = 0; 130 size_t frame_count = 0;
131 131
132 // Pass data to decoder byte by byte. 132 // Pass data to decoder byte by byte.
133 for (size_t length = 1; length <= data->size(); ++length) { 133 for (size_t length = 1; length <= data->size(); ++length) {
134 RefPtr<SharedBuffer> temp_data = SharedBuffer::Create(data->Data(), length); 134 RefPtr<SharedBuffer> temp_data = SharedBuffer::Create(data->Data(), length);
135 decoder->SetData(temp_data.Get(), length == data->size()); 135 decoder->SetData(temp_data.Get(), length == data->size());
136 136
137 EXPECT_LE(frame_count, decoder->FrameCount()); 137 EXPECT_LE(frame_count, decoder->FrameCount());
138 frame_count = decoder->FrameCount(); 138 frame_count = decoder->FrameCount();
139 } 139 }
140 140
141 EXPECT_EQ(2u, decoder->FrameCount()); 141 EXPECT_EQ(2u, decoder->FrameCount());
142 142
143 decoder->FrameBufferAtIndex(0); 143 decoder->FrameBufferAtIndex(0);
144 decoder->FrameBufferAtIndex(1); 144 decoder->FrameBufferAtIndex(1);
145 EXPECT_EQ(kAnimationLoopInfinite, decoder->RepetitionCount()); 145 EXPECT_EQ(kCAnimationLoopInfinite, decoder->RepetitionCount());
146 } 146 }
147 147
148 TEST(GIFImageDecoderTest, parseAndDecodeByteByByte) { 148 TEST(GIFImageDecoderTest, parseAndDecodeByteByByte) {
149 TestByteByByteDecode(&CreateDecoder, kLayoutTestResourcesDir, 149 TestByteByByteDecode(&CreateDecoder, kLayoutTestResourcesDir,
150 "animated-gif-with-offsets.gif", 5u, 150 "animated-gif-with-offsets.gif", 5u,
151 kAnimationLoopInfinite); 151 kCAnimationLoopInfinite);
152 } 152 }
153 153
154 TEST(GIFImageDecoderTest, brokenSecondFrame) { 154 TEST(GIFImageDecoderTest, brokenSecondFrame) {
155 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); 155 std::unique_ptr<ImageDecoder> decoder = CreateDecoder();
156 156
157 RefPtr<SharedBuffer> data = ReadFile(kDecodersTestingDir, "broken.gif"); 157 RefPtr<SharedBuffer> data = ReadFile(kDecodersTestingDir, "broken.gif");
158 ASSERT_TRUE(data.Get()); 158 ASSERT_TRUE(data.Get());
159 decoder->SetData(data.Get(), true); 159 decoder->SetData(data.Get(), true);
160 160
161 // One frame is detected but cannot be decoded. 161 // One frame is detected but cannot be decoded.
(...skipping 30 matching lines...) Expand all
192 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); 192 std::unique_ptr<ImageDecoder> decoder = CreateDecoder();
193 193
194 RefPtr<SharedBuffer> data = ReadFile(kLayoutTestResourcesDir, "animated.gif"); 194 RefPtr<SharedBuffer> data = ReadFile(kLayoutTestResourcesDir, "animated.gif");
195 ASSERT_TRUE(data.Get()); 195 ASSERT_TRUE(data.Get());
196 decoder->SetData(data.Get(), true); 196 decoder->SetData(data.Get(), true);
197 197
198 EXPECT_EQ(2u, decoder->FrameCount()); 198 EXPECT_EQ(2u, decoder->FrameCount());
199 EXPECT_FALSE(decoder->Failed()); 199 EXPECT_FALSE(decoder->Failed());
200 EXPECT_TRUE(decoder->FrameIsCompleteAtIndex(0)); 200 EXPECT_TRUE(decoder->FrameIsCompleteAtIndex(0));
201 EXPECT_TRUE(decoder->FrameIsCompleteAtIndex(1)); 201 EXPECT_TRUE(decoder->FrameIsCompleteAtIndex(1));
202 EXPECT_EQ(kAnimationLoopInfinite, decoder->RepetitionCount()); 202 EXPECT_EQ(kCAnimationLoopInfinite, decoder->RepetitionCount());
203 } 203 }
204 204
205 TEST(GIFImageDecoderTest, frameIsCompleteLoading) { 205 TEST(GIFImageDecoderTest, frameIsCompleteLoading) {
206 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); 206 std::unique_ptr<ImageDecoder> decoder = CreateDecoder();
207 207
208 RefPtr<SharedBuffer> data = ReadFile(kLayoutTestResourcesDir, "animated.gif"); 208 RefPtr<SharedBuffer> data = ReadFile(kLayoutTestResourcesDir, "animated.gif");
209 ASSERT_TRUE(data.Get()); 209 ASSERT_TRUE(data.Get());
210 210
211 ASSERT_GE(data->size(), 10u); 211 ASSERT_GE(data->size(), 10u);
212 RefPtr<SharedBuffer> temp_data = 212 RefPtr<SharedBuffer> temp_data =
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 continue; 346 continue;
347 } 347 }
348 348
349 ASSERT_EQ(frame_size.Width(), decoder->DecodedSize().Width()); 349 ASSERT_EQ(frame_size.Width(), decoder->DecodedSize().Width());
350 ASSERT_EQ(frame_size.Height(), decoder->DecodedSize().Height()); 350 ASSERT_EQ(frame_size.Height(), decoder->DecodedSize().Height());
351 } 351 }
352 } 352 }
353 353
354 TEST(GIFImageDecoderTest, verifyRepetitionCount) { 354 TEST(GIFImageDecoderTest, verifyRepetitionCount) {
355 TestRepetitionCount(kLayoutTestResourcesDir, "full2loop.gif", 2); 355 TestRepetitionCount(kLayoutTestResourcesDir, "full2loop.gif", 2);
356 TestRepetitionCount(kDecodersTestingDir, "radient.gif", kAnimationNone); 356 TestRepetitionCount(kDecodersTestingDir, "radient.gif", kCAnimationNone);
357 } 357 }
358 358
359 TEST(GIFImageDecoderTest, bitmapAlphaType) { 359 TEST(GIFImageDecoderTest, bitmapAlphaType) {
360 RefPtr<SharedBuffer> full_data = ReadFile(kDecodersTestingDir, "radient.gif"); 360 RefPtr<SharedBuffer> full_data = ReadFile(kDecodersTestingDir, "radient.gif");
361 ASSERT_TRUE(full_data.Get()); 361 ASSERT_TRUE(full_data.Get());
362 362
363 // Empirically chosen truncation size: 363 // Empirically chosen truncation size:
364 // a) large enough to produce a partial frame && 364 // a) large enough to produce a partial frame &&
365 // b) small enough to not fully decode the frame 365 // b) small enough to not fully decode the frame
366 const size_t kTruncateSize = 800; 366 const size_t kTruncateSize = 800;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 EXPECT_EQ(1u, decoder->FrameCount()); 431 EXPECT_EQ(1u, decoder->FrameCount());
432 ImageFrame* frame = decoder->FrameBufferAtIndex(0); 432 ImageFrame* frame = decoder->FrameBufferAtIndex(0);
433 decoder->SetMemoryAllocator(nullptr); 433 decoder->SetMemoryAllocator(nullptr);
434 434
435 ASSERT_TRUE(frame); 435 ASSERT_TRUE(frame);
436 EXPECT_EQ(IntRect(IntPoint(), decoder->Size()), frame->OriginalFrameRect()); 436 EXPECT_EQ(IntRect(IntPoint(), decoder->Size()), frame->OriginalFrameRect());
437 EXPECT_FALSE(frame->HasAlpha()); 437 EXPECT_FALSE(frame->HasAlpha());
438 } 438 }
439 439
440 } // namespace blink 440 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698