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 "extensions/browser/image_loader.h" | 5 #include "extensions/browser/image_loader.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "chrome/common/chrome_paths.h" | |
13 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
14 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread.h" |
15 #include "extensions/browser/component_extension_resource_manager.h" | |
16 #include "extensions/browser/extensions_browser_client.h" | 14 #include "extensions/browser/extensions_browser_client.h" |
17 #include "extensions/browser/notification_types.h" | 15 #include "extensions/browser/notification_types.h" |
18 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
19 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
20 #include "extensions/common/extension_icon_set.h" | 18 #include "extensions/common/extension_icon_set.h" |
| 19 #include "extensions/common/extension_paths.h" |
21 #include "extensions/common/extension_resource.h" | 20 #include "extensions/common/extension_resource.h" |
22 #include "extensions/common/manifest.h" | 21 #include "extensions/common/manifest.h" |
23 #include "extensions/common/manifest_handlers/icons_handler.h" | 22 #include "extensions/common/manifest_handlers/icons_handler.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
26 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
27 #include "ui/gfx/image/image_family.h" | 26 #include "ui/gfx/image/image_family.h" |
28 #include "ui/gfx/image/image_skia.h" | 27 #include "ui/gfx/image/image_skia.h" |
29 #include "ui/gfx/size.h" | 28 #include "ui/gfx/size.h" |
30 | 29 |
31 #if defined(OS_CHROMEOS) | 30 using content::BrowserThread; |
32 #include "ui/file_manager/grit/file_manager_resources.h" | 31 using content::NotificationService; |
33 #endif | |
34 | 32 |
35 using content::BrowserThread; | 33 namespace extensions { |
36 using extensions::Extension; | |
37 using extensions::ExtensionResource; | |
38 using extensions::ImageLoader; | |
39 using extensions::Manifest; | |
40 using extensions::UnloadedExtensionInfo; | |
41 | 34 |
42 class ImageLoaderTest : public testing::Test { | 35 class ImageLoaderTest : public testing::Test { |
43 public: | 36 public: |
44 ImageLoaderTest() | 37 ImageLoaderTest() |
45 : image_loaded_count_(0), | 38 : image_loaded_count_(0), |
46 quit_in_image_loaded_(false), | 39 quit_in_image_loaded_(false), |
47 ui_thread_(BrowserThread::UI, &ui_loop_), | 40 ui_thread_(BrowserThread::UI, &ui_loop_), |
48 file_thread_(BrowserThread::FILE), | 41 file_thread_(BrowserThread::FILE), |
49 io_thread_(BrowserThread::IO) { | 42 io_thread_(BrowserThread::IO), |
50 } | 43 notification_service_(NotificationService::Create()) {} |
51 | 44 |
52 void OnImageLoaded(const gfx::Image& image) { | 45 void OnImageLoaded(const gfx::Image& image) { |
53 image_loaded_count_++; | 46 image_loaded_count_++; |
54 if (quit_in_image_loaded_) | 47 if (quit_in_image_loaded_) |
55 base::MessageLoop::current()->Quit(); | 48 base::MessageLoop::current()->Quit(); |
56 image_ = image; | 49 image_ = image; |
57 } | 50 } |
58 | 51 |
59 void OnImageFamilyLoaded(const gfx::ImageFamily& image_family) { | 52 void OnImageFamilyLoaded(const gfx::ImageFamily& image_family) { |
60 image_loaded_count_++; | 53 image_loaded_count_++; |
61 if (quit_in_image_loaded_) | 54 if (quit_in_image_loaded_) |
62 base::MessageLoop::current()->Quit(); | 55 base::MessageLoop::current()->Quit(); |
63 image_family_ = image_family; | 56 image_family_ = image_family; |
64 } | 57 } |
65 | 58 |
66 void WaitForImageLoad() { | 59 void WaitForImageLoad() { |
67 quit_in_image_loaded_ = true; | 60 quit_in_image_loaded_ = true; |
68 base::MessageLoop::current()->Run(); | 61 base::MessageLoop::current()->Run(); |
69 quit_in_image_loaded_ = false; | 62 quit_in_image_loaded_ = false; |
70 } | 63 } |
71 | 64 |
72 int image_loaded_count() { | 65 int image_loaded_count() { |
73 int result = image_loaded_count_; | 66 int result = image_loaded_count_; |
74 image_loaded_count_ = 0; | 67 image_loaded_count_ = 0; |
75 return result; | 68 return result; |
76 } | 69 } |
77 | 70 |
78 scoped_refptr<Extension> CreateExtension(const char* name, | 71 scoped_refptr<Extension> CreateExtension(const char* dir_name, |
79 Manifest::Location location) { | 72 Manifest::Location location) { |
80 // Create and load an extension. | 73 // Create and load an extension. |
81 base::FilePath test_file; | 74 base::FilePath extension_dir; |
82 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_file)) { | 75 if (!PathService::Get(DIR_TEST_DATA, &extension_dir)) { |
83 EXPECT_FALSE(true); | 76 EXPECT_FALSE(true); |
84 return NULL; | 77 return NULL; |
85 } | 78 } |
86 test_file = test_file.AppendASCII("extensions") | 79 extension_dir = extension_dir.AppendASCII(dir_name); |
87 .AppendASCII(name); | |
88 int error_code = 0; | 80 int error_code = 0; |
89 std::string error; | 81 std::string error; |
90 JSONFileValueSerializer serializer(test_file.AppendASCII("app.json")); | 82 JSONFileValueSerializer serializer( |
| 83 extension_dir.AppendASCII("manifest.json")); |
91 scoped_ptr<base::DictionaryValue> valid_value( | 84 scoped_ptr<base::DictionaryValue> valid_value( |
92 static_cast<base::DictionaryValue*>(serializer.Deserialize(&error_code, | 85 static_cast<base::DictionaryValue*>(serializer.Deserialize(&error_code, |
93 &error))); | 86 &error))); |
94 EXPECT_EQ(0, error_code) << error; | 87 EXPECT_EQ(0, error_code) << error; |
95 if (error_code != 0) | 88 if (error_code != 0) |
96 return NULL; | 89 return NULL; |
97 | 90 |
98 EXPECT_TRUE(valid_value.get()); | 91 EXPECT_TRUE(valid_value.get()); |
99 if (!valid_value) | 92 if (!valid_value) |
100 return NULL; | 93 return NULL; |
101 | 94 |
102 if (location == Manifest::COMPONENT) { | 95 return Extension::Create( |
103 if (!PathService::Get(chrome::DIR_RESOURCES, &test_file)) { | 96 extension_dir, location, *valid_value, Extension::NO_FLAGS, &error); |
104 EXPECT_FALSE(true); | |
105 return NULL; | |
106 } | |
107 test_file = test_file.AppendASCII(name); | |
108 } | |
109 return Extension::Create(test_file, location, *valid_value, | |
110 Extension::NO_FLAGS, &error); | |
111 } | 97 } |
112 | 98 |
113 gfx::Image image_; | 99 gfx::Image image_; |
114 gfx::ImageFamily image_family_; | 100 gfx::ImageFamily image_family_; |
115 | 101 |
116 private: | 102 private: |
117 virtual void SetUp() OVERRIDE { | 103 virtual void SetUp() OVERRIDE { |
118 testing::Test::SetUp(); | 104 testing::Test::SetUp(); |
119 file_thread_.Start(); | 105 file_thread_.Start(); |
120 io_thread_.Start(); | 106 io_thread_.Start(); |
121 } | 107 } |
122 | 108 |
123 int image_loaded_count_; | 109 int image_loaded_count_; |
124 bool quit_in_image_loaded_; | 110 bool quit_in_image_loaded_; |
125 base::MessageLoop ui_loop_; | 111 base::MessageLoop ui_loop_; |
126 content::TestBrowserThread ui_thread_; | 112 content::TestBrowserThread ui_thread_; |
127 content::TestBrowserThread file_thread_; | 113 content::TestBrowserThread file_thread_; |
128 content::TestBrowserThread io_thread_; | 114 content::TestBrowserThread io_thread_; |
| 115 scoped_ptr<NotificationService> notification_service_; |
129 }; | 116 }; |
130 | 117 |
131 // Tests loading an image works correctly. | 118 // Tests loading an image works correctly. |
132 TEST_F(ImageLoaderTest, LoadImage) { | 119 TEST_F(ImageLoaderTest, LoadImage) { |
133 scoped_refptr<Extension> extension(CreateExtension( | 120 scoped_refptr<Extension> extension( |
134 "image_loading_tracker", Manifest::INVALID_LOCATION)); | 121 CreateExtension("image_loader", Manifest::INVALID_LOCATION)); |
135 ASSERT_TRUE(extension.get() != NULL); | 122 ASSERT_TRUE(extension.get() != NULL); |
136 | 123 |
137 ExtensionResource image_resource = extensions::IconsInfo::GetIconResource( | 124 ExtensionResource image_resource = |
138 extension.get(), | 125 IconsInfo::GetIconResource(extension.get(), |
139 extension_misc::EXTENSION_ICON_SMALLISH, | 126 extension_misc::EXTENSION_ICON_SMALLISH, |
140 ExtensionIconSet::MATCH_EXACTLY); | 127 ExtensionIconSet::MATCH_EXACTLY); |
141 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, | 128 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, |
142 extension_misc::EXTENSION_ICON_SMALLISH); | 129 extension_misc::EXTENSION_ICON_SMALLISH); |
143 ImageLoader loader; | 130 ImageLoader loader; |
144 loader.LoadImageAsync(extension.get(), | 131 loader.LoadImageAsync(extension.get(), |
145 image_resource, | 132 image_resource, |
146 max_size, | 133 max_size, |
147 base::Bind(&ImageLoaderTest::OnImageLoaded, | 134 base::Bind(&ImageLoaderTest::OnImageLoaded, |
148 base::Unretained(this))); | 135 base::Unretained(this))); |
149 | 136 |
150 // The image isn't cached, so we should not have received notification. | 137 // The image isn't cached, so we should not have received notification. |
151 EXPECT_EQ(0, image_loaded_count()); | 138 EXPECT_EQ(0, image_loaded_count()); |
152 | 139 |
153 WaitForImageLoad(); | 140 WaitForImageLoad(); |
154 | 141 |
155 // We should have gotten the image. | 142 // We should have gotten the image. |
| 143 EXPECT_FALSE(image_.IsEmpty()); |
156 EXPECT_EQ(1, image_loaded_count()); | 144 EXPECT_EQ(1, image_loaded_count()); |
157 | 145 |
158 // Check that the image was loaded. | 146 // Check that the image was loaded. |
159 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, | 147 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, |
160 image_.ToSkBitmap()->width()); | 148 image_.ToSkBitmap()->width()); |
161 } | 149 } |
162 | 150 |
163 // Tests deleting an extension while waiting for the image to load doesn't cause | 151 // Tests deleting an extension while waiting for the image to load doesn't cause |
164 // problems. | 152 // problems. |
165 TEST_F(ImageLoaderTest, DeleteExtensionWhileWaitingForCache) { | 153 TEST_F(ImageLoaderTest, DeleteExtensionWhileWaitingForCache) { |
166 scoped_refptr<Extension> extension(CreateExtension( | 154 scoped_refptr<Extension> extension( |
167 "image_loading_tracker", Manifest::INVALID_LOCATION)); | 155 CreateExtension("image_loader", Manifest::INVALID_LOCATION)); |
168 ASSERT_TRUE(extension.get() != NULL); | 156 ASSERT_TRUE(extension.get() != NULL); |
169 | 157 |
170 ExtensionResource image_resource = extensions::IconsInfo::GetIconResource( | 158 ExtensionResource image_resource = |
171 extension.get(), | 159 IconsInfo::GetIconResource(extension.get(), |
172 extension_misc::EXTENSION_ICON_SMALLISH, | 160 extension_misc::EXTENSION_ICON_SMALLISH, |
173 ExtensionIconSet::MATCH_EXACTLY); | 161 ExtensionIconSet::MATCH_EXACTLY); |
174 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, | 162 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, |
175 extension_misc::EXTENSION_ICON_SMALLISH); | 163 extension_misc::EXTENSION_ICON_SMALLISH); |
176 ImageLoader loader; | 164 ImageLoader loader; |
177 std::set<int> sizes; | 165 std::set<int> sizes; |
178 sizes.insert(extension_misc::EXTENSION_ICON_SMALLISH); | 166 sizes.insert(extension_misc::EXTENSION_ICON_SMALLISH); |
179 loader.LoadImageAsync(extension.get(), | 167 loader.LoadImageAsync(extension.get(), |
180 image_resource, | 168 image_resource, |
181 max_size, | 169 max_size, |
182 base::Bind(&ImageLoaderTest::OnImageLoaded, | 170 base::Bind(&ImageLoaderTest::OnImageLoaded, |
183 base::Unretained(this))); | 171 base::Unretained(this))); |
184 | 172 |
185 // The image isn't cached, so we should not have received notification. | 173 // The image isn't cached, so we should not have received notification. |
186 EXPECT_EQ(0, image_loaded_count()); | 174 EXPECT_EQ(0, image_loaded_count()); |
187 | 175 |
188 // Send out notification the extension was uninstalled. | 176 // Send out notification the extension was uninstalled. |
189 UnloadedExtensionInfo details(extension.get(), | 177 UnloadedExtensionInfo details(extension.get(), |
190 UnloadedExtensionInfo::REASON_UNINSTALL); | 178 UnloadedExtensionInfo::REASON_UNINSTALL); |
191 content::NotificationService::current()->Notify( | 179 content::NotificationService::current()->Notify( |
192 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 180 NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
193 content::NotificationService::AllSources(), | 181 content::NotificationService::AllSources(), |
194 content::Details<UnloadedExtensionInfo>(&details)); | 182 content::Details<UnloadedExtensionInfo>(&details)); |
195 | 183 |
196 // Chuck the extension, that way if anyone tries to access it we should crash | 184 // Chuck the extension, that way if anyone tries to access it we should crash |
197 // or get valgrind errors. | 185 // or get valgrind errors. |
198 extension = NULL; | 186 extension = NULL; |
199 | 187 |
200 WaitForImageLoad(); | 188 WaitForImageLoad(); |
201 | 189 |
202 // Even though we deleted the extension, we should still get the image. | 190 // Even though we deleted the extension, we should still get the image. |
203 // We should still have gotten the image. | 191 // We should still have gotten the image. |
204 EXPECT_EQ(1, image_loaded_count()); | 192 EXPECT_EQ(1, image_loaded_count()); |
205 | 193 |
206 // Check that the image was loaded. | 194 // Check that the image was loaded. |
207 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, | 195 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, |
208 image_.ToSkBitmap()->width()); | 196 image_.ToSkBitmap()->width()); |
209 } | 197 } |
210 | 198 |
211 // Tests loading multiple dimensions of the same image. | 199 // Tests loading multiple dimensions of the same image. |
212 TEST_F(ImageLoaderTest, MultipleImages) { | 200 TEST_F(ImageLoaderTest, MultipleImages) { |
213 scoped_refptr<Extension> extension(CreateExtension( | 201 scoped_refptr<Extension> extension( |
214 "image_loading_tracker", Manifest::INVALID_LOCATION)); | 202 CreateExtension("image_loader", Manifest::INVALID_LOCATION)); |
215 ASSERT_TRUE(extension.get() != NULL); | 203 ASSERT_TRUE(extension.get() != NULL); |
216 | 204 |
217 std::vector<ImageLoader::ImageRepresentation> info_list; | 205 std::vector<ImageLoader::ImageRepresentation> info_list; |
218 int sizes[] = {extension_misc::EXTENSION_ICON_BITTY, | 206 int sizes[] = {extension_misc::EXTENSION_ICON_BITTY, |
219 extension_misc::EXTENSION_ICON_SMALLISH, }; | 207 extension_misc::EXTENSION_ICON_SMALLISH, }; |
220 for (size_t i = 0; i < arraysize(sizes); ++i) { | 208 for (size_t i = 0; i < arraysize(sizes); ++i) { |
221 ExtensionResource resource = extensions::IconsInfo::GetIconResource( | 209 ExtensionResource resource = IconsInfo::GetIconResource( |
222 extension.get(), sizes[i], ExtensionIconSet::MATCH_EXACTLY); | 210 extension.get(), sizes[i], ExtensionIconSet::MATCH_EXACTLY); |
223 info_list.push_back(ImageLoader::ImageRepresentation( | 211 info_list.push_back(ImageLoader::ImageRepresentation( |
224 resource, | 212 resource, |
225 ImageLoader::ImageRepresentation::RESIZE_WHEN_LARGER, | 213 ImageLoader::ImageRepresentation::RESIZE_WHEN_LARGER, |
226 gfx::Size(sizes[i], sizes[i]), | 214 gfx::Size(sizes[i], sizes[i]), |
227 ui::SCALE_FACTOR_NONE)); | 215 ui::SCALE_FACTOR_NONE)); |
228 } | 216 } |
229 | 217 |
230 ImageLoader loader; | 218 ImageLoader loader; |
231 loader.LoadImagesAsync(extension.get(), info_list, | 219 loader.LoadImagesAsync(extension.get(), info_list, |
(...skipping 17 matching lines...) Expand all Loading... |
249 const gfx::ImageSkiaRep* img_rep2 = &image_reps[1]; | 237 const gfx::ImageSkiaRep* img_rep2 = &image_reps[1]; |
250 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY, | 238 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY, |
251 img_rep1->pixel_width()); | 239 img_rep1->pixel_width()); |
252 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, | 240 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, |
253 img_rep2->pixel_width()); | 241 img_rep2->pixel_width()); |
254 } | 242 } |
255 | 243 |
256 // Tests loading multiple dimensions of the same image into an image family. | 244 // Tests loading multiple dimensions of the same image into an image family. |
257 TEST_F(ImageLoaderTest, LoadImageFamily) { | 245 TEST_F(ImageLoaderTest, LoadImageFamily) { |
258 scoped_refptr<Extension> extension( | 246 scoped_refptr<Extension> extension( |
259 CreateExtension("image_loading_tracker", Manifest::INVALID_LOCATION)); | 247 CreateExtension("image_loader", Manifest::INVALID_LOCATION)); |
260 ASSERT_TRUE(extension.get() != NULL); | 248 ASSERT_TRUE(extension.get() != NULL); |
261 | 249 |
262 std::vector<ImageLoader::ImageRepresentation> info_list; | 250 std::vector<ImageLoader::ImageRepresentation> info_list; |
263 int sizes[] = {extension_misc::EXTENSION_ICON_BITTY, | 251 int sizes[] = {extension_misc::EXTENSION_ICON_BITTY, |
264 extension_misc::EXTENSION_ICON_SMALLISH, }; | 252 extension_misc::EXTENSION_ICON_SMALLISH, }; |
265 for (size_t i = 0; i < arraysize(sizes); ++i) { | 253 for (size_t i = 0; i < arraysize(sizes); ++i) { |
266 ExtensionResource resource = extensions::IconsInfo::GetIconResource( | 254 ExtensionResource resource = IconsInfo::GetIconResource( |
267 extension.get(), sizes[i], ExtensionIconSet::MATCH_EXACTLY); | 255 extension.get(), sizes[i], ExtensionIconSet::MATCH_EXACTLY); |
268 info_list.push_back(ImageLoader::ImageRepresentation( | 256 info_list.push_back(ImageLoader::ImageRepresentation( |
269 resource, | 257 resource, |
270 ImageLoader::ImageRepresentation::NEVER_RESIZE, | 258 ImageLoader::ImageRepresentation::NEVER_RESIZE, |
271 gfx::Size(sizes[i], sizes[i]), | 259 gfx::Size(sizes[i], sizes[i]), |
272 ui::SCALE_FACTOR_100P)); | 260 ui::SCALE_FACTOR_100P)); |
273 } | 261 } |
274 | 262 |
275 // Add a second icon of 200P which should get grouped with the smaller icon's | 263 // Add a second icon of 200P which should get grouped with the smaller icon's |
276 // ImageSkia. | 264 // ImageSkia. |
277 ExtensionResource resource = extensions::IconsInfo::GetIconResource( | 265 ExtensionResource resource = |
278 extension.get(), | 266 IconsInfo::GetIconResource(extension.get(), |
279 extension_misc::EXTENSION_ICON_SMALLISH, | 267 extension_misc::EXTENSION_ICON_SMALLISH, |
280 ExtensionIconSet::MATCH_EXACTLY); | 268 ExtensionIconSet::MATCH_EXACTLY); |
281 info_list.push_back(ImageLoader::ImageRepresentation( | 269 info_list.push_back(ImageLoader::ImageRepresentation( |
282 resource, | 270 resource, |
283 ImageLoader::ImageRepresentation::NEVER_RESIZE, | 271 ImageLoader::ImageRepresentation::NEVER_RESIZE, |
284 gfx::Size(extension_misc::EXTENSION_ICON_BITTY, | 272 gfx::Size(extension_misc::EXTENSION_ICON_BITTY, |
285 extension_misc::EXTENSION_ICON_BITTY), | 273 extension_misc::EXTENSION_ICON_BITTY), |
286 ui::SCALE_FACTOR_200P)); | 274 ui::SCALE_FACTOR_200P)); |
287 | 275 |
288 ImageLoader loader; | 276 ImageLoader loader; |
289 loader.LoadImageFamilyAsync(extension.get(), | 277 loader.LoadImageFamilyAsync(extension.get(), |
290 info_list, | 278 info_list, |
(...skipping 24 matching lines...) Expand all Loading... |
315 ASSERT_EQ(2u, image_reps.size()); | 303 ASSERT_EQ(2u, image_reps.size()); |
316 | 304 |
317 const gfx::ImageSkiaRep* img_rep1 = &image_reps[0]; | 305 const gfx::ImageSkiaRep* img_rep1 = &image_reps[0]; |
318 const gfx::ImageSkiaRep* img_rep2 = &image_reps[1]; | 306 const gfx::ImageSkiaRep* img_rep2 = &image_reps[1]; |
319 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY, img_rep1->pixel_width()); | 307 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY, img_rep1->pixel_width()); |
320 EXPECT_EQ(1.0f, img_rep1->scale()); | 308 EXPECT_EQ(1.0f, img_rep1->scale()); |
321 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, img_rep2->pixel_width()); | 309 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, img_rep2->pixel_width()); |
322 EXPECT_EQ(2.0f, img_rep2->scale()); | 310 EXPECT_EQ(2.0f, img_rep2->scale()); |
323 } | 311 } |
324 | 312 |
325 // Tests IsComponentExtensionResource function. | 313 } // namespace extensions |
326 // TODO(mukai): move this to ChromeComponentExtensionResourceManager's test. | |
327 TEST_F(ImageLoaderTest, IsComponentExtensionResource) { | |
328 extensions::ComponentExtensionResourceManager* resource_manager = | |
329 extensions::ExtensionsBrowserClient::Get()-> | |
330 GetComponentExtensionResourceManager(); | |
331 if (!resource_manager) | |
332 return; | |
333 | |
334 scoped_refptr<Extension> extension(CreateExtension( | |
335 "file_manager", Manifest::COMPONENT)); | |
336 ASSERT_TRUE(extension.get() != NULL); | |
337 | |
338 ExtensionResource resource = extensions::IconsInfo::GetIconResource( | |
339 extension.get(), | |
340 extension_misc::EXTENSION_ICON_BITTY, | |
341 ExtensionIconSet::MATCH_EXACTLY); | |
342 | |
343 #if defined(OS_CHROMEOS) | |
344 int resource_id; | |
345 ASSERT_TRUE(resource_manager->IsComponentExtensionResource( | |
346 extension->path(), | |
347 resource.relative_path(), | |
348 &resource_id)); | |
349 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); | |
350 #endif | |
351 } | |
OLD | NEW |