Commit ebb8289a authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Chromium LUCI CQ

desktop-pwas: Move InstallFromInfo to PendingAppInstallTask

Continue to simplify PendingAppManager by moving the logic to decide
if we should use InstallFromInfo into PendingAppInstallTask.

Also adds unit tests for installing apps from a WebApplicationInfo.

Bug: 1158722
Change-Id: I396f41b55d42d5183be60dab659fc6315c6147ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2607085Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840908}
parent 7d9f0b90
......@@ -1005,6 +1005,96 @@ TEST_F(PendingAppInstallTaskTest, FailedWebContentsDestroyed) {
base::RunLoop().RunUntilIdle();
}
TEST_F(PendingAppInstallTaskTest, InstallWithWebAppInfo_Succeeds) {
ExternalInstallOptions options(WebAppUrl(), DisplayMode::kStandalone,
ExternalInstallSource::kSystemInstalled);
options.only_use_app_info_factory = true;
options.app_info_factory = base::BindLambdaForTesting([]() {
auto info = std::make_unique<WebApplicationInfo>();
info->start_url = WebAppUrl();
info->scope = WebAppUrl().GetWithoutFilename();
info->title = base::UTF8ToUTF16("Foo Web App");
return info;
});
PendingAppInstallTask task(
profile(), /*url_loader=*/nullptr, registrar(), os_integration_manager(),
ui_manager(), finalizer(), install_manager(), std::move(options));
finalizer()->SetNextFinalizeInstallResult(
WebAppUrl(), InstallResultCode::kSuccessNewInstall);
base::RunLoop run_loop;
task.Install(
/*web_contents=*/nullptr,
base::BindLambdaForTesting([&](base::Optional<AppId> app_id,
PendingAppManager::InstallResult result) {
base::Optional<AppId> id =
ExternallyInstalledWebAppPrefs(profile()->GetPrefs())
.LookupAppId(WebAppUrl());
EXPECT_EQ(InstallResultCode::kSuccessOfflineOnlyInstall, result.code);
EXPECT_TRUE(app_id.has_value());
EXPECT_FALSE(IsPlaceholderApp(profile(), WebAppUrl()));
EXPECT_EQ(app_id.value(), id.value());
// Installing with an App Info doesn't call into OS Integration Manager.
// This might be an issue for default apps.
EXPECT_FALSE(
os_integration_manager()->get_last_install_options().has_value());
EXPECT_EQ(0u, finalizer()->num_reparent_tab_calls());
EXPECT_TRUE(web_app_info().open_as_window);
EXPECT_EQ(webapps::WebappInstallSource::SYSTEM_DEFAULT,
finalize_options().install_source);
run_loop.Quit();
}));
run_loop.Run();
}
TEST_F(PendingAppInstallTaskTest, InstallWithWebAppInfo_Fails) {
ExternalInstallOptions options(WebAppUrl(), DisplayMode::kStandalone,
ExternalInstallSource::kSystemInstalled);
options.only_use_app_info_factory = true;
options.app_info_factory = base::BindLambdaForTesting([]() {
auto info = std::make_unique<WebApplicationInfo>();
info->start_url = WebAppUrl();
info->scope = WebAppUrl().GetWithoutFilename();
info->title = base::UTF8ToUTF16("Foo Web App");
return info;
});
PendingAppInstallTask task(
profile(), /*url_loader=*/nullptr, registrar(), os_integration_manager(),
ui_manager(), finalizer(), install_manager(), std::move(options));
finalizer()->SetNextFinalizeInstallResult(
WebAppUrl(), InstallResultCode::kWriteDataFailed);
base::RunLoop run_loop;
task.Install(
web_contents(),
base::BindLambdaForTesting([&](base::Optional<AppId> app_id,
PendingAppManager::InstallResult result) {
base::Optional<AppId> id =
ExternallyInstalledWebAppPrefs(profile()->GetPrefs())
.LookupAppId(WebAppUrl());
EXPECT_EQ(InstallResultCode::kWriteDataFailed, result.code);
EXPECT_FALSE(app_id.has_value());
EXPECT_FALSE(id.has_value());
run_loop.Quit();
}));
run_loop.Run();
}
TEST_F(PendingAppInstallTaskWithRunOnOsLoginTest,
WebAppOrShortcutFromContents_RunOnOsLogin) {
ExternalInstallOptions install_options(
......
......@@ -58,6 +58,12 @@ PendingAppInstallTask::~PendingAppInstallTask() = default;
void PendingAppInstallTask::Install(content::WebContents* web_contents,
ResultCallback result_callback) {
if (install_options_.only_use_app_info_factory) {
DCHECK(install_options_.app_info_factory);
InstallFromInfo(std::move(result_callback));
return;
}
url_loader_->PrepareForLoad(
web_contents, base::BindOnce(&PendingAppInstallTask::OnWebContentsReady,
weak_ptr_factory_.GetWeakPtr(), web_contents,
......
......@@ -70,13 +70,13 @@ class PendingAppInstallTask {
virtual void Install(content::WebContents* web_contents,
ResultCallback result_callback);
// Install directly from a fully specified WebApplicationInfo struct. Used
// by system apps.
virtual void InstallFromInfo(ResultCallback result_callback);
const ExternalInstallOptions& install_options() { return install_options_; }
private:
// Install directly from a fully specified WebApplicationInfo struct. Used
// by system apps.
void InstallFromInfo(ResultCallback result_callback);
void OnWebContentsReady(content::WebContents* web_contents,
ResultCallback result_callback,
WebAppUrlLoader::Result prepare_for_load_result);
......
......@@ -220,15 +220,8 @@ void PendingAppManagerImpl::StartInstallationTask(
pending_registrations_.push_front(current_registration_->install_url());
current_registration_.reset();
}
current_install_ = std::move(task);
if (current_install_->task->install_options().only_use_app_info_factory) {
DCHECK(current_install_->task->install_options().app_info_factory);
current_install_->task->InstallFromInfo(base::BindOnce(
&PendingAppManagerImpl::OnInstalled, weak_ptr_factory_.GetWeakPtr()));
return;
}
current_install_ = std::move(task);
CreateWebContentsIfNecessary();
current_install_->task->Install(
web_contents_.get(), base::BindOnce(&PendingAppManagerImpl::OnInstalled,
......
......@@ -339,17 +339,10 @@ class TestPendingAppManagerImpl : public PendingAppManagerImpl {
ResultCallback callback) override {
pending_app_manager_impl_->OnInstallCalled(install_options());
const GURL install_url = install_options().install_url;
test_install_task_manager_.RunOrSaveRequest(base::BindLambdaForTesting(
[&, install_url, callback = std::move(callback)]() mutable {
DoInstall(install_url, std::move(callback));
}));
}
void InstallFromInfo(ResultCallback callback) override {
pending_app_manager_impl_->OnInstallCalled(install_options());
GURL install_url = install_options().app_info_factory.Run()->start_url;
const GURL install_url =
install_options().only_use_app_info_factory
? install_options().app_info_factory.Run()->start_url
: install_options().install_url;
test_install_task_manager_.RunOrSaveRequest(base::BindLambdaForTesting(
[&, install_url, callback = std::move(callback)]() mutable {
DoInstall(install_url, std::move(callback));
......
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