Commit 19c93cb2 authored by Christopher Lam's avatar Christopher Lam Committed by Commit Bot

[Web Apps] Refactor PendingAppManagerImpl unit test.

This CL makes the PendingAppManagerImpl unit test use the
TestWebAppProvider paradigm for more consistent test flow.

Bug: None
Change-Id: Ifea2c7ebae72a87a75b75dfddb725e1d105033fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1732699
Commit-Queue: calamity <calamity@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683918}
parent 90d303d1
......@@ -129,6 +129,7 @@ source_set("web_applications_unit_tests") {
deps = [
":web_app_test_group",
":web_applications",
":web_applications_on_extensions_test_support",
":web_applications_test_support",
"//base/test:test_support",
"//chrome/browser",
......
......@@ -21,19 +21,6 @@
namespace web_app {
namespace {
std::unique_ptr<PendingAppInstallTask> InstallationTaskCreateWrapper(
Profile* profile,
AppRegistrar* registrar,
InstallFinalizer* install_finalizer,
ExternalInstallOptions install_options) {
return std::make_unique<PendingAppInstallTask>(
profile, registrar, install_finalizer, std::move(install_options));
}
} // namespace
struct PendingAppManagerImpl::TaskAndCallback {
TaskAndCallback(std::unique_ptr<PendingAppInstallTask> task,
OnceInstallCallback callback)
......@@ -47,17 +34,14 @@ struct PendingAppManagerImpl::TaskAndCallback {
PendingAppManagerImpl::PendingAppManagerImpl(Profile* profile)
: profile_(profile),
externally_installed_app_prefs_(profile->GetPrefs()),
url_loader_(std::make_unique<WebAppUrlLoader>()),
task_factory_(base::BindRepeating(&InstallationTaskCreateWrapper)) {}
url_loader_(std::make_unique<WebAppUrlLoader>()) {}
PendingAppManagerImpl::~PendingAppManagerImpl() = default;
void PendingAppManagerImpl::Install(ExternalInstallOptions install_options,
OnceInstallCallback callback) {
pending_tasks_and_callbacks_.push_front(std::make_unique<TaskAndCallback>(
task_factory_.Run(profile_, registrar(), finalizer(),
std::move(install_options)),
std::move(callback)));
CreateInstallationTask(std::move(install_options)), std::move(callback)));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
......@@ -70,9 +54,7 @@ void PendingAppManagerImpl::InstallApps(
const RepeatingInstallCallback& callback) {
for (auto& install_options : install_options_list) {
pending_tasks_and_callbacks_.push_back(std::make_unique<TaskAndCallback>(
task_factory_.Run(profile_, registrar(), finalizer(),
std::move(install_options)),
callback));
CreateInstallationTask(std::move(install_options)), callback));
}
base::ThreadTaskRunnerHandle::Get()->PostTask(
......@@ -98,15 +80,18 @@ void PendingAppManagerImpl::Shutdown() {
web_contents_.reset();
}
void PendingAppManagerImpl::SetTaskFactoryForTesting(TaskFactory task_factory) {
task_factory_ = std::move(task_factory);
}
void PendingAppManagerImpl::SetUrlLoaderForTesting(
std::unique_ptr<WebAppUrlLoader> url_loader) {
url_loader_ = std::move(url_loader);
}
std::unique_ptr<PendingAppInstallTask>
PendingAppManagerImpl::CreateInstallationTask(
ExternalInstallOptions install_options) {
return std::make_unique<PendingAppInstallTask>(
profile_, registrar(), finalizer(), std::move(install_options));
}
void PendingAppManagerImpl::MaybeStartNextInstallation() {
if (current_task_and_callback_)
return;
......
......@@ -29,22 +29,12 @@ class WebContents;
namespace web_app {
class AppRegistrar;
class InstallFinalizer;
class WebAppUiManager;
// WebAppProvider creates an instance of this class and manages its
// lifetime. This class should only be used from the UI thread.
class PendingAppManagerImpl final : public PendingAppManager {
class PendingAppManagerImpl : public PendingAppManager {
public:
using WebContentsFactory =
base::RepeatingCallback<std::unique_ptr<content::WebContents>(Profile*)>;
using TaskFactory =
base::RepeatingCallback<std::unique_ptr<PendingAppInstallTask>(
Profile*,
AppRegistrar*,
InstallFinalizer*,
ExternalInstallOptions)>;
explicit PendingAppManagerImpl(Profile* profile);
~PendingAppManagerImpl() override;
......@@ -58,14 +48,17 @@ class PendingAppManagerImpl final : public PendingAppManager {
const UninstallCallback& callback) override;
void Shutdown() override;
void SetTaskFactoryForTesting(TaskFactory task_factory);
void SetUrlLoaderForTesting(std::unique_ptr<WebAppUrlLoader> url_loader);
protected:
virtual std::unique_ptr<PendingAppInstallTask> CreateInstallationTask(
ExternalInstallOptions install_options);
Profile* profile() { return profile_; }
private:
struct TaskAndCallback;
WebAppUiManager& GetUiManager();
void MaybeStartNextInstallation();
void StartInstallationTask(std::unique_ptr<TaskAndCallback> task);
......@@ -89,8 +82,6 @@ class PendingAppManagerImpl final : public PendingAppManager {
// unique_ptr so that it can be replaced in tests.
std::unique_ptr<WebAppUrlLoader> url_loader_;
TaskFactory task_factory_;
std::unique_ptr<content::WebContents> web_contents_;
std::unique_ptr<TaskAndCallback> current_task_and_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