| 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 EXPECT_TRUE(image.HasRepresentation(scale)); | 315 EXPECT_TRUE(image.HasRepresentation(scale)); |
| 316 const gfx::ImageSkiaRep& representation = image.GetRepresentation(scale); | 316 const gfx::ImageSkiaRep& representation = image.GetRepresentation(scale); |
| 317 EXPECT_FALSE(representation.is_null()); | 317 EXPECT_FALSE(representation.is_null()); |
| 318 EXPECT_EQ(gfx::ToCeiledInt(app_list::kGridIconDimension * scale), | 318 EXPECT_EQ(gfx::ToCeiledInt(app_list::kGridIconDimension * scale), |
| 319 representation.pixel_width()); | 319 representation.pixel_width()); |
| 320 EXPECT_EQ(gfx::ToCeiledInt(app_list::kGridIconDimension * scale), | 320 EXPECT_EQ(gfx::ToCeiledInt(app_list::kGridIconDimension * scale), |
| 321 representation.pixel_height()); | 321 representation.pixel_height()); |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 | 324 |
| 325 // Removes icon request record and allowd re-sending icon request. |
| 326 void MaybeRemoveIconRequestRecord(const std::string& app_id) { |
| 327 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 328 ASSERT_NE(nullptr, prefs); |
| 329 |
| 330 prefs->MaybeRemoveIconRequestRecord(app_id); |
| 331 } |
| 332 |
| 325 void AddPackage(const arc::mojom::ArcPackageInfo& package) { | 333 void AddPackage(const arc::mojom::ArcPackageInfo& package) { |
| 326 arc_test_.AddPackage(package); | 334 arc_test_.AddPackage(package); |
| 327 } | 335 } |
| 328 | 336 |
| 329 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { | 337 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { |
| 330 arc_test_.RemovePackage(package); | 338 arc_test_.RemovePackage(package); |
| 331 } | 339 } |
| 332 | 340 |
| 333 AppListControllerDelegate* controller() { return controller_.get(); } | 341 AppListControllerDelegate* controller() { return controller_.get(); } |
| 334 | 342 |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 ASSERT_NE(nullptr, prefs); | 873 ASSERT_NE(nullptr, prefs); |
| 866 | 874 |
| 867 const std::string app_id = ArcAppTest::GetAppId(app); | 875 const std::string app_id = ArcAppTest::GetAppId(app); |
| 868 const base::FilePath app_path = prefs->GetAppPath(app_id); | 876 const base::FilePath app_path = prefs->GetAppPath(app_id); |
| 869 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0]; | 877 const ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactors()[0]; |
| 870 | 878 |
| 871 // No app folder by default. | 879 // No app folder by default. |
| 872 base::RunLoop().RunUntilIdle(); | 880 base::RunLoop().RunUntilIdle(); |
| 873 EXPECT_FALSE(base::PathExists(app_path)); | 881 EXPECT_FALSE(base::PathExists(app_path)); |
| 874 | 882 |
| 875 // Request icon, this will create app folder. | |
| 876 prefs->RequestIcon(app_id, scale_factor); | |
| 877 // Now send generated icon for the app. | 883 // Now send generated icon for the app. |
| 878 std::string png_data; | 884 std::string png_data; |
| 879 EXPECT_TRUE(app_instance()->GenerateAndSendIcon( | 885 EXPECT_TRUE(app_instance()->GenerateAndSendIcon( |
| 880 app, static_cast<arc::mojom::ScaleFactor>(scale_factor), &png_data)); | 886 app, static_cast<arc::mojom::ScaleFactor>(scale_factor), &png_data)); |
| 881 WaitForIconReady(prefs, app_id, scale_factor); | 887 WaitForIconReady(prefs, app_id, scale_factor); |
| 882 EXPECT_TRUE(base::PathExists(app_path)); | 888 EXPECT_TRUE(base::PathExists(app_path)); |
| 883 | 889 |
| 884 // Send empty app list. This will delete app and its folder. | 890 // Send empty app list. This will delete app and its folder. |
| 885 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>()); | 891 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>()); |
| 886 // This cannot be WaitForIconReady since it needs to wait until the icon is | 892 // This cannot be WaitForIconReady since it needs to wait until the icon is |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 | 1021 |
| 1016 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 1022 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1017 ASSERT_NE(nullptr, prefs); | 1023 ASSERT_NE(nullptr, prefs); |
| 1018 | 1024 |
| 1019 app_instance()->RefreshAppList(); | 1025 app_instance()->RefreshAppList(); |
| 1020 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( | 1026 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
| 1021 fake_apps().begin(), fake_apps().begin() + 1)); | 1027 fake_apps().begin(), fake_apps().begin() + 1)); |
| 1022 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 1028 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 1023 base::RunLoop().RunUntilIdle(); | 1029 base::RunLoop().RunUntilIdle(); |
| 1024 | 1030 |
| 1025 // Store number of requests generated during the App List item creation. | 1031 // Store number of requests generated during the App List item creation. Same |
| 1032 // request will not be re-sent without clearing the request record in |
| 1033 // ArcAppListPrefs. |
| 1026 const size_t initial_icon_request_count = | 1034 const size_t initial_icon_request_count = |
| 1027 app_instance()->icon_requests().size(); | 1035 app_instance()->icon_requests().size(); |
| 1028 | 1036 |
| 1029 std::vector<arc::mojom::ShortcutInfo> shortcuts = | 1037 std::vector<arc::mojom::ShortcutInfo> shortcuts = |
| 1030 arc_test()->fake_shortcuts(); | 1038 arc_test()->fake_shortcuts(); |
| 1031 shortcuts.resize(1); | 1039 shortcuts.resize(1); |
| 1032 shortcuts[0].intent_uri += | 1040 shortcuts[0].intent_uri += |
| 1033 ";S.org.chromium.arc.shelf_group_id=arc_test_shelf_group;end"; | 1041 ";S.org.chromium.arc.shelf_group_id=arc_test_shelf_group;end"; |
| 1034 app_instance()->SendInstallShortcuts(shortcuts); | 1042 app_instance()->SendInstallShortcuts(shortcuts); |
| 1035 const std::string shortcut_id = ArcAppTest::GetAppId(shortcuts[0]); | 1043 const std::string shortcut_id = ArcAppTest::GetAppId(shortcuts[0]); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1053 base::RunLoop().RunUntilIdle(); | 1061 base::RunLoop().RunUntilIdle(); |
| 1054 const size_t shortcut_request_cnt = | 1062 const size_t shortcut_request_cnt = |
| 1055 app_instance()->shortcut_icon_requests().size(); | 1063 app_instance()->shortcut_icon_requests().size(); |
| 1056 EXPECT_NE(0U, shortcut_request_cnt); | 1064 EXPECT_NE(0U, shortcut_request_cnt); |
| 1057 EXPECT_EQ(initial_icon_request_count, app_instance()->icon_requests().size()); | 1065 EXPECT_EQ(initial_icon_request_count, app_instance()->icon_requests().size()); |
| 1058 for (const auto& request : app_instance()->shortcut_icon_requests()) { | 1066 for (const auto& request : app_instance()->shortcut_icon_requests()) { |
| 1059 EXPECT_EQ(shortcuts[0].icon_resource_id, request->icon_resource_id()); | 1067 EXPECT_EQ(shortcuts[0].icon_resource_id, request->icon_resource_id()); |
| 1060 } | 1068 } |
| 1061 | 1069 |
| 1062 // Fallback when shortcut is not found for shelf group id, use app id instead. | 1070 // Fallback when shortcut is not found for shelf group id, use app id instead. |
| 1071 // Remove the IconRequestRecord for |app_id| to observe the icon request for |
| 1072 // |app_id| is re-sent. |
| 1073 MaybeRemoveIconRequestRecord(app_id); |
| 1063 icon_loader.FetchImage(id_shortcut_absent); | 1074 icon_loader.FetchImage(id_shortcut_absent); |
| 1064 EXPECT_EQ(2UL, delegate.update_image_cnt()); | 1075 EXPECT_EQ(2UL, delegate.update_image_cnt()); |
| 1065 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 1076 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 1066 base::RunLoop().RunUntilIdle(); | 1077 base::RunLoop().RunUntilIdle(); |
| 1067 EXPECT_TRUE(app_instance()->icon_requests().size() > | 1078 EXPECT_TRUE(app_instance()->icon_requests().size() > |
| 1068 initial_icon_request_count); | 1079 initial_icon_request_count); |
| 1069 EXPECT_EQ(shortcut_request_cnt, | 1080 EXPECT_EQ(shortcut_request_cnt, |
| 1070 app_instance()->shortcut_icon_requests().size()); | 1081 app_instance()->shortcut_icon_requests().size()); |
| 1071 for (size_t i = initial_icon_request_count; | 1082 for (size_t i = initial_icon_request_count; |
| 1072 i < app_instance()->icon_requests().size(); ++i) { | 1083 i < app_instance()->icon_requests().size(); ++i) { |
| 1073 const auto& request = app_instance()->icon_requests()[i]; | 1084 const auto& request = app_instance()->icon_requests()[i]; |
| 1074 EXPECT_TRUE(request->IsForApp(app)); | 1085 EXPECT_TRUE(request->IsForApp(app)); |
| 1075 } | 1086 } |
| 1076 } | 1087 } |
| 1077 | 1088 |
| 1089 // If the cached icon file is corrupted, we expect send request to ARC for a new |
| 1090 // icon. |
| 1091 TEST_F(ArcAppModelBuilderTest, IconLoaderWithBadIcon) { |
| 1092 const arc::mojom::AppInfo& app = fake_apps()[0]; |
| 1093 const std::string app_id = ArcAppTest::GetAppId(app); |
| 1094 |
| 1095 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1096 ASSERT_NE(nullptr, prefs); |
| 1097 |
| 1098 app_instance()->RefreshAppList(); |
| 1099 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
| 1100 fake_apps().begin(), fake_apps().begin() + 1)); |
| 1101 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 1102 base::RunLoop().RunUntilIdle(); |
| 1103 |
| 1104 // Store number of requests generated during the App List item creation. Same |
| 1105 // request will not be re-sent without clearing the request record in |
| 1106 // ArcAppListPrefs. |
| 1107 const size_t initial_icon_request_count = |
| 1108 app_instance()->icon_requests().size(); |
| 1109 |
| 1110 FakeAppIconLoaderDelegate delegate; |
| 1111 ArcAppIconLoader icon_loader(profile(), app_list::kListIconSize, &delegate); |
| 1112 icon_loader.FetchImage(app_id); |
| 1113 |
| 1114 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 1115 base::RunLoop().RunUntilIdle(); |
| 1116 // Although icon file is still missing, expect no new request sent to ARC as |
| 1117 // them are recorded in IconRequestRecord in ArcAppListPrefs. |
| 1118 EXPECT_EQ(app_instance()->icon_requests().size(), initial_icon_request_count); |
| 1119 // Validate default image. |
| 1120 ValidateIcon(delegate.image()); |
| 1121 |
| 1122 MaybeRemoveIconRequestRecord(app_id); |
| 1123 |
| 1124 // Install Bad image. |
| 1125 const std::vector<ui::ScaleFactor>& scale_factors = |
| 1126 ui::GetSupportedScaleFactors(); |
| 1127 ArcAppItem* app_item = FindArcItem(app_id); |
| 1128 for (auto& scale_factor : scale_factors) { |
| 1129 app_instance()->GenerateAndSendBadIcon( |
| 1130 app, static_cast<arc::mojom::ScaleFactor>(scale_factor)); |
| 1131 const float scale = ui::GetScaleForScaleFactor(scale_factor); |
| 1132 // Force the icon to be loaded. |
| 1133 app_item->icon().GetRepresentation(scale); |
| 1134 WaitForIconReady(prefs, app_id, scale_factor); |
| 1135 } |
| 1136 // After clear request record related to |app_id|, when bad icon is installed, |
| 1137 // decoding failure will trigger re-sending new icon request to ARC. |
| 1138 EXPECT_TRUE(app_instance()->icon_requests().size() > |
| 1139 initial_icon_request_count); |
| 1140 for (size_t i = initial_icon_request_count; |
| 1141 i < app_instance()->icon_requests().size(); ++i) { |
| 1142 const auto& request = app_instance()->icon_requests()[i]; |
| 1143 EXPECT_TRUE(request->IsForApp(app)); |
| 1144 } |
| 1145 } |
| 1146 |
| 1078 // TODO(crbug.com/628425) -- reenable once this test is less flaky. | 1147 // TODO(crbug.com/628425) -- reenable once this test is less flaky. |
| 1079 TEST_F(ArcAppModelBuilderTest, DISABLED_IconLoader) { | 1148 TEST_F(ArcAppModelBuilderTest, DISABLED_IconLoader) { |
| 1080 const arc::mojom::AppInfo& app = fake_apps()[0]; | 1149 const arc::mojom::AppInfo& app = fake_apps()[0]; |
| 1081 const std::string app_id = ArcAppTest::GetAppId(app); | 1150 const std::string app_id = ArcAppTest::GetAppId(app); |
| 1082 | 1151 |
| 1083 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 1152 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1084 ASSERT_NE(nullptr, prefs); | 1153 ASSERT_NE(nullptr, prefs); |
| 1085 | 1154 |
| 1086 app_instance()->RefreshAppList(); | 1155 app_instance()->RefreshAppList(); |
| 1087 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( | 1156 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get()); | 1429 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1361 ASSERT_TRUE(prefs); | 1430 ASSERT_TRUE(prefs); |
| 1362 | 1431 |
| 1363 // There is no default app for managed users except Play Store | 1432 // There is no default app for managed users except Play Store |
| 1364 for (const auto& app : fake_default_apps()) { | 1433 for (const auto& app : fake_default_apps()) { |
| 1365 const std::string app_id = ArcAppTest::GetAppId(app); | 1434 const std::string app_id = ArcAppTest::GetAppId(app); |
| 1366 EXPECT_FALSE(prefs->IsRegistered(app_id)); | 1435 EXPECT_FALSE(prefs->IsRegistered(app_id)); |
| 1367 EXPECT_FALSE(prefs->GetApp(app_id)); | 1436 EXPECT_FALSE(prefs->GetApp(app_id)); |
| 1368 } | 1437 } |
| 1369 } | 1438 } |
| OLD | NEW |