| OLD | NEW |
| 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 <stddef.h> |
| 8 |
| 7 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 10 #include "base/md5.h" | 12 #include "base/md5.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 13 #include "base/strings/pattern.h" | 15 #include "base/strings/pattern.h" |
| 14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "build/build_config.h" |
| 16 #include "third_party/WebKit/public/platform/WebData.h" | 19 #include "third_party/WebKit/public/platform/WebData.h" |
| 17 #include "third_party/WebKit/public/platform/WebImage.h" | 20 #include "third_party/WebKit/public/platform/WebImage.h" |
| 18 #include "third_party/WebKit/public/platform/WebSize.h" | 21 #include "third_party/WebKit/public/platform/WebSize.h" |
| 19 #include "third_party/WebKit/public/web/WebImageDecoder.h" | 22 #include "third_party/WebKit/public/web/WebImageDecoder.h" |
| 20 | 23 |
| 21 // Uncomment this to recalculate the MD5 sums; see header comments. | 24 // Uncomment this to recalculate the MD5 sums; see header comments. |
| 22 // #define CALCULATE_MD5_SUMS | 25 // #define CALCULATE_MD5_SUMS |
| 23 | 26 |
| 24 namespace { | 27 namespace { |
| 25 | 28 |
| 26 const int kFirstFrameIndex = 0; | 29 const int kFirstFrameIndex = 0; |
| 27 | 30 |
| 28 // Determine if we should test with file specified by |path| based | 31 // Determine if we should test with file specified by |path| based |
| 29 // on |file_selection| and the |threshold| for the file size. | 32 // on |file_selection| and the |threshold| for the file size. |
| 30 bool ShouldSkipFile(const base::FilePath& path, | 33 bool ShouldSkipFile(const base::FilePath& path, |
| 31 ImageDecoderTestFileSelection file_selection, | 34 ImageDecoderTestFileSelection file_selection, |
| 32 const int64 threshold) { | 35 const int64_t threshold) { |
| 33 if (file_selection == TEST_ALL) | 36 if (file_selection == TEST_ALL) |
| 34 return false; | 37 return false; |
| 35 | 38 |
| 36 int64 image_size = 0; | 39 int64_t image_size = 0; |
| 37 base::GetFileSize(path, &image_size); | 40 base::GetFileSize(path, &image_size); |
| 38 return (file_selection == TEST_SMALLER) == (image_size > threshold); | 41 return (file_selection == TEST_SMALLER) == (image_size > threshold); |
| 39 } | 42 } |
| 40 | 43 |
| 41 } // namespace | 44 } // namespace |
| 42 | 45 |
| 43 void ReadFileToVector(const base::FilePath& path, std::vector<char>* contents) { | 46 void ReadFileToVector(const base::FilePath& path, std::vector<char>* contents) { |
| 44 std::string raw_image_data; | 47 std::string raw_image_data; |
| 45 base::ReadFileToString(path, &raw_image_data); | 48 base::ReadFileToString(path, &raw_image_data); |
| 46 contents->resize(raw_image_data.size()); | 49 contents->resize(raw_image_data.size()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 bool ImageDecoderTest::ShouldImageFail(const base::FilePath& path) const { | 146 bool ImageDecoderTest::ShouldImageFail(const base::FilePath& path) const { |
| 144 const base::FilePath::StringType kBadSuffix(FILE_PATH_LITERAL(".bad.")); | 147 const base::FilePath::StringType kBadSuffix(FILE_PATH_LITERAL(".bad.")); |
| 145 return (path.value().length() > (kBadSuffix.length() + format_.length()) && | 148 return (path.value().length() > (kBadSuffix.length() + format_.length()) && |
| 146 !path.value().compare(path.value().length() - format_.length() - | 149 !path.value().compare(path.value().length() - format_.length() - |
| 147 kBadSuffix.length(), | 150 kBadSuffix.length(), |
| 148 kBadSuffix.length(), kBadSuffix)); | 151 kBadSuffix.length(), kBadSuffix)); |
| 149 } | 152 } |
| 150 | 153 |
| 151 void ImageDecoderTest::TestDecoding( | 154 void ImageDecoderTest::TestDecoding( |
| 152 ImageDecoderTestFileSelection file_selection, | 155 ImageDecoderTestFileSelection file_selection, |
| 153 const int64 threshold) { | 156 const int64_t threshold) { |
| 154 if (data_dir_.empty()) | 157 if (data_dir_.empty()) |
| 155 return; | 158 return; |
| 156 const std::vector<base::FilePath> image_files(GetImageFiles()); | 159 const std::vector<base::FilePath> image_files(GetImageFiles()); |
| 157 for (std::vector<base::FilePath>::const_iterator i = image_files.begin(); | 160 for (std::vector<base::FilePath>::const_iterator i = image_files.begin(); |
| 158 i != image_files.end(); ++i) { | 161 i != image_files.end(); ++i) { |
| 159 if (!ShouldSkipFile(*i, file_selection, threshold)) | 162 if (!ShouldSkipFile(*i, file_selection, threshold)) |
| 160 TestWebKitImageDecoder(*i, GetMD5SumPath(*i), kFirstFrameIndex); | 163 TestWebKitImageDecoder(*i, GetMD5SumPath(*i), kFirstFrameIndex); |
| 161 } | 164 } |
| 162 } | 165 } |
| 163 | 166 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 EXPECT_TRUE(decoder->isFailed()); | 205 EXPECT_TRUE(decoder->isFailed()); |
| 203 } else { | 206 } else { |
| 204 EXPECT_FALSE(decoder->isFailed()) << image_path.value(); | 207 EXPECT_FALSE(decoder->isFailed()) << image_path.value(); |
| 205 #if defined(CALCULATE_MD5_SUMS) | 208 #if defined(CALCULATE_MD5_SUMS) |
| 206 SaveMD5Sum(md5_sum_path, decoder->getFrameAtIndex(desired_frame_index)); | 209 SaveMD5Sum(md5_sum_path, decoder->getFrameAtIndex(desired_frame_index)); |
| 207 #else | 210 #else |
| 208 VerifyImage(*decoder, image_path, md5_sum_path, desired_frame_index); | 211 VerifyImage(*decoder, image_path, md5_sum_path, desired_frame_index); |
| 209 #endif | 212 #endif |
| 210 } | 213 } |
| 211 } | 214 } |
| OLD | NEW |