Commit c29a9edc authored by Nancy Wang's avatar Nancy Wang Committed by Commit Bot

Fix the flake unit test IconInvalidationOnFrameworkUpdate.

AppServiceAppIconLoader could call LoadIcon multiple times, because the
icon image is updated for each scale. Waiting icon update once might
cause the AppServiceAppIconLoader is destroyed before the icon loading
process is finish, so it might cause below error:
[app_service.mojom.cc(1174)] Check failed: !connected.
AppService::LoadIconCallback was destroyed...

This CL modifies the expected icon update count to wait the icon loading
process finish to avoid AppServiceAppIconLoader to be destroyed early.

BUG=1124972

Change-Id: Id7efc80d14ac1a0f6e4cfbe77223256922898599
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2494215
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarLong Cheng <lgcheng@google.com>
Cr-Commit-Position: refs/heads/master@{#823392}
parent b010a259
......@@ -108,6 +108,8 @@ constexpr int kFrameworkPiVersion = 28;
constexpr size_t kMaxSimultaneousIconRequests = 250;
constexpr int kDefaultIconUpdateCount = 1;
class FakeAppIconLoaderDelegate : public AppIconLoaderDelegate {
public:
FakeAppIconLoaderDelegate() = default;
......@@ -301,13 +303,15 @@ void WaitForIconCreation(ArcAppListPrefs* prefs,
} while (!base::PathExists(icon_path));
}
void WaitForIconUpdates(Profile* profile, const std::string& app_id) {
void WaitForIconUpdates(Profile* profile,
const std::string& app_id,
int expected_update_count = kDefaultIconUpdateCount) {
FakeAppIconLoaderDelegate delegate;
AppServiceAppIconLoader icon_loader(
profile, ash::AppListConfig::instance().grid_icon_dimension(), &delegate);
icon_loader.FetchImage(app_id);
delegate.WaitForIconUpdates(1);
delegate.WaitForIconUpdates(expected_update_count);
}
void VerifyIcon(const gfx::ImageSkia& src, const gfx::ImageSkia& dst) {
......@@ -907,7 +911,7 @@ class ArcAppModelIconTest : public ArcAppModelBuilderRecreate,
}
// Ensures that icons for the test app were updated for each scale factor.
void EnsureIconsUpdated() {
void EnsureIconsUpdated(int expected_update_count = kDefaultIconUpdateCount) {
const arc::mojom::AppInfo app = test_app();
const std::string app_id = ArcAppTest::GetAppId(app);
......@@ -921,7 +925,7 @@ class ArcAppModelIconTest : public ArcAppModelBuilderRecreate,
ASSERT_EQ(GetAppListIconDimensionForScaleFactor(ui::SCALE_FACTOR_200P),
icon_requests[1]->dimension());
WaitForIconUpdates(profile_.get(), app_id);
WaitForIconUpdates(profile_.get(), app_id, expected_update_count);
}
// ArcAppListPrefs::Observer overrides.
......@@ -2858,7 +2862,10 @@ TEST_P(ArcAppModelIconTest, IconInvalidationOnFrameworkUpdate) {
CreatePackageWithVersion(kFrameworkPackageName, kFrameworkNycVersion));
app_instance()->SendRefreshPackageList(std::move(packages));
WaitForIconUpdates(profile_.get(), app_id);
const std::vector<ui::ScaleFactor>& scale_factors =
ui::GetSupportedScaleFactors();
WaitForIconUpdates(profile_.get(), app_id,
scale_factors.size() + kDefaultIconUpdateCount);
RestartArc();
......@@ -2884,7 +2891,7 @@ TEST_P(ArcAppModelIconTest, IconInvalidationOnFrameworkUpdate) {
app_instance()->SendRefreshPackageList(std::move(packages));
EXPECT_FALSE(app_instance()->icon_requests().empty());
EnsureIconsUpdated();
EnsureIconsUpdated(scale_factors.size() + kDefaultIconUpdateCount);
}
// This verifies that app icons are invalidated in case icon version was
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment