| 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 "webkit/tools/test_shell/image_decoder_unittest.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_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/md5.h" | 9 #include "base/md5.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" | 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" |
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebImage.h" | 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebImage.h" |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 web_image.getSkBitmap().unlockPixels(); | 101 web_image.getSkBitmap().unlockPixels(); |
| 102 } | 102 } |
| 103 #endif | 103 #endif |
| 104 | 104 |
| 105 void ImageDecoderTest::SetUp() { | 105 void ImageDecoderTest::SetUp() { |
| 106 base::FilePath data_dir; | 106 base::FilePath data_dir; |
| 107 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_dir)); | 107 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_dir)); |
| 108 data_dir_ = data_dir.AppendASCII("webkit"). | 108 data_dir_ = data_dir.AppendASCII("webkit"). |
| 109 AppendASCII("data"). | 109 AppendASCII("data"). |
| 110 AppendASCII(format_ + "_decoder"); | 110 AppendASCII(format_ + "_decoder"); |
| 111 ASSERT_TRUE(file_util::PathExists(data_dir_)) << data_dir_.value(); | 111 if (!file_util::PathExists(data_dir_)) { |
| 112 const testing::TestInfo* const test_info = |
| 113 testing::UnitTest::GetInstance()->current_test_info(); |
| 114 LOG(INFO) << test_info->name() << |
| 115 " not running because test data wasn't found."; |
| 116 data_dir_.clear(); |
| 117 return; |
| 118 } |
| 112 } | 119 } |
| 113 | 120 |
| 114 std::vector<base::FilePath> ImageDecoderTest::GetImageFiles() const { | 121 std::vector<base::FilePath> ImageDecoderTest::GetImageFiles() const { |
| 115 std::string pattern = "*." + format_; | 122 std::string pattern = "*." + format_; |
| 116 | 123 |
| 117 file_util::FileEnumerator enumerator(data_dir_, | 124 file_util::FileEnumerator enumerator(data_dir_, |
| 118 false, | 125 false, |
| 119 file_util::FileEnumerator::FILES); | 126 file_util::FileEnumerator::FILES); |
| 120 | 127 |
| 121 std::vector<base::FilePath> image_files; | 128 std::vector<base::FilePath> image_files; |
| 122 base::FilePath next_file_name; | 129 base::FilePath next_file_name; |
| 123 while (!(next_file_name = enumerator.Next()).empty()) { | 130 while (!(next_file_name = enumerator.Next()).empty()) { |
| 124 base::FilePath base_name = next_file_name.BaseName(); | 131 base::FilePath base_name = next_file_name.BaseName(); |
| 125 #if defined(OS_WIN) | 132 #if defined(OS_WIN) |
| 126 std::string base_name_ascii = WideToASCII(base_name.value()); | 133 std::string base_name_ascii = WideToASCII(base_name.value()); |
| 127 #else | 134 #else |
| 128 std::string base_name_ascii = base_name.value(); | 135 std::string base_name_ascii = base_name.value(); |
| 129 #endif | 136 #endif |
| 130 if (!MatchPattern(base_name_ascii, pattern)) | 137 if (!MatchPattern(base_name_ascii, pattern)) |
| 131 continue; | 138 continue; |
| 132 image_files.push_back(next_file_name); | 139 image_files.push_back(next_file_name); |
| 133 } | 140 } |
| 134 | 141 |
| 135 return image_files; | 142 return image_files; |
| 136 } | 143 } |
| 137 | 144 |
| 138 bool ImageDecoderTest::ShouldImageFail(const base::FilePath& path) const { | 145 bool ImageDecoderTest::ShouldImageFail(const base::FilePath& path) const { |
| 139 static const base::FilePath::StringType kBadSuffix(FILE_PATH_LITERAL(".bad."))
; | 146 const base::FilePath::StringType kBadSuffix(FILE_PATH_LITERAL(".bad.")); |
| 140 return (path.value().length() > (kBadSuffix.length() + format_.length()) && | 147 return (path.value().length() > (kBadSuffix.length() + format_.length()) && |
| 141 !path.value().compare(path.value().length() - format_.length() - | 148 !path.value().compare(path.value().length() - format_.length() - |
| 142 kBadSuffix.length(), | 149 kBadSuffix.length(), |
| 143 kBadSuffix.length(), kBadSuffix)); | 150 kBadSuffix.length(), kBadSuffix)); |
| 144 } | 151 } |
| 145 | 152 |
| 146 void ImageDecoderTest::TestDecoding( | 153 void ImageDecoderTest::TestDecoding( |
| 147 ImageDecoderTestFileSelection file_selection, | 154 ImageDecoderTestFileSelection file_selection, |
| 148 const int64 threshold) { | 155 const int64 threshold) { |
| 156 if (data_dir_.empty()) |
| 157 return; |
| 149 const std::vector<base::FilePath> image_files(GetImageFiles()); | 158 const std::vector<base::FilePath> image_files(GetImageFiles()); |
| 150 for (std::vector<base::FilePath>::const_iterator i = image_files.begin(); | 159 for (std::vector<base::FilePath>::const_iterator i = image_files.begin(); |
| 151 i != image_files.end(); ++i) { | 160 i != image_files.end(); ++i) { |
| 152 if (ShouldSkipFile(*i, file_selection, threshold)) | 161 if (ShouldSkipFile(*i, file_selection, threshold)) |
| 153 continue; | 162 continue; |
| 154 const base::FilePath md5_sum_path(GetMD5SumPath(*i)); | 163 const base::FilePath md5_sum_path(GetMD5SumPath(*i)); |
| 155 TestWebKitImageDecoder(*i, md5_sum_path, kFirstFrameIndex); | 164 TestWebKitImageDecoder(*i, md5_sum_path, kFirstFrameIndex); |
| 156 } | 165 } |
| 157 } | 166 } |
| 158 | 167 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 // Since WebImage does not expose get data by frame, get the size | 216 // Since WebImage does not expose get data by frame, get the size |
| 208 // through decoder and pass it to fromData so that the closest | 217 // through decoder and pass it to fromData so that the closest |
| 209 // image dats to the size is returned. | 218 // image dats to the size is returned. |
| 210 WebKit::WebSize size(decoder->getImage(desired_frame_index).size()); | 219 WebKit::WebSize size(decoder->getImage(desired_frame_index).size()); |
| 211 const WebKit::WebImage& image = WebKit::WebImage::fromData(data, size); | 220 const WebKit::WebImage& image = WebKit::WebImage::fromData(data, size); |
| 212 SaveMD5Sum(md5_sum_path, image); | 221 SaveMD5Sum(md5_sum_path, image); |
| 213 #else | 222 #else |
| 214 VerifyImage(*decoder, image_path, md5_sum_path, desired_frame_index); | 223 VerifyImage(*decoder, image_path, md5_sum_path, desired_frame_index); |
| 215 #endif | 224 #endif |
| 216 } | 225 } |
| OLD | NEW |