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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | extensions/browser/extension_icon_image.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_icon_manager_unittest.cc
diff --git a/chrome/browser/extensions/extension_icon_manager_unittest.cc b/chrome/browser/extensions/extension_icon_manager_unittest.cc
index 623ae0b0877f067a36c699ab587734d4d252f000..e6b37f8a446cf3aaaa754c46c1cf3d9d085a8960 100644
--- a/chrome/browser/extensions/extension_icon_manager_unittest.cc
+++ b/chrome/browser/extensions/extension_icon_manager_unittest.cc
@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/command_line.h"
#include "base/json/json_file_value_serializer.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/run_loop.h"
+#include "base/strings/stringprintf.h"
+#include "base/test/scoped_command_line.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/extension_icon_manager.h"
@@ -18,6 +21,9 @@
#include "extensions/common/extension.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/layout.h"
+#include "ui/display/display_list.h"
+#include "ui/display/display_switches.h"
+#include "ui/display/test/test_screen.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
@@ -27,6 +33,31 @@
namespace extensions {
namespace {
+class ScopedSetDeviceScaleFactor {
+ public:
+ explicit ScopedSetDeviceScaleFactor(float scale) {
+ display::Display::ResetForceDeviceScaleFactorForTesting();
+ // It should be enough just to call Display::SetScaleAndBounds, but on Mac
+ // that rounds the scale unless there's a forced device scale factor.
+ command_line_.GetProcessCommandLine()->AppendSwitchASCII(
+ switches::kForceDeviceScaleFactor, base::StringPrintf("%3.2f", scale));
+ // This has to be inited after fiddling with the command line.
+ test_screen_ = base::MakeUnique<display::test::TestScreen>();
+ display::Screen::SetScreenInstance(test_screen_.get());
+ }
+
+ ~ScopedSetDeviceScaleFactor() {
+ display::Display::ResetForceDeviceScaleFactorForTesting();
+ display::Screen::SetScreenInstance(nullptr);
+ }
+
+ private:
+ std::unique_ptr<display::test::TestScreen> test_screen_;
+ base::test::ScopedCommandLine command_line_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedSetDeviceScaleFactor);
+};
+
using content::BrowserThread;
// Our test class that takes care of managing the necessary threads for loading
@@ -232,13 +263,17 @@ TEST_F(ExtensionIconManagerTest, ScaleFactors) {
for (size_t i = 0; i < supported_scales.size(); ++i) {
SCOPED_TRACE(testing::Message() << "Test case: " << i);
+ // Since active Displays' scale factors are also taken into account, to make
+ // the logic in this test work, we need to set the scale factor to one of
+ // the "supported" scales.
+ ScopedSetDeviceScaleFactor scoped_dsf(
+ ui::GetScaleForScaleFactor(supported_scales[i][0]));
ui::test::ScopedSetSupportedScaleFactors scoped(supported_scales[i]);
TestIconManager icon_manager(this);
icon_manager.LoadIcon(profile.get(), extension.get());
WaitForImageLoad();
gfx::Image icon = icon_manager.GetIcon(extension->id());
-
// Determine if the default icon fallback will be used. We'll use the
// default when none of the supported scale factors can find an appropriate
// icon.
@@ -272,6 +307,16 @@ TEST_F(ExtensionIconManagerTest, ScaleFactors) {
EXPECT_EQ(ui::IsSupportedScale(scale), has_representation);
}
}
+
+ // Now check that the scale factors for active displays are respected, even
+ // when it's not a supported scale.
+ EXPECT_FALSE(ui::IsSupportedScale(ui::SCALE_FACTOR_150P));
+ ScopedSetDeviceScaleFactor scoped_dsf(1.5f);
+ TestIconManager icon_manager(this);
+ icon_manager.LoadIcon(profile.get(), extension.get());
+ WaitForImageLoad();
+ gfx::ImageSkia icon = icon_manager.GetIcon(extension->id()).AsImageSkia();
+ EXPECT_TRUE(icon.HasRepresentation(1.5f));
}
} // namespace
« 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