| OLD | NEW |
| 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 Loading... |
| 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 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1399 | 1400 |
| 1400 prefs = ArcAppListPrefs::Get(profile_.get()); | 1401 prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1401 ASSERT_NE(nullptr, prefs); | 1402 ASSERT_NE(nullptr, prefs); |
| 1402 app_instance()->RefreshAppList(); | 1403 app_instance()->RefreshAppList(); |
| 1403 app_instance()->SendRefreshAppList(apps); | 1404 app_instance()->SendRefreshAppList(apps); |
| 1404 | 1405 |
| 1405 // No new icon update requests on restart. Icons were invalidated and updated. | 1406 // No new icon update requests on restart. Icons were invalidated and updated. |
| 1406 EXPECT_TRUE(app_instance()->icon_requests().empty()); | 1407 EXPECT_TRUE(app_instance()->icon_requests().empty()); |
| 1407 } | 1408 } |
| 1408 | 1409 |
| 1410 TEST_P(ArcAppModelBuilderTest, IconLoadNonSupportedScales) { |
| 1411 std::vector<ui::ScaleFactor> supported_scale_factors; |
| 1412 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); |
| 1413 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P); |
| 1414 ui::test::ScopedSetSupportedScaleFactors scoped_supported_scale_factors( |
| 1415 supported_scale_factors); |
| 1416 |
| 1417 // Initialize one ARC app. |
| 1418 const arc::mojom::AppInfo& app = fake_apps()[0]; |
| 1419 const std::string app_id = ArcAppTest::GetAppId(app); |
| 1420 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1421 ASSERT_NE(nullptr, prefs); |
| 1422 app_instance()->RefreshAppList(); |
| 1423 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
| 1424 fake_apps().begin(), fake_apps().begin() + 1)); |
| 1425 |
| 1426 FakeAppIconLoaderDelegate delegate; |
| 1427 ArcAppIconLoader icon_loader(profile(), app_list::kListIconSize, &delegate); |
| 1428 icon_loader.FetchImage(app_id); |
| 1429 // Expected 1 update with default image and 2 representations should be |
| 1430 // allocated. |
| 1431 EXPECT_EQ(1U, delegate.update_image_cnt()); |
| 1432 gfx::ImageSkia app_icon = delegate.image(); |
| 1433 EXPECT_EQ(2U, app_icon.image_reps().size()); |
| 1434 EXPECT_TRUE(app_icon.HasRepresentation(1.0f)); |
| 1435 EXPECT_TRUE(app_icon.HasRepresentation(2.0f)); |
| 1436 |
| 1437 // Request non-supported scales. Cached supported representations with |
| 1438 // default image should be used. 1.0 is used to scale 1.15 and |
| 1439 // 2.0 is used to scale 1.25. |
| 1440 app_icon.GetRepresentation(1.15f); |
| 1441 app_icon.GetRepresentation(1.25f); |
| 1442 EXPECT_EQ(1U, delegate.update_image_cnt()); |
| 1443 EXPECT_EQ(4U, app_icon.image_reps().size()); |
| 1444 EXPECT_TRUE(app_icon.HasRepresentation(1.0f)); |
| 1445 EXPECT_TRUE(app_icon.HasRepresentation(2.0f)); |
| 1446 EXPECT_TRUE(app_icon.HasRepresentation(1.15f)); |
| 1447 EXPECT_TRUE(app_icon.HasRepresentation(1.25f)); |
| 1448 |
| 1449 // Keep default images for reference. |
| 1450 const SkBitmap bitmap_1_0 = app_icon.GetRepresentation(1.0f).sk_bitmap(); |
| 1451 const SkBitmap bitmap_1_15 = app_icon.GetRepresentation(1.15f).sk_bitmap(); |
| 1452 const SkBitmap bitmap_1_25 = app_icon.GetRepresentation(1.25f).sk_bitmap(); |
| 1453 const SkBitmap bitmap_2_0 = app_icon.GetRepresentation(2.0f).sk_bitmap(); |
| 1454 |
| 1455 // Send icon image for 100P. 1.0 and 1.15 should be updated. |
| 1456 std::string png_data; |
| 1457 EXPECT_TRUE(app_instance()->GenerateAndSendIcon( |
| 1458 app, arc::mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data)); |
| 1459 delegate.WaitForIconUpdates(1); |
| 1460 |
| 1461 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1462 app_icon.GetRepresentation(1.0f).sk_bitmap(), bitmap_1_0)); |
| 1463 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1464 app_icon.GetRepresentation(1.15f).sk_bitmap(), bitmap_1_15)); |
| 1465 EXPECT_TRUE(gfx::test::AreBitmapsEqual( |
| 1466 app_icon.GetRepresentation(1.25f).sk_bitmap(), bitmap_1_25)); |
| 1467 EXPECT_TRUE(gfx::test::AreBitmapsEqual( |
| 1468 app_icon.GetRepresentation(2.0f).sk_bitmap(), bitmap_2_0)); |
| 1469 |
| 1470 // Send icon image for 200P. 2.0 and 1.25 should be updated. |
| 1471 EXPECT_TRUE(app_instance()->GenerateAndSendIcon( |
| 1472 app, arc::mojom::ScaleFactor::SCALE_FACTOR_200P, &png_data)); |
| 1473 delegate.WaitForIconUpdates(1); |
| 1474 |
| 1475 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1476 app_icon.GetRepresentation(1.0f).sk_bitmap(), bitmap_1_0)); |
| 1477 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1478 app_icon.GetRepresentation(1.15f).sk_bitmap(), bitmap_1_15)); |
| 1479 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1480 app_icon.GetRepresentation(1.25f).sk_bitmap(), bitmap_1_25)); |
| 1481 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1482 app_icon.GetRepresentation(2.0f).sk_bitmap(), bitmap_2_0)); |
| 1483 } |
| 1484 |
| 1409 TEST_P(ArcAppModelBuilderTest, AppLauncher) { | 1485 TEST_P(ArcAppModelBuilderTest, AppLauncher) { |
| 1410 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); | 1486 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); |
| 1411 ASSERT_NE(nullptr, prefs); | 1487 ASSERT_NE(nullptr, prefs); |
| 1412 | 1488 |
| 1413 // App1 is called in deferred mode, after refreshing apps. | 1489 // App1 is called in deferred mode, after refreshing apps. |
| 1414 // App2 is never called since app is not avaialble. | 1490 // App2 is never called since app is not avaialble. |
| 1415 // App3 is never called immediately because app is available already. | 1491 // App3 is never called immediately because app is available already. |
| 1416 const arc::mojom::AppInfo& app1 = fake_apps()[0]; | 1492 const arc::mojom::AppInfo& app1 = fake_apps()[0]; |
| 1417 const arc::mojom::AppInfo& app2 = fake_apps()[1]; | 1493 const arc::mojom::AppInfo& app2 = fake_apps()[1]; |
| 1418 const arc::mojom::AppInfo& app3 = fake_apps()[2]; | 1494 const arc::mojom::AppInfo& app3 = fake_apps()[2]; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1725 ::testing::ValuesIn(kUnmanagedArcStates)); | 1801 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1726 INSTANTIATE_TEST_CASE_P(, | 1802 INSTANTIATE_TEST_CASE_P(, |
| 1727 ArcDefaulAppForManagedUserTest, | 1803 ArcDefaulAppForManagedUserTest, |
| 1728 ::testing::ValuesIn(kManagedArcStates)); | 1804 ::testing::ValuesIn(kManagedArcStates)); |
| 1729 INSTANTIATE_TEST_CASE_P(, | 1805 INSTANTIATE_TEST_CASE_P(, |
| 1730 ArcPlayStoreAppTest, | 1806 ArcPlayStoreAppTest, |
| 1731 ::testing::ValuesIn(kUnmanagedArcStates)); | 1807 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1732 INSTANTIATE_TEST_CASE_P(, | 1808 INSTANTIATE_TEST_CASE_P(, |
| 1733 ArcAppModelBuilderRecreate, | 1809 ArcAppModelBuilderRecreate, |
| 1734 ::testing::ValuesIn(kUnmanagedArcStates)); | 1810 ::testing::ValuesIn(kUnmanagedArcStates)); |
| OLD | NEW |