| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/webp_transcode/webp_decoder.h" | 5 #include "ios/chrome/browser/webp_transcode/webp_decoder.h" |
| 6 | 6 |
| 7 #import <CoreGraphics/CoreGraphics.h> | 7 #import <CoreGraphics/CoreGraphics.h> |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 | 11 |
| 12 #include <memory> | 12 #include <memory> |
| 13 | 13 |
| 14 #include "base/base_paths.h" | 14 #include "base/base_paths.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 class WebpDecoderTest : public testing::Test { | 49 class WebpDecoderTest : public testing::Test { |
| 50 public: | 50 public: |
| 51 WebpDecoderTest() | 51 WebpDecoderTest() |
| 52 : delegate_(new WebpDecoderDelegate), | 52 : delegate_(new WebpDecoderDelegate), |
| 53 decoder_(new WebpDecoder(delegate_.get())) {} | 53 decoder_(new WebpDecoder(delegate_.get())) {} |
| 54 | 54 |
| 55 NSData* LoadImage(const base::FilePath& filename) { | 55 NSData* LoadImage(const base::FilePath& filename) { |
| 56 base::FilePath path; | 56 base::FilePath path; |
| 57 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 57 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 58 path = path.AppendASCII("components/test/data/webp_transcode") | 58 path = path.AppendASCII("ios/chrome/test/data/webp_transcode") |
| 59 .Append(filename); | 59 .Append(filename); |
| 60 return | 60 return |
| 61 [NSData dataWithContentsOfFile:base::SysUTF8ToNSString(path.value())]; | 61 [NSData dataWithContentsOfFile:base::SysUTF8ToNSString(path.value())]; |
| 62 } | 62 } |
| 63 | 63 |
| 64 std::vector<uint8_t>* DecompressData(NSData* data, | 64 std::vector<uint8_t>* DecompressData(NSData* data, |
| 65 WebpDecoder::DecodedImageFormat format) { | 65 WebpDecoder::DecodedImageFormat format) { |
| 66 base::ScopedCFTypeRef<CGDataProviderRef> provider( | 66 base::ScopedCFTypeRef<CGDataProviderRef> provider( |
| 67 CGDataProviderCreateWithCFData((CFDataRef)data)); | 67 CGDataProviderCreateWithCFData((CFDataRef)data)); |
| 68 base::ScopedCFTypeRef<CGImageRef> image; | 68 base::ScopedCFTypeRef<CGImageRef> image; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 // Load a WebP image from disk. | 220 // Load a WebP image from disk. |
| 221 base::scoped_nsobject<NSData> webp_image( | 221 base::scoped_nsobject<NSData> webp_image( |
| 222 [LoadImage(base::FilePath("test_small.webp")) retain]); | 222 [LoadImage(base::FilePath("test_small.webp")) retain]); |
| 223 ASSERT_TRUE(webp_image != nil); | 223 ASSERT_TRUE(webp_image != nil); |
| 224 // Load reference image. | 224 // Load reference image. |
| 225 base::scoped_nsobject<NSData> tiff_image( | 225 base::scoped_nsobject<NSData> tiff_image( |
| 226 [LoadImage(base::FilePath("test_small.tiff")) retain]); | 226 [LoadImage(base::FilePath("test_small.tiff")) retain]); |
| 227 ASSERT_TRUE(tiff_image != nil); | 227 ASSERT_TRUE(tiff_image != nil); |
| 228 // Convert to TIFF. | 228 // Convert to TIFF. |
| 229 EXPECT_CALL(*delegate_, OnFinishedDecoding(true)).Times(1); | 229 EXPECT_CALL(*delegate_, OnFinishedDecoding(true)).Times(1); |
| 230 EXPECT_CALL(*delegate_, SetImageFeatures([tiff_image length], | 230 EXPECT_CALL(*delegate_, |
| 231 WebpDecoder::TIFF)).Times(1); | 231 SetImageFeatures([tiff_image length], WebpDecoder::TIFF)) |
| 232 .Times(1); |
| 232 decoder_->OnDataReceived(webp_image); | 233 decoder_->OnDataReceived(webp_image); |
| 233 // Compare to reference image. | 234 // Compare to reference image. |
| 234 EXPECT_TRUE(CheckTiffImagesEqual(tiff_image, delegate_->GetImage())); | 235 EXPECT_TRUE(CheckTiffImagesEqual(tiff_image, delegate_->GetImage())); |
| 235 } | 236 } |
| 236 | 237 |
| 237 TEST_F(WebpDecoderTest, StreamedDecode) { | 238 TEST_F(WebpDecoderTest, StreamedDecode) { |
| 238 // TODO(droger): This test fails on iOS 9 x64 devices. http://crbug.com/523235 | 239 // TODO(droger): This test fails on iOS 9 x64 devices. http://crbug.com/523235 |
| 239 #if defined(OS_IOS) && defined(ARCH_CPU_ARM64) && !TARGET_IPHONE_SIMULATOR | 240 #if defined(OS_IOS) && defined(ARCH_CPU_ARM64) && !TARGET_IPHONE_SIMULATOR |
| 240 if (base::ios::IsRunningOnIOS9OrLater()) | 241 if (base::ios::IsRunningOnIOS9OrLater()) |
| 241 return; | 242 return; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 EXPECT_EQ(0u, [delegate_->GetImage() length]); | 283 EXPECT_EQ(0u, [delegate_->GetImage() length]); |
| 283 } | 284 } |
| 284 | 285 |
| 285 TEST_F(WebpDecoderTest, DecodeAborted) { | 286 TEST_F(WebpDecoderTest, DecodeAborted) { |
| 286 EXPECT_CALL(*delegate_, OnFinishedDecoding(false)).Times(1); | 287 EXPECT_CALL(*delegate_, OnFinishedDecoding(false)).Times(1); |
| 287 decoder_->Stop(); | 288 decoder_->Stop(); |
| 288 EXPECT_EQ(0u, [delegate_->GetImage() length]); | 289 EXPECT_EQ(0u, [delegate_->GetImage() length]); |
| 289 } | 290 } |
| 290 | 291 |
| 291 } // namespace webp_transcode | 292 } // namespace webp_transcode |
| OLD | NEW |