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

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

Issue 19579005: Move ReadFileToString to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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 21 matching lines...) Expand all
32 32
33 int64 image_size = 0; 33 int64 image_size = 0;
34 file_util::GetFileSize(path, &image_size); 34 file_util::GetFileSize(path, &image_size);
35 return (file_selection == TEST_SMALLER) == (image_size > threshold); 35 return (file_selection == TEST_SMALLER) == (image_size > threshold);
36 } 36 }
37 37
38 } // namespace 38 } // namespace
39 39
40 void ReadFileToVector(const base::FilePath& path, std::vector<char>* contents) { 40 void ReadFileToVector(const base::FilePath& path, std::vector<char>* contents) {
41 std::string raw_image_data; 41 std::string raw_image_data;
42 file_util::ReadFileToString(path, &raw_image_data); 42 base::ReadFileToString(path, &raw_image_data);
43 contents->resize(raw_image_data.size()); 43 contents->resize(raw_image_data.size());
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
(...skipping 30 matching lines...) Expand all
83 base::MD5Digest actual_digest; 83 base::MD5Digest actual_digest;
84 WebKit::WebImage web_image = decoder.getFrameAtIndex(frame_index); 84 WebKit::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 file_util::ReadFileToString(md5_sum_path, &file_bytes); 93 base::ReadFileToString(md5_sum_path, &file_bytes);
94 base::MD5Digest expected_digest; 94 base::MD5Digest expected_digest;
95 ASSERT_EQ(sizeof expected_digest, file_bytes.size()) << path.value(); 95 ASSERT_EQ(sizeof expected_digest, file_bytes.size()) << path.value();
96 memcpy(&expected_digest, file_bytes.data(), sizeof expected_digest); 96 memcpy(&expected_digest, file_bytes.data(), sizeof expected_digest);
97 97
98 // Verify that the sums are the same. 98 // Verify that the sums are the same.
99 EXPECT_EQ(0, 99 EXPECT_EQ(0,
100 memcmp(&expected_digest, &actual_digest, sizeof(base::MD5Digest))) 100 memcmp(&expected_digest, &actual_digest, sizeof(base::MD5Digest)))
101 << path.value(); 101 << path.value();
102 web_image.getSkBitmap().unlockPixels(); 102 web_image.getSkBitmap().unlockPixels();
103 } 103 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 WebKit::WebSize size(decoder->getImage(desired_frame_index).size());
221 const WebKit::WebImage& image = WebKit::WebImage::fromData(data, size); 221 const WebKit::WebImage& image = WebKit::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/shell/browser/shell_message_filter.cc ('k') | content/test/net/url_request_mock_http_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698