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/extension_icon_image.h" | 5 #include "extensions/browser/extension_icon_image.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 base::FilePath test_file; | 98 base::FilePath test_file; |
99 if (!PathService::Get(DIR_TEST_DATA, &test_file)) { | 99 if (!PathService::Get(DIR_TEST_DATA, &test_file)) { |
100 EXPECT_FALSE(true); | 100 EXPECT_FALSE(true); |
101 return NULL; | 101 return NULL; |
102 } | 102 } |
103 test_file = test_file.AppendASCII(name); | 103 test_file = test_file.AppendASCII(name); |
104 int error_code = 0; | 104 int error_code = 0; |
105 std::string error; | 105 std::string error; |
106 JSONFileValueDeserializer deserializer( | 106 JSONFileValueDeserializer deserializer( |
107 test_file.AppendASCII("manifest.json")); | 107 test_file.AppendASCII("manifest.json")); |
108 scoped_ptr<base::DictionaryValue> valid_value = base::DictionaryValue::From( | 108 std::unique_ptr<base::DictionaryValue> valid_value = |
109 deserializer.Deserialize(&error_code, &error)); | 109 base::DictionaryValue::From( |
| 110 deserializer.Deserialize(&error_code, &error)); |
110 EXPECT_EQ(0, error_code) << error; | 111 EXPECT_EQ(0, error_code) << error; |
111 if (error_code != 0) | 112 if (error_code != 0) |
112 return NULL; | 113 return NULL; |
113 | 114 |
114 EXPECT_TRUE(valid_value.get()); | 115 EXPECT_TRUE(valid_value.get()); |
115 if (!valid_value) | 116 if (!valid_value) |
116 return NULL; | 117 return NULL; |
117 | 118 |
118 return Extension::Create(test_file, location, *valid_value, | 119 return Extension::Create(test_file, location, *valid_value, |
119 Extension::NO_FLAGS, &error); | 120 Extension::NO_FLAGS, &error); |
(...skipping 16 matching lines...) Expand all Loading... |
136 return gfx::ImageSkia(gfx::ImageSkiaRep(gfx::Size(16, 16), 1.0f)); | 137 return gfx::ImageSkia(gfx::ImageSkiaRep(gfx::Size(16, 16), 1.0f)); |
137 } | 138 } |
138 | 139 |
139 private: | 140 private: |
140 int image_loaded_count_; | 141 int image_loaded_count_; |
141 bool quit_in_image_loaded_; | 142 bool quit_in_image_loaded_; |
142 base::MessageLoop ui_loop_; | 143 base::MessageLoop ui_loop_; |
143 content::TestBrowserThread ui_thread_; | 144 content::TestBrowserThread ui_thread_; |
144 content::TestBrowserThread file_thread_; | 145 content::TestBrowserThread file_thread_; |
145 content::TestBrowserThread io_thread_; | 146 content::TestBrowserThread io_thread_; |
146 scoped_ptr<content::NotificationService> notification_service_; | 147 std::unique_ptr<content::NotificationService> notification_service_; |
147 | 148 |
148 DISALLOW_COPY_AND_ASSIGN(ExtensionIconImageTest); | 149 DISALLOW_COPY_AND_ASSIGN(ExtensionIconImageTest); |
149 }; | 150 }; |
150 | 151 |
151 } // namespace | 152 } // namespace |
152 | 153 |
153 TEST_F(ExtensionIconImageTest, Basic) { | 154 TEST_F(ExtensionIconImageTest, Basic) { |
154 std::vector<ui::ScaleFactor> supported_factors; | 155 std::vector<ui::ScaleFactor> supported_factors; |
155 supported_factors.push_back(ui::SCALE_FACTOR_100P); | 156 supported_factors.push_back(ui::SCALE_FACTOR_100P); |
156 supported_factors.push_back(ui::SCALE_FACTOR_200P); | 157 supported_factors.push_back(ui::SCALE_FACTOR_200P); |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 ASSERT_TRUE(extension.get() != NULL); | 466 ASSERT_TRUE(extension.get() != NULL); |
466 | 467 |
467 gfx::ImageSkia default_icon = GetDefaultIcon(); | 468 gfx::ImageSkia default_icon = GetDefaultIcon(); |
468 | 469 |
469 // Load images we expect to find as representations in icon_image, so we | 470 // Load images we expect to find as representations in icon_image, so we |
470 // can later use them to validate icon_image. | 471 // can later use them to validate icon_image. |
471 SkBitmap bitmap_16 = | 472 SkBitmap bitmap_16 = |
472 TestImageLoader::LoadAndGetExtensionBitmap(extension.get(), "16.png", 16); | 473 TestImageLoader::LoadAndGetExtensionBitmap(extension.get(), "16.png", 16); |
473 ASSERT_FALSE(bitmap_16.empty()); | 474 ASSERT_FALSE(bitmap_16.empty()); |
474 | 475 |
475 scoped_ptr<IconImage> image( | 476 std::unique_ptr<IconImage> image(new IconImage( |
476 new IconImage(browser_context(), | 477 browser_context(), extension.get(), IconsInfo::GetIcons(extension.get()), |
477 extension.get(), | 478 16, default_icon, this)); |
478 IconsInfo::GetIcons(extension.get()), | |
479 16, | |
480 default_icon, | |
481 this)); | |
482 | 479 |
483 // Load an image representation. | 480 // Load an image representation. |
484 gfx::ImageSkiaRep representation = | 481 gfx::ImageSkiaRep representation = |
485 image->image_skia().GetRepresentation(1.0f); | 482 image->image_skia().GetRepresentation(1.0f); |
486 | 483 |
487 WaitForImageLoad(); | 484 WaitForImageLoad(); |
488 EXPECT_EQ(1, ImageLoadedCount()); | 485 EXPECT_EQ(1, ImageLoadedCount()); |
489 ASSERT_EQ(1u, image->image_skia().image_reps().size()); | 486 ASSERT_EQ(1u, image->image_skia().image_reps().size()); |
490 | 487 |
491 // Stash loaded image skia, and destroy |image|. | 488 // Stash loaded image skia, and destroy |image|. |
(...skipping 19 matching lines...) Expand all Loading... |
511 } | 508 } |
512 | 509 |
513 // Test that new representations added to the image of an IconImage are cached | 510 // Test that new representations added to the image of an IconImage are cached |
514 // for future use. | 511 // for future use. |
515 TEST_F(ExtensionIconImageTest, ImageCachesNewRepresentations) { | 512 TEST_F(ExtensionIconImageTest, ImageCachesNewRepresentations) { |
516 // Load up an extension and create an icon image. | 513 // Load up an extension and create an icon image. |
517 scoped_refptr<Extension> extension( | 514 scoped_refptr<Extension> extension( |
518 CreateExtension("extension_icon_image", Manifest::INVALID_LOCATION)); | 515 CreateExtension("extension_icon_image", Manifest::INVALID_LOCATION)); |
519 ASSERT_TRUE(extension.get() != NULL); | 516 ASSERT_TRUE(extension.get() != NULL); |
520 gfx::ImageSkia default_icon = GetDefaultIcon(); | 517 gfx::ImageSkia default_icon = GetDefaultIcon(); |
521 scoped_ptr<IconImage> icon_image( | 518 std::unique_ptr<IconImage> icon_image(new IconImage( |
522 new IconImage(browser_context(), | 519 browser_context(), extension.get(), IconsInfo::GetIcons(extension.get()), |
523 extension.get(), | 520 16, default_icon, this)); |
524 IconsInfo::GetIcons(extension.get()), | |
525 16, | |
526 default_icon, | |
527 this)); | |
528 | 521 |
529 // Load an image representation. | 522 // Load an image representation. |
530 gfx::ImageSkiaRep representation = | 523 gfx::ImageSkiaRep representation = |
531 icon_image->image_skia().GetRepresentation(1.0f); | 524 icon_image->image_skia().GetRepresentation(1.0f); |
532 WaitForImageLoad(); | 525 WaitForImageLoad(); |
533 | 526 |
534 // Cache for later use. | 527 // Cache for later use. |
535 gfx::Image prior_image = icon_image->image(); | 528 gfx::Image prior_image = icon_image->image(); |
536 | 529 |
537 // Now the fun part: access the image from the IconImage, and create a png | 530 // Now the fun part: access the image from the IconImage, and create a png |
538 // representation of it. | 531 // representation of it. |
539 gfx::Image image = icon_image->image(); | 532 gfx::Image image = icon_image->image(); |
540 scoped_refptr<base::RefCountedMemory> image_as_png = image.As1xPNGBytes(); | 533 scoped_refptr<base::RefCountedMemory> image_as_png = image.As1xPNGBytes(); |
541 | 534 |
542 // Access the image from the IconImage again, and get a png representation. | 535 // Access the image from the IconImage again, and get a png representation. |
543 // The two png representations should be exactly equal (the same object), | 536 // The two png representations should be exactly equal (the same object), |
544 // because image storage is shared, so when we created one from the first | 537 // because image storage is shared, so when we created one from the first |
545 // image, all other images should also have that representation... | 538 // image, all other images should also have that representation... |
546 gfx::Image image2 = icon_image->image(); | 539 gfx::Image image2 = icon_image->image(); |
547 EXPECT_EQ(image_as_png.get(), image2.As1xPNGBytes().get()); | 540 EXPECT_EQ(image_as_png.get(), image2.As1xPNGBytes().get()); |
548 | 541 |
549 // ...even images that were copied before the representation was constructed. | 542 // ...even images that were copied before the representation was constructed. |
550 EXPECT_EQ(image_as_png.get(), prior_image.As1xPNGBytes().get()); | 543 EXPECT_EQ(image_as_png.get(), prior_image.As1xPNGBytes().get()); |
551 } | 544 } |
552 | 545 |
553 } // namespace extensions | 546 } // namespace extensions |
OLD | NEW |