Index: chrome/browser/extensions/image_loading_tracker_unittest.cc |
diff --git a/chrome/browser/extensions/image_loading_tracker_unittest.cc b/chrome/browser/extensions/image_loading_tracker_unittest.cc |
index 54d1958ec2f4e69cce927653e45a256b299c7c6c..2f7aa406ad35bb04cfa299b8d65d33ecf8b43706 100644 |
--- a/chrome/browser/extensions/image_loading_tracker_unittest.cc |
+++ b/chrome/browser/extensions/image_loading_tracker_unittest.cc |
@@ -2,10 +2,13 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "chrome/browser/extensions/image_loading_tracker.h" |
+ |
+#include <algorithm> |
+ |
#include "base/json/json_file_value_serializer.h" |
#include "base/message_loop.h" |
#include "base/path_service.h" |
-#include "chrome/browser/extensions/image_loading_tracker.h" |
#include "chrome/common/chrome_notification_types.h" |
#include "chrome/common/chrome_paths.h" |
#include "chrome/common/extensions/extension.h" |
@@ -197,14 +200,17 @@ TEST_F(ImageLoadingTrackerTest, MultipleImages) { |
"image_loading_tracker", Extension::INVALID)); |
ASSERT_TRUE(extension.get() != NULL); |
- std::vector<ImageLoadingTracker::ImageInfo> info_list; |
+ std::vector<ImageLoadingTracker::ImageRepInfo> info_list; |
int sizes[] = {ExtensionIconSet::EXTENSION_ICON_SMALLISH, |
ExtensionIconSet::EXTENSION_ICON_BITTY}; |
for (size_t i = 0; i < arraysize(sizes); ++i) { |
ExtensionResource resource = |
extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY); |
- info_list.push_back(ImageLoadingTracker::ImageInfo( |
- resource, gfx::Size(sizes[i], sizes[i]))); |
+ info_list.push_back(ImageLoadingTracker::ImageRepInfo( |
+ resource, |
+ ImageLoadingTracker::ImageRepInfo::RESIZE_WHEN_LARGER, |
+ gfx::Size(sizes[i], sizes[i]), |
+ ui::SCALE_FACTOR_NONE)); |
} |
ImageLoadingTracker loader(this); |
@@ -253,3 +259,108 @@ TEST_F(ImageLoadingTrackerTest, IsComponentExtensionResource) { |
ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); |
#endif |
} |
+ |
+// Tests loading image that supports DIP. |
+TEST_F(ImageLoadingTrackerTest, LoadImageSkia) { |
+ scoped_refptr<Extension> extension(CreateExtension( |
+ "image_loading_tracker", Extension::INVALID)); |
+ ASSERT_TRUE(extension.get() != NULL); |
+ |
+ ImageLoadingTracker loader(this); |
+ loader.LoadImageSkia(extension, |
+ ExtensionIconSet::EXTENSION_ICON_BITTY, |
+ ExtensionIconSet::MATCH_SMALLER, |
+ gfx::Size(ExtensionIconSet::EXTENSION_ICON_BITTY, |
+ ExtensionIconSet::EXTENSION_ICON_BITTY), |
+ ImageLoadingTracker::DONT_CACHE); |
+ |
+ // Observer's OnImageLoaded is called before LoadImageSkia returns. |
+ EXPECT_EQ(1, image_loaded_count()); |
+ |
+ // No representations in |image_| yet. |
+ std::vector<gfx::ImageSkiaRep> image_reps = |
+ image_.ToImageSkia()->image_reps(); |
+ ASSERT_EQ(0u, image_reps.size()); |
+ |
+ // Gets representation for a scale factor. |
+ image_.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P); |
+ WaitForImageLoad(); |
+ EXPECT_EQ(1, image_loaded_count()); |
+ |
+ gfx::ImageSkiaRep image_rep = |
+ image_.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P); |
+ EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_BITTY, |
+ image_rep.pixel_width()); |
+ |
+ // Gets representation for an additional scale factor. |
+ image_.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_200P); |
+ WaitForImageLoad(); |
+ EXPECT_EQ(1, image_loaded_count()); |
+ |
+ image_rep = image_.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_200P); |
+ EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALL, |
+ image_rep.pixel_width()); |
+} |
+ |
+// Tests LoadImageSkia with a non-existent resource. |
+TEST_F(ImageLoadingTrackerTest, LoadImageSkiaBadResource) { |
+ scoped_refptr<Extension> extension(CreateExtension( |
+ "image_loading_tracker", Extension::INVALID)); |
+ ASSERT_TRUE(extension.get() != NULL); |
+ |
+ ImageLoadingTracker loader(this); |
+ loader.LoadImageSkia(extension, |
+ ExtensionIconSet::EXTENSION_ICON_GIGANTOR, |
+ ExtensionIconSet::MATCH_BIGGER, |
+ gfx::Size(ExtensionIconSet::EXTENSION_ICON_GIGANTOR, |
+ ExtensionIconSet::EXTENSION_ICON_GIGANTOR), |
+ ImageLoadingTracker::DONT_CACHE); |
+ |
+ // Observer's OnImageLoaded is called before LoadImageSkia returns. |
+ EXPECT_EQ(1, image_loaded_count()); |
+ |
+ EXPECT_TRUE(image_.IsEmpty()); |
+} |
+ |
+// Tests LoadImageSkia with a resource that does not have 2x. |
+TEST_F(ImageLoadingTrackerTest, LoadImageSkiaMissing2x) { |
+ scoped_refptr<Extension> extension(CreateExtension( |
+ "image_loading_tracker", Extension::INVALID)); |
+ ASSERT_TRUE(extension.get() != NULL); |
+ |
+ ImageLoadingTracker loader(this); |
+ loader.LoadImageSkia(extension, |
+ ExtensionIconSet::EXTENSION_ICON_SMALLISH, |
+ ExtensionIconSet::MATCH_BIGGER, |
+ gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALLISH, |
+ ExtensionIconSet::EXTENSION_ICON_SMALLISH), |
+ ImageLoadingTracker::DONT_CACHE); |
+ |
+ // Observer's OnImageLoaded is called before LoadImageSkia returns. |
+ EXPECT_EQ(1, image_loaded_count()); |
+ |
+ // Gets representation for 1x. |
+ image_.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P); |
+ WaitForImageLoad(); |
+ EXPECT_EQ(1, image_loaded_count()); |
+ |
+ gfx::ImageSkiaRep image_rep = |
+ image_.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P); |
+ EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH, |
+ image_rep.pixel_width()); |
+ |
+ // Get representation for 2x. |
+ image_.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_200P); |
+ |
+ // Resource does not exist and OnImageLoaded is notified before above |
+ // GetRepresentation returns. |
+ EXPECT_EQ(1, image_loaded_count()); |
+ |
+ image_rep = image_.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_200P); |
+ |
+ // 1x representation would be returned since there is no 2x resource. |
+ EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor()); |
+ EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH, |
+ image_rep.pixel_width()); |
+} |
+ |