OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "components/leveldb_proto/proto_database.h" | 9 #include "components/leveldb_proto/proto_database.h" |
10 #include "components/leveldb_proto/testing/fake_db.h" | 10 #include "components/leveldb_proto/testing/fake_db.h" |
11 #include "components/suggestions/image_fetcher.h" | 11 #include "components/suggestions/image_fetcher.h" |
12 #include "components/suggestions/image_fetcher_delegate.h" | 12 #include "components/suggestions/image_fetcher_delegate.h" |
13 #include "components/suggestions/image_manager.h" | 13 #include "components/suggestions/image_manager.h" |
14 #include "components/suggestions/proto/suggestions.pb.h" | 14 #include "components/suggestions/proto/suggestions.pb.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "ui/gfx/image/image_skia.h" | 17 #include "ui/gfx/image/image_skia.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 | 19 |
| 20 #if defined(OS_IOS) |
| 21 #include "components/suggestions/image_encoder_ios.h" |
| 22 #else |
| 23 #include "components/suggestions/image_encoder.h" |
| 24 #endif |
| 25 |
20 using ::testing::Return; | 26 using ::testing::Return; |
21 using ::testing::StrictMock; | 27 using ::testing::StrictMock; |
22 using ::testing::_; | 28 using ::testing::_; |
23 | 29 |
24 namespace suggestions { | 30 namespace suggestions { |
25 | 31 |
26 const char kTestUrl1[] = "http://go.com/"; | 32 const char kTestUrl1[] = "http://go.com/"; |
27 const char kTestUrl2[] = "http://goal.com/"; | 33 const char kTestUrl2[] = "http://goal.com/"; |
28 const char kTestImagePath[] = "files/image_decoding/droids.png"; | 34 const char kTestImagePath[] = "files/image_decoding/droids.png"; |
29 const char kInvalidImagePath[] = "files/DOESNOTEXIST"; | 35 const char kInvalidImagePath[] = "files/DOESNOTEXIST"; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 ImageData GetSampleImageData(const std::string& url) { | 91 ImageData GetSampleImageData(const std::string& url) { |
86 // Create test bitmap. | 92 // Create test bitmap. |
87 SkBitmap bm; | 93 SkBitmap bm; |
88 // Being careful with the Bitmap. There are memory-related issue in | 94 // Being careful with the Bitmap. There are memory-related issue in |
89 // crbug.com/101781. | 95 // crbug.com/101781. |
90 bm.allocN32Pixels(4, 4); | 96 bm.allocN32Pixels(4, 4); |
91 bm.eraseColor(SK_ColorRED); | 97 bm.eraseColor(SK_ColorRED); |
92 ImageData data; | 98 ImageData data; |
93 data.set_url(url); | 99 data.set_url(url); |
94 std::vector<unsigned char> encoded; | 100 std::vector<unsigned char> encoded; |
95 EXPECT_TRUE(ImageManager::EncodeImage(bm, &encoded)); | 101 EXPECT_TRUE(EncodeSkBitmapToJPEG(bm, &encoded)); |
96 data.set_data(std::string(encoded.begin(), encoded.end())); | 102 data.set_data(std::string(encoded.begin(), encoded.end())); |
97 return data; | 103 return data; |
98 } | 104 } |
99 | 105 |
100 void OnImageAvailable(base::RunLoop* loop, const GURL& url, | 106 void OnImageAvailable(base::RunLoop* loop, const GURL& url, |
101 const SkBitmap* bitmap) { | 107 const SkBitmap* bitmap) { |
102 if (bitmap) { | 108 if (bitmap) { |
103 num_callback_valid_called_++; | 109 num_callback_valid_called_++; |
104 } else { | 110 } else { |
105 num_callback_null_called_++; | 111 num_callback_null_called_++; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 image_manager_->GetImageForURL(GURL(kTestUrl1), | 193 image_manager_->GetImageForURL(GURL(kTestUrl1), |
188 base::Bind(&ImageManagerTest::OnImageAvailable, | 194 base::Bind(&ImageManagerTest::OnImageAvailable, |
189 base::Unretained(this), &run_loop)); | 195 base::Unretained(this), &run_loop)); |
190 run_loop.Run(); | 196 run_loop.Run(); |
191 | 197 |
192 EXPECT_EQ(0, num_callback_null_called_); | 198 EXPECT_EQ(0, num_callback_null_called_); |
193 EXPECT_EQ(1, num_callback_valid_called_); | 199 EXPECT_EQ(1, num_callback_valid_called_); |
194 } | 200 } |
195 | 201 |
196 } // namespace suggestions | 202 } // namespace suggestions |
OLD | NEW |