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

Side by Side Diff: Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp

Issue 1358643002: Fix caching bug in JPEGImageDecoder (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Respond to pkasting's comments in patch set 1 Created 5 years, 3 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
« no previous file with comments | « Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 TEST(JPEGImageDecoderTest, byteByByte) 234 TEST(JPEGImageDecoderTest, byteByByte)
235 { 235 {
236 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/len na.jpg", 1u, cAnimationNone); 236 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/len na.jpg", 1u, cAnimationNone);
237 // Progressive image 237 // Progressive image
238 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/flo wchart.jpg", 1u, cAnimationNone); 238 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/flo wchart.jpg", 1u, cAnimationNone);
239 // Image with restart markers 239 // Image with restart markers
240 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/red -at-12-oclock-with-color-profile.jpg", 1u, cAnimationNone); 240 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/red -at-12-oclock-with-color-profile.jpg", 1u, cAnimationNone);
241 } 241 }
242 242
243 static unsigned createDecodingBaseline(SharedBuffer* data)
244 {
245 OwnPtr<ImageDecoder> decoder = createDecoder();
246 decoder->setData(data, true);
247 ImageFrame* frame = decoder->frameBufferAtIndex(0);
248 return hashBitmap(frame->bitmap());
249 }
250
251 // This test verifies that calling SharedBuffer::mergeSegmentsIntoBuffer() does
252 // not break JPEG decoding at a critical point: in between a call to decode the
253 // size (when JPEGImageDecoder stops while it may still have input data to
254 // read) and a call to do a full decode.
255 TEST(JPEGImageDecoderTest, mergeBuffer)
256 {
257 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg";
258 RefPtr<SharedBuffer> data = readFile(jpegFile);
259 ASSERT_TRUE(data);
260
261 const unsigned hash = createDecodingBaseline(data.get());
262
263 // In order to do any verification, this test needs to move the data owned
264 // by the SharedBuffer. A way to guarantee that is to create a new one, and
265 // then append a string of characters greater than kSegmentSize. This
266 // results in writing the data into a segment, skipping the internal
267 // contiguous buffer.
268 RefPtr<SharedBuffer> segmentedData = SharedBuffer::create();
269 segmentedData->append(data->data(), data->size());
270
271 OwnPtr<ImageDecoder> decoder = createDecoder();
272 decoder->setData(segmentedData.get(), true);
273
274 ASSERT_TRUE(decoder->isSizeAvailable());
275
276 // This will call SharedBuffer::mergeSegmentsIntoBuffer, copying all
277 // segments into the contiguous buffer. If JPEGImageDecoder was pointing to
278 // data in a segment, its pointer would no longer be valid.
279 segmentedData->data();
280
281 ImageFrame* frame = decoder->frameBufferAtIndex(0);
282 ASSERT_FALSE(decoder->failed());
283 EXPECT_EQ(frame->status(), ImageFrame::FrameComplete);
284 EXPECT_EQ(hashBitmap(frame->bitmap()), hash);
285 }
286
243 } // namespace blink 287 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698