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

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

Issue 11786003: Move Icons out of Extension class (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_browser_action
Patch Set: Created 7 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_icon_image.h" 5 #include "chrome/browser/extensions/extension_icon_image.h"
6 6
7 #include "base/json/json_file_value_serializer.h" 7 #include "base/json/json_file_value_serializer.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "chrome/browser/extensions/image_loader.h" 10 #include "chrome/browser/extensions/image_loader.h"
11 #include "chrome/common/chrome_paths.h" 11 #include "chrome/common/chrome_paths.h"
12 #include "chrome/common/extensions/api/icons/icons_handler.h"
12 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_constants.h" 14 #include "chrome/common/extensions/extension_constants.h"
14 #include "chrome/common/extensions/manifest.h" 15 #include "chrome/common/extensions/manifest.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
16 #include "content/public/test/test_browser_thread.h" 17 #include "content/public/test/test_browser_thread.h"
17 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
18 #include "skia/ext/image_operations.h" 19 #include "skia/ext/image_operations.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/image/image_skia_source.h" 22 #include "ui/gfx/image/image_skia_source.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 SkBitmap bitmap_16 = 222 SkBitmap bitmap_16 =
222 GetTestBitmap(extension, "16.png", 16); 223 GetTestBitmap(extension, "16.png", 16);
223 ASSERT_FALSE(bitmap_16.empty()); 224 ASSERT_FALSE(bitmap_16.empty());
224 225
225 // There is no image of size 32 defined in the extension manifest, so we 226 // There is no image of size 32 defined in the extension manifest, so we
226 // should expect manifest image of size 48 resized to size 32. 227 // should expect manifest image of size 48 resized to size 32.
227 SkBitmap bitmap_48_resized_to_32 = 228 SkBitmap bitmap_48_resized_to_32 =
228 GetTestBitmap(extension, "48.png", 32); 229 GetTestBitmap(extension, "48.png", 32);
229 ASSERT_FALSE(bitmap_48_resized_to_32.empty()); 230 ASSERT_FALSE(bitmap_48_resized_to_32.empty());
230 231
231 IconImage image(profile.get(), extension, extension->icons(), 16, 232 IconImage image(profile.get(),
233 extension,
234 extensions::IconsInfo::GetIcons(extension),
235 16,
232 default_icon, this); 236 default_icon, this);
233 237
234 // No representations in |image_| yet. 238 // No representations in |image_| yet.
235 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps(); 239 gfx::ImageSkia::ImageSkiaReps image_reps = image.image_skia().image_reps();
236 ASSERT_EQ(0u, image_reps.size()); 240 ASSERT_EQ(0u, image_reps.size());
237 241
238 // Gets representation for a scale factor. 242 // Gets representation for a scale factor.
239 gfx::ImageSkiaRep representation = 243 gfx::ImageSkiaRep representation =
240 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 244 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
241 245
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 ASSERT_TRUE(extension.get() != NULL); 287 ASSERT_TRUE(extension.get() != NULL);
284 288
285 gfx::ImageSkia default_icon = GetDefaultIcon(); 289 gfx::ImageSkia default_icon = GetDefaultIcon();
286 290
287 // Load images we expect to find as representations in icon_image, so we 291 // Load images we expect to find as representations in icon_image, so we
288 // can later use them to validate icon_image. 292 // can later use them to validate icon_image.
289 SkBitmap bitmap_48 = 293 SkBitmap bitmap_48 =
290 GetTestBitmap(extension, "48.png", 48); 294 GetTestBitmap(extension, "48.png", 48);
291 ASSERT_FALSE(bitmap_48.empty()); 295 ASSERT_FALSE(bitmap_48.empty());
292 296
293 IconImage image(profile.get(), extension, extension->icons(), 32, 297 IconImage image(profile.get(),
298 extension,
299 extensions::IconsInfo::GetIcons(extension),
300 32,
294 default_icon, this); 301 default_icon, this);
295 302
296 gfx::ImageSkiaRep representation = 303 gfx::ImageSkiaRep representation =
297 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P); 304 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
298 305
299 WaitForImageLoad(); 306 WaitForImageLoad();
300 EXPECT_EQ(1, ImageLoadedCount()); 307 EXPECT_EQ(1, ImageLoadedCount());
301 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 308 ASSERT_EQ(1u, image.image_skia().image_reps().size());
302 309
303 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P); 310 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_200P);
(...skipping 16 matching lines...) Expand all
320 ASSERT_TRUE(extension.get() != NULL); 327 ASSERT_TRUE(extension.get() != NULL);
321 328
322 gfx::ImageSkia default_icon = GetDefaultIcon(); 329 gfx::ImageSkia default_icon = GetDefaultIcon();
323 330
324 // Load images we expect to find as representations in icon_image, so we 331 // Load images we expect to find as representations in icon_image, so we
325 // can later use them to validate icon_image. 332 // can later use them to validate icon_image.
326 SkBitmap bitmap_16 = 333 SkBitmap bitmap_16 =
327 GetTestBitmap(extension, "16.png", 16); 334 GetTestBitmap(extension, "16.png", 16);
328 ASSERT_FALSE(bitmap_16.empty()); 335 ASSERT_FALSE(bitmap_16.empty());
329 336
330 IconImage image(profile.get(), extension, extension->icons(), 17, 337 IconImage image(profile.get(),
338 extension,
339 extensions::IconsInfo::GetIcons(extension),
340 17,
331 default_icon, this); 341 default_icon, this);
332 342
333 gfx::ImageSkiaRep representation = 343 gfx::ImageSkiaRep representation =
334 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 344 image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
335 345
336 WaitForImageLoad(); 346 WaitForImageLoad();
337 EXPECT_EQ(1, ImageLoadedCount()); 347 EXPECT_EQ(1, ImageLoadedCount());
338 ASSERT_EQ(1u, image.image_skia().image_reps().size()); 348 ASSERT_EQ(1u, image.image_skia().image_reps().size());
339 349
340 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 350 representation = image.image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 514
505 gfx::ImageSkia default_icon = GetDefaultIcon(); 515 gfx::ImageSkia default_icon = GetDefaultIcon();
506 516
507 // Load images we expect to find as representations in icon_image, so we 517 // Load images we expect to find as representations in icon_image, so we
508 // can later use them to validate icon_image. 518 // can later use them to validate icon_image.
509 SkBitmap bitmap_16 = 519 SkBitmap bitmap_16 =
510 GetTestBitmap(extension, "16.png", 16); 520 GetTestBitmap(extension, "16.png", 16);
511 ASSERT_FALSE(bitmap_16.empty()); 521 ASSERT_FALSE(bitmap_16.empty());
512 522
513 scoped_ptr<IconImage> image( 523 scoped_ptr<IconImage> image(
514 new IconImage(profile.get(), extension, extension->icons(), 16, 524 new IconImage(profile.get(),
525 extension,
526 extensions::IconsInfo::GetIcons(extension),
527 16,
515 default_icon, this)); 528 default_icon, this));
516 529
517 // Load an image representation. 530 // Load an image representation.
518 gfx::ImageSkiaRep representation = 531 gfx::ImageSkiaRep representation =
519 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P); 532 image->image_skia().GetRepresentation(ui::SCALE_FACTOR_100P);
520 533
521 WaitForImageLoad(); 534 WaitForImageLoad();
522 EXPECT_EQ(1, ImageLoadedCount()); 535 EXPECT_EQ(1, ImageLoadedCount());
523 ASSERT_EQ(1u, image->image_skia().image_reps().size()); 536 ASSERT_EQ(1u, image->image_skia().image_reps().size());
524 537
525 // Stash loaded image skia, and destroy |image|. 538 // Stash loaded image skia, and destroy |image|.
526 gfx::ImageSkia image_skia = image->image_skia(); 539 gfx::ImageSkia image_skia = image->image_skia();
527 image.reset(); 540 image.reset();
528 extension = NULL; 541 extension = NULL;
529 542
530 // Image skia should still be able to get previously loaded representation. 543 // Image skia should still be able to get previously loaded representation.
531 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_100P); 544 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_100P);
532 545
533 EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor()); 546 EXPECT_EQ(ui::SCALE_FACTOR_100P, representation.scale_factor());
534 EXPECT_EQ(16, representation.pixel_width()); 547 EXPECT_EQ(16, representation.pixel_width());
535 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16)); 548 EXPECT_TRUE(gfx::BitmapsAreEqual(representation.sk_bitmap(), bitmap_16));
536 549
537 // When requesting another representation, we should get blank image. 550 // When requesting another representation, we should get blank image.
538 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_200P); 551 representation = image_skia.GetRepresentation(ui::SCALE_FACTOR_200P);
539 552
540 EXPECT_TRUE(gfx::BitmapsAreEqual( 553 EXPECT_TRUE(gfx::BitmapsAreEqual(
541 representation.sk_bitmap(), 554 representation.sk_bitmap(),
542 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P))); 555 CreateBlankBitmapForScale(16, ui::SCALE_FACTOR_200P)));
543 } 556 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698