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