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