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

Side by Side Diff: chrome/browser/extensions/image_loading_tracker_unittest.cc

Issue 10701087: chromeos: Fix pixelated icons in app list and launcher (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for comments in #3, add an ImageSource and makes ImageLoadingTracker auto load image for additional… Created 8 years, 5 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 | Annotate | Revision Log
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_loading_tracker.h"
6
7 #include <algorithm>
8
5 #include "base/json/json_file_value_serializer.h" 9 #include "base/json/json_file_value_serializer.h"
6 #include "base/message_loop.h" 10 #include "base/message_loop.h"
7 #include "base/path_service.h" 11 #include "base/path_service.h"
8 #include "chrome/browser/extensions/image_loading_tracker.h"
9 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
11 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/extension_icon_set.h" 15 #include "chrome/common/extensions/extension_icon_set.h"
13 #include "chrome/common/extensions/extension_resource.h" 16 #include "chrome/common/extensions/extension_resource.h"
14 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
15 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
16 #include "grit/component_extension_resources.h" 19 #include "grit/component_extension_resources.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 "image_loading_tracker", Extension::INVALID)); 200 "image_loading_tracker", Extension::INVALID));
198 ASSERT_TRUE(extension.get() != NULL); 201 ASSERT_TRUE(extension.get() != NULL);
199 202
200 std::vector<ImageLoadingTracker::ImageInfo> info_list; 203 std::vector<ImageLoadingTracker::ImageInfo> info_list;
201 int sizes[] = {ExtensionIconSet::EXTENSION_ICON_SMALLISH, 204 int sizes[] = {ExtensionIconSet::EXTENSION_ICON_SMALLISH,
202 ExtensionIconSet::EXTENSION_ICON_BITTY}; 205 ExtensionIconSet::EXTENSION_ICON_BITTY};
203 for (size_t i = 0; i < arraysize(sizes); ++i) { 206 for (size_t i = 0; i < arraysize(sizes); ++i) {
204 ExtensionResource resource = 207 ExtensionResource resource =
205 extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY); 208 extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY);
206 info_list.push_back(ImageLoadingTracker::ImageInfo( 209 info_list.push_back(ImageLoadingTracker::ImageInfo(
207 resource, gfx::Size(sizes[i], sizes[i]))); 210 resource, gfx::Size(sizes[i], sizes[i]), ui::SCALE_FACTOR_NONE));
208 } 211 }
209 212
210 ImageLoadingTracker loader(this); 213 ImageLoadingTracker loader(this);
211 loader.LoadImages(extension.get(), info_list, ImageLoadingTracker::CACHE); 214 loader.LoadImages(extension.get(), info_list, ImageLoadingTracker::CACHE);
212 215
213 // The image isn't cached, so we should not have received notification. 216 // The image isn't cached, so we should not have received notification.
214 EXPECT_EQ(0, image_loaded_count()); 217 EXPECT_EQ(0, image_loaded_count());
215 218
216 WaitForImageLoad(); 219 WaitForImageLoad();
217 220
(...skipping 28 matching lines...) Expand all
246 #if defined(FILE_MANAGER_EXTENSION) 249 #if defined(FILE_MANAGER_EXTENSION)
247 ImageLoadingTracker loader(this); 250 ImageLoadingTracker loader(this);
248 int resource_id; 251 int resource_id;
249 ASSERT_EQ(true, 252 ASSERT_EQ(true,
250 loader.IsComponentExtensionResource(extension.get(), 253 loader.IsComponentExtensionResource(extension.get(),
251 resource, 254 resource,
252 resource_id)); 255 resource_id));
253 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id); 256 ASSERT_EQ(IDR_FILE_MANAGER_ICON_16, resource_id);
254 #endif 257 #endif
255 } 258 }
259
260 // Tests loading image that supports DIP.
261 TEST_F(ImageLoadingTrackerTest, LoadImageInDIP) {
262 scoped_refptr<Extension> extension(CreateExtension(
263 "image_loading_tracker", Extension::INVALID));
264 ASSERT_TRUE(extension.get() != NULL);
265
266 ImageLoadingTracker loader(this);
267 loader.LoadImageInDIP(extension,
268 ExtensionIconSet::EXTENSION_ICON_BITTY,
269 ExtensionIconSet::MATCH_SMALLER,
270 gfx::Size(ExtensionIconSet::EXTENSION_ICON_BITTY,
271 ExtensionIconSet::EXTENSION_ICON_BITTY),
272 ImageLoadingTracker::DONT_CACHE);
273
274 EXPECT_EQ(0, image_loaded_count());
275 WaitForImageLoad();
276 EXPECT_EQ(1, image_loaded_count());
277
278 std::vector<gfx::ImageSkiaRep> image_reps =
279 image_.ToImageSkia()->image_reps();
280 ASSERT_EQ(1u, image_reps.size());
281 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_reps[0].scale_factor());
282 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_SMALLISH,
283 image_reps[0].pixel_width());
284
285 // Nows, asks image for a different scale factor.
286 image_.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P);
287 WaitForImageLoad();
288 EXPECT_EQ(1, image_loaded_count());
289
290 image_reps = image_.ToImageSkia()->image_reps();
291 // TODO(xiyaun): Uncomment the following after peter's CL that keeps
292 // only one representation for one scale factor change is in.
293 // ASSERT_EQ(2u, image_reps.size());
294 gfx::ImageSkiaRep image_rep =
295 image_.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P);
296 EXPECT_EQ(ExtensionIconSet::EXTENSION_ICON_BITTY,
297 image_rep.pixel_width());
298 }
299
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698