Commit 4f68ef3f authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

Desktop PWAs: Browser tests wait for registry

The browser test helper methods in web_app_browsertest_util.cc
that install PWAs (InstallWebApp, InstallWebAppFromManifest,
PendingAppManagerInstall) now wait for on_registry_ready().

Bug: 1119807
Change-Id: I60c16e04b75603a8d0979fd09e9f6746335cd788
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450133
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814065}
parent f23173da
......@@ -4,6 +4,7 @@
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "base/one_shot_event.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h"
......@@ -29,6 +30,7 @@
#include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/browser/web_applications/components/web_app_tab_helper_base.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/web_application_info.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/security_interstitials/content/security_interstitial_tab_helper.h"
......@@ -42,6 +44,19 @@
namespace web_app {
namespace {
void WaitUntilReady(WebAppProvider* provider) {
if (provider->on_registry_ready().is_signaled())
return;
base::RunLoop run_loop;
provider->on_registry_ready().Post(FROM_HERE, run_loop.QuitClosure());
run_loop.Run();
}
} // namespace
AppId InstallWebApp(Profile* profile,
std::unique_ptr<WebApplicationInfo> web_app_info) {
if (web_app_info->title.empty())
......@@ -49,8 +64,9 @@ AppId InstallWebApp(Profile* profile,
AppId app_id;
base::RunLoop run_loop;
auto* provider = WebAppProviderBase::GetProviderBase(profile);
auto* provider = WebAppProvider::Get(profile);
DCHECK(provider);
WaitUntilReady(provider);
provider->install_manager().InstallWebAppFromInfo(
std::move(web_app_info), ForInstallableSite::kYes,
WebappInstallSource::OMNIBOX_INSTALL_ICON,
......@@ -71,8 +87,9 @@ AppId InstallWebAppFromManifest(Browser* browser, const GURL& app_url) {
AppId app_id;
base::RunLoop run_loop;
auto* provider = WebAppProviderBase::GetProviderBase(browser->profile());
auto* provider = WebAppProvider::Get(browser->profile());
DCHECK(provider);
WaitUntilReady(provider);
provider->install_manager().InstallWebAppFromManifestWithFallback(
browser->tab_strip_model()->GetActiveWebContents(),
/*force_shortcut_app=*/true, WebappInstallSource::MENU_BROWSER_TAB,
......@@ -162,8 +179,9 @@ InstallResultCode PendingAppManagerInstall(
Profile* profile,
ExternalInstallOptions install_options) {
DCHECK(profile);
auto* provider = WebAppProviderBase::GetProviderBase(profile);
auto* provider = WebAppProvider::Get(profile);
DCHECK(provider);
WaitUntilReady(provider);
base::RunLoop run_loop;
InstallResultCode result_code;
......
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