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

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

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/image-decoders/ImageDecoderTestHelpers.h" 5 #include "platform/image-decoders/ImageDecoderTestHelpers.h"
6 6
7 #include "platform/SharedBuffer.h" 7 #include "platform/SharedBuffer.h"
8 #include "platform/image-decoders/ImageDecoder.h" 8 #include "platform/image-decoders/ImageDecoder.h"
9 #include "platform/image-decoders/ImageFrame.h" 9 #include "platform/image-decoders/ImageFrame.h"
10 #include "platform/testing/UnitTestHelpers.h" 10 #include "platform/testing/UnitTestHelpers.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "wtf/OwnPtr.h"
12 #include "wtf/StringHasher.h" 13 #include "wtf/StringHasher.h"
13 #include <memory>
14 14
15 namespace blink { 15 namespace blink {
16 16
17 PassRefPtr<SharedBuffer> readFile(const char* fileName) 17 PassRefPtr<SharedBuffer> readFile(const char* fileName)
18 { 18 {
19 String filePath = testing::blinkRootDir(); 19 String filePath = testing::blinkRootDir();
20 filePath.append(fileName); 20 filePath.append(fileName);
21 return testing::readFromFile(filePath); 21 return testing::readFromFile(filePath);
22 } 22 }
23 23
24 PassRefPtr<SharedBuffer> readFile(const char* dir, const char* fileName) 24 PassRefPtr<SharedBuffer> readFile(const char* dir, const char* fileName)
25 { 25 {
26 String filePath = testing::blinkRootDir(); 26 String filePath = testing::blinkRootDir();
27 filePath.append("/"); 27 filePath.append("/");
28 filePath.append(dir); 28 filePath.append(dir);
29 filePath.append("/"); 29 filePath.append("/");
30 filePath.append(fileName); 30 filePath.append(fileName);
31 31
32 return testing::readFromFile(filePath); 32 return testing::readFromFile(filePath);
33 } 33 }
34 34
35 unsigned hashBitmap(const SkBitmap& bitmap) 35 unsigned hashBitmap(const SkBitmap& bitmap)
36 { 36 {
37 return StringHasher::hashMemory(bitmap.getPixels(), bitmap.getSize()); 37 return StringHasher::hashMemory(bitmap.getPixels(), bitmap.getSize());
38 } 38 }
39 39
40 static unsigned createDecodingBaseline(DecoderCreator createDecoder, SharedBuffe r* data) 40 static unsigned createDecodingBaseline(DecoderCreator createDecoder, SharedBuffe r* data)
41 { 41 {
42 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 42 OwnPtr<ImageDecoder> decoder = createDecoder();
43 decoder->setData(data, true); 43 decoder->setData(data, true);
44 ImageFrame* frame = decoder->frameBufferAtIndex(0); 44 ImageFrame* frame = decoder->frameBufferAtIndex(0);
45 return hashBitmap(frame->bitmap()); 45 return hashBitmap(frame->bitmap());
46 } 46 }
47 47
48 void createDecodingBaseline(DecoderCreator createDecoder, SharedBuffer* data, Ve ctor<unsigned>* baselineHashes) 48 void createDecodingBaseline(DecoderCreator createDecoder, SharedBuffer* data, Ve ctor<unsigned>* baselineHashes)
49 { 49 {
50 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 50 OwnPtr<ImageDecoder> decoder = createDecoder();
51 decoder->setData(data, true); 51 decoder->setData(data, true);
52 size_t frameCount = decoder->frameCount(); 52 size_t frameCount = decoder->frameCount();
53 for (size_t i = 0; i < frameCount; ++i) { 53 for (size_t i = 0; i < frameCount; ++i) {
54 ImageFrame* frame = decoder->frameBufferAtIndex(i); 54 ImageFrame* frame = decoder->frameBufferAtIndex(i);
55 baselineHashes->append(hashBitmap(frame->bitmap())); 55 baselineHashes->append(hashBitmap(frame->bitmap()));
56 } 56 }
57 } 57 }
58 58
59 void testByteByByteDecode(DecoderCreator createDecoder, const char* file, size_t expectedFrameCount, int expectedRepetitionCount) 59 void testByteByByteDecode(DecoderCreator createDecoder, const char* file, size_t expectedFrameCount, int expectedRepetitionCount)
60 { 60 {
61 RefPtr<SharedBuffer> data = readFile(file); 61 RefPtr<SharedBuffer> data = readFile(file);
62 ASSERT_TRUE(data.get()); 62 ASSERT_TRUE(data.get());
63 ASSERT_TRUE(data->data()); 63 ASSERT_TRUE(data->data());
64 64
65 Vector<unsigned> baselineHashes; 65 Vector<unsigned> baselineHashes;
66 createDecodingBaseline(createDecoder, data.get(), &baselineHashes); 66 createDecodingBaseline(createDecoder, data.get(), &baselineHashes);
67 67
68 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 68 OwnPtr<ImageDecoder> decoder = createDecoder();
69 69
70 size_t frameCount = 0; 70 size_t frameCount = 0;
71 size_t framesDecoded = 0; 71 size_t framesDecoded = 0;
72 72
73 // Pass data to decoder byte by byte. 73 // Pass data to decoder byte by byte.
74 RefPtr<SharedBuffer> sourceData[2] = { SharedBuffer::create(), SharedBuffer: :create() }; 74 RefPtr<SharedBuffer> sourceData[2] = { SharedBuffer::create(), SharedBuffer: :create() };
75 const char* source = data->data(); 75 const char* source = data->data();
76 76
77 for (size_t length = 1; length <= data->size() && !decoder->failed(); ++leng th) { 77 for (size_t length = 1; length <= data->size() && !decoder->failed(); ++leng th) {
78 sourceData[0]->append(source, 1u); 78 sourceData[0]->append(source, 1u);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 const unsigned hash = createDecodingBaseline(createDecoder, data.get()); 122 const unsigned hash = createDecodingBaseline(createDecoder, data.get());
123 123
124 // In order to do any verification, this test needs to move the data owned 124 // In order to do any verification, this test needs to move the data owned
125 // by the SharedBuffer. A way to guarantee that is to create a new one, and 125 // by the SharedBuffer. A way to guarantee that is to create a new one, and
126 // then append a string of characters greater than kSegmentSize. This 126 // then append a string of characters greater than kSegmentSize. This
127 // results in writing the data into a segment, skipping the internal 127 // results in writing the data into a segment, skipping the internal
128 // contiguous buffer. 128 // contiguous buffer.
129 RefPtr<SharedBuffer> segmentedData = SharedBuffer::create(); 129 RefPtr<SharedBuffer> segmentedData = SharedBuffer::create();
130 segmentedData->append(data->data(), data->size()); 130 segmentedData->append(data->data(), data->size());
131 131
132 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 132 OwnPtr<ImageDecoder> decoder = createDecoder();
133 decoder->setData(segmentedData.get(), true); 133 decoder->setData(segmentedData.get(), true);
134 134
135 ASSERT_TRUE(decoder->isSizeAvailable()); 135 ASSERT_TRUE(decoder->isSizeAvailable());
136 136
137 // This will call SharedBuffer::mergeSegmentsIntoBuffer, copying all 137 // This will call SharedBuffer::mergeSegmentsIntoBuffer, copying all
138 // segments into the contiguous buffer. If the ImageDecoder was pointing to 138 // segments into the contiguous buffer. If the ImageDecoder was pointing to
139 // data in a segment, its pointer would no longer be valid. 139 // data in a segment, its pointer would no longer be valid.
140 segmentedData->data(); 140 segmentedData->data();
141 141
142 ImageFrame* frame = decoder->frameBufferAtIndex(0); 142 ImageFrame* frame = decoder->frameBufferAtIndex(0);
143 ASSERT_FALSE(decoder->failed()); 143 ASSERT_FALSE(decoder->failed());
144 EXPECT_EQ(frame->getStatus(), ImageFrame::FrameComplete); 144 EXPECT_EQ(frame->getStatus(), ImageFrame::FrameComplete);
145 EXPECT_EQ(hashBitmap(frame->bitmap()), hash); 145 EXPECT_EQ(hashBitmap(frame->bitmap()), hash);
146 } 146 }
147 147
148 } // namespace blink 148 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698