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/thread_task_runner_handle.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 #include "testing/platform_test.h" | |
15 #include "ui/gfx/image/image.h" | |
16 | |
17 namespace { | |
18 | |
19 static unsigned char kJPGImage[] = { | |
20 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, | |
21 72, 0, 72, 0, 0, 255, 254, 0, 19, 67, 114, 101, 97, 116, 101, | |
22 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 255, 219, 0, 67, | |
23 0, 5, 3, 4, 4, 4, 3, 5, 4, 4, 4, 5, 5, 5, 6, | |
24 7, 12, 8, 7, 7, 7, 7, 15, 11, 11, 9, 12, 17, 15, 18, | |
25 18, 17, 15, 17, 17, 19, 22, 28, 23, 19, 20, 26, 21, 17, 17, | |
26 24, 33, 24, 26, 29, 29, 31, 31, 31, 19, 23, 34, 36, 34, 30, | |
27 36, 28, 30, 31, 30, 255, 219, 0, 67, 1, 5, 5, 5, 7, 6, | |
28 7, 14, 8, 8, 14, 30, 20, 17, 20, 30, 30, 30, 30, 30, 30, | |
29 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, | |
30 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, | |
31 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 255, | |
32 192, 0, 17, 8, 0, 1, 0, 1, 3, 1, 34, 0, 2, 17, 1, | |
33 3, 17, 1, 255, 196, 0, 21, 0, 1, 1, 0, 0, 0, 0, 0, | |
34 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 255, 196, 0, 20, | |
35 16, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
36 0, 0, 0, 255, 196, 0, 20, 1, 1, 0, 0, 0, 0, 0, 0, | |
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 196, 0, 20, 17, | |
38 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
39 0, 0, 255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, | |
40 0, 178, 192, 7, 255, 217}; | |
41 | |
42 static unsigned char kWEBPImage[] = { | |
43 82, 73, 70, 70, 74, 0, 0, 0, 87, 69, 66, 80, 86, 80, 56, 88, 10, | |
44 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 76, 80, 72, | |
45 12, 0, 0, 0, 1, 7, 16, 17, 253, 15, 68, 68, 255, 3, 0, 0, 86, | |
46 80, 56, 32, 24, 0, 0, 0, 48, 1, 0, 157, 1, 42, 1, 0, 1, 0, | |
47 3, 0, 52, 37, 164, 0, 3, 112, 0, 254, 251, 253, 80, 0}; | |
48 | |
49 } // namespace | |
50 | |
51 namespace suggestions { | |
52 | |
53 class IOSImageDecoderImplTest : public PlatformTest { | |
noyau (Ping after 24h)
2016/09/09 15:20:02
I believe this test is now completely platform ind
vitaliii
2016/09/29 10:10:39
Acknowledged.
| |
54 public: | |
55 void OnImageDecoded(const gfx::Image& image) { decoded_image_ = image; } | |
56 | |
57 protected: | |
58 IOSImageDecoderImplTest() | |
59 : pool_(new base::SequencedWorkerPool(1, | |
60 "TestPool", | |
61 base::TaskPriority::USER_VISIBLE)) { | |
62 ios_image_decoder_impl_ = createIOSImageDecoder(pool_); | |
63 } | |
64 | |
65 ~IOSImageDecoderImplTest() override { pool_->Shutdown(); } | |
66 | |
67 base::MessageLoop loop_; | |
68 scoped_refptr<base::SequencedWorkerPool> pool_; | |
69 std::unique_ptr<image_fetcher::ImageDecoder> ios_image_decoder_impl_; | |
70 | |
71 gfx::Image decoded_image_; | |
72 }; | |
73 | |
74 TEST_F(IOSImageDecoderImplTest, JPGImage) { | |
75 ASSERT_TRUE(decoded_image_.IsEmpty()); | |
76 | |
77 std::string image_data = | |
78 std::string(reinterpret_cast<char*>(kJPGImage), sizeof(kJPGImage)); | |
79 ios_image_decoder_impl_->DecodeImage( | |
80 image_data, base::Bind(&IOSImageDecoderImplTest::OnImageDecoded, | |
81 base::Unretained(this))); | |
82 | |
83 pool_->FlushForTesting(); | |
84 base::RunLoop().RunUntilIdle(); | |
85 | |
86 EXPECT_FALSE(decoded_image_.IsEmpty()); | |
87 } | |
88 | |
89 TEST_F(IOSImageDecoderImplTest, WebpImage) { | |
90 ASSERT_TRUE(decoded_image_.IsEmpty()); | |
91 | |
92 std::string image_data = | |
93 std::string(reinterpret_cast<char*>(kWEBPImage), sizeof(kWEBPImage)); | |
94 ios_image_decoder_impl_->DecodeImage( | |
95 image_data, base::Bind(&IOSImageDecoderImplTest::OnImageDecoded, | |
96 base::Unretained(this))); | |
97 | |
98 pool_->FlushForTesting(); | |
99 base::RunLoop().RunUntilIdle(); | |
100 | |
101 EXPECT_FALSE(decoded_image_.IsEmpty()); | |
102 } | |
103 | |
104 } // namespace suggestions | |
OLD | NEW |