Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flaky LacrosWebAppsControllerBrowserTest
We add AppRegistrationWaiter, to wait for the app's registration to appear in AppRegistryCache. Bug: 1309148 Change-Id: Id78c90ced22c2c52dbeef522ed0b6f0f900e4461 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3551941 Auto-Submit: Eric Willigers <ericwilligers@chromium.org> Reviewed-by: Daniel Murphy <dmurph@chromium.org> Commit-Queue: Daniel Murphy <dmurph@chromium.org> Cr-Commit-Position: refs/heads/main@{#985547}
- Loading branch information
1 parent
8dc2195
commit 54fdc46
Showing
4 changed files
with
98 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
chrome/browser/web_applications/test/app_registration_waiter.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/web_applications/test/app_registration_waiter.h" | ||
|
||
#include "chrome/browser/apps/app_service/app_service_proxy.h" | ||
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h" | ||
|
||
namespace web_app { | ||
|
||
AppRegistrationWaiter::AppRegistrationWaiter(Profile* profile, | ||
const AppId& app_id) | ||
: app_id_(app_id) { | ||
apps::AppRegistryCache& cache = | ||
apps::AppServiceProxyFactory::GetForProfile(profile)->AppRegistryCache(); | ||
Observe(&cache); | ||
if (cache.ForOneApp(app_id, [](const apps::AppUpdate&) {})) | ||
run_loop_.Quit(); | ||
} | ||
AppRegistrationWaiter::~AppRegistrationWaiter() = default; | ||
|
||
void AppRegistrationWaiter::Await() { | ||
run_loop_.Run(); | ||
} | ||
|
||
void AppRegistrationWaiter::OnAppUpdate(const apps::AppUpdate& update) { | ||
if (update.AppId() == app_id_) | ||
run_loop_.Quit(); | ||
} | ||
void AppRegistrationWaiter::OnAppRegistryCacheWillBeDestroyed( | ||
apps::AppRegistryCache* cache) { | ||
Observe(nullptr); | ||
} | ||
|
||
} // namespace web_app |
36 changes: 36 additions & 0 deletions
36
chrome/browser/web_applications/test/app_registration_waiter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_WEB_APPLICATIONS_TEST_APP_REGISTRATION_WAITER_H_ | ||
#define CHROME_BROWSER_WEB_APPLICATIONS_TEST_APP_REGISTRATION_WAITER_H_ | ||
|
||
#include "base/run_loop.h" | ||
#include "chrome/browser/web_applications/web_app_id.h" | ||
#include "components/services/app_service/public/cpp/app_registry_cache.h" | ||
#include "components/services/app_service/public/cpp/app_update.h" | ||
|
||
class Profile; | ||
|
||
namespace web_app { | ||
|
||
class AppRegistrationWaiter : public apps::AppRegistryCache::Observer { | ||
public: | ||
AppRegistrationWaiter(Profile* profile, const AppId& app_id); | ||
~AppRegistrationWaiter() override; | ||
|
||
void Await(); | ||
|
||
private: | ||
// apps::AppRegistryCache::Observer: | ||
void OnAppUpdate(const apps::AppUpdate& update) override; | ||
void OnAppRegistryCacheWillBeDestroyed( | ||
apps::AppRegistryCache* cache) override; | ||
|
||
const AppId app_id_; | ||
base::RunLoop run_loop_; | ||
}; | ||
|
||
} // namespace web_app | ||
|
||
#endif // CHROME_BROWSER_WEB_APPLICATIONS_TEST_APP_REGISTRATION_WAITER_H_ |