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_PENDING_APP_MANAGER_H_
6 #define CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_PENDING_APP_MANAGER_H_
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 #include "chrome/browser/web_applications/components/pending_app_manager.h"
13 #include "chrome/browser/web_applications/test/test_app_registrar.h"
14 #include "url/gurl.h"
15 
16 namespace web_app {
17 
18 class TestAppRegistrar;
19 
20 // Deprecated. Please use TestPendingAppManagerImpl instead.
21 class TestPendingAppManager : public PendingAppManager {
22  public:
23   explicit TestPendingAppManager(TestAppRegistrar* registrar);
24   TestPendingAppManager(const TestPendingAppManager&) = delete;
25   TestPendingAppManager& operator=(const TestPendingAppManager&) = delete;
26   ~TestPendingAppManager() override;
27 
28   // The foo_requests methods may return duplicates, if the underlying
29   // InstallApps or UninstallApps arguments do. The deduped_foo_count methods
30   // only count new installs or new uninstalls.
31 
install_requests()32   const std::vector<ExternalInstallOptions>& install_requests() const {
33     return install_requests_;
34   }
uninstall_requests()35   const std::vector<GURL>& uninstall_requests() const {
36     return uninstall_requests_;
37   }
38 
deduped_install_count()39   int deduped_install_count() const { return deduped_install_count_; }
deduped_uninstall_count()40   int deduped_uninstall_count() const { return deduped_uninstall_count_; }
41 
ResetCounts()42   void ResetCounts() {
43     deduped_install_count_ = 0;
44     deduped_uninstall_count_ = 0;
45   }
46 
47   void SimulatePreviouslyInstalledApp(const GURL& url,
48                                       ExternalInstallSource install_source);
49 
50   void SetInstallResultCode(InstallResultCode result_code);
51 
52   // PendingAppManager:
53   void Install(ExternalInstallOptions install_options,
54                OnceInstallCallback callback) override;
55   void InstallApps(std::vector<ExternalInstallOptions> install_options_list,
56                    const RepeatingInstallCallback& callback) override;
57   void UninstallApps(std::vector<GURL> uninstall_urls,
58                      ExternalInstallSource install_source,
59                      const UninstallCallback& callback) override;
Shutdown()60   void Shutdown() override {}
61 
62  private:
63   void DoInstall(ExternalInstallOptions install_options,
64                  OnceInstallCallback callback);
65   std::vector<ExternalInstallOptions> install_requests_;
66   std::vector<GURL> uninstall_requests_;
67 
68   // TODO(calamity): Remove and replace with TestAppRegistrar methods.
69   int deduped_install_count_;
70   int deduped_uninstall_count_;
71 
72   InstallResultCode install_result_code_ =
73       InstallResultCode::kSuccessNewInstall;
74 
75   TestAppRegistrar* registrar_;
76 
77   base::WeakPtrFactory<TestPendingAppManager> weak_ptr_factory_{this};
78 
79 };
80 
81 }  // namespace web_app
82 
83 #endif  // CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_PENDING_APP_MANAGER_H_
84