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

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

Issue 2915963002: [Merge M60] arg: Support non-standard display scale factors. (Closed)
Patch Set: Created 3 years, 6 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "content/public/test/test_utils.h" 45 #include "content/public/test/test_utils.h"
46 #include "extensions/browser/extension_system.h" 46 #include "extensions/browser/extension_system.h"
47 #include "extensions/common/extension.h" 47 #include "extensions/common/extension.h"
48 #include "extensions/common/manifest_constants.h" 48 #include "extensions/common/manifest_constants.h"
49 #include "testing/gtest/include/gtest/gtest.h" 49 #include "testing/gtest/include/gtest/gtest.h"
50 #include "ui/app_list/app_list_constants.h" 50 #include "ui/app_list/app_list_constants.h"
51 #include "ui/app_list/app_list_model.h" 51 #include "ui/app_list/app_list_model.h"
52 #include "ui/events/event_constants.h" 52 #include "ui/events/event_constants.h"
53 #include "ui/gfx/geometry/safe_integer_conversions.h" 53 #include "ui/gfx/geometry/safe_integer_conversions.h"
54 #include "ui/gfx/image/image_skia.h" 54 #include "ui/gfx/image/image_skia.h"
55 #include "ui/gfx/image/image_unittest_util.h"
55 56
56 namespace { 57 namespace {
57 58
58 constexpr char kTestPackageName[] = "fake.package.name2"; 59 constexpr char kTestPackageName[] = "fake.package.name2";
59 60
60 class FakeAppIconLoaderDelegate : public AppIconLoaderDelegate { 61 class FakeAppIconLoaderDelegate : public AppIconLoaderDelegate {
61 public: 62 public:
62 FakeAppIconLoaderDelegate() = default; 63 FakeAppIconLoaderDelegate() = default;
63 ~FakeAppIconLoaderDelegate() override = default; 64 ~FakeAppIconLoaderDelegate() override = default;
64 65
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 1403
1403 prefs = ArcAppListPrefs::Get(profile_.get()); 1404 prefs = ArcAppListPrefs::Get(profile_.get());
1404 ASSERT_NE(nullptr, prefs); 1405 ASSERT_NE(nullptr, prefs);
1405 app_instance()->RefreshAppList(); 1406 app_instance()->RefreshAppList();
1406 app_instance()->SendRefreshAppList(apps); 1407 app_instance()->SendRefreshAppList(apps);
1407 1408
1408 // No new icon update requests on restart. Icons were invalidated and updated. 1409 // No new icon update requests on restart. Icons were invalidated and updated.
1409 EXPECT_TRUE(app_instance()->icon_requests().empty()); 1410 EXPECT_TRUE(app_instance()->icon_requests().empty());
1410 } 1411 }
1411 1412
1413 TEST_P(ArcAppModelBuilderTest, IconLoadNonSupportedScales) {
1414 std::vector<ui::ScaleFactor> supported_scale_factors;
1415 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
1416 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
1417 ui::test::ScopedSetSupportedScaleFactors scoped_supported_scale_factors(
1418 supported_scale_factors);
1419
1420 // Initialize one ARC app.
1421 const arc::mojom::AppInfo& app = fake_apps()[0];
1422 const std::string app_id = ArcAppTest::GetAppId(app);
1423 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1424 ASSERT_NE(nullptr, prefs);
1425 app_instance()->RefreshAppList();
1426 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
1427 fake_apps().begin(), fake_apps().begin() + 1));
1428
1429 FakeAppIconLoaderDelegate delegate;
1430 ArcAppIconLoader icon_loader(profile(), app_list::kListIconSize, &delegate);
1431 icon_loader.FetchImage(app_id);
1432 // Expected 1 update with default image and 2 representations should be
1433 // allocated.
1434 EXPECT_EQ(1U, delegate.update_image_cnt());
1435 gfx::ImageSkia app_icon = delegate.image();
1436 EXPECT_EQ(2U, app_icon.image_reps().size());
1437 EXPECT_TRUE(app_icon.HasRepresentation(1.0f));
1438 EXPECT_TRUE(app_icon.HasRepresentation(2.0f));
1439
1440 // Request non-supported scales. Cached supported representations with
1441 // default image should be used. 1.0 is used to scale 1.15 and
1442 // 2.0 is used to scale 1.25.
1443 app_icon.GetRepresentation(1.15f);
1444 app_icon.GetRepresentation(1.25f);
1445 EXPECT_EQ(1U, delegate.update_image_cnt());
1446 EXPECT_EQ(4U, app_icon.image_reps().size());
1447 EXPECT_TRUE(app_icon.HasRepresentation(1.0f));
1448 EXPECT_TRUE(app_icon.HasRepresentation(2.0f));
1449 EXPECT_TRUE(app_icon.HasRepresentation(1.15f));
1450 EXPECT_TRUE(app_icon.HasRepresentation(1.25f));
1451
1452 // Keep default images for reference.
1453 const SkBitmap bitmap_1_0 = app_icon.GetRepresentation(1.0f).sk_bitmap();
1454 const SkBitmap bitmap_1_15 = app_icon.GetRepresentation(1.15f).sk_bitmap();
1455 const SkBitmap bitmap_1_25 = app_icon.GetRepresentation(1.25f).sk_bitmap();
1456 const SkBitmap bitmap_2_0 = app_icon.GetRepresentation(2.0f).sk_bitmap();
1457
1458 // Send icon image for 100P. 1.0 and 1.15 should be updated.
1459 std::string png_data;
1460 EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
1461 app, arc::mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data));
1462 delegate.WaitForIconUpdates(1);
1463
1464 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1465 app_icon.GetRepresentation(1.0f).sk_bitmap(), bitmap_1_0));
1466 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1467 app_icon.GetRepresentation(1.15f).sk_bitmap(), bitmap_1_15));
1468 EXPECT_TRUE(gfx::test::AreBitmapsEqual(
1469 app_icon.GetRepresentation(1.25f).sk_bitmap(), bitmap_1_25));
1470 EXPECT_TRUE(gfx::test::AreBitmapsEqual(
1471 app_icon.GetRepresentation(2.0f).sk_bitmap(), bitmap_2_0));
1472
1473 // Send icon image for 200P. 2.0 and 1.25 should be updated.
1474 EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
1475 app, arc::mojom::ScaleFactor::SCALE_FACTOR_200P, &png_data));
1476 delegate.WaitForIconUpdates(1);
1477
1478 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1479 app_icon.GetRepresentation(1.0f).sk_bitmap(), bitmap_1_0));
1480 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1481 app_icon.GetRepresentation(1.15f).sk_bitmap(), bitmap_1_15));
1482 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1483 app_icon.GetRepresentation(1.25f).sk_bitmap(), bitmap_1_25));
1484 EXPECT_FALSE(gfx::test::AreBitmapsEqual(
1485 app_icon.GetRepresentation(2.0f).sk_bitmap(), bitmap_2_0));
1486 }
1487
1412 TEST_P(ArcAppModelBuilderTest, AppLauncher) { 1488 TEST_P(ArcAppModelBuilderTest, AppLauncher) {
1413 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); 1489 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile());
1414 ASSERT_NE(nullptr, prefs); 1490 ASSERT_NE(nullptr, prefs);
1415 1491
1416 // App1 is called in deferred mode, after refreshing apps. 1492 // App1 is called in deferred mode, after refreshing apps.
1417 // App2 is never called since app is not avaialble. 1493 // App2 is never called since app is not avaialble.
1418 // App3 is never called immediately because app is available already. 1494 // App3 is never called immediately because app is available already.
1419 const arc::mojom::AppInfo& app1 = fake_apps()[0]; 1495 const arc::mojom::AppInfo& app1 = fake_apps()[0];
1420 const arc::mojom::AppInfo& app2 = fake_apps()[1]; 1496 const arc::mojom::AppInfo& app2 = fake_apps()[1];
1421 const arc::mojom::AppInfo& app3 = fake_apps()[2]; 1497 const arc::mojom::AppInfo& app3 = fake_apps()[2];
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 ::testing::ValuesIn(kUnmanagedArcStates)); 1804 ::testing::ValuesIn(kUnmanagedArcStates));
1729 INSTANTIATE_TEST_CASE_P(, 1805 INSTANTIATE_TEST_CASE_P(,
1730 ArcDefaulAppForManagedUserTest, 1806 ArcDefaulAppForManagedUserTest,
1731 ::testing::ValuesIn(kManagedArcStates)); 1807 ::testing::ValuesIn(kManagedArcStates));
1732 INSTANTIATE_TEST_CASE_P(, 1808 INSTANTIATE_TEST_CASE_P(,
1733 ArcPlayStoreAppTest, 1809 ArcPlayStoreAppTest,
1734 ::testing::ValuesIn(kUnmanagedArcStates)); 1810 ::testing::ValuesIn(kUnmanagedArcStates));
1735 INSTANTIATE_TEST_CASE_P(, 1811 INSTANTIATE_TEST_CASE_P(,
1736 ArcAppModelBuilderRecreate, 1812 ArcAppModelBuilderRecreate,
1737 ::testing::ValuesIn(kUnmanagedArcStates)); 1813 ::testing::ValuesIn(kUnmanagedArcStates));
OLDNEW
« 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