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

Unified Diff: chrome/browser/ui/app_list/arc/arc_app_unittest.cc

Issue 2902153002: arc: Support non-standard display scale factors. (Closed)
Patch Set: rebase + unit test update to match this CL Created 3 years, 7 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
Index: chrome/browser/ui/app_list/arc/arc_app_unittest.cc
diff --git a/chrome/browser/ui/app_list/arc/arc_app_unittest.cc b/chrome/browser/ui/app_list/arc/arc_app_unittest.cc
index 919b6be531c9969116eeb326c665d12bcbb221f5..b88e07229a94d426c40ebac9646e5647fd33ea60 100644
--- a/chrome/browser/ui/app_list/arc/arc_app_unittest.cc
+++ b/chrome/browser/ui/app_list/arc/arc_app_unittest.cc
@@ -52,6 +52,7 @@
#include "ui/events/event_constants.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/image/image_skia.h"
+#include "ui/gfx/image/image_unittest_util.h"
namespace {
@@ -1406,6 +1407,81 @@ TEST_P(ArcAppModelBuilderRecreate, IconInvalidation) {
EXPECT_TRUE(app_instance()->icon_requests().empty());
}
+TEST_P(ArcAppModelBuilderTest, IconLoadNonSupportedScales) {
+ std::vector<ui::ScaleFactor> supported_scale_factors;
+ supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
+ supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
+ ui::test::ScopedSetSupportedScaleFactors scoped_supported_scale_factors(
+ supported_scale_factors);
+
+ // Initialize one ARC app.
+ const arc::mojom::AppInfo& app = fake_apps()[0];
+ const std::string app_id = ArcAppTest::GetAppId(app);
+ ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
+ ASSERT_NE(nullptr, prefs);
+ app_instance()->RefreshAppList();
+ app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
+ fake_apps().begin(), fake_apps().begin() + 1));
+
+ FakeAppIconLoaderDelegate delegate;
+ ArcAppIconLoader icon_loader(profile(), app_list::kListIconSize, &delegate);
+ icon_loader.FetchImage(app_id);
+ // Expected 1 update with default image and 2 representations should be
+ // allocated.
+ EXPECT_EQ(1U, delegate.update_image_cnt());
+ gfx::ImageSkia app_icon = delegate.image();
+ EXPECT_EQ(2U, app_icon.image_reps().size());
+ EXPECT_TRUE(app_icon.HasRepresentation(1.0f));
+ EXPECT_TRUE(app_icon.HasRepresentation(2.0f));
+
+ // Request non-supported scales. Cached supported representations with
+ // default image should be used. 1.0 is used to scale 1.15 and
+ // 2.0 is used to scale 1.25.
+ app_icon.GetRepresentation(1.15f);
+ app_icon.GetRepresentation(1.25f);
+ EXPECT_EQ(1U, delegate.update_image_cnt());
+ EXPECT_EQ(4U, app_icon.image_reps().size());
+ EXPECT_TRUE(app_icon.HasRepresentation(1.0f));
+ EXPECT_TRUE(app_icon.HasRepresentation(2.0f));
+ EXPECT_TRUE(app_icon.HasRepresentation(1.15f));
+ EXPECT_TRUE(app_icon.HasRepresentation(1.25f));
+
+ // Keep default images for reference.
+ const SkBitmap bitmap_1_0 = app_icon.GetRepresentation(1.0f).sk_bitmap();
+ const SkBitmap bitmap_1_15 = app_icon.GetRepresentation(1.15f).sk_bitmap();
+ const SkBitmap bitmap_1_25 = app_icon.GetRepresentation(1.25f).sk_bitmap();
+ const SkBitmap bitmap_2_0 = app_icon.GetRepresentation(2.0f).sk_bitmap();
+
+ // Send icon image for 100P. 1.0 and 1.15 should be updated.
+ std::string png_data;
+ EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
+ app, arc::mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data));
+ delegate.WaitForIconUpdates(1);
+
+ EXPECT_FALSE(gfx::test::AreBitmapsEqual(
+ app_icon.GetRepresentation(1.0f).sk_bitmap(), bitmap_1_0));
+ EXPECT_FALSE(gfx::test::AreBitmapsEqual(
+ app_icon.GetRepresentation(1.15f).sk_bitmap(), bitmap_1_15));
+ EXPECT_TRUE(gfx::test::AreBitmapsEqual(
+ app_icon.GetRepresentation(1.25f).sk_bitmap(), bitmap_1_25));
+ EXPECT_TRUE(gfx::test::AreBitmapsEqual(
+ app_icon.GetRepresentation(2.0f).sk_bitmap(), bitmap_2_0));
+
+ // Send icon image for 200P. 2.0 and 1.25 should be updated.
+ EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
+ app, arc::mojom::ScaleFactor::SCALE_FACTOR_200P, &png_data));
+ delegate.WaitForIconUpdates(1);
+
+ EXPECT_FALSE(gfx::test::AreBitmapsEqual(
+ app_icon.GetRepresentation(1.0f).sk_bitmap(), bitmap_1_0));
+ EXPECT_FALSE(gfx::test::AreBitmapsEqual(
+ app_icon.GetRepresentation(1.15f).sk_bitmap(), bitmap_1_15));
+ EXPECT_FALSE(gfx::test::AreBitmapsEqual(
+ app_icon.GetRepresentation(1.25f).sk_bitmap(), bitmap_1_25));
+ EXPECT_FALSE(gfx::test::AreBitmapsEqual(
+ app_icon.GetRepresentation(2.0f).sk_bitmap(), bitmap_2_0));
+}
+
TEST_P(ArcAppModelBuilderTest, AppLauncher) {
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile());
ASSERT_NE(nullptr, prefs);
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_icon.cc ('k') | chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698