Index: chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
diff --git a/chrome/browser/ui/app_list/arc/arc_app_unittest.cc b/chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
index 2f660845023e3af37d9342674a6b4a1335e20c52..4b35b2d2fe787d34e63ff26dce5209f83ce4d50c 100644 |
--- a/chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
+++ b/chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
@@ -373,6 +373,14 @@ class ArcAppModelBuilderTest : public extensions::ExtensionServiceTestBase, |
} |
} |
+ // Removes icon request record and allowd re-sending icon request. |
+ void MaybeRemoveIconRequestRecord(const std::string& app_id) { |
+ ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
+ ASSERT_NE(nullptr, prefs); |
+ |
+ prefs->MaybeRemoveIconRequestRecord(app_id); |
+ } |
+ |
void AddPackage(const arc::mojom::ArcPackageInfo& package) { |
arc_test_.AddPackage(package); |
} |
@@ -938,8 +946,6 @@ TEST_P(ArcAppModelBuilderTest, RemoveAppCleanUpFolder) { |
base::RunLoop().RunUntilIdle(); |
EXPECT_FALSE(base::PathExists(app_path)); |
- // Request icon, this will create app folder. |
- prefs->RequestIcon(app_id, scale_factor); |
// Now send generated icon for the app. |
std::string png_data; |
EXPECT_TRUE(app_instance()->GenerateAndSendIcon( |
@@ -1092,7 +1098,9 @@ TEST_P(ArcAppModelBuilderTest, IconLoaderForShelfGroup) { |
content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
base::RunLoop().RunUntilIdle(); |
- // Store number of requests generated during the App List item creation. |
+ // Store number of requests generated during the App List item creation. Same |
+ // request will not be re-sent without clearing the request record in |
+ // ArcAppListPrefs. |
const size_t initial_icon_request_count = |
app_instance()->icon_requests().size(); |
@@ -1130,6 +1138,9 @@ TEST_P(ArcAppModelBuilderTest, IconLoaderForShelfGroup) { |
} |
// Fallback when shortcut is not found for shelf group id, use app id instead. |
+ // Remove the IconRequestRecord for |app_id| to observe the icon request for |
+ // |app_id| is re-sent. |
+ MaybeRemoveIconRequestRecord(app_id); |
icon_loader.FetchImage(id_shortcut_absent); |
EXPECT_EQ(2UL, delegate.update_image_cnt()); |
content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
@@ -1145,6 +1156,64 @@ TEST_P(ArcAppModelBuilderTest, IconLoaderForShelfGroup) { |
} |
} |
+// If the cached icon file is corrupted, we expect send request to ARC for a new |
+// icon. |
+TEST_P(ArcAppModelBuilderTest, IconLoaderWithBadIcon) { |
+ const arc::mojom::AppInfo& app = fake_apps()[0]; |
+ const std::string app_id = ArcAppTest::GetAppId(app); |
+ |
+ ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
+ ASSERT_NE(nullptr, prefs); |
+ |
+ app_instance()->RefreshAppList(); |
+ app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
+ fake_apps().begin(), fake_apps().begin() + 1)); |
+ content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ // Store number of requests generated during the App List item creation. Same |
+ // request will not be re-sent without clearing the request record in |
+ // ArcAppListPrefs. |
+ const size_t initial_icon_request_count = |
+ app_instance()->icon_requests().size(); |
+ |
+ FakeAppIconLoaderDelegate delegate; |
+ ArcAppIconLoader icon_loader(profile(), app_list::kListIconSize, &delegate); |
+ icon_loader.FetchImage(app_id); |
+ |
+ content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
+ base::RunLoop().RunUntilIdle(); |
+ // Although icon file is still missing, expect no new request sent to ARC as |
+ // them are recorded in IconRequestRecord in ArcAppListPrefs. |
+ EXPECT_EQ(app_instance()->icon_requests().size(), initial_icon_request_count); |
+ // Validate default image. |
+ ValidateIcon(delegate.image()); |
+ |
+ MaybeRemoveIconRequestRecord(app_id); |
+ |
+ // Install Bad image. |
+ const std::vector<ui::ScaleFactor>& scale_factors = |
+ ui::GetSupportedScaleFactors(); |
+ ArcAppItem* app_item = FindArcItem(app_id); |
+ for (auto& scale_factor : scale_factors) { |
+ app_instance()->GenerateAndSendBadIcon( |
+ app, static_cast<arc::mojom::ScaleFactor>(scale_factor)); |
+ const float scale = ui::GetScaleForScaleFactor(scale_factor); |
+ // Force the icon to be loaded. |
+ app_item->icon().GetRepresentation(scale); |
+ WaitForIconReady(prefs, app_id, scale_factor); |
+ } |
+ // After clear request record related to |app_id|, when bad icon is installed, |
+ // decoding failure will trigger re-sending new icon request to ARC. |
+ EXPECT_TRUE(app_instance()->icon_requests().size() > |
+ initial_icon_request_count); |
+ for (size_t i = initial_icon_request_count; |
+ i < app_instance()->icon_requests().size(); ++i) { |
+ const auto& request = app_instance()->icon_requests()[i]; |
+ EXPECT_TRUE(request->IsForApp(app)); |
+ } |
+} |
+ |
// TODO(crbug.com/628425) -- reenable once this test is less flaky. |
TEST_P(ArcAppModelBuilderTest, DISABLED_IconLoader) { |
const arc::mojom::AppInfo& app = fake_apps()[0]; |