Commit f87fd634 authored by nancylingwang's avatar nancylingwang Committed by Commit Bot

Fix the flaky unit tests IconInvalidationOnIconVersionUpdate.

The test case includes restarting ARC. However, the ARC apps are not
removed from AppService AppRegistryCache, so when the ARC is restarted,
the previous icon loading requests before ARC restart might affect the
icon loading account.

Modify the tests, when the ARC restart, remove the ARC apps saved in
AppService AppRegistryCache, which is the consistent operation as
running on Chromebook. Also add waiting icon loading operation after
StartApp, because the icon loading operation might be slow.

BUG=1115830

Change-Id: Icc7acdb49ca41232712b141db93e41645a2f1287
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2379432
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarLong Cheng <lgcheng@google.com>
Cr-Commit-Position: refs/heads/master@{#803323}
parent bc252630
...@@ -253,6 +253,19 @@ void RemoveNonArcApps(Profile* profile, ...@@ -253,6 +253,19 @@ void RemoveNonArcApps(Profile* profile,
model_updater->RemoveItem(update.AppId()); model_updater->RemoveItem(update.AppId());
} }
}); });
base::RunLoop().RunUntilIdle();
}
// Remove all ARC apps.
void RemoveArcApps(Profile* profile, FakeAppListModelUpdater* model_updater) {
apps::AppServiceProxyFactory::GetForProfile(profile)
->AppRegistryCache()
.ForEachApp([&model_updater](const apps::AppUpdate& update) {
if (update.AppType() == apps::mojom::AppType::kArc) {
model_updater->RemoveItem(update.AppId());
}
});
base::RunLoop().RunUntilIdle();
} }
} // namespace } // namespace
...@@ -694,6 +707,7 @@ class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest { ...@@ -694,6 +707,7 @@ class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest {
FlushMojoCallsForAppService(); FlushMojoCallsForAppService();
apps::ArcAppsFactory::GetInstance()->ShutDownForTesting(profile_.get()); apps::ArcAppsFactory::GetInstance()->ShutDownForTesting(profile_.get());
arc_test()->TearDown(); arc_test()->TearDown();
RemoveArcApps(profile_.get(), model_updater());
ResetBuilder(); ResetBuilder();
} }
...@@ -707,7 +721,8 @@ class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest { ...@@ -707,7 +721,8 @@ class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest {
DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderRecreate); DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderRecreate);
}; };
class ArcAppModelIconTest : public ArcAppModelBuilderRecreate { class ArcAppModelIconTest : public ArcAppModelBuilderRecreate,
public ArcAppListPrefs::Observer {
public: public:
ArcAppModelIconTest() = default; ArcAppModelIconTest() = default;
~ArcAppModelIconTest() override = default; ~ArcAppModelIconTest() override = default;
...@@ -733,17 +748,29 @@ class ArcAppModelIconTest : public ArcAppModelBuilderRecreate { ...@@ -733,17 +748,29 @@ class ArcAppModelIconTest : public ArcAppModelBuilderRecreate {
std::string StartApp(int package_version) { std::string StartApp(int package_version) {
DCHECK(!fake_apps().empty()); DCHECK(!fake_apps().empty());
const arc::mojom::AppInfo app = test_app();
const std::string app_id = ArcAppTest::GetAppId(app);
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
DCHECK(prefs); DCHECK(prefs);
icon_updated_count_ = 0;
arc_test()->arc_app_list_prefs()->AddObserver(this);
const arc::mojom::AppInfo app = test_app();
const std::string app_id = ArcAppTest::GetAppId(app);
SendRefreshAppList({app}); SendRefreshAppList({app});
AddPackage(CreatePackageWithVersion(app.package_name, package_version)); AddPackage(CreatePackageWithVersion(app.package_name, package_version));
return app_id; return app_id;
} }
// Wait the icon to be updated twice for the 2 scales separately.
void WaitForIconUpdate() {
if (icon_updated_count_ < 2) {
run_loop_ = std::make_unique<base::RunLoop>();
icon_update_callback_ = run_loop_->QuitClosure();
run_loop_->Run();
}
}
// Simulates package of the test app is updated. // Simulates package of the test app is updated.
void UpdatePackage(int package_version) { void UpdatePackage(int package_version) {
const arc::mojom::AppInfo app = test_app(); const arc::mojom::AppInfo app = test_app();
...@@ -770,11 +797,27 @@ class ArcAppModelIconTest : public ArcAppModelBuilderRecreate { ...@@ -770,11 +797,27 @@ class ArcAppModelIconTest : public ArcAppModelBuilderRecreate {
WaitForIconUpdates(profile_.get(), app_id); WaitForIconUpdates(profile_.get(), app_id);
} }
// ArcAppListPrefs::Observer overrides.
void OnAppIconUpdated(const std::string& app_id,
const ArcAppIconDescriptor& descriptor) override {
icon_updated_count_++;
// The icon should be updated twice for the 2 scales separately.
if (icon_updated_count_ >= 2) {
if (icon_update_callback_)
std::move(icon_update_callback_).Run();
ArcAppListPrefs::Get(profile_.get())->RemoveObserver(this);
}
}
arc::mojom::AppInfo test_app() const { return fake_apps()[0]; } arc::mojom::AppInfo test_app() const { return fake_apps()[0]; }
private: private:
std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors>
scoped_supported_scale_factors_; scoped_supported_scale_factors_;
std::unique_ptr<base::RunLoop> run_loop_;
base::OnceClosure icon_update_callback_;
int icon_updated_count_;
DISALLOW_COPY_AND_ASSIGN(ArcAppModelIconTest); DISALLOW_COPY_AND_ASSIGN(ArcAppModelIconTest);
}; };
...@@ -2361,12 +2404,14 @@ TEST_P(ArcAppModelIconTest, IconInvalidationOnIconVersionUpdate) { ...@@ -2361,12 +2404,14 @@ TEST_P(ArcAppModelIconTest, IconInvalidationOnIconVersionUpdate) {
ASSERT_TRUE(prefs); ASSERT_TRUE(prefs);
const std::string app_id = StartApp(1 /* package_version */); const std::string app_id = StartApp(1 /* package_version */);
WaitForIconUpdate();
// Simulate ARC restart. // Simulate ARC restart.
RestartArc(); RestartArc();
// Simulate new icons version. // Simulate new icons version.
ArcAppListPrefs::UprevCurrentIconsVersionForTesting(); ArcAppListPrefs::UprevCurrentIconsVersionForTesting();
StartApp(1 /* package_version */); StartApp(1 /* package_version */);
WaitForIconUpdate();
// Requests to reload icons are issued for all supported scales. // Requests to reload icons are issued for all supported scales.
EnsureIconsUpdated(); EnsureIconsUpdated();
......
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