1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_INSTALL_FINALIZER_H_ 6 #define CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_INSTALL_FINALIZER_H_ 7 8 #include <map> 9 #include <memory> 10 #include <set> 11 12 #include "base/optional.h" 13 #include "chrome/browser/web_applications/components/install_finalizer.h" 14 15 struct WebApplicationInfo; 16 17 namespace web_app { 18 19 class TestInstallFinalizer final : public InstallFinalizer { 20 public: 21 // Returns what would be the AppId if an app is installed with |url|. 22 static AppId GetAppIdForUrl(const GURL& url); 23 24 TestInstallFinalizer(); 25 TestInstallFinalizer(const TestInstallFinalizer&) = delete; 26 TestInstallFinalizer& operator=(const TestInstallFinalizer&) = delete; 27 ~TestInstallFinalizer() override; 28 29 // InstallFinalizer: 30 void FinalizeInstall(const WebApplicationInfo& web_app_info, 31 const FinalizeOptions& options, 32 InstallFinalizedCallback callback) override; 33 void FinalizeUninstallAfterSync(const AppId& app_id, 34 UninstallWebAppCallback callback) override; 35 void FinalizeUpdate(const WebApplicationInfo& web_app_info, 36 InstallFinalizedCallback callback) override; 37 void UninstallExternalWebApp(const AppId& app_id, 38 ExternalInstallSource external_install_source, 39 UninstallWebAppCallback callback) override; 40 void UninstallExternalWebAppByUrl( 41 const GURL& app_url, 42 ExternalInstallSource external_install_source, 43 UninstallWebAppCallback callback) override; 44 bool CanUserUninstallFromSync(const AppId& app_id) const override; 45 void UninstallWebAppFromSyncByUser(const AppId& app_id, 46 UninstallWebAppCallback callback) override; 47 bool CanUserUninstallExternalApp(const AppId& app_id) const override; 48 void UninstallExternalAppByUser(const AppId& app_id, 49 UninstallWebAppCallback callback) override; 50 bool WasExternalAppUninstalledByUser(const AppId& app_id) const override; 51 bool CanReparentTab(const AppId& app_id, 52 bool shortcut_created) const override; 53 void ReparentTab(const AppId& app_id, 54 bool shortcut_created, 55 content::WebContents* web_contents) override; 56 57 void SetNextFinalizeInstallResult(const AppId& app_id, 58 InstallResultCode code); 59 void SetNextUninstallExternalWebAppResult(const GURL& app_url, 60 bool uninstalled); 61 62 // Uninstall the app and add |app_id| to the map of external extensions 63 // uninstalled by the user. May be called on an app that isn't installed to 64 // simulate that the app was uninstalled previously. 65 void SimulateExternalAppUninstalledByUser(const AppId& app_id); 66 web_app_info()67 std::unique_ptr<WebApplicationInfo> web_app_info() { 68 return std::move(web_app_info_copy_); 69 } 70 finalize_options_list()71 const std::vector<FinalizeOptions>& finalize_options_list() const { 72 return finalize_options_list_; 73 } 74 uninstall_external_web_app_urls()75 const std::vector<GURL>& uninstall_external_web_app_urls() const { 76 return uninstall_external_web_app_urls_; 77 } 78 num_reparent_tab_calls()79 int num_reparent_tab_calls() { return num_reparent_tab_calls_; } 80 81 private: 82 void Finalize(const WebApplicationInfo& web_app_info, 83 InstallResultCode code, 84 InstallFinalizedCallback callback); 85 86 std::unique_ptr<WebApplicationInfo> web_app_info_copy_; 87 std::vector<FinalizeOptions> finalize_options_list_; 88 std::vector<GURL> uninstall_external_web_app_urls_; 89 90 base::Optional<AppId> next_app_id_; 91 base::Optional<InstallResultCode> next_result_code_; 92 std::map<GURL, bool> next_uninstall_external_web_app_results_; 93 std::set<AppId> user_uninstalled_external_apps_; 94 95 int num_reparent_tab_calls_ = 0; 96 97 }; 98 99 } // namespace web_app 100 101 #endif // CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_INSTALL_FINALIZER_H_ 102