| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/image_loading_tracker.h" | 5 #include "chrome/browser/extensions/image_loading_tracker.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/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.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/extension_icon_set.h" | 15 #include "chrome/common/extensions/extension_icon_set.h" |
| 15 #include "chrome/common/extensions/extension_resource.h" | 16 #include "chrome/common/extensions/extension_resource.h" |
| 16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| 18 #include "grit/component_extension_resources.h" | 19 #include "grit/component_extension_resources.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 content::TestBrowserThread file_thread_; | 108 content::TestBrowserThread file_thread_; |
| 108 content::TestBrowserThread io_thread_; | 109 content::TestBrowserThread io_thread_; |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 // Tests asking ImageLoadingTracker to cache pushes the result to the Extension. | 112 // Tests asking ImageLoadingTracker to cache pushes the result to the Extension. |
| 112 TEST_F(ImageLoadingTrackerTest, Cache) { | 113 TEST_F(ImageLoadingTrackerTest, Cache) { |
| 113 scoped_refptr<Extension> extension(CreateExtension( | 114 scoped_refptr<Extension> extension(CreateExtension( |
| 114 "image_loading_tracker", Extension::INVALID)); | 115 "image_loading_tracker", Extension::INVALID)); |
| 115 ASSERT_TRUE(extension.get() != NULL); | 116 ASSERT_TRUE(extension.get() != NULL); |
| 116 | 117 |
| 117 ExtensionResource image_resource = | 118 ExtensionResource image_resource = extensions::IconsInfo::GetIconResource( |
| 118 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH, | 119 extension, |
| 119 ExtensionIconSet::MATCH_EXACTLY); | 120 extension_misc::EXTENSION_ICON_SMALLISH, |
| 121 ExtensionIconSet::MATCH_EXACTLY); |
| 120 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, | 122 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, |
| 121 extension_misc::EXTENSION_ICON_SMALLISH); | 123 extension_misc::EXTENSION_ICON_SMALLISH); |
| 122 ImageLoadingTracker loader(this); | 124 ImageLoadingTracker loader(this); |
| 123 loader.LoadImage(extension.get(), | 125 loader.LoadImage(extension.get(), |
| 124 image_resource, | 126 image_resource, |
| 125 max_size, | 127 max_size, |
| 126 ImageLoadingTracker::CACHE); | 128 ImageLoadingTracker::CACHE); |
| 127 | 129 |
| 128 // The image isn't cached, so we should not have received notification. | 130 // The image isn't cached, so we should not have received notification. |
| 129 EXPECT_EQ(0, image_loaded_count()); | 131 EXPECT_EQ(0, image_loaded_count()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 157 image_.ToSkBitmap()->width()); | 159 image_.ToSkBitmap()->width()); |
| 158 } | 160 } |
| 159 | 161 |
| 160 // Tests deleting an extension while waiting for the image to load doesn't cause | 162 // Tests deleting an extension while waiting for the image to load doesn't cause |
| 161 // problems. | 163 // problems. |
| 162 TEST_F(ImageLoadingTrackerTest, DeleteExtensionWhileWaitingForCache) { | 164 TEST_F(ImageLoadingTrackerTest, DeleteExtensionWhileWaitingForCache) { |
| 163 scoped_refptr<Extension> extension(CreateExtension( | 165 scoped_refptr<Extension> extension(CreateExtension( |
| 164 "image_loading_tracker", Extension::INVALID)); | 166 "image_loading_tracker", Extension::INVALID)); |
| 165 ASSERT_TRUE(extension.get() != NULL); | 167 ASSERT_TRUE(extension.get() != NULL); |
| 166 | 168 |
| 167 ExtensionResource image_resource = | 169 ExtensionResource image_resource = extensions::IconsInfo::GetIconResource( |
| 168 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH, | 170 extension, |
| 169 ExtensionIconSet::MATCH_EXACTLY); | 171 extension_misc::EXTENSION_ICON_SMALLISH, |
| 172 ExtensionIconSet::MATCH_EXACTLY); |
| 170 ImageLoadingTracker loader(this); | 173 ImageLoadingTracker loader(this); |
| 171 loader.LoadImage(extension.get(), | 174 loader.LoadImage(extension.get(), |
| 172 image_resource, | 175 image_resource, |
| 173 gfx::Size(extension_misc::EXTENSION_ICON_SMALLISH, | 176 gfx::Size(extension_misc::EXTENSION_ICON_SMALLISH, |
| 174 extension_misc::EXTENSION_ICON_SMALLISH), | 177 extension_misc::EXTENSION_ICON_SMALLISH), |
| 175 ImageLoadingTracker::CACHE); | 178 ImageLoadingTracker::CACHE); |
| 176 | 179 |
| 177 // The image isn't cached, so we should not have received notification. | 180 // The image isn't cached, so we should not have received notification. |
| 178 EXPECT_EQ(0, image_loaded_count()); | 181 EXPECT_EQ(0, image_loaded_count()); |
| 179 | 182 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 203 // Tests loading multiple dimensions of the same image. | 206 // Tests loading multiple dimensions of the same image. |
| 204 TEST_F(ImageLoadingTrackerTest, MultipleImages) { | 207 TEST_F(ImageLoadingTrackerTest, MultipleImages) { |
| 205 scoped_refptr<Extension> extension(CreateExtension( | 208 scoped_refptr<Extension> extension(CreateExtension( |
| 206 "image_loading_tracker", Extension::INVALID)); | 209 "image_loading_tracker", Extension::INVALID)); |
| 207 ASSERT_TRUE(extension.get() != NULL); | 210 ASSERT_TRUE(extension.get() != NULL); |
| 208 | 211 |
| 209 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; | 212 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; |
| 210 int sizes[] = {extension_misc::EXTENSION_ICON_SMALLISH, | 213 int sizes[] = {extension_misc::EXTENSION_ICON_SMALLISH, |
| 211 extension_misc::EXTENSION_ICON_BITTY}; | 214 extension_misc::EXTENSION_ICON_BITTY}; |
| 212 for (size_t i = 0; i < arraysize(sizes); ++i) { | 215 for (size_t i = 0; i < arraysize(sizes); ++i) { |
| 213 ExtensionResource resource = | 216 ExtensionResource resource = extensions::IconsInfo::GetIconResource( |
| 214 extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY); | 217 extension, sizes[i], ExtensionIconSet::MATCH_EXACTLY); |
| 215 info_list.push_back(ImageLoadingTracker::ImageRepresentation( | 218 info_list.push_back(ImageLoadingTracker::ImageRepresentation( |
| 216 resource, | 219 resource, |
| 217 ImageLoadingTracker::ImageRepresentation::RESIZE_WHEN_LARGER, | 220 ImageLoadingTracker::ImageRepresentation::RESIZE_WHEN_LARGER, |
| 218 gfx::Size(sizes[i], sizes[i]), | 221 gfx::Size(sizes[i], sizes[i]), |
| 219 ui::SCALE_FACTOR_NONE)); | 222 ui::SCALE_FACTOR_NONE)); |
| 220 } | 223 } |
| 221 | 224 |
| 222 ImageLoadingTracker loader(this); | 225 ImageLoadingTracker loader(this); |
| 223 loader.LoadImages(extension.get(), info_list, ImageLoadingTracker::CACHE); | 226 loader.LoadImages(extension.get(), info_list, ImageLoadingTracker::CACHE); |
| 224 | 227 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 237 const gfx::ImageSkiaRep* img_rep1 = &image_reps[0]; | 240 const gfx::ImageSkiaRep* img_rep1 = &image_reps[0]; |
| 238 const gfx::ImageSkiaRep* img_rep2 = &image_reps[1]; | 241 const gfx::ImageSkiaRep* img_rep2 = &image_reps[1]; |
| 239 if (img_rep1->pixel_width() > img_rep2->pixel_width()) { | 242 if (img_rep1->pixel_width() > img_rep2->pixel_width()) { |
| 240 std::swap(img_rep1, img_rep2); | 243 std::swap(img_rep1, img_rep2); |
| 241 } | 244 } |
| 242 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY, | 245 EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY, |
| 243 img_rep1->pixel_width()); | 246 img_rep1->pixel_width()); |
| 244 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, | 247 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, |
| 245 img_rep2->pixel_width()); | 248 img_rep2->pixel_width()); |
| 246 } | 249 } |
| OLD | NEW |