Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(710)

Side by Side Diff: extensions/browser/extension_icon_image_unittest.cc

Issue 546933002: Move ExtensionIconImageTest to extensions_unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | extensions/extensions.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/extension_icon_image.h" 5 #include "extensions/browser/extension_icon_image.h"
6 6
7 #include <vector>
8
7 #include "base/json/json_file_value_serializer.h" 9 #include "base/json/json_file_value_serializer.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "base/path_service.h" 11 #include "base/path_service.h"
10 #include "chrome/test/base/testing_profile.h" 12 #include "content/public/browser/notification_service.h"
13 #include "content/public/test/test_browser_context.h"
11 #include "content/public/test/test_browser_thread.h" 14 #include "content/public/test/test_browser_thread.h"
15 #include "extensions/browser/extensions_test.h"
12 #include "extensions/browser/image_loader.h" 16 #include "extensions/browser/image_loader.h"
13 #include "extensions/common/extension.h" 17 #include "extensions/common/extension.h"
14 #include "extensions/common/extension_paths.h" 18 #include "extensions/common/extension_paths.h"
15 #include "extensions/common/manifest.h" 19 #include "extensions/common/manifest.h"
16 #include "extensions/common/manifest_handlers/icons_handler.h" 20 #include "extensions/common/manifest_handlers/icons_handler.h"
17 #include "skia/ext/image_operations.h" 21 #include "skia/ext/image_operations.h"
18 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/image/image_skia_source.h" 24 #include "ui/gfx/image/image_skia_source.h"
21 #include "ui/gfx/skia_util.h" 25 #include "ui/gfx/skia_util.h"
22 26
23 using content::BrowserThread; 27 using content::BrowserThread;
24 using extensions::Extension;
25 using extensions::IconImage;
26 using extensions::Manifest;
27 28
29 namespace extensions {
28 namespace { 30 namespace {
29 31
30 SkBitmap CreateBlankBitmapForScale(int size_dip, ui::ScaleFactor scale_factor) { 32 SkBitmap CreateBlankBitmapForScale(int size_dip, ui::ScaleFactor scale_factor) {
31 SkBitmap bitmap; 33 SkBitmap bitmap;
32 const float scale = ui::GetScaleForScaleFactor(scale_factor); 34 const float scale = ui::GetScaleForScaleFactor(scale_factor);
33 bitmap.allocN32Pixels(static_cast<int>(size_dip * scale), 35 bitmap.allocN32Pixels(static_cast<int>(size_dip * scale),
34 static_cast<int>(size_dip * scale)); 36 static_cast<int>(size_dip * scale));
35 bitmap.eraseColor(SkColorSetARGB(0, 0, 0, 0)); 37 bitmap.eraseColor(SkColorSetARGB(0, 0, 0, 0));
36 return bitmap; 38 return bitmap;
37 } 39 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 EXPECT_TRUE(image_loaded_); 102 EXPECT_TRUE(image_loaded_);
101 103
102 return image_.IsEmpty() ? SkBitmap() : *image_.ToSkBitmap(); 104 return image_.IsEmpty() ? SkBitmap() : *image_.ToSkBitmap();
103 } 105 }
104 106
105 private: 107 private:
106 const Extension* extension_; 108 const Extension* extension_;
107 bool waiting_; 109 bool waiting_;
108 bool image_loaded_; 110 bool image_loaded_;
109 gfx::Image image_; 111 gfx::Image image_;
110 extensions::ImageLoader image_loader_; 112 ImageLoader image_loader_;
111 113
112 DISALLOW_COPY_AND_ASSIGN(TestImageLoader); 114 DISALLOW_COPY_AND_ASSIGN(TestImageLoader);
113 }; 115 };
114 116
115 class ExtensionIconImageTest : public testing::Test, 117 class ExtensionIconImageTest : public ExtensionsTest,
116 public IconImage::Observer { 118 public IconImage::Observer {
117 public: 119 public:
118 ExtensionIconImageTest() 120 ExtensionIconImageTest()
119 : image_loaded_count_(0), 121 : image_loaded_count_(0),
120 quit_in_image_loaded_(false), 122 quit_in_image_loaded_(false),
121 ui_thread_(BrowserThread::UI, &ui_loop_), 123 ui_thread_(BrowserThread::UI, &ui_loop_),
122 file_thread_(BrowserThread::FILE), 124 file_thread_(BrowserThread::FILE),
123 io_thread_(BrowserThread::IO) { 125 io_thread_(BrowserThread::IO),
124 } 126 notification_service_(content::NotificationService::Create()) {}
125 127
126 virtual ~ExtensionIconImageTest() {} 128 virtual ~ExtensionIconImageTest() {}
127 129
128 void WaitForImageLoad() { 130 void WaitForImageLoad() {
129 quit_in_image_loaded_ = true; 131 quit_in_image_loaded_ = true;
130 base::MessageLoop::current()->Run(); 132 base::MessageLoop::current()->Run();
131 quit_in_image_loaded_ = false; 133 quit_in_image_loaded_ = false;
132 } 134 }
133 135
134 int ImageLoadedCount() { 136 int ImageLoadedCount() {
135 int result = image_loaded_count_; 137 int result = image_loaded_count_;
136 image_loaded_count_ = 0; 138 image_loaded_count_ = 0;
137 return result; 139 return result;
138 } 140 }
139 141
140 scoped_refptr<Extension> CreateExtension(const char* name, 142 scoped_refptr<Extension> CreateExtension(const char* name,
141 Manifest::Location location) { 143 Manifest::Location location) {
142 // Create and load an extension. 144 // Create and load an extension.
143 base::FilePath test_file; 145 base::FilePath test_file;
144 if (!PathService::Get(extensions::DIR_TEST_DATA, &test_file)) { 146 if (!PathService::Get(DIR_TEST_DATA, &test_file)) {
145 EXPECT_FALSE(true); 147 EXPECT_FALSE(true);
146 return NULL; 148 return NULL;
147 } 149 }
148 test_file = test_file.AppendASCII(name); 150 test_file = test_file.AppendASCII(name);
149 int error_code = 0; 151 int error_code = 0;
150 std::string error; 152 std::string error;
151 JSONFileValueSerializer serializer(test_file.AppendASCII("manifest.json")); 153 JSONFileValueSerializer serializer(test_file.AppendASCII("manifest.json"));
152 scoped_ptr<base::DictionaryValue> valid_value( 154 scoped_ptr<base::DictionaryValue> valid_value(
153 static_cast<base::DictionaryValue*>(serializer.Deserialize(&error_code, 155 static_cast<base::DictionaryValue*>(serializer.Deserialize(&error_code,
154 &error))); 156 &error)));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 return image_loader.LoadBitmap(path, size); 192 return image_loader.LoadBitmap(path, size);
191 } 193 }
192 194
193 private: 195 private:
194 int image_loaded_count_; 196 int image_loaded_count_;
195 bool quit_in_image_loaded_; 197 bool quit_in_image_loaded_;
196 base::MessageLoop ui_loop_; 198 base::MessageLoop ui_loop_;
197 content::TestBrowserThread ui_thread_; 199 content::TestBrowserThread ui_thread_;
198 content::TestBrowserThread file_thread_; 200 content::TestBrowserThread file_thread_;
199 content::TestBrowserThread io_thread_; 201 content::TestBrowserThread io_thread_;
202 scoped_ptr<content::NotificationService> notification_service_;
200 203
201 DISALLOW_COPY_AND_ASSIGN(ExtensionIconImageTest); 204 DISALLOW_COPY_AND_ASSIGN(ExtensionIconImageTest);
202 }; 205 };
203 206
204 } // namespace 207 } // namespace
205 208
206 TEST_F(ExtensionIconImageTest, Basic) { 209 TEST_F(ExtensionIconImageTest, Basic) {
207 std::vector<ui::ScaleFactor> supported_factors; 210 std::vector<ui::ScaleFactor> supported_factors;
208 supported_factors.push_back(ui::SCALE_FACTOR_100P); 211 supported_factors.push_back(ui::SCALE_FACTOR_100P);
209 supported_factors.push_back(ui::SCALE_FACTOR_200P); 212 supported_factors.push_back(ui::SCALE_FACTOR_200P);
210 ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors); 213 ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
211 scoped_ptr<content::BrowserContext> profile(new TestingProfile());
212 scoped_refptr<Extension> extension(CreateExtension( 214 scoped_refptr<Extension> extension(CreateExtension(
213 "extension_icon_image", Manifest::INVALID_LOCATION)); 215 "extension_icon_image", Manifest::INVALID_LOCATION));
214 ASSERT_TRUE(extension.get() != NULL); 216 ASSERT_TRUE(extension.get() != NULL);
215 217
216 gfx::ImageSkia default_icon = GetDefaultIcon(); 218 gfx::ImageSkia default_icon = GetDefaultIcon();
217 219
218 // Load images we expect to find as representations in icon_image, so we 220 // Load images we expect to find as representations in icon_image, so we
219 // can later use them to validate icon_image. 221 // can later use them to validate icon_image.
220 SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16); 222 SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16);
221 ASSERT_FALSE(bitmap_16.empty()); 223 ASSERT_FALSE(bitmap_16.empty());
222 224
223 // There is no image of size 32 defined in the extension manifest, so we 225 // There is no image of size 32 defined in the extension manifest, so we
224 // should expect manifest image of size 48 resized to size 32. 226 // should expect manifest image of size 48 resized to size 32.
225 SkBitmap bitmap_48_resized_to_32 = 227 SkBitmap bitmap_48_resized_to_32 =
226 GetTestBitmap(extension.get(), "48.png", 32); 228 GetTestBitmap(extension.get(), "48.png", 32);
227 ASSERT_FALSE(bitmap_48_resized_to_32.empty()); 229 ASSERT_FALSE(bitmap_48_resized_to_32.empty());
228 230
229 IconImage image(profile.get(), 231 IconImage image(browser_context(),
230 extension.get(), 232 extension.get(),
231 extensions::IconsInfo::GetIcons(extension.get()), 233 IconsInfo::GetIcons(extension.get()),
232 16, 234 16,
233 default_icon, 235 default_icon,
234 this); 236 this);
235 237
236 // No representations in |image_| yet. 238 // No representations in |image_| yet.
237 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps(); 239 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps();
238 ASSERT_EQ(0u, image_reps.size()); 240 ASSERT_EQ(0u, image_reps.size());
239 241
240 // Gets representation for a scale factor. 242 // Gets representation for a scale factor.
241 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); 243 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 bitmap_48_resized_to_32)); 277 bitmap_48_resized_to_32));
276 } 278 }
277 279
278 // There is no resource with either exact or bigger size, but there is a smaller 280 // There is no resource with either exact or bigger size, but there is a smaller
279 // resource. 281 // resource.
280 TEST_F(ExtensionIconImageTest, FallbackToSmallerWhenNoBigger) { 282 TEST_F(ExtensionIconImageTest, FallbackToSmallerWhenNoBigger) {
281 std::vector<ui::ScaleFactor> supported_factors; 283 std::vector<ui::ScaleFactor> supported_factors;
282 supported_factors.push_back(ui::SCALE_FACTOR_100P); 284 supported_factors.push_back(ui::SCALE_FACTOR_100P);
283 supported_factors.push_back(ui::SCALE_FACTOR_200P); 285 supported_factors.push_back(ui::SCALE_FACTOR_200P);
284 ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors); 286 ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
285 scoped_ptr<content::BrowserContext> profile(new TestingProfile());
286 scoped_refptr<Extension> extension(CreateExtension( 287 scoped_refptr<Extension> extension(CreateExtension(
287 "extension_icon_image", Manifest::INVALID_LOCATION)); 288 "extension_icon_image", Manifest::INVALID_LOCATION));
288 ASSERT_TRUE(extension.get() != NULL); 289 ASSERT_TRUE(extension.get() != NULL);
289 290
290 gfx::ImageSkia default_icon = GetDefaultIcon(); 291 gfx::ImageSkia default_icon = GetDefaultIcon();
291 292
292 // Load images we expect to find as representations in icon_image, so we 293 // Load images we expect to find as representations in icon_image, so we
293 // can later use them to validate icon_image. 294 // can later use them to validate icon_image.
294 SkBitmap bitmap_48 = GetTestBitmap(extension.get(), "48.png", 48); 295 SkBitmap bitmap_48 = GetTestBitmap(extension.get(), "48.png", 48);
295 ASSERT_FALSE(bitmap_48.empty()); 296 ASSERT_FALSE(bitmap_48.empty());
296 297
297 IconImage image(profile.get(), 298 IconImage image(browser_context(),
298 extension.get(), 299 extension.get(),
299 extensions::IconsInfo::GetIcons(extension.get()), 300 IconsInfo::GetIcons(extension.get()),
300 32, 301 32,
301 default_icon, 302 default_icon,
302 this); 303 this);
303 304
304 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(2.0f); 305 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(2.0f);
305 306
306 WaitForImageLoad(); 307 WaitForImageLoad();
307 EXPECT_EQ(1, ImageLoadedCount()); 308 EXPECT_EQ(1, ImageLoadedCount());
308 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 309 ASSERT_EQ(1u, image.image_skia().image_reps().size());
309 310
310 representation = image.image_skia().GetRepresentation(2.0f); 311 representation = image.image_skia().GetRepresentation(2.0f);
311 312
312 // We should have loaded the biggest smaller resource resized to the actual 313 // We should have loaded the biggest smaller resource resized to the actual
313 // size. 314 // size.
314 EXPECT_EQ(2.0f, representation.scale()); 315 EXPECT_EQ(2.0f, representation.scale());
315 EXPECT_EQ(64, representation.pixel_width()); 316 EXPECT_EQ(64, representation.pixel_width());
316 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), 317 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(),
317 EnsureBitmapSize(bitmap_48, 64))); 318 EnsureBitmapSize(bitmap_48, 64)));
318 } 319 }
319 320
320 // There is no resource with exact size, but there is a smaller and a bigger 321 // There is no resource with exact size, but there is a smaller and a bigger
321 // one. The bigger resource should be loaded. 322 // one. The bigger resource should be loaded.
322 TEST_F(ExtensionIconImageTest, FallbackToBigger) { 323 TEST_F(ExtensionIconImageTest, FallbackToBigger) {
323 scoped_ptr<content::BrowserContext> profile(new TestingProfile());
324 scoped_refptr<Extension> extension(CreateExtension( 324 scoped_refptr<Extension> extension(CreateExtension(
325 "extension_icon_image", Manifest::INVALID_LOCATION)); 325 "extension_icon_image", Manifest::INVALID_LOCATION));
326 ASSERT_TRUE(extension.get() != NULL); 326 ASSERT_TRUE(extension.get() != NULL);
327 327
328 gfx::ImageSkia default_icon = GetDefaultIcon(); 328 gfx::ImageSkia default_icon = GetDefaultIcon();
329 329
330 // Load images we expect to find as representations in icon_image, so we 330 // Load images we expect to find as representations in icon_image, so we
331 // can later use them to validate icon_image. 331 // can later use them to validate icon_image.
332 SkBitmap bitmap_24 = GetTestBitmap(extension.get(), "24.png", 24); 332 SkBitmap bitmap_24 = GetTestBitmap(extension.get(), "24.png", 24);
333 ASSERT_FALSE(bitmap_24.empty()); 333 ASSERT_FALSE(bitmap_24.empty());
334 334
335 IconImage image(profile.get(), 335 IconImage image(browser_context(),
336 extension.get(), 336 extension.get(),
337 extensions::IconsInfo::GetIcons(extension.get()), 337 IconsInfo::GetIcons(extension.get()),
338 17, 338 17,
339 default_icon, 339 default_icon,
340 this); 340 this);
341 341
342 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); 342 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
343 343
344 WaitForImageLoad(); 344 WaitForImageLoad();
345 EXPECT_EQ(1, ImageLoadedCount()); 345 EXPECT_EQ(1, ImageLoadedCount());
346 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 346 ASSERT_EQ(1u, image.image_skia().image_reps().size());
347 347
348 representation = image.image_skia().GetRepresentation(1.0f); 348 representation = image.image_skia().GetRepresentation(1.0f);
349 349
350 // We should have loaded the smallest bigger (resized) resource. 350 // We should have loaded the smallest bigger (resized) resource.
351 EXPECT_EQ(1.0f, representation.scale()); 351 EXPECT_EQ(1.0f, representation.scale());
352 EXPECT_EQ(17, representation.pixel_width()); 352 EXPECT_EQ(17, representation.pixel_width());
353 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), 353 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(),
354 EnsureBitmapSize(bitmap_24, 17))); 354 EnsureBitmapSize(bitmap_24, 17)));
355 } 355 }
356 356
357 // If resource set is empty, |GetRepresentation| should synchronously return 357 // If resource set is empty, |GetRepresentation| should synchronously return
358 // default icon, without notifying observer of image change. 358 // default icon, without notifying observer of image change.
359 TEST_F(ExtensionIconImageTest, NoResources) { 359 TEST_F(ExtensionIconImageTest, NoResources) {
360 scoped_ptr<content::BrowserContext> profile(new TestingProfile());
361 scoped_refptr<Extension> extension(CreateExtension( 360 scoped_refptr<Extension> extension(CreateExtension(
362 "extension_icon_image", Manifest::INVALID_LOCATION)); 361 "extension_icon_image", Manifest::INVALID_LOCATION));
363 ASSERT_TRUE(extension.get() != NULL); 362 ASSERT_TRUE(extension.get() != NULL);
364 363
365 ExtensionIconSet empty_icon_set; 364 ExtensionIconSet empty_icon_set;
366 gfx::ImageSkia default_icon = GetDefaultIcon(); 365 gfx::ImageSkia default_icon = GetDefaultIcon();
367 366
368 const int kRequestedSize = 24; 367 const int kRequestedSize = 24;
369 IconImage image(profile.get(), 368 IconImage image(browser_context(),
370 extension.get(), 369 extension.get(),
371 empty_icon_set, 370 empty_icon_set,
372 kRequestedSize, 371 kRequestedSize,
373 default_icon, 372 default_icon,
374 this); 373 this);
375 374
376 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); 375 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
377 EXPECT_TRUE(gfx::BitmapsAreEqual( 376 EXPECT_TRUE(gfx::BitmapsAreEqual(
378 representation.sk_bitmap(), 377 representation.sk_bitmap(),
379 EnsureBitmapSize( 378 EnsureBitmapSize(
380 default_icon.GetRepresentation(1.0f).sk_bitmap(), 379 default_icon.GetRepresentation(1.0f).sk_bitmap(),
381 kRequestedSize))); 380 kRequestedSize)));
382 381
383 EXPECT_EQ(0, ImageLoadedCount()); 382 EXPECT_EQ(0, ImageLoadedCount());
384 // We should have a default icon representation. 383 // We should have a default icon representation.
385 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 384 ASSERT_EQ(1u, image.image_skia().image_reps().size());
386 385
387 representation = image.image_skia().GetRepresentation(1.0f); 386 representation = image.image_skia().GetRepresentation(1.0f);
388 EXPECT_TRUE(gfx::BitmapsAreEqual( 387 EXPECT_TRUE(gfx::BitmapsAreEqual(
389 representation.sk_bitmap(), 388 representation.sk_bitmap(),
390 EnsureBitmapSize( 389 EnsureBitmapSize(
391 default_icon.GetRepresentation(1.0f).sk_bitmap(), 390 default_icon.GetRepresentation(1.0f).sk_bitmap(),
392 kRequestedSize))); 391 kRequestedSize)));
393 } 392 }
394 393
395 // If resource set is invalid, image load should be done asynchronously and 394 // If resource set is invalid, image load should be done asynchronously and
396 // the observer should be notified when it's done. |GetRepresentation| should 395 // the observer should be notified when it's done. |GetRepresentation| should
397 // return the default icon representation once image load is done. 396 // return the default icon representation once image load is done.
398 TEST_F(ExtensionIconImageTest, InvalidResource) { 397 TEST_F(ExtensionIconImageTest, InvalidResource) {
399 scoped_ptr<content::BrowserContext> profile(new TestingProfile());
400 scoped_refptr<Extension> extension(CreateExtension( 398 scoped_refptr<Extension> extension(CreateExtension(
401 "extension_icon_image", Manifest::INVALID_LOCATION)); 399 "extension_icon_image", Manifest::INVALID_LOCATION));
402 ASSERT_TRUE(extension.get() != NULL); 400 ASSERT_TRUE(extension.get() != NULL);
403 401
404 const int kInvalidIconSize = 24; 402 const int kInvalidIconSize = 24;
405 ExtensionIconSet invalid_icon_set; 403 ExtensionIconSet invalid_icon_set;
406 invalid_icon_set.Add(kInvalidIconSize, "invalid.png"); 404 invalid_icon_set.Add(kInvalidIconSize, "invalid.png");
407 405
408 gfx::ImageSkia default_icon = GetDefaultIcon(); 406 gfx::ImageSkia default_icon = GetDefaultIcon();
409 407
410 IconImage image(profile.get(), 408 IconImage image(browser_context(),
411 extension.get(), 409 extension.get(),
412 invalid_icon_set, 410 invalid_icon_set,
413 kInvalidIconSize, 411 kInvalidIconSize,
414 default_icon, 412 default_icon,
415 this); 413 this);
416 414
417 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); 415 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
418 EXPECT_TRUE(gfx::BitmapsAreEqual( 416 EXPECT_TRUE(gfx::BitmapsAreEqual(
419 representation.sk_bitmap(), 417 representation.sk_bitmap(),
420 CreateBlankBitmapForScale(kInvalidIconSize, ui::SCALE_FACTOR_100P))); 418 CreateBlankBitmapForScale(kInvalidIconSize, ui::SCALE_FACTOR_100P)));
421 419
422 WaitForImageLoad(); 420 WaitForImageLoad();
423 EXPECT_EQ(1, ImageLoadedCount()); 421 EXPECT_EQ(1, ImageLoadedCount());
424 // We should have default icon representation now. 422 // We should have default icon representation now.
425 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 423 ASSERT_EQ(1u, image.image_skia().image_reps().size());
426 424
427 representation = image.image_skia().GetRepresentation(1.0f); 425 representation = image.image_skia().GetRepresentation(1.0f);
428 EXPECT_TRUE(gfx::BitmapsAreEqual( 426 EXPECT_TRUE(gfx::BitmapsAreEqual(
429 representation.sk_bitmap(), 427 representation.sk_bitmap(),
430 EnsureBitmapSize( 428 EnsureBitmapSize(
431 default_icon.GetRepresentation(1.0f).sk_bitmap(), 429 default_icon.GetRepresentation(1.0f).sk_bitmap(),
432 kInvalidIconSize))); 430 kInvalidIconSize)));
433 } 431 }
434 432
435 // Test that IconImage works with lazily (but synchronously) created default 433 // Test that IconImage works with lazily (but synchronously) created default
436 // icon when IconImage returns synchronously. 434 // icon when IconImage returns synchronously.
437 TEST_F(ExtensionIconImageTest, LazyDefaultIcon) { 435 TEST_F(ExtensionIconImageTest, LazyDefaultIcon) {
438 scoped_ptr<content::BrowserContext> profile(new TestingProfile());
439 scoped_refptr<Extension> extension(CreateExtension( 436 scoped_refptr<Extension> extension(CreateExtension(
440 "extension_icon_image", Manifest::INVALID_LOCATION)); 437 "extension_icon_image", Manifest::INVALID_LOCATION));
441 ASSERT_TRUE(extension.get() != NULL); 438 ASSERT_TRUE(extension.get() != NULL);
442 439
443 gfx::ImageSkia default_icon = GetDefaultIcon(); 440 gfx::ImageSkia default_icon = GetDefaultIcon();
444 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon), 441 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon),
445 default_icon.size()); 442 default_icon.size());
446 443
447 ExtensionIconSet empty_icon_set; 444 ExtensionIconSet empty_icon_set;
448 445
449 const int kRequestedSize = 128; 446 const int kRequestedSize = 128;
450 IconImage image(profile.get(), 447 IconImage image(browser_context(),
451 extension.get(), 448 extension.get(),
452 empty_icon_set, 449 empty_icon_set,
453 kRequestedSize, 450 kRequestedSize,
454 lazy_default_icon, 451 lazy_default_icon,
455 this); 452 this);
456 453
457 ASSERT_FALSE(lazy_default_icon.HasRepresentation(1.0f)); 454 ASSERT_FALSE(lazy_default_icon.HasRepresentation(1.0f));
458 455
459 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); 456 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
460 457
461 // The resouce set is empty, so we should get the result right away. 458 // The resouce set is empty, so we should get the result right away.
462 EXPECT_TRUE(lazy_default_icon.HasRepresentation(1.0f)); 459 EXPECT_TRUE(lazy_default_icon.HasRepresentation(1.0f));
463 EXPECT_TRUE(gfx::BitmapsAreEqual( 460 EXPECT_TRUE(gfx::BitmapsAreEqual(
464 representation.sk_bitmap(), 461 representation.sk_bitmap(),
465 EnsureBitmapSize( 462 EnsureBitmapSize(
466 default_icon.GetRepresentation(1.0f).sk_bitmap(), 463 default_icon.GetRepresentation(1.0f).sk_bitmap(),
467 kRequestedSize))); 464 kRequestedSize)));
468 465
469 // We should have a default icon representation. 466 // We should have a default icon representation.
470 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 467 ASSERT_EQ(1u, image.image_skia().image_reps().size());
471 } 468 }
472 469
473 // Test that IconImage works with lazily (but synchronously) created default 470 // Test that IconImage works with lazily (but synchronously) created default
474 // icon when IconImage returns asynchronously. 471 // icon when IconImage returns asynchronously.
475 TEST_F(ExtensionIconImageTest, LazyDefaultIcon_AsyncIconImage) { 472 TEST_F(ExtensionIconImageTest, LazyDefaultIcon_AsyncIconImage) {
476 scoped_ptr<content::BrowserContext> profile(new TestingProfile());
477 scoped_refptr<Extension> extension(CreateExtension( 473 scoped_refptr<Extension> extension(CreateExtension(
478 "extension_icon_image", Manifest::INVALID_LOCATION)); 474 "extension_icon_image", Manifest::INVALID_LOCATION));
479 ASSERT_TRUE(extension.get() != NULL); 475 ASSERT_TRUE(extension.get() != NULL);
480 476
481 gfx::ImageSkia default_icon = GetDefaultIcon(); 477 gfx::ImageSkia default_icon = GetDefaultIcon();
482 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon), 478 gfx::ImageSkia lazy_default_icon(new MockImageSkiaSource(default_icon),
483 default_icon.size()); 479 default_icon.size());
484 480
485 const int kInvalidIconSize = 24; 481 const int kInvalidIconSize = 24;
486 ExtensionIconSet invalid_icon_set; 482 ExtensionIconSet invalid_icon_set;
487 invalid_icon_set.Add(kInvalidIconSize, "invalid.png"); 483 invalid_icon_set.Add(kInvalidIconSize, "invalid.png");
488 484
489 IconImage image(profile.get(), 485 IconImage image(browser_context(),
490 extension.get(), 486 extension.get(),
491 invalid_icon_set, 487 invalid_icon_set,
492 kInvalidIconSize, 488 kInvalidIconSize,
493 lazy_default_icon, 489 lazy_default_icon,
494 this); 490 this);
495 491
496 ASSERT_FALSE(lazy_default_icon.HasRepresentation(1.0f)); 492 ASSERT_FALSE(lazy_default_icon.HasRepresentation(1.0f));
497 493
498 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f); 494 gfx::ImageSkiaRep representation = image.image_skia().GetRepresentation(1.0f);
499 495
(...skipping 10 matching lines...) Expand all
510 EnsureBitmapSize( 506 EnsureBitmapSize(
511 default_icon.GetRepresentation(1.0f).sk_bitmap(), 507 default_icon.GetRepresentation(1.0f).sk_bitmap(),
512 kInvalidIconSize))); 508 kInvalidIconSize)));
513 } 509 }
514 510
515 // Tests behavior of image created by IconImage after IconImage host goes 511 // Tests behavior of image created by IconImage after IconImage host goes
516 // away. The image should still return loaded representations. If requested 512 // away. The image should still return loaded representations. If requested
517 // representation was not loaded while IconImage host was around, transparent 513 // representation was not loaded while IconImage host was around, transparent
518 // representations should be returned. 514 // representations should be returned.
519 TEST_F(ExtensionIconImageTest, IconImageDestruction) { 515 TEST_F(ExtensionIconImageTest, IconImageDestruction) {
520 scoped_ptr<content::BrowserContext> profile(new TestingProfile());
521 scoped_refptr<Extension> extension(CreateExtension( 516 scoped_refptr<Extension> extension(CreateExtension(
522 "extension_icon_image", Manifest::INVALID_LOCATION)); 517 "extension_icon_image", Manifest::INVALID_LOCATION));
523 ASSERT_TRUE(extension.get() != NULL); 518 ASSERT_TRUE(extension.get() != NULL);
524 519
525 gfx::ImageSkia default_icon = GetDefaultIcon(); 520 gfx::ImageSkia default_icon = GetDefaultIcon();
526 521
527 // Load images we expect to find as representations in icon_image, so we 522 // Load images we expect to find as representations in icon_image, so we
528 // can later use them to validate icon_image. 523 // can later use them to validate icon_image.
529 SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16); 524 SkBitmap bitmap_16 = GetTestBitmap(extension.get(), "16.png", 16);
530 ASSERT_FALSE(bitmap_16.empty()); 525 ASSERT_FALSE(bitmap_16.empty());
531 526
532 scoped_ptr<IconImage> image( 527 scoped_ptr<IconImage> image(
533 new IconImage(profile.get(), 528 new IconImage(browser_context(),
534 extension.get(), 529 extension.get(),
535 extensions::IconsInfo::GetIcons(extension.get()), 530 IconsInfo::GetIcons(extension.get()),
536 16, 531 16,
537 default_icon, 532 default_icon,
538 this)); 533 this));
539 534
540 // Load an image representation. 535 // Load an image representation.
541 gfx::ImageSkiaRep representation = 536 gfx::ImageSkiaRep representation =
542 image->image_skia().GetRepresentation(1.0f); 537 image->image_skia().GetRepresentation(1.0f);
543 538
544 WaitForImageLoad(); 539 WaitForImageLoad();
545 EXPECT_EQ(1, ImageLoadedCount()); 540 EXPECT_EQ(1, ImageLoadedCount());
(...skipping 13 matching lines...) Expand all
559 554
560 // When requesting another representation, we should not crash and return some 555 // When requesting another representation, we should not crash and return some
561 // image of the size. It could be blank or a rescale from the existing 1.0f 556 // image of the size. It could be blank or a rescale from the existing 1.0f
562 // icon. 557 // icon.
563 representation = image_skia.GetRepresentation(2.0f); 558 representation = image_skia.GetRepresentation(2.0f);
564 559
565 EXPECT_EQ(16, representation.GetWidth()); 560 EXPECT_EQ(16, representation.GetWidth());
566 EXPECT_EQ(16, representation.GetHeight()); 561 EXPECT_EQ(16, representation.GetHeight());
567 EXPECT_EQ(2.0f, representation.scale()); 562 EXPECT_EQ(2.0f, representation.scale());
568 } 563 }
564
565 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | extensions/extensions.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698