| OLD | NEW |
| 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/image_loading_tracker.h" |
| 6 |
| 5 #include "base/json/json_file_value_serializer.h" | 7 #include "base/json/json_file_value_serializer.h" |
| 6 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 7 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 8 #include "chrome/browser/extensions/image_loading_tracker.h" | |
| 9 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
| 10 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 12 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
| 13 #include "chrome/common/extensions/extension_icon_set.h" | 14 #include "chrome/common/extensions/extension_icon_set.h" |
| 14 #include "chrome/common/extensions/extension_resource.h" | 15 #include "chrome/common/extensions/extension_resource.h" |
| 15 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
| 17 #include "grit/component_extension_resources.h" | 18 #include "grit/component_extension_resources.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, | 192 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, |
| 192 image_.ToSkBitmap()->width()); | 193 image_.ToSkBitmap()->width()); |
| 193 } | 194 } |
| 194 | 195 |
| 195 // Tests loading multiple dimensions of the same image. | 196 // Tests loading multiple dimensions of the same image. |
| 196 TEST_F(ImageLoadingTrackerTest, MultipleImages) { | 197 TEST_F(ImageLoadingTrackerTest, MultipleImages) { |
| 197 scoped_refptr<Extension> extension(CreateExtension( | 198 scoped_refptr<Extension> extension(CreateExtension( |
| 198 "image_loading_tracker", Extension::INVALID)); | 199 "image_loading_tracker", Extension::INVALID)); |
| 199 ASSERT_TRUE(extension.get() != NULL); | 200 ASSERT_TRUE(extension.get() != NULL); |
| 200 | 201 |
| 201 std::vector<ImageLoadingTracker::ImageInfo> info_list; | 202 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; |
| 202 int sizes[] = {extension_misc::EXTENSION_ICON_SMALLISH, | 203 int sizes[] = {extension_misc::EXTENSION_ICON_SMALLISH, |
| 203 extension_misc::EXTENSION_ICON_BITTY}; | 204 extension_misc::EXTENSION_ICON_BITTY}; |
| 204 for (size_t i = 0; i < arraysize(sizes); ++i) { | 205 for (size_t i = 0; i < arraysize(sizes); ++i) { |
| 205 ExtensionResource resource = | 206 ExtensionResource resource = |
| 206 extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY); | 207 extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY); |
| 207 info_list.push_back(ImageLoadingTracker::ImageInfo( | 208 info_list.push_back(ImageLoadingTracker::ImageRepresentation( |
| 208 resource, gfx::Size(sizes[i], sizes[i]))); | 209 resource, |
| 210 ImageLoadingTracker::ImageRepresentation::RESIZE_WHEN_LARGER, |
| 211 gfx::Size(sizes[i], sizes[i]), |
| 212 ui::SCALE_FACTOR_NONE)); |
| 209 } | 213 } |
| 210 | 214 |
| 211 ImageLoadingTracker loader(this); | 215 ImageLoadingTracker loader(this); |
| 212 loader.LoadImages(extension.get(), info_list, ImageLoadingTracker::CACHE); | 216 loader.LoadImages(extension.get(), info_list, ImageLoadingTracker::CACHE); |
| 213 | 217 |
| 214 // The image isn't cached, so we should not have received notification. | 218 // The image isn't cached, so we should not have received notification. |
| 215 EXPECT_EQ(0, image_loaded_count()); | 219 EXPECT_EQ(0, image_loaded_count()); |
| 216 | 220 |
| 217 WaitForImageLoad(); | 221 WaitForImageLoad(); |
| 218 | 222 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 247 #if defined(FILE_MANAGER_EXTENSION) | 251 #if defined(FILE_MANAGER_EXTENSION) |
| 248 ImageLoadingTracker loader(this); | 252 ImageLoadingTracker loader(this); |
| 249 int resource_id; | 253 int resource_id; |
| 250 ASSERT_EQ(true, | 254 ASSERT_EQ(true, |
| 251 loader.IsComponentExtensionResource(extension.get(), | 255 loader.IsComponentExtensionResource(extension.get(), |
| 252 resource, | 256 resource, |
| 253 resource_id)); | 257 resource_id)); |
| 254 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); | 258 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); |
| 255 #endif | 259 #endif |
| 256 } | 260 } |
| OLD | NEW |