| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/chrome/browser/suggestions/ios_image_decoder_impl.h" | |
| 6 | |
| 7 #import <UIKit/UIKit.h> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/run_loop.h" | |
| 12 #include "base/threading/sequenced_worker_pool.h" | |
| 13 #include "base/threading/thread_task_runner_handle.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 #include "testing/platform_test.h" | |
| 16 #include "ui/gfx/geometry/size.h" | |
| 17 #include "ui/gfx/image/image.h" | |
| 18 | |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 20 #error "This file requires ARC support." | |
| 21 #endif | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 static unsigned char kJPGImage[] = { | |
| 26 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, | |
| 27 72, 0, 72, 0, 0, 255, 254, 0, 19, 67, 114, 101, 97, 116, 101, | |
| 28 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 255, 219, 0, 67, | |
| 29 0, 5, 3, 4, 4, 4, 3, 5, 4, 4, 4, 5, 5, 5, 6, | |
| 30 7, 12, 8, 7, 7, 7, 7, 15, 11, 11, 9, 12, 17, 15, 18, | |
| 31 18, 17, 15, 17, 17, 19, 22, 28, 23, 19, 20, 26, 21, 17, 17, | |
| 32 24, 33, 24, 26, 29, 29, 31, 31, 31, 19, 23, 34, 36, 34, 30, | |
| 33 36, 28, 30, 31, 30, 255, 219, 0, 67, 1, 5, 5, 5, 7, 6, | |
| 34 7, 14, 8, 8, 14, 30, 20, 17, 20, 30, 30, 30, 30, 30, 30, | |
| 35 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, | |
| 36 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, | |
| 37 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 255, | |
| 38 192, 0, 17, 8, 0, 1, 0, 1, 3, 1, 34, 0, 2, 17, 1, | |
| 39 3, 17, 1, 255, 196, 0, 21, 0, 1, 1, 0, 0, 0, 0, 0, | |
| 40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 255, 196, 0, 20, | |
| 41 16, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 42 0, 0, 0, 255, 196, 0, 20, 1, 1, 0, 0, 0, 0, 0, 0, | |
| 43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 196, 0, 20, 17, | |
| 44 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 45 0, 0, 255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, | |
| 46 0, 178, 192, 7, 255, 217}; | |
| 47 | |
| 48 static unsigned char kWEBPImage[] = { | |
| 49 82, 73, 70, 70, 74, 0, 0, 0, 87, 69, 66, 80, 86, 80, 56, 88, 10, | |
| 50 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 76, 80, 72, | |
| 51 12, 0, 0, 0, 1, 7, 16, 17, 253, 15, 68, 68, 255, 3, 0, 0, 86, | |
| 52 80, 56, 32, 24, 0, 0, 0, 48, 1, 0, 157, 1, 42, 1, 0, 1, 0, | |
| 53 3, 0, 52, 37, 164, 0, 3, 112, 0, 254, 251, 253, 80, 0}; | |
| 54 | |
| 55 } // namespace | |
| 56 | |
| 57 namespace suggestions { | |
| 58 | |
| 59 class IOSImageDecoderImplTest : public PlatformTest { | |
| 60 public: | |
| 61 void OnImageDecoded(const gfx::Image& image) { decoded_image_ = image; } | |
| 62 | |
| 63 protected: | |
| 64 IOSImageDecoderImplTest() | |
| 65 : pool_(new base::SequencedWorkerPool(2, | |
| 66 "TestPool", | |
| 67 base::TaskPriority::USER_VISIBLE)) { | |
| 68 ios_image_decoder_impl_ = CreateIOSImageDecoder(pool_); | |
| 69 } | |
| 70 | |
| 71 ~IOSImageDecoderImplTest() override { pool_->Shutdown(); } | |
| 72 | |
| 73 base::MessageLoop loop_; | |
| 74 scoped_refptr<base::SequencedWorkerPool> pool_; | |
| 75 std::unique_ptr<image_fetcher::ImageDecoder> ios_image_decoder_impl_; | |
| 76 | |
| 77 gfx::Image decoded_image_; | |
| 78 }; | |
| 79 | |
| 80 TEST_F(IOSImageDecoderImplTest, JPGImage) { | |
| 81 ASSERT_TRUE(decoded_image_.IsEmpty()); | |
| 82 | |
| 83 std::string image_data = | |
| 84 std::string(reinterpret_cast<char*>(kJPGImage), sizeof(kJPGImage)); | |
| 85 ios_image_decoder_impl_->DecodeImage( | |
| 86 image_data, gfx::Size(), | |
| 87 base::Bind(&IOSImageDecoderImplTest::OnImageDecoded, | |
| 88 base::Unretained(this))); | |
| 89 | |
| 90 pool_->FlushForTesting(); | |
| 91 base::RunLoop().RunUntilIdle(); | |
| 92 | |
| 93 EXPECT_FALSE(decoded_image_.IsEmpty()); | |
| 94 } | |
| 95 | |
| 96 TEST_F(IOSImageDecoderImplTest, WebpImage) { | |
| 97 ASSERT_TRUE(decoded_image_.IsEmpty()); | |
| 98 | |
| 99 std::string image_data = | |
| 100 std::string(reinterpret_cast<char*>(kWEBPImage), sizeof(kWEBPImage)); | |
| 101 ios_image_decoder_impl_->DecodeImage( | |
| 102 image_data, gfx::Size(), | |
| 103 base::Bind(&IOSImageDecoderImplTest::OnImageDecoded, | |
| 104 base::Unretained(this))); | |
| 105 | |
| 106 pool_->FlushForTesting(); | |
| 107 base::RunLoop().RunUntilIdle(); | |
| 108 | |
| 109 EXPECT_FALSE(decoded_image_.IsEmpty()); | |
| 110 } | |
| 111 | |
| 112 } // namespace suggestions | |
| OLD | NEW |