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

Side by Side Diff: chrome/browser/extensions/image_loader_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/image_loader.h" 5 #include "chrome/browser/extensions/image_loader.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"
16 #include "chrome/common/extensions/extension_manifest_constants.h"
15 #include "chrome/common/extensions/extension_resource.h" 17 #include "chrome/common/extensions/extension_resource.h"
16 #include "chrome/common/extensions/manifest.h" 18 #include "chrome/common/extensions/manifest.h"
19 #include "chrome/common/extensions/manifest_handler.h"
17 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
18 #include "content/public/test/test_browser_thread.h" 21 #include "content/public/test/test_browser_thread.h"
19 #include "grit/component_extension_resources.h" 22 #include "grit/component_extension_resources.h"
20 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 24 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
23 #include "ui/gfx/image/image_skia.h" 26 #include "ui/gfx/image/image_skia.h"
24 #include "ui/gfx/size.h" 27 #include "ui/gfx/size.h"
25 28
26 using content::BrowserThread; 29 using content::BrowserThread;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 91 }
89 test_file = test_file.AppendASCII(name); 92 test_file = test_file.AppendASCII(name);
90 } 93 }
91 return Extension::Create(test_file, location, *valid_value, 94 return Extension::Create(test_file, location, *valid_value,
92 Extension::NO_FLAGS, &error); 95 Extension::NO_FLAGS, &error);
93 } 96 }
94 97
95 gfx::Image image_; 98 gfx::Image image_;
96 99
97 private: 100 private:
98 virtual void SetUp() { 101 virtual void SetUp() OVERRIDE {
102 testing::Test::SetUp();
103 extensions::ManifestHandler::Register(
104 extension_manifest_keys::kIcons,
105 make_linked_ptr(new extensions::IconsHandler));
106
99 file_thread_.Start(); 107 file_thread_.Start();
100 io_thread_.Start(); 108 io_thread_.Start();
101 } 109 }
102 110
103 int image_loaded_count_; 111 int image_loaded_count_;
104 bool quit_in_image_loaded_; 112 bool quit_in_image_loaded_;
105 MessageLoop ui_loop_; 113 MessageLoop ui_loop_;
106 content::TestBrowserThread ui_thread_; 114 content::TestBrowserThread ui_thread_;
107 content::TestBrowserThread file_thread_; 115 content::TestBrowserThread file_thread_;
108 content::TestBrowserThread io_thread_; 116 content::TestBrowserThread io_thread_;
109 }; 117 };
110 118
111 // Tests loading an image works correctly. 119 // Tests loading an image works correctly.
112 TEST_F(ImageLoaderTest, LoadImage) { 120 TEST_F(ImageLoaderTest, LoadImage) {
113 scoped_refptr<Extension> extension(CreateExtension( 121 scoped_refptr<Extension> extension(CreateExtension(
114 "image_loading_tracker", Manifest::INVALID_LOCATION)); 122 "image_loading_tracker", Manifest::INVALID_LOCATION));
115 ASSERT_TRUE(extension.get() != NULL); 123 ASSERT_TRUE(extension.get() != NULL);
116 124
117 ExtensionResource image_resource = 125 ExtensionResource image_resource = extensions::IconsInfo::GetIconResource(
118 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH, 126 extension,
119 ExtensionIconSet::MATCH_EXACTLY); 127 extension_misc::EXTENSION_ICON_SMALLISH,
128 ExtensionIconSet::MATCH_EXACTLY);
120 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, 129 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH,
121 extension_misc::EXTENSION_ICON_SMALLISH); 130 extension_misc::EXTENSION_ICON_SMALLISH);
122 ImageLoader loader; 131 ImageLoader loader;
123 loader.LoadImageAsync(extension.get(), 132 loader.LoadImageAsync(extension.get(),
124 image_resource, 133 image_resource,
125 max_size, 134 max_size,
126 base::Bind(&ImageLoaderTest::OnImageLoaded, 135 base::Bind(&ImageLoaderTest::OnImageLoaded,
127 base::Unretained(this))); 136 base::Unretained(this)));
128 137
129 // The image isn't cached, so we should not have received notification. 138 // The image isn't cached, so we should not have received notification.
130 EXPECT_EQ(0, image_loaded_count()); 139 EXPECT_EQ(0, image_loaded_count());
131 140
132 WaitForImageLoad(); 141 WaitForImageLoad();
133 142
134 // We should have gotten the image. 143 // We should have gotten the image.
135 EXPECT_EQ(1, image_loaded_count()); 144 EXPECT_EQ(1, image_loaded_count());
136 145
137 // Check that the image was loaded. 146 // Check that the image was loaded.
138 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, 147 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH,
139 image_.ToSkBitmap()->width()); 148 image_.ToSkBitmap()->width());
140 } 149 }
141 150
142 // Tests deleting an extension while waiting for the image to load doesn't cause 151 // Tests deleting an extension while waiting for the image to load doesn't cause
143 // problems. 152 // problems.
144 TEST_F(ImageLoaderTest, DeleteExtensionWhileWaitingForCache) { 153 TEST_F(ImageLoaderTest, DeleteExtensionWhileWaitingForCache) {
145 scoped_refptr<Extension> extension(CreateExtension( 154 scoped_refptr<Extension> extension(CreateExtension(
146 "image_loading_tracker", Manifest::INVALID_LOCATION)); 155 "image_loading_tracker", Manifest::INVALID_LOCATION));
147 ASSERT_TRUE(extension.get() != NULL); 156 ASSERT_TRUE(extension.get() != NULL);
148 157
149 ExtensionResource image_resource = 158 ExtensionResource image_resource = extensions::IconsInfo::GetIconResource(
150 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH, 159 extension,
151 ExtensionIconSet::MATCH_EXACTLY); 160 extension_misc::EXTENSION_ICON_SMALLISH,
161 ExtensionIconSet::MATCH_EXACTLY);
152 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH, 162 gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH,
153 extension_misc::EXTENSION_ICON_SMALLISH); 163 extension_misc::EXTENSION_ICON_SMALLISH);
154 ImageLoader loader; 164 ImageLoader loader;
155 std::set<int> sizes; 165 std::set<int> sizes;
156 sizes.insert(extension_misc::EXTENSION_ICON_SMALLISH); 166 sizes.insert(extension_misc::EXTENSION_ICON_SMALLISH);
157 loader.LoadImageAsync(extension.get(), 167 loader.LoadImageAsync(extension.get(),
158 image_resource, 168 image_resource,
159 max_size, 169 max_size,
160 base::Bind(&ImageLoaderTest::OnImageLoaded, 170 base::Bind(&ImageLoaderTest::OnImageLoaded,
161 base::Unretained(this))); 171 base::Unretained(this)));
(...skipping 27 matching lines...) Expand all
189 // Tests loading multiple dimensions of the same image. 199 // Tests loading multiple dimensions of the same image.
190 TEST_F(ImageLoaderTest, MultipleImages) { 200 TEST_F(ImageLoaderTest, MultipleImages) {
191 scoped_refptr<Extension> extension(CreateExtension( 201 scoped_refptr<Extension> extension(CreateExtension(
192 "image_loading_tracker", Manifest::INVALID_LOCATION)); 202 "image_loading_tracker", Manifest::INVALID_LOCATION));
193 ASSERT_TRUE(extension.get() != NULL); 203 ASSERT_TRUE(extension.get() != NULL);
194 204
195 std::vector<ImageLoader::ImageRepresentation> info_list; 205 std::vector<ImageLoader::ImageRepresentation> info_list;
196 int sizes[] = {extension_misc::EXTENSION_ICON_SMALLISH, 206 int sizes[] = {extension_misc::EXTENSION_ICON_SMALLISH,
197 extension_misc::EXTENSION_ICON_BITTY}; 207 extension_misc::EXTENSION_ICON_BITTY};
198 for (size_t i = 0; i < arraysize(sizes); ++i) { 208 for (size_t i = 0; i < arraysize(sizes); ++i) {
199 ExtensionResource resource = 209 ExtensionResource resource = extensions::IconsInfo::GetIconResource(
200 extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY); 210 extension, sizes[i], ExtensionIconSet::MATCH_EXACTLY);
201 info_list.push_back(ImageLoader::ImageRepresentation( 211 info_list.push_back(ImageLoader::ImageRepresentation(
202 resource, 212 resource,
203 ImageLoader::ImageRepresentation::RESIZE_WHEN_LARGER, 213 ImageLoader::ImageRepresentation::RESIZE_WHEN_LARGER,
204 gfx::Size(sizes[i], sizes[i]), 214 gfx::Size(sizes[i], sizes[i]),
205 ui::SCALE_FACTOR_NONE)); 215 ui::SCALE_FACTOR_NONE));
206 } 216 }
207 217
208 ImageLoader loader; 218 ImageLoader loader;
209 loader.LoadImagesAsync(extension.get(), info_list, 219 loader.LoadImagesAsync(extension.get(), info_list,
210 base::Bind(&ImageLoaderTest::OnImageLoaded, 220 base::Bind(&ImageLoaderTest::OnImageLoaded,
(...skipping 21 matching lines...) Expand all
232 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH, 242 EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH,
233 img_rep2->pixel_width()); 243 img_rep2->pixel_width());
234 } 244 }
235 245
236 // Tests IsComponentExtensionResource function. 246 // Tests IsComponentExtensionResource function.
237 TEST_F(ImageLoaderTest, IsComponentExtensionResource) { 247 TEST_F(ImageLoaderTest, IsComponentExtensionResource) {
238 scoped_refptr<Extension> extension(CreateExtension( 248 scoped_refptr<Extension> extension(CreateExtension(
239 "file_manager", Manifest::COMPONENT)); 249 "file_manager", Manifest::COMPONENT));
240 ASSERT_TRUE(extension.get() != NULL); 250 ASSERT_TRUE(extension.get() != NULL);
241 251
242 ExtensionResource resource = 252 ExtensionResource resource = extensions::IconsInfo::GetIconResource(
243 extension->GetIconResource(extension_misc::EXTENSION_ICON_BITTY, 253 extension,
244 ExtensionIconSet::MATCH_EXACTLY); 254 extension_misc::EXTENSION_ICON_BITTY,
255 ExtensionIconSet::MATCH_EXACTLY);
245 256
246 #if defined(FILE_MANAGER_EXTENSION) 257 #if defined(FILE_MANAGER_EXTENSION)
247 int resource_id; 258 int resource_id;
248 ASSERT_EQ(true, 259 ASSERT_EQ(true,
249 ImageLoader::IsComponentExtensionResource(extension->path(), 260 ImageLoader::IsComponentExtensionResource(extension->path(),
250 resource.relative_path(), 261 resource.relative_path(),
251 &resource_id)); 262 &resource_id));
252 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); 263 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id);
253 #endif 264 #endif
254 } 265 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698