| 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 1261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 // Validate loaded image. | 1327 // Validate loaded image. |
| 1327 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); | 1328 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); |
| 1328 EXPECT_EQ(app_id, delegate.app_id()); | 1329 EXPECT_EQ(app_id, delegate.app_id()); |
| 1329 ValidateIcon(delegate.image()); | 1330 ValidateIcon(delegate.image()); |
| 1330 | 1331 |
| 1331 // No more updates are expected. | 1332 // No more updates are expected. |
| 1332 base::RunLoop().RunUntilIdle(); | 1333 base::RunLoop().RunUntilIdle(); |
| 1333 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); | 1334 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); |
| 1334 } | 1335 } |
| 1335 | 1336 |
| 1337 TEST_P(ArcAppModelBuilderTest, IconLoadNonSupportedScales) { |
| 1338 std::vector<ui::ScaleFactor> supported_scale_factors; |
| 1339 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); |
| 1340 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P); |
| 1341 ui::test::ScopedSetSupportedScaleFactors scoped_supported_scale_factors( |
| 1342 supported_scale_factors); |
| 1343 |
| 1344 // Initialize one ARC app. |
| 1345 const arc::mojom::AppInfo& app = fake_apps()[0]; |
| 1346 const std::string app_id = ArcAppTest::GetAppId(app); |
| 1347 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1348 ASSERT_NE(nullptr, prefs); |
| 1349 app_instance()->RefreshAppList(); |
| 1350 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
| 1351 fake_apps().begin(), fake_apps().begin() + 1)); |
| 1352 |
| 1353 FakeAppIconLoaderDelegate delegate; |
| 1354 ArcAppIconLoader icon_loader(profile(), app_list::kListIconSize, &delegate); |
| 1355 icon_loader.FetchImage(app_id); |
| 1356 // Expected 1 update with default image and 2 representations should be |
| 1357 // allocated. |
| 1358 EXPECT_EQ(1U, delegate.update_image_cnt()); |
| 1359 gfx::ImageSkia app_icon = delegate.image(); |
| 1360 EXPECT_EQ(2U, app_icon.image_reps().size()); |
| 1361 EXPECT_TRUE(app_icon.HasRepresentation(1.0f)); |
| 1362 EXPECT_TRUE(app_icon.HasRepresentation(2.0f)); |
| 1363 |
| 1364 // Request non-supported scales. Cached supported representations with |
| 1365 // default image should be used. 1.0 is used to scale 1.15 and |
| 1366 // 2.0 is used to scale 1.25. |
| 1367 app_icon.GetRepresentation(1.15f); |
| 1368 app_icon.GetRepresentation(1.25f); |
| 1369 EXPECT_EQ(1U, delegate.update_image_cnt()); |
| 1370 EXPECT_EQ(4U, app_icon.image_reps().size()); |
| 1371 EXPECT_TRUE(app_icon.HasRepresentation(1.0f)); |
| 1372 EXPECT_TRUE(app_icon.HasRepresentation(2.0f)); |
| 1373 EXPECT_TRUE(app_icon.HasRepresentation(1.15f)); |
| 1374 EXPECT_TRUE(app_icon.HasRepresentation(1.25f)); |
| 1375 |
| 1376 // Keep default images for reference. |
| 1377 const SkBitmap bitmap_1_0 = app_icon.GetRepresentation(1.0f).sk_bitmap(); |
| 1378 const SkBitmap bitmap_1_15 = app_icon.GetRepresentation(1.15f).sk_bitmap(); |
| 1379 const SkBitmap bitmap_1_25 = app_icon.GetRepresentation(1.25f).sk_bitmap(); |
| 1380 const SkBitmap bitmap_2_0 = app_icon.GetRepresentation(2.0f).sk_bitmap(); |
| 1381 |
| 1382 // Send icon image for 100P. 1.0 and 1.15 should be updated. |
| 1383 std::string png_data; |
| 1384 EXPECT_TRUE(app_instance()->GenerateAndSendIcon( |
| 1385 app, arc::mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data)); |
| 1386 delegate.WaitForIconUpdates(1); |
| 1387 |
| 1388 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1389 app_icon.GetRepresentation(1.0f).sk_bitmap(), bitmap_1_0)); |
| 1390 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1391 app_icon.GetRepresentation(1.15f).sk_bitmap(), bitmap_1_15)); |
| 1392 EXPECT_TRUE(gfx::test::AreBitmapsEqual( |
| 1393 app_icon.GetRepresentation(1.25f).sk_bitmap(), bitmap_1_25)); |
| 1394 EXPECT_TRUE(gfx::test::AreBitmapsEqual( |
| 1395 app_icon.GetRepresentation(2.0f).sk_bitmap(), bitmap_2_0)); |
| 1396 |
| 1397 // Send icon image for 200P. 2.0 and 1.25 should be updated. |
| 1398 EXPECT_TRUE(app_instance()->GenerateAndSendIcon( |
| 1399 app, arc::mojom::ScaleFactor::SCALE_FACTOR_200P, &png_data)); |
| 1400 delegate.WaitForIconUpdates(1); |
| 1401 |
| 1402 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1403 app_icon.GetRepresentation(1.0f).sk_bitmap(), bitmap_1_0)); |
| 1404 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1405 app_icon.GetRepresentation(1.15f).sk_bitmap(), bitmap_1_15)); |
| 1406 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1407 app_icon.GetRepresentation(1.25f).sk_bitmap(), bitmap_1_25)); |
| 1408 EXPECT_FALSE(gfx::test::AreBitmapsEqual( |
| 1409 app_icon.GetRepresentation(2.0f).sk_bitmap(), bitmap_2_0)); |
| 1410 } |
| 1411 |
| 1336 TEST_P(ArcAppModelBuilderTest, AppLauncher) { | 1412 TEST_P(ArcAppModelBuilderTest, AppLauncher) { |
| 1337 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); | 1413 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); |
| 1338 ASSERT_NE(nullptr, prefs); | 1414 ASSERT_NE(nullptr, prefs); |
| 1339 | 1415 |
| 1340 // App1 is called in deferred mode, after refreshing apps. | 1416 // App1 is called in deferred mode, after refreshing apps. |
| 1341 // App2 is never called since app is not avaialble. | 1417 // App2 is never called since app is not avaialble. |
| 1342 // App3 is never called immediately because app is available already. | 1418 // App3 is never called immediately because app is available already. |
| 1343 const arc::mojom::AppInfo& app1 = fake_apps()[0]; | 1419 const arc::mojom::AppInfo& app1 = fake_apps()[0]; |
| 1344 const arc::mojom::AppInfo& app2 = fake_apps()[1]; | 1420 const arc::mojom::AppInfo& app2 = fake_apps()[1]; |
| 1345 const arc::mojom::AppInfo& app3 = fake_apps()[2]; | 1421 const arc::mojom::AppInfo& app3 = fake_apps()[2]; |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1657 ::testing::ValuesIn(kUnmanagedArcStates)); | 1733 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1658 INSTANTIATE_TEST_CASE_P(, | 1734 INSTANTIATE_TEST_CASE_P(, |
| 1659 ArcDefaulAppForManagedUserTest, | 1735 ArcDefaulAppForManagedUserTest, |
| 1660 ::testing::ValuesIn(kManagedArcStates)); | 1736 ::testing::ValuesIn(kManagedArcStates)); |
| 1661 INSTANTIATE_TEST_CASE_P(, | 1737 INSTANTIATE_TEST_CASE_P(, |
| 1662 ArcPlayStoreAppTest, | 1738 ArcPlayStoreAppTest, |
| 1663 ::testing::ValuesIn(kUnmanagedArcStates)); | 1739 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1664 INSTANTIATE_TEST_CASE_P(, | 1740 INSTANTIATE_TEST_CASE_P(, |
| 1665 ArcAppModelBuilderRecreate, | 1741 ArcAppModelBuilderRecreate, |
| 1666 ::testing::ValuesIn(kUnmanagedArcStates)); | 1742 ::testing::ValuesIn(kUnmanagedArcStates)); |
| OLD | NEW |