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

Unified Diff: chrome/browser/ui/app_list/arc/arc_app_unittest.cc

Issue 2763753003: [Merge To M58]Fix Default icon issue when cached icon file is corrupted. (Closed)
Patch Set: Rebase. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc ('k') | components/arc/test/fake_app_instance.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 505ca0f0392961c52c8ae8f8eaa63fa13c410dfe..902018e89c06ae999b8478e0d260142a4b7d99eb 100644
--- a/chrome/browser/ui/app_list/arc/arc_app_unittest.cc
+++ b/chrome/browser/ui/app_list/arc/arc_app_unittest.cc
@@ -322,6 +322,14 @@ class ArcAppModelBuilderTest : public AppListTestBase {
}
}
+ // 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);
}
@@ -872,8 +880,6 @@ TEST_F(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(
@@ -1022,7 +1028,9 @@ TEST_F(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();
@@ -1060,6 +1068,9 @@ TEST_F(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();
@@ -1075,6 +1086,64 @@ TEST_F(ArcAppModelBuilderTest, IconLoaderForShelfGroup) {
}
}
+// If the cached icon file is corrupted, we expect send request to ARC for a new
+// icon.
+TEST_F(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_F(ArcAppModelBuilderTest, DISABLED_IconLoader) {
const arc::mojom::AppInfo& app = fake_apps()[0];
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc ('k') | components/arc/test/fake_app_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698