1 // Copyright 2020 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_OS_INTEGRATION_MANAGER_H_
6 #define CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_OS_INTEGRATION_MANAGER_H_
7 
8 #include <map>
9 
10 #include "base/optional.h"
11 #include "chrome/browser/web_applications/components/os_integration_manager.h"
12 #include "chrome/browser/web_applications/components/web_app_id.h"
13 
14 namespace web_app {
15 
16 class AppShortcutManager;
17 class FileHandlerManager;
18 
19 class TestOsIntegrationManager : public OsIntegrationManager {
20  public:
21   explicit TestOsIntegrationManager(
22       Profile* profile,
23       std::unique_ptr<AppShortcutManager> shortcut_manager,
24       std::unique_ptr<FileHandlerManager> file_handler_manager);
25   ~TestOsIntegrationManager() override;
26 
27   // OsIntegrationManager:
28   void InstallOsHooks(const AppId& app_id,
29                       InstallOsHooksCallback callback,
30                       std::unique_ptr<WebApplicationInfo> web_app_info,
31                       InstallOsHooksOptions options) override;
32   void UninstallOsHooks(const AppId& app_id,
33                         const OsHooksResults& os_hooks,
34                         UninstallOsHooksCallback callback) override;
35   void UninstallAllOsHooks(const AppId& app_id,
36                            UninstallOsHooksCallback callback) override;
37   void UpdateOsHooks(const AppId& app_id,
38                      base::StringPiece old_name,
39                      const WebApplicationInfo& web_app_info) override;
40 
num_create_shortcuts_calls()41   size_t num_create_shortcuts_calls() const {
42     return num_create_shortcuts_calls_;
43   }
44 
num_register_run_on_os_login_calls()45   size_t num_register_run_on_os_login_calls() const {
46     return num_register_run_on_os_login_calls_;
47   }
48 
num_add_app_to_quick_launch_bar_calls()49   size_t num_add_app_to_quick_launch_bar_calls() const {
50     return num_add_app_to_quick_launch_bar_calls_;
51   }
52 
set_can_create_shortcuts(bool can_create_shortcuts)53   void set_can_create_shortcuts(bool can_create_shortcuts) {
54     can_create_shortcuts_ = can_create_shortcuts;
55   }
56 
did_add_to_desktop()57   base::Optional<bool> did_add_to_desktop() const {
58     return did_add_to_desktop_;
59   }
60 
get_last_install_options()61   base::Optional<InstallOsHooksOptions> get_last_install_options() const {
62     return last_options_;
63   }
64 
65   void SetNextCreateShortcutsResult(const AppId& app_id, bool success);
66 
67   void SetFileHandlerManager(
68       std::unique_ptr<FileHandlerManager> file_handler_manager);
69 
70   TestOsIntegrationManager* AsTestOsIntegrationManager() override;
71 
72  private:
73   size_t num_create_shortcuts_calls_ = 0;
74   size_t num_register_run_on_os_login_calls_ = 0;
75   size_t num_add_app_to_quick_launch_bar_calls_ = 0;
76   base::Optional<bool> did_add_to_desktop_;
77   base::Optional<InstallOsHooksOptions> last_options_;
78 
79   bool can_create_shortcuts_ = true;
80   std::map<AppId, bool> next_create_shortcut_results_;
81 };
82 
83 // Stub test shortcut manager.
84 class TestShortcutManager : public AppShortcutManager {
85  public:
86   explicit TestShortcutManager(Profile* profile);
87   ~TestShortcutManager() override;
88   std::unique_ptr<ShortcutInfo> BuildShortcutInfo(const AppId& app_id) override;
89   void GetShortcutInfoForApp(const AppId& app_id,
90                              GetShortcutInfoCallback callback) override;
91 };
92 }  // namespace web_app
93 
94 #endif  // CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_OS_INTEGRATION_MANAGER_H_
95