From aaddfad5a387db4d1c0a50ced4412b68745a61a2 Mon Sep 17 00:00:00 2001 From: Glen Robertson Date: Thu, 24 Mar 2022 03:37:46 +0000 Subject: [PATCH] CodeHealth: Add method to set fake subsystems in FakeWebAppProvider Using an actual provider with fakes set on it means less boilerplate setting up various managers in many unit tests, and less need to manually set subsystems or make sure the right manager is used in code under test. Ideally fakes would be set by default in FakeWebAppProvider::BuildDefault but that breaks some tests so it can be done in a separate CL. This makes FakeWebAppRegistryController redundant. We should remove it in a follow-up CL so there's one correct way to do things. As a trial/example, removed WebAppRegistryController from web_app_install_finalizer_unittest.cc and web_app_translation_manager_unittest.cc Also fixed to IWYU in these classes. Bug: 973324 Change-Id: Iaafef580f434d6839712a788d1ec74e07734b7f1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3526299 Reviewed-by: Daniel Murphy Reviewed-by: Alan Cutter Commit-Queue: Glen Robertson Cr-Commit-Position: refs/heads/main@{#984678} --- ...nally_managed_app_install_task_unittest.cc | 1 + .../manifest_update_manager_browsertest.cc | 1 + .../test/fake_web_app_provider.cc | 116 +++++++++++++++--- .../test/fake_web_app_provider.h | 32 +++-- .../test/fake_web_app_registry_controller.h | 1 + .../web_app_install_finalizer_unittest.cc | 87 ++++++------- .../web_applications/web_app_provider.h | 4 +- .../web_app_translation_manager_unittest.cc | 80 +++++------- 8 files changed, 197 insertions(+), 125 deletions(-) diff --git a/chrome/browser/web_applications/extensions/externally_managed_app_install_task_unittest.cc b/chrome/browser/web_applications/extensions/externally_managed_app_install_task_unittest.cc index a7072045914ab0..2c85d6cd2712f2 100644 --- a/chrome/browser/web_applications/extensions/externally_managed_app_install_task_unittest.cc +++ b/chrome/browser/web_applications/extensions/externally_managed_app_install_task_unittest.cc @@ -39,6 +39,7 @@ #include "chrome/browser/web_applications/web_app_install_manager.h" #include "chrome/browser/web_applications/web_app_provider.h" #include "chrome/browser/web_applications/web_app_registrar.h" +#include "chrome/browser/web_applications/web_app_sync_bridge.h" #include "chrome/common/chrome_features.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" diff --git a/chrome/browser/web_applications/manifest_update_manager_browsertest.cc b/chrome/browser/web_applications/manifest_update_manager_browsertest.cc index 805bfea9a63ef7..7bb244f8690f75 100644 --- a/chrome/browser/web_applications/manifest_update_manager_browsertest.cc +++ b/chrome/browser/web_applications/manifest_update_manager_browsertest.cc @@ -47,6 +47,7 @@ #include "chrome/browser/web_applications/web_app_provider.h" #include "chrome/browser/web_applications/web_app_registrar.h" #include "chrome/browser/web_applications/web_app_registry_update.h" +#include "chrome/browser/web_applications/web_app_sync_bridge.h" #include "chrome/browser/web_applications/web_app_utils.h" #include "chrome/common/chrome_features.h" #include "chrome/test/base/in_process_browser_test.h" diff --git a/chrome/browser/web_applications/test/fake_web_app_provider.cc b/chrome/browser/web_applications/test/fake_web_app_provider.cc index 5dd1a96e8eb9fd..680270c45b1a3e 100644 --- a/chrome/browser/web_applications/test/fake_web_app_provider.cc +++ b/chrome/browser/web_applications/test/fake_web_app_provider.cc @@ -4,23 +4,41 @@ #include "chrome/browser/web_applications/test/fake_web_app_provider.h" +#include +#include #include #include "base/bind.h" +#include "base/check.h" +#include "base/command_line.h" +#include "base/memory/scoped_refptr.h" +#include "base/one_shot_event.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/web_applications/externally_managed_app_manager.h" #include "chrome/browser/web_applications/os_integration/os_integration_manager.h" #include "chrome/browser/web_applications/policy/web_app_policy_manager.h" #include "chrome/browser/web_applications/system_web_apps/system_web_app_manager.h" #include "chrome/browser/web_applications/system_web_apps/test/test_system_web_app_manager.h" +#include "chrome/browser/web_applications/test/fake_externally_managed_app_manager.h" +#include "chrome/browser/web_applications/test/fake_os_integration_manager.h" +#include "chrome/browser/web_applications/test/fake_web_app_database_factory.h" +#include "chrome/browser/web_applications/test/fake_web_app_ui_manager.h" +#include "chrome/browser/web_applications/test/test_file_utils.h" #include "chrome/browser/web_applications/web_app_database_factory.h" #include "chrome/browser/web_applications/web_app_icon_manager.h" #include "chrome/browser/web_applications/web_app_install_finalizer.h" #include "chrome/browser/web_applications/web_app_install_manager.h" #include "chrome/browser/web_applications/web_app_provider_factory.h" #include "chrome/browser/web_applications/web_app_registrar.h" +#include "chrome/browser/web_applications/web_app_sync_bridge.h" +#include "chrome/browser/web_applications/web_app_translation_manager.h" #include "chrome/browser/web_applications/web_app_ui_manager.h" #include "chrome/browser/web_applications/web_app_utils.h" +#include "chrome/common/chrome_switches.h" +#include "components/keyed_service/content/browser_context_dependency_manager.h" +#include "components/keyed_service/core/keyed_service.h" +#include "components/sync/test/model/mock_model_type_change_processor.h" +#include "testing/gmock/include/gmock/gmock.h" namespace web_app { @@ -33,7 +51,7 @@ std::unique_ptr FakeWebAppProvider::BuildDefault( // Do not call default production StartImpl if in TestingProfile. provider->SetRunSubsystemStartupTasks(false); - // TODO(crbug.com/973324): Replace core subsystems with fakes by default. + // TODO(crbug.com/973324): `SetDefaultFakeSubsystems` by default. provider->ConnectSubsystems(); return provider; @@ -69,12 +87,36 @@ void FakeWebAppProvider::SetRegistrar( registrar_ = std::move(registrar); } +void FakeWebAppProvider::SetDatabaseFactory( + std::unique_ptr database_factory) { + CheckNotStarted(); + database_factory_ = std::move(database_factory_); +} + void FakeWebAppProvider::SetSyncBridge( std::unique_ptr sync_bridge) { CheckNotStarted(); sync_bridge_ = std::move(sync_bridge); } +void FakeWebAppProvider::SetIconManager( + std::unique_ptr icon_manager) { + CheckNotStarted(); + icon_manager_ = std::move(icon_manager); +} + +void FakeWebAppProvider::SetTranslationManager( + std::unique_ptr translation_manager) { + CheckNotStarted(); + translation_manager_ = std::move(translation_manager); +} + +void FakeWebAppProvider::SetOsIntegrationManager( + std::unique_ptr os_integration_manager) { + CheckNotStarted(); + os_integration_manager_ = std::move(os_integration_manager); +} + void FakeWebAppProvider::SetInstallManager( std::unique_ptr install_manager) { CheckNotStarted(); @@ -112,10 +154,19 @@ void FakeWebAppProvider::SetWebAppPolicyManager( web_app_policy_manager_ = std::move(web_app_policy_manager); } -void FakeWebAppProvider::SetOsIntegrationManager( - std::unique_ptr os_integration_manager) { - CheckNotStarted(); - os_integration_manager_ = std::move(os_integration_manager); +WebAppRegistrarMutable& FakeWebAppProvider::GetRegistrarMutable() const { + DCHECK(registrar_); + return *static_cast(registrar_.get()); +} + +WebAppIconManager& FakeWebAppProvider::GetIconManager() const { + DCHECK(icon_manager_); + return *icon_manager_; +} + +AbstractWebAppDatabaseFactory& FakeWebAppProvider::GetDatabaseFactory() const { + DCHECK(database_factory_); + return *database_factory_; } void FakeWebAppProvider::SkipAwaitingExtensionSystem() { @@ -128,24 +179,55 @@ void FakeWebAppProvider::StartWithSubsystems() { SetRunSubsystemStartupTasks(true); // Use a TestSystemWebAppManager to skip system web apps being // auto-installed on |Start|. + // TODO(crbug.com/973324): This is set in `SetDefaultFakeSubsystems`. Remove + // it from here. SetSystemWebAppManager( - std::make_unique(profile_.get())); + std::make_unique(profile_)); Start(); } -WebAppRegistrarMutable& FakeWebAppProvider::GetRegistrarMutable() const { - DCHECK(registrar_); - return *static_cast(registrar_.get()); -} +void FakeWebAppProvider::SetDefaultFakeSubsystems() { + // Disable preinstalled apps by default as they add noise and time to tests + // that don't need them. + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kDisablePreinstalledApps); -WebAppIconManager& FakeWebAppProvider::GetIconManager() const { - DCHECK(icon_manager_); - return *icon_manager_; -} + // Default to not wait for a test extension system, that is usually never + // started in web app tests. + SkipAwaitingExtensionSystem(); -AbstractWebAppDatabaseFactory& FakeWebAppProvider::GetDatabaseFactory() const { - DCHECK(database_factory_); - return *database_factory_; + SetRegistrar(std::make_unique(profile_)); + SetDatabaseFactory(std::make_unique()); + + SetOsIntegrationManager(std::make_unique( + profile_, /*app_shortcut_manager=*/nullptr, + /*file_handler_manager=*/nullptr, + /*protocol_handler_manager=*/nullptr, + /*url_handler_manager=*/nullptr)); + + SetSyncBridge(std::make_unique( + &GetRegistrarMutable(), processor().CreateForwardingProcessor())); + + SetIconManager(std::make_unique( + profile_, base::MakeRefCounted())); + + SetTranslationManager(std::make_unique( + profile_, base::MakeRefCounted())); + + SetWebAppUiManager(std::make_unique()); + + SetExternallyManagedAppManager( + std::make_unique(profile_)); + + SetWebAppPolicyManager(std::make_unique(profile_)); + + // Use a TestSystemWebAppManager to skip system web apps being + // auto-installed on |Start|. + SetSystemWebAppManager( + std::make_unique(profile_)); + + ON_CALL(processor(), IsTrackingMetadata()) + .WillByDefault(testing::Return(true)); } void FakeWebAppProvider::CheckNotStarted() const { diff --git a/chrome/browser/web_applications/test/fake_web_app_provider.h b/chrome/browser/web_applications/test/fake_web_app_provider.h index 32f91bee2a4de7..470848a6f229cf 100644 --- a/chrome/browser/web_applications/test/fake_web_app_provider.h +++ b/chrome/browser/web_applications/test/fake_web_app_provider.h @@ -8,11 +8,13 @@ #include #include "base/callback.h" +#include "base/callback_forward.h" +#include "base/callback_list.h" #include "chrome/browser/web_applications/web_app_provider.h" -#include "chrome/browser/web_applications/web_app_registrar.h" -#include "chrome/browser/web_applications/web_app_sync_bridge.h" -#include "components/keyed_service/content/browser_context_dependency_manager.h" +#include "components/sync/test/model/mock_model_type_change_processor.h" +#include "testing/gmock/include/gmock/gmock.h" +class KeyedService; class Profile; namespace content { @@ -30,6 +32,10 @@ class SystemWebAppManager; class WebAppInstallManager; class WebAppPolicyManager; class WebAppIconManager; +class WebAppTranslationManager; +class WebAppRegistrarMutable; +class WebAppSyncBridge; +class WebAppUiManager; class FakeWebAppProvider : public WebAppProvider { public: @@ -58,7 +64,12 @@ class FakeWebAppProvider : public WebAppProvider { // NB: If you replace the Registrar, you also have to replace the SyncBridge // accordingly. void SetRegistrar(std::unique_ptr registrar); + void SetDatabaseFactory( + std::unique_ptr database_factory); void SetSyncBridge(std::unique_ptr sync_bridge); + void SetIconManager(std::unique_ptr icon_manager); + void SetTranslationManager( + std::unique_ptr translation_manager); void SetOsIntegrationManager( std::unique_ptr os_integration_manager); void SetInstallManager(std::unique_ptr install_manager); @@ -72,10 +83,6 @@ class FakeWebAppProvider : public WebAppProvider { std::unique_ptr system_web_app_manager); void SetWebAppPolicyManager( std::unique_ptr web_app_policy_manager); - void SkipAwaitingExtensionSystem(); - // Starts this WebAppProvider and its subsystems. It does not wait for systems - // to be ready. - void StartWithSubsystems(); // These getters can be called at any time: no // WebAppProvider::CheckIsConnected() check performed. See @@ -86,6 +93,16 @@ class FakeWebAppProvider : public WebAppProvider { WebAppIconManager& GetIconManager() const; AbstractWebAppDatabaseFactory& GetDatabaseFactory() const; + void SkipAwaitingExtensionSystem(); + // Starts this WebAppProvider and its subsystems. It does not wait for systems + // to be ready. + void StartWithSubsystems(); + + // Create and set default fake subsystems. + void SetDefaultFakeSubsystems(); + + syncer::MockModelTypeChangeProcessor& processor() { return mock_processor_; } + private: void CheckNotStarted() const; @@ -96,6 +113,7 @@ class FakeWebAppProvider : public WebAppProvider { // WebAppProvider::StartImpl() and fire startup tasks like a real // WebAppProvider. bool run_subsystem_startup_tasks_ = true; + testing::NiceMock mock_processor_; }; // Used in BrowserTests to ensure that the WebAppProvider that is create on diff --git a/chrome/browser/web_applications/test/fake_web_app_registry_controller.h b/chrome/browser/web_applications/test/fake_web_app_registry_controller.h index b6aed80a5eaa81..05cb1049611cd4 100644 --- a/chrome/browser/web_applications/test/fake_web_app_registry_controller.h +++ b/chrome/browser/web_applications/test/fake_web_app_registry_controller.h @@ -29,6 +29,7 @@ class WebAppTranslationManager; class WebApp; class WebAppPolicyManager; +// Deprecated: Prefer to use `FakeWebAppProvider::SetDefaultFakeSubsystems()`. class FakeWebAppRegistryController : public SyncInstallDelegate { public: FakeWebAppRegistryController(); diff --git a/chrome/browser/web_applications/web_app_install_finalizer_unittest.cc b/chrome/browser/web_applications/web_app_install_finalizer_unittest.cc index 81a3a56272fd51..c3f1fd7b4d4ef9 100644 --- a/chrome/browser/web_applications/web_app_install_finalizer_unittest.cc +++ b/chrome/browser/web_applications/web_app_install_finalizer_unittest.cc @@ -4,29 +4,39 @@ #include "chrome/browser/web_applications/web_app_install_finalizer.h" +#include #include +#include -#include "base/command_line.h" -#include "base/memory/scoped_refptr.h" +#include "base/feature_list.h" #include "base/run_loop.h" -#include "base/strings/utf_string_conversions.h" +#include "base/scoped_observation.h" +#include "base/strings/string_piece_forward.h" #include "base/test/bind.h" -#include "chrome/browser/web_applications/file_utils_wrapper.h" -#include "chrome/browser/web_applications/policy/web_app_policy_manager.h" -#include "chrome/browser/web_applications/test/fake_web_app_registry_controller.h" -#include "chrome/browser/web_applications/test/fake_web_app_ui_manager.h" +#include "base/test/scoped_feature_list.h" +#include "base/traits_bag.h" +#include "build/build_config.h" +#include "build/buildflag.h" +#include "chrome/browser/web_applications/test/fake_os_integration_manager.h" +#include "chrome/browser/web_applications/test/fake_web_app_provider.h" +#include "chrome/browser/web_applications/test/web_app_install_test_utils.h" #include "chrome/browser/web_applications/test/web_app_test.h" #include "chrome/browser/web_applications/web_app_helpers.h" -#include "chrome/browser/web_applications/web_app_icon_manager.h" #include "chrome/browser/web_applications/web_app_install_info.h" #include "chrome/browser/web_applications/web_app_install_manager.h" #include "chrome/browser/web_applications/web_app_install_manager_observer.h" -#include "chrome/browser/web_applications/web_app_prefs_utils.h" -#include "chrome/browser/web_applications/web_app_sync_bridge.h" +#include "chrome/browser/web_applications/web_app_install_utils.h" +#include "chrome/browser/web_applications/web_app_provider.h" +#include "chrome/browser/web_applications/web_app_registrar.h" +#include "chrome/test/base/testing_profile.h" +#include "components/services/app_service/public/cpp/file_handler.h" #include "components/webapps/browser/install_result_code.h" +#include "mojo/public/cpp/bindings/struct_ptr.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "third_party/blink/public/common/features.h" +#include "third_party/blink/public/mojom/manifest/manifest.mojom-forward.h" +#include "third_party/blink/public/mojom/manifest/manifest.mojom.h" #include "url/gurl.h" namespace web_app { @@ -78,37 +88,20 @@ class WebAppInstallFinalizerUnitTest : public WebAppTest { void SetUp() override { WebAppTest::SetUp(); - fake_registry_controller_ = - std::make_unique(); - install_manager_ = std::make_unique(profile()); + FakeWebAppProvider* provider = FakeWebAppProvider::Get(profile()); + provider->SetDefaultFakeSubsystems(); + auto install_manager = std::make_unique(profile()); install_manager_observer_ = - std::make_unique(install_manager_.get()); - fake_registry_controller_->SetUp(profile()); - icon_manager_ = std::make_unique( - profile(), base::MakeRefCounted()); - policy_manager_ = std::make_unique(profile()); - ui_manager_ = std::make_unique(); - finalizer_ = std::make_unique(profile()); - - icon_manager_->SetSubsystems(®istrar(), &install_manager()); - finalizer_->SetSubsystems( - &install_manager(), ®istrar(), ui_manager_.get(), - &fake_registry_controller_->sync_bridge(), - &fake_registry_controller_->os_integration_manager(), - icon_manager_.get(), policy_manager_.get(), - &fake_registry_controller_->translation_manager()); - fake_registry_controller_->Init(); - finalizer_->Start(); + std::make_unique(install_manager.get()); + provider->SetInstallManager(std::move(install_manager)); + provider->SetInstallFinalizer( + std::make_unique(profile())); + + test::AwaitStartWebAppProviderAndSubsystems(profile()); } void TearDown() override { install_manager_observer_.reset(); - finalizer_.reset(); - ui_manager_.reset(); - policy_manager_.reset(); - icon_manager_.reset(); - fake_registry_controller_.reset(); - install_manager_.reset(); WebAppTest::TearDown(); } @@ -141,25 +134,21 @@ class WebAppInstallFinalizerUnitTest : public WebAppTest { file_handlers->push_back(std::move(file_handler)); } - WebAppInstallFinalizer& finalizer() { return *finalizer_; } - WebAppRegistrar& registrar() { - return fake_registry_controller_->registrar(); + WebAppProvider& provider() { return *WebAppProvider::GetForTest(profile()); } + WebAppInstallFinalizer& finalizer() { return provider().install_finalizer(); } + WebAppRegistrar& registrar() { return provider().registrar(); } + WebAppInstallManager& install_manager() { + return provider().install_manager(); } - WebAppInstallManager& install_manager() const { return *install_manager_; } protected: FakeOsIntegrationManager& os_integration_manager() { - return fake_registry_controller_->os_integration_manager(); + return static_cast( + provider().os_integration_manager()); } - std::unique_ptr finalizer_; std::unique_ptr install_manager_observer_; private: - std::unique_ptr install_manager_; - std::unique_ptr fake_registry_controller_; - std::unique_ptr icon_manager_; - std::unique_ptr policy_manager_; - std::unique_ptr ui_manager_; base::test::ScopedFeatureList scoped_feature_list_; }; @@ -259,7 +248,7 @@ TEST_F(WebAppInstallFinalizerUnitTest, OnWebAppManifestUpdatedTriggered) { FinalizeInstallResult result = AwaitFinalizeInstall(*info, options); base::RunLoop runloop; - finalizer_->FinalizeUpdate( + finalizer().FinalizeUpdate( *info, base::BindLambdaForTesting( [&](const web_app::AppId& app_id, webapps::InstallResultCode code, @@ -394,7 +383,7 @@ TEST_F(WebAppInstallFinalizerUnitTest, InstallOsHooksDisabledForDefaultApps) { CreateFileHandlersFromManifest(file_handlers, info->start_url); base::RunLoop runloop; - finalizer_->FinalizeUpdate( + finalizer().FinalizeUpdate( *info, base::BindLambdaForTesting([&](const web_app::AppId& app_id, webapps::InstallResultCode code, diff --git a/chrome/browser/web_applications/web_app_provider.h b/chrome/browser/web_applications/web_app_provider.h index 89202538fd02a0..c21362c7bcd03c 100644 --- a/chrome/browser/web_applications/web_app_provider.h +++ b/chrome/browser/web_applications/web_app_provider.h @@ -28,7 +28,7 @@ class PrefRegistrySyncable; namespace web_app { -class WebAppDatabaseFactory; +class AbstractWebAppDatabaseFactory; class WebAppSyncBridge; class WebAppIconManager; class PreinstalledWebAppManager; @@ -172,7 +172,7 @@ class WebAppProvider : public KeyedService { void DoMigrateProfilePrefs(Profile* profile); - std::unique_ptr database_factory_; + std::unique_ptr database_factory_; std::unique_ptr registrar_; std::unique_ptr sync_bridge_; std::unique_ptr preinstalled_web_app_manager_; diff --git a/chrome/browser/web_applications/web_app_translation_manager_unittest.cc b/chrome/browser/web_applications/web_app_translation_manager_unittest.cc index 5c20480d53dbc2..f014b9fb37a397 100644 --- a/chrome/browser/web_applications/web_app_translation_manager_unittest.cc +++ b/chrome/browser/web_applications/web_app_translation_manager_unittest.cc @@ -4,16 +4,25 @@ #include "chrome/browser/web_applications/web_app_translation_manager.h" +#include +#include +#include + #include "base/run_loop.h" #include "base/test/bind.h" +#include "base/test/scoped_feature_list.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/web_applications/test/fake_web_app_provider.h" -#include "chrome/browser/web_applications/test/fake_web_app_registry_controller.h" -#include "chrome/browser/web_applications/test/test_file_utils.h" #include "chrome/browser/web_applications/test/web_app_install_test_utils.h" #include "chrome/browser/web_applications/test/web_app_test.h" -#include "chrome/browser/web_applications/test/web_app_test_utils.h" +#include "chrome/browser/web_applications/web_app_install_info.h" +#include "chrome/browser/web_applications/web_app_provider.h" +#include "chrome/browser/web_applications/web_app_registrar.h" +#include "chrome/test/base/testing_profile.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "third_party/blink/public/common/features.h" +#include "url/gurl.h" namespace web_app { @@ -21,14 +30,9 @@ class WebAppTranslationManagerTest : public WebAppTest { void SetUp() override { WebAppTest::SetUp(); - fake_registry_controller_ = - std::make_unique(); - fake_registry_controller_->SetUp(profile()); - - file_utils_ = base::MakeRefCounted(); - - controller().Init(); - InitWebAppProvider(); + FakeWebAppProvider* provider = FakeWebAppProvider::Get(profile()); + provider->SetDefaultFakeSubsystems(); + test::AwaitStartWebAppProviderAndSubsystems(profile()); } protected: @@ -67,52 +71,27 @@ class WebAppTranslationManagerTest : public WebAppTest { return result; } - void InitWebAppProvider() { - provider_ = web_app::FakeWebAppProvider::Get(profile()); - provider_->SetOsIntegrationManager( - std::make_unique(profile(), nullptr, nullptr, - nullptr, nullptr)); - // FakeWebAppProvider should not wait for a test extension system, that is - // never started, to be ready. - provider_->SkipAwaitingExtensionSystem(); - web_app::test::AwaitStartWebAppProviderAndSubsystems(profile()); - } - - FakeWebAppRegistryController& controller() { - return *fake_registry_controller_; - } - - WebAppInstallManager& install_manager() { return *install_manager_; } - - FakeWebAppProvider& provider() { return *provider_; } - WebAppRegistrar& registrar() { return controller().registrar(); } + WebAppProvider& provider() { return *WebAppProvider::GetForTest(profile()); } + WebAppRegistrar& registrar() { return provider().registrar(); } WebAppTranslationManager& translation_manager() { - return controller().translation_manager(); - } - TestFileUtils& file_utils() { - DCHECK(file_utils_); - return *file_utils_; + return provider().translation_manager(); } private: - std::unique_ptr fake_registry_controller_; - std::unique_ptr install_manager_; - scoped_refptr file_utils_; - web_app::FakeWebAppProvider* provider_; base::test::ScopedFeatureList features_{ blink::features::kWebAppEnableTranslations}; }; TEST_F(WebAppTranslationManagerTest, WriteReadAndDelete) { - auto web_app1 = test::CreateWebApp(GURL("https://example.com/path")); - const AppId app_id1 = web_app1->app_id(); - web_app1->SetName("App1 name"); - controller().RegisterApp(std::move(web_app1)); + auto app_info1 = std::make_unique(); + app_info1->start_url = GURL("https://example.com/path"); + app_info1->title = u"App1 name"; + const AppId app_id1 = test::InstallWebApp(profile(), std::move(app_info1)); - auto web_app2 = test::CreateWebApp(GURL("https://example.com/path2")); - const AppId app_id2 = web_app2->app_id(); - web_app2->SetName("App2 name"); - controller().RegisterApp(std::move(web_app2)); + auto app_info2 = std::make_unique(); + app_info2->start_url = GURL("https://example.com/path2"); + app_info2->title = u"App2 name"; + const AppId app_id2 = test::InstallWebApp(profile(), std::move(app_info2)); g_browser_process->SetApplicationLocale("en"); @@ -190,9 +169,10 @@ TEST_F(WebAppTranslationManagerTest, WriteReadAndDelete) { } TEST_F(WebAppTranslationManagerTest, UpdateTranslations) { - auto web_app1 = test::CreateWebApp(GURL("https://example.com/path")); - const AppId app_id1 = web_app1->app_id(); - controller().RegisterApp(std::move(web_app1)); + auto app_info1 = std::make_unique(); + app_info1->start_url = GURL("https://example.com/path"); + app_info1->title = u"App1 name"; + const AppId app_id1 = test::InstallWebApp(profile(), std::move(app_info1)); g_browser_process->SetApplicationLocale("en");