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

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_unittest.cc

Issue 2902153002: arc: Support non-standard display scale factors. (Closed)
Patch Set: comment updated 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "content/public/test/test_utils.h" 46 #include "content/public/test/test_utils.h"
47 #include "extensions/browser/extension_system.h" 47 #include "extensions/browser/extension_system.h"
48 #include "extensions/common/extension.h" 48 #include "extensions/common/extension.h"
49 #include "extensions/common/manifest_constants.h" 49 #include "extensions/common/manifest_constants.h"
50 #include "testing/gtest/include/gtest/gtest.h" 50 #include "testing/gtest/include/gtest/gtest.h"
51 #include "ui/app_list/app_list_constants.h" 51 #include "ui/app_list/app_list_constants.h"
52 #include "ui/app_list/app_list_model.h" 52 #include "ui/app_list/app_list_model.h"
53 #include "ui/events/event_constants.h" 53 #include "ui/events/event_constants.h"
54 #include "ui/gfx/geometry/safe_integer_conversions.h" 54 #include "ui/gfx/geometry/safe_integer_conversions.h"
55 #include "ui/gfx/image/image_skia.h" 55 #include "ui/gfx/image/image_skia.h"
56 #include "ui/gfx/image/image_unittest_util.h"
56 57
57 namespace { 58 namespace {
58 59
59 constexpr char kTestPackageName[] = "fake.package.name2"; 60 constexpr char kTestPackageName[] = "fake.package.name2";
60 61
61 class FakeAppIconLoaderDelegate : public AppIconLoaderDelegate { 62 class FakeAppIconLoaderDelegate : public AppIconLoaderDelegate {
62 public: 63 public:
63 FakeAppIconLoaderDelegate() = default; 64 FakeAppIconLoaderDelegate() = default;
64 ~FakeAppIconLoaderDelegate() override = default; 65 ~FakeAppIconLoaderDelegate() override = default;
65 66
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 // Validate loaded image. 1335 // Validate loaded image.
1335 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); 1336 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt());
1336 EXPECT_EQ(app_id, delegate.app_id()); 1337 EXPECT_EQ(app_id, delegate.app_id());
1337 ValidateIcon(delegate.image()); 1338 ValidateIcon(delegate.image());
1338 1339
1339 // No more updates are expected. 1340 // No more updates are expected.
1340 base::RunLoop().RunUntilIdle(); 1341 base::RunLoop().RunUntilIdle();
1341 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); 1342 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt());
1342 } 1343 }
1343 1344
1345 TEST_P(ArcAppModelBuilderTest, IconLoadNonSupportedScales) {
1346 std::vector<ui::ScaleFactor> supported_scale_factors;
1347 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
1348 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
1349 ui::test::ScopedSetSupportedScaleFactors scoped_supported_scale_factors(
1350 supported_scale_factors);
1351
1352 // Initialize one ARC app.
1353 const arc::mojom::AppInfo& app = fake_apps()[0];
1354 const std::string app_id = ArcAppTest::GetAppId(app);
1355 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1356 ASSERT_NE(nullptr, prefs);
1357 app_instance()->RefreshAppList();
1358 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
1359 fake_apps().begin(), fake_apps().begin() + 1));
1360
1361 FakeAppIconLoaderDelegate delegate;
1362 ArcAppIconLoader icon_loader(profile(), app_list::kListIconSize, &delegate);
1363 icon_loader.FetchImage(app_id);
1364 // Expected 1 update with default image and 2 representations should be
1365 // allocated.
1366 EXPECT_EQ(1U, delegate.update_image_cnt());
1367 gfx::ImageSkia app_icon = delegate.image();
1368 EXPECT_EQ(2U, app_icon.image_reps().size());
1369 EXPECT_TRUE(app_icon.HasRepresentation(1.0f));
1370 EXPECT_TRUE(app_icon.HasRepresentation(2.0f));
1371
1372 // Request non-supported scales. Cached supported representations with
1373 // default image should be used. 1.0 is used to scale 1.15 and
1374 // 2.0 is used to scale 1.25.
1375 app_icon.GetRepresentation(1.15f);
1376 app_icon.GetRepresentation(1.25f);
1377 EXPECT_EQ(1U, delegate.update_image_cnt());
1378 EXPECT_EQ(4U, app_icon.image_reps().size());
1379 EXPECT_TRUE(app_icon.HasRepresentation(1.0f));
1380 EXPECT_TRUE(app_icon.HasRepresentation(2.0f));
1381 EXPECT_TRUE(app_icon.HasRepresentation(1.15f));
1382 EXPECT_TRUE(app_icon.HasRepresentation(1.25f));
1383
1384 // Keep default images for reference.
1385 const SkBitmap bitmap_1_0 = app_icon.GetRepresentation(1.0f).sk_bitmap();
1386 const SkBitmap bitmap_1_15 = app_icon.GetRepresentation(1.15f).sk_bitmap();
1387 const SkBitmap bitmap_1_25 = app_icon.GetRepresentation(1.25f).sk_bitmap();
1388 const SkBitmap bitmap_2_0 = app_icon.GetRepresentation(2.0f).sk_bitmap();
1389
1390 // Send icon image for 100P. 1.0 and 1.15 should be updated.
1391 std::string png_data;
1392 EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
1393 app, arc::mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data));
1394 delegate.WaitForIconUpdates(1);
1395
1396 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1397 app_icon.GetRepresentation(1.0f).sk_bitmap(), bitmap_1_0));
1398 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1399 app_icon.GetRepresentation(1.15f).sk_bitmap(), bitmap_1_15));
1400 EXPECT_TRUE(gfx::test::AreBitmapsEqual(
1401 app_icon.GetRepresentation(1.25f).sk_bitmap(), bitmap_1_25));
1402 EXPECT_TRUE(gfx::test::AreBitmapsEqual(
1403 app_icon.GetRepresentation(2.0f).sk_bitmap(), bitmap_2_0));
1404
1405 // Send icon image for 200P. 2.0 and 1.25 should be updated.
1406 EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
1407 app, arc::mojom::ScaleFactor::SCALE_FACTOR_200P, &png_data));
1408 delegate.WaitForIconUpdates(1);
1409
1410 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1411 app_icon.GetRepresentation(1.0f).sk_bitmap(), bitmap_1_0));
1412 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1413 app_icon.GetRepresentation(1.15f).sk_bitmap(), bitmap_1_15));
1414 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1415 app_icon.GetRepresentation(1.25f).sk_bitmap(), bitmap_1_25));
1416 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1417 app_icon.GetRepresentation(2.0f).sk_bitmap(), bitmap_2_0));
1418 }
1419
1344 TEST_P(ArcAppModelBuilderTest, AppLauncher) { 1420 TEST_P(ArcAppModelBuilderTest, AppLauncher) {
1345 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); 1421 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile());
1346 ASSERT_NE(nullptr, prefs); 1422 ASSERT_NE(nullptr, prefs);
1347 1423
1348 // App1 is called in deferred mode, after refreshing apps. 1424 // App1 is called in deferred mode, after refreshing apps.
1349 // App2 is never called since app is not avaialble. 1425 // App2 is never called since app is not avaialble.
1350 // App3 is never called immediately because app is available already. 1426 // App3 is never called immediately because app is available already.
1351 const arc::mojom::AppInfo& app1 = fake_apps()[0]; 1427 const arc::mojom::AppInfo& app1 = fake_apps()[0];
1352 const arc::mojom::AppInfo& app2 = fake_apps()[1]; 1428 const arc::mojom::AppInfo& app2 = fake_apps()[1];
1353 const arc::mojom::AppInfo& app3 = fake_apps()[2]; 1429 const arc::mojom::AppInfo& app3 = fake_apps()[2];
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 ::testing::ValuesIn(kUnmanagedArcStates)); 1741 ::testing::ValuesIn(kUnmanagedArcStates));
1666 INSTANTIATE_TEST_CASE_P(, 1742 INSTANTIATE_TEST_CASE_P(,
1667 ArcDefaulAppForManagedUserTest, 1743 ArcDefaulAppForManagedUserTest,
1668 ::testing::ValuesIn(kManagedArcStates)); 1744 ::testing::ValuesIn(kManagedArcStates));
1669 INSTANTIATE_TEST_CASE_P(, 1745 INSTANTIATE_TEST_CASE_P(,
1670 ArcPlayStoreAppTest, 1746 ArcPlayStoreAppTest,
1671 ::testing::ValuesIn(kUnmanagedArcStates)); 1747 ::testing::ValuesIn(kUnmanagedArcStates));
1672 INSTANTIATE_TEST_CASE_P(, 1748 INSTANTIATE_TEST_CASE_P(,
1673 ArcAppModelBuilderRecreate, 1749 ArcAppModelBuilderRecreate,
1674 ::testing::ValuesIn(kUnmanagedArcStates)); 1750 ::testing::ValuesIn(kUnmanagedArcStates));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698