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

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

Issue 2609853003: Load extension icons for more scale factors. (Closed)
Patch Set: rebase Created 3 years, 11 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
« no previous file with comments | « no previous file | extensions/browser/extension_icon_image.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/command_line.h"
5 #include "base/json/json_file_value_serializer.h" 6 #include "base/json/json_file_value_serializer.h"
6 #include "base/macros.h" 7 #include "base/macros.h"
7 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/path_service.h" 10 #include "base/path_service.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/stringprintf.h"
13 #include "base/test/scoped_command_line.h"
11 #include "base/values.h" 14 #include "base/values.h"
12 #include "build/build_config.h" 15 #include "build/build_config.h"
13 #include "chrome/browser/extensions/extension_icon_manager.h" 16 #include "chrome/browser/extensions/extension_icon_manager.h"
14 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
15 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
16 #include "components/crx_file/id_util.h" 19 #include "components/crx_file/id_util.h"
17 #include "content/public/test/test_browser_thread.h" 20 #include "content/public/test/test_browser_thread.h"
18 #include "extensions/common/extension.h" 21 #include "extensions/common/extension.h"
19 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/base/layout.h" 23 #include "ui/base/layout.h"
24 #include "ui/display/display_list.h"
25 #include "ui/display/display_switches.h"
26 #include "ui/display/test/test_screen.h"
21 #include "ui/gfx/favicon_size.h" 27 #include "ui/gfx/favicon_size.h"
22 #include "ui/gfx/image/image.h" 28 #include "ui/gfx/image/image.h"
23 #include "ui/gfx/image/image_skia.h" 29 #include "ui/gfx/image/image_skia.h"
24 #include "ui/gfx/image/image_unittest_util.h" 30 #include "ui/gfx/image/image_unittest_util.h"
25 #include "ui/gfx/skia_util.h" 31 #include "ui/gfx/skia_util.h"
26 32
27 namespace extensions { 33 namespace extensions {
28 namespace { 34 namespace {
29 35
36 class ScopedSetDeviceScaleFactor {
37 public:
38 explicit ScopedSetDeviceScaleFactor(float scale) {
39 display::Display::ResetForceDeviceScaleFactorForTesting();
40 // It should be enough just to call Display::SetScaleAndBounds, but on Mac
41 // that rounds the scale unless there's a forced device scale factor.
42 command_line_.GetProcessCommandLine()->AppendSwitchASCII(
43 switches::kForceDeviceScaleFactor, base::StringPrintf("%3.2f", scale));
44 // This has to be inited after fiddling with the command line.
45 test_screen_ = base::MakeUnique<display::test::TestScreen>();
46 display::Screen::SetScreenInstance(test_screen_.get());
47 }
48
49 ~ScopedSetDeviceScaleFactor() {
50 display::Display::ResetForceDeviceScaleFactorForTesting();
51 display::Screen::SetScreenInstance(nullptr);
52 }
53
54 private:
55 std::unique_ptr<display::test::TestScreen> test_screen_;
56 base::test::ScopedCommandLine command_line_;
57
58 DISALLOW_COPY_AND_ASSIGN(ScopedSetDeviceScaleFactor);
59 };
60
30 using content::BrowserThread; 61 using content::BrowserThread;
31 62
32 // Our test class that takes care of managing the necessary threads for loading 63 // Our test class that takes care of managing the necessary threads for loading
33 // extension icons, and waiting for those loads to happen. 64 // extension icons, and waiting for those loads to happen.
34 class ExtensionIconManagerTest : public testing::Test { 65 class ExtensionIconManagerTest : public testing::Test {
35 public: 66 public:
36 ExtensionIconManagerTest() : 67 ExtensionIconManagerTest() :
37 unwaited_image_loads_(0), 68 unwaited_image_loads_(0),
38 waiting_(false), 69 waiting_(false),
39 ui_thread_(BrowserThread::UI, &ui_loop_), 70 ui_thread_(BrowserThread::UI, &ui_loop_),
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 {ui::SCALE_FACTOR_125P}, 256 {ui::SCALE_FACTOR_125P},
226 // One scale factor for which we have an icon, one scale factor for which 257 // One scale factor for which we have an icon, one scale factor for which
227 // we don't. 258 // we don't.
228 {ui::SCALE_FACTOR_100P, ui::SCALE_FACTOR_300P}, 259 {ui::SCALE_FACTOR_100P, ui::SCALE_FACTOR_300P},
229 // Just a scale factor where we don't have any icon. This falls back to 260 // Just a scale factor where we don't have any icon. This falls back to
230 // the default icon. 261 // the default icon.
231 {ui::SCALE_FACTOR_300P}}; 262 {ui::SCALE_FACTOR_300P}};
232 263
233 for (size_t i = 0; i < supported_scales.size(); ++i) { 264 for (size_t i = 0; i < supported_scales.size(); ++i) {
234 SCOPED_TRACE(testing::Message() << "Test case: " << i); 265 SCOPED_TRACE(testing::Message() << "Test case: " << i);
266 // Since active Displays' scale factors are also taken into account, to make
267 // the logic in this test work, we need to set the scale factor to one of
268 // the "supported" scales.
269 ScopedSetDeviceScaleFactor scoped_dsf(
270 ui::GetScaleForScaleFactor(supported_scales[i][0]));
235 ui::test::ScopedSetSupportedScaleFactors scoped(supported_scales[i]); 271 ui::test::ScopedSetSupportedScaleFactors scoped(supported_scales[i]);
236 TestIconManager icon_manager(this); 272 TestIconManager icon_manager(this);
237 273
238 icon_manager.LoadIcon(profile.get(), extension.get()); 274 icon_manager.LoadIcon(profile.get(), extension.get());
239 WaitForImageLoad(); 275 WaitForImageLoad();
240 gfx::Image icon = icon_manager.GetIcon(extension->id()); 276 gfx::Image icon = icon_manager.GetIcon(extension->id());
241
242 // Determine if the default icon fallback will be used. We'll use the 277 // Determine if the default icon fallback will be used. We'll use the
243 // default when none of the supported scale factors can find an appropriate 278 // default when none of the supported scale factors can find an appropriate
244 // icon. 279 // icon.
245 bool should_fall_back_to_default = true; 280 bool should_fall_back_to_default = true;
246 for (auto supported_scale : supported_scales[i]) { 281 for (auto supported_scale : supported_scales[i]) {
247 if (gfx::kFaviconSize * ui::GetScaleForScaleFactor(supported_scale) <= 282 if (gfx::kFaviconSize * ui::GetScaleForScaleFactor(supported_scale) <=
248 kMaxIconSizeInManifest) { 283 kMaxIconSizeInManifest) {
249 should_fall_back_to_default = false; 284 should_fall_back_to_default = false;
250 break; 285 break;
251 } 286 }
(...skipping 13 matching lines...) Expand all
265 300
266 const bool has_representation = image_skia.HasRepresentation(scale); 301 const bool has_representation = image_skia.HasRepresentation(scale);
267 // We shouldn't have a representation if the extension didn't provide a 302 // We shouldn't have a representation if the extension didn't provide a
268 // big enough icon. 303 // big enough icon.
269 if (gfx::kFaviconSize * scale > kMaxIconSizeInManifest) 304 if (gfx::kFaviconSize * scale > kMaxIconSizeInManifest)
270 EXPECT_FALSE(has_representation); 305 EXPECT_FALSE(has_representation);
271 else 306 else
272 EXPECT_EQ(ui::IsSupportedScale(scale), has_representation); 307 EXPECT_EQ(ui::IsSupportedScale(scale), has_representation);
273 } 308 }
274 } 309 }
310
311 // Now check that the scale factors for active displays are respected, even
312 // when it's not a supported scale.
313 EXPECT_FALSE(ui::IsSupportedScale(ui::SCALE_FACTOR_150P));
314 ScopedSetDeviceScaleFactor scoped_dsf(1.5f);
315 TestIconManager icon_manager(this);
316 icon_manager.LoadIcon(profile.get(), extension.get());
317 WaitForImageLoad();
318 gfx::ImageSkia icon = icon_manager.GetIcon(extension->id()).AsImageSkia();
319 EXPECT_TRUE(icon.HasRepresentation(1.5f));
275 } 320 }
276 321
277 } // namespace 322 } // namespace
278 } // namespace extensions 323 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/extension_icon_image.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698