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

Side by Side Diff: content/test/image_decoder_test.cc

Issue 63253002: Rename WebKit namespace to blink (part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « content/test/image_decoder_test.h ('k') | content/test/layouttest_support.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/test/image_decoder_test.h" 5 #include "content/test/image_decoder_test.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_enumerator.h" 8 #include "base/files/file_enumerator.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/md5.h" 10 #include "base/md5.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 memcpy(&contents->at(0), raw_image_data.data(), raw_image_data.size()); 44 memcpy(&contents->at(0), raw_image_data.data(), raw_image_data.size());
45 } 45 }
46 46
47 base::FilePath GetMD5SumPath(const base::FilePath& path) { 47 base::FilePath GetMD5SumPath(const base::FilePath& path) {
48 static const base::FilePath::StringType kDecodedDataExtension( 48 static const base::FilePath::StringType kDecodedDataExtension(
49 FILE_PATH_LITERAL(".md5sum")); 49 FILE_PATH_LITERAL(".md5sum"));
50 return base::FilePath(path.value() + kDecodedDataExtension); 50 return base::FilePath(path.value() + kDecodedDataExtension);
51 } 51 }
52 52
53 #if defined(CALCULATE_MD5_SUMS) 53 #if defined(CALCULATE_MD5_SUMS)
54 void SaveMD5Sum(const base::FilePath& path, const WebKit::WebImage& web_image) { 54 void SaveMD5Sum(const base::FilePath& path, const blink::WebImage& web_image) {
55 // Calculate MD5 sum. 55 // Calculate MD5 sum.
56 base::MD5Digest digest; 56 base::MD5Digest digest;
57 web_image.getSkBitmap().lockPixels(); 57 web_image.getSkBitmap().lockPixels();
58 base::MD5Sum(web_image.getSkBitmap().getPixels(), 58 base::MD5Sum(web_image.getSkBitmap().getPixels(),
59 web_image.getSkBitmap().width() * web_image.getSkBitmap().height() * 59 web_image.getSkBitmap().width() * web_image.getSkBitmap().height() *
60 sizeof(uint32_t), 60 sizeof(uint32_t),
61 &digest); 61 &digest);
62 62
63 // Write sum to disk. 63 // Write sum to disk.
64 int bytes_written = file_util::WriteFile(path, 64 int bytes_written = file_util::WriteFile(path,
65 reinterpret_cast<const char*>(&digest), sizeof digest); 65 reinterpret_cast<const char*>(&digest), sizeof digest);
66 ASSERT_EQ(sizeof digest, bytes_written); 66 ASSERT_EQ(sizeof digest, bytes_written);
67 web_image.getSkBitmap().unlockPixels(); 67 web_image.getSkBitmap().unlockPixels();
68 } 68 }
69 #endif 69 #endif
70 70
71 #if !defined(CALCULATE_MD5_SUMS) 71 #if !defined(CALCULATE_MD5_SUMS)
72 void VerifyImage(const WebKit::WebImageDecoder& decoder, 72 void VerifyImage(const blink::WebImageDecoder& decoder,
73 const base::FilePath& path, 73 const base::FilePath& path,
74 const base::FilePath& md5_sum_path, 74 const base::FilePath& md5_sum_path,
75 size_t frame_index) { 75 size_t frame_index) {
76 // Make sure decoding can complete successfully. 76 // Make sure decoding can complete successfully.
77 EXPECT_TRUE(decoder.isSizeAvailable()) << path.value(); 77 EXPECT_TRUE(decoder.isSizeAvailable()) << path.value();
78 EXPECT_GE(decoder.frameCount(), frame_index) << path.value(); 78 EXPECT_GE(decoder.frameCount(), frame_index) << path.value();
79 EXPECT_TRUE(decoder.isFrameCompleteAtIndex(frame_index)) << path.value(); 79 EXPECT_TRUE(decoder.isFrameCompleteAtIndex(frame_index)) << path.value();
80 EXPECT_FALSE(decoder.isFailed()); 80 EXPECT_FALSE(decoder.isFailed());
81 81
82 // Calculate MD5 sum. 82 // Calculate MD5 sum.
83 base::MD5Digest actual_digest; 83 base::MD5Digest actual_digest;
84 WebKit::WebImage web_image = decoder.getFrameAtIndex(frame_index); 84 blink::WebImage web_image = decoder.getFrameAtIndex(frame_index);
85 web_image.getSkBitmap().lockPixels(); 85 web_image.getSkBitmap().lockPixels();
86 base::MD5Sum(web_image.getSkBitmap().getPixels(), 86 base::MD5Sum(web_image.getSkBitmap().getPixels(),
87 web_image.getSkBitmap().width() * web_image.getSkBitmap().height() * 87 web_image.getSkBitmap().width() * web_image.getSkBitmap().height() *
88 sizeof(uint32_t), 88 sizeof(uint32_t),
89 &actual_digest); 89 &actual_digest);
90 90
91 // Read the MD5 sum off disk. 91 // Read the MD5 sum off disk.
92 std::string file_bytes; 92 std::string file_bytes;
93 base::ReadFileToString(md5_sum_path, &file_bytes); 93 base::ReadFileToString(md5_sum_path, &file_bytes);
94 base::MD5Digest expected_digest; 94 base::MD5Digest expected_digest;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 bool should_test_failed_images = true; 172 bool should_test_failed_images = true;
173 #ifdef CALCULATE_MD5_SUMS 173 #ifdef CALCULATE_MD5_SUMS
174 // Do not test anything just get the md5 sums. 174 // Do not test anything just get the md5 sums.
175 should_test_chunking = false; 175 should_test_chunking = false;
176 should_test_failed_images = false; 176 should_test_failed_images = false;
177 #endif 177 #endif
178 178
179 std::vector<char> image_contents; 179 std::vector<char> image_contents;
180 ReadFileToVector(image_path, &image_contents); 180 ReadFileToVector(image_path, &image_contents);
181 EXPECT_TRUE(image_contents.size()); 181 EXPECT_TRUE(image_contents.size());
182 scoped_ptr<WebKit::WebImageDecoder> decoder(CreateWebKitImageDecoder()); 182 scoped_ptr<blink::WebImageDecoder> decoder(CreateWebKitImageDecoder());
183 EXPECT_FALSE(decoder->isFailed()); 183 EXPECT_FALSE(decoder->isFailed());
184 184
185 if (should_test_chunking) { 185 if (should_test_chunking) {
186 // Test chunking file into half. 186 // Test chunking file into half.
187 const int partial_size = image_contents.size()/2; 187 const int partial_size = image_contents.size()/2;
188 188
189 WebKit::WebData partial_data( 189 blink::WebData partial_data(
190 reinterpret_cast<const char*>(&(image_contents.at(0))), partial_size); 190 reinterpret_cast<const char*>(&(image_contents.at(0))), partial_size);
191 191
192 // Make Sure the image decoder doesn't fail when we ask for the frame 192 // Make Sure the image decoder doesn't fail when we ask for the frame
193 // buffer for this partial image. 193 // buffer for this partial image.
194 // NOTE: We can't check that frame 0 is non-NULL, because if this is an 194 // NOTE: We can't check that frame 0 is non-NULL, because if this is an
195 // ICO and we haven't yet supplied enough data to read the directory, 195 // ICO and we haven't yet supplied enough data to read the directory,
196 // there is no framecount and thus no first frame. 196 // there is no framecount and thus no first frame.
197 decoder->setData(const_cast<WebKit::WebData&>(partial_data), false); 197 decoder->setData(const_cast<blink::WebData&>(partial_data), false);
198 EXPECT_FALSE(decoder->isFailed()) << image_path.value(); 198 EXPECT_FALSE(decoder->isFailed()) << image_path.value();
199 } 199 }
200 200
201 // Make sure passing the complete image results in successful decoding. 201 // Make sure passing the complete image results in successful decoding.
202 WebKit::WebData data(reinterpret_cast<const char*>(&(image_contents.at(0))), 202 blink::WebData data(reinterpret_cast<const char*>(&(image_contents.at(0))),
203 image_contents.size()); 203 image_contents.size());
204 decoder->setData(const_cast<WebKit::WebData&>(data), true); 204 decoder->setData(const_cast<blink::WebData&>(data), true);
205 205
206 if (should_test_failed_images) { 206 if (should_test_failed_images) {
207 if (ShouldImageFail(image_path)) { 207 if (ShouldImageFail(image_path)) {
208 EXPECT_FALSE(decoder->isFrameCompleteAtIndex(kFirstFrameIndex)); 208 EXPECT_FALSE(decoder->isFrameCompleteAtIndex(kFirstFrameIndex));
209 EXPECT_TRUE(decoder->isFailed()); 209 EXPECT_TRUE(decoder->isFailed());
210 return; 210 return;
211 } 211 }
212 } 212 }
213 213
214 EXPECT_FALSE(decoder->isFailed()) << image_path.value(); 214 EXPECT_FALSE(decoder->isFailed()) << image_path.value();
215 215
216 #ifdef CALCULATE_MD5_SUMS 216 #ifdef CALCULATE_MD5_SUMS
217 // Since WebImage does not expose get data by frame, get the size 217 // Since WebImage does not expose get data by frame, get the size
218 // through decoder and pass it to fromData so that the closest 218 // through decoder and pass it to fromData so that the closest
219 // image dats to the size is returned. 219 // image dats to the size is returned.
220 WebKit::WebSize size(decoder->getImage(desired_frame_index).size()); 220 blink::WebSize size(decoder->getImage(desired_frame_index).size());
221 const WebKit::WebImage& image = WebKit::WebImage::fromData(data, size); 221 const blink::WebImage& image = blink::WebImage::fromData(data, size);
222 SaveMD5Sum(md5_sum_path, image); 222 SaveMD5Sum(md5_sum_path, image);
223 #else 223 #else
224 VerifyImage(*decoder, image_path, md5_sum_path, desired_frame_index); 224 VerifyImage(*decoder, image_path, md5_sum_path, desired_frame_index);
225 #endif 225 #endif
226 } 226 }
OLDNEW
« no previous file with comments | « content/test/image_decoder_test.h ('k') | content/test/layouttest_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698