| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 #import "ios/chrome/browser/suggestions/ios_image_decoder_impl.h" | 5 #import "ios/chrome/browser/suggestions/ios_image_decoder_impl.h" |
| 6 | 6 |
| 7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| 16 #include "ui/gfx/geometry/size.h" |
| 16 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
| 17 | 18 |
| 18 #if !defined(__has_feature) || !__has_feature(objc_arc) | 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 19 #error "This file requires ARC support." | 20 #error "This file requires ARC support." |
| 20 #endif | 21 #endif |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 static unsigned char kJPGImage[] = { | 25 static unsigned char kJPGImage[] = { |
| 25 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, | 26 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 76 |
| 76 gfx::Image decoded_image_; | 77 gfx::Image decoded_image_; |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 TEST_F(IOSImageDecoderImplTest, JPGImage) { | 80 TEST_F(IOSImageDecoderImplTest, JPGImage) { |
| 80 ASSERT_TRUE(decoded_image_.IsEmpty()); | 81 ASSERT_TRUE(decoded_image_.IsEmpty()); |
| 81 | 82 |
| 82 std::string image_data = | 83 std::string image_data = |
| 83 std::string(reinterpret_cast<char*>(kJPGImage), sizeof(kJPGImage)); | 84 std::string(reinterpret_cast<char*>(kJPGImage), sizeof(kJPGImage)); |
| 84 ios_image_decoder_impl_->DecodeImage( | 85 ios_image_decoder_impl_->DecodeImage( |
| 85 image_data, base::Bind(&IOSImageDecoderImplTest::OnImageDecoded, | 86 image_data, gfx::Size(), |
| 86 base::Unretained(this))); | 87 base::Bind(&IOSImageDecoderImplTest::OnImageDecoded, |
| 88 base::Unretained(this))); |
| 87 | 89 |
| 88 pool_->FlushForTesting(); | 90 pool_->FlushForTesting(); |
| 89 base::RunLoop().RunUntilIdle(); | 91 base::RunLoop().RunUntilIdle(); |
| 90 | 92 |
| 91 EXPECT_FALSE(decoded_image_.IsEmpty()); | 93 EXPECT_FALSE(decoded_image_.IsEmpty()); |
| 92 } | 94 } |
| 93 | 95 |
| 94 TEST_F(IOSImageDecoderImplTest, WebpImage) { | 96 TEST_F(IOSImageDecoderImplTest, WebpImage) { |
| 95 ASSERT_TRUE(decoded_image_.IsEmpty()); | 97 ASSERT_TRUE(decoded_image_.IsEmpty()); |
| 96 | 98 |
| 97 std::string image_data = | 99 std::string image_data = |
| 98 std::string(reinterpret_cast<char*>(kWEBPImage), sizeof(kWEBPImage)); | 100 std::string(reinterpret_cast<char*>(kWEBPImage), sizeof(kWEBPImage)); |
| 99 ios_image_decoder_impl_->DecodeImage( | 101 ios_image_decoder_impl_->DecodeImage( |
| 100 image_data, base::Bind(&IOSImageDecoderImplTest::OnImageDecoded, | 102 image_data, gfx::Size(), |
| 101 base::Unretained(this))); | 103 base::Bind(&IOSImageDecoderImplTest::OnImageDecoded, |
| 104 base::Unretained(this))); |
| 102 | 105 |
| 103 pool_->FlushForTesting(); | 106 pool_->FlushForTesting(); |
| 104 base::RunLoop().RunUntilIdle(); | 107 base::RunLoop().RunUntilIdle(); |
| 105 | 108 |
| 106 EXPECT_FALSE(decoded_image_.IsEmpty()); | 109 EXPECT_FALSE(decoded_image_.IsEmpty()); |
| 107 } | 110 } |
| 108 | 111 |
| 109 } // namespace suggestions | 112 } // namespace suggestions |
| OLD | NEW |