OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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_EXTENSIONS_EXTENSION_SERVICE_TEST_WITH_INSTALL_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_TEST_WITH_INSTALL_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/files/file_path.h" | |
11 #include "chrome/browser/extensions/extension_service_test_base.h" | |
12 #include "content/public/browser/notification_observer.h" | |
13 #include "content/public/browser/notification_registrar.h" | |
14 #include "extensions/common/extension.h" | |
15 | |
16 namespace extensions { | |
17 | |
18 // An enhancement of ExtensionServiceTestBase that provides helpers to install, | |
19 // update, and uninstall extensions. | |
20 class ExtensionServiceTestWithInstall : public ExtensionServiceTestBase, | |
21 public content::NotificationObserver { | |
22 public: | |
23 ExtensionServiceTestWithInstall(); | |
24 ~ExtensionServiceTestWithInstall() override; | |
25 | |
26 protected: | |
27 static std::vector<base::string16> GetErrors(); | |
28 | |
29 void PackCRX(const base::FilePath& dir_path, | |
30 const base::FilePath& pem_path, | |
31 const base::FilePath& crx_path); | |
32 | |
33 enum InstallState { | |
34 INSTALL_FAILED, | |
35 INSTALL_UPDATED, | |
36 INSTALL_NEW, | |
37 INSTALL_WITHOUT_LOAD, | |
38 }; | |
39 | |
40 const Extension* PackAndInstallCRX(const base::FilePath& dir_path, | |
41 const base::FilePath& pem_path, | |
42 InstallState install_state, | |
43 int creation_flags); | |
44 const Extension* PackAndInstallCRX(const base::FilePath& dir_path, | |
45 const base::FilePath& pem_path, | |
46 InstallState install_state); | |
47 const Extension* PackAndInstallCRX(const base::FilePath& dir_path, | |
48 InstallState install_state); | |
49 | |
50 const Extension* InstallCRX(const base::FilePath& path, | |
51 InstallState install_state, | |
52 int creation_flags, | |
53 const std::string& expected_old_name); | |
54 const Extension* InstallCRX(const base::FilePath& path, | |
55 InstallState install_state, | |
56 int creation_flags); | |
57 const Extension* InstallCRX(const base::FilePath& path, | |
58 InstallState install_state); | |
59 const Extension* InstallCRXFromWebStore(const base::FilePath& path, | |
60 InstallState install_state); | |
61 const Extension* InstallCRXWithLocation(const base::FilePath& crx_path, | |
62 Manifest::Location install_location, | |
63 InstallState install_state); | |
64 | |
65 // Verifies the result of a CRX installation. Used by InstallCRX. Set the | |
66 // |install_state| to INSTALL_FAILED if the installation is expected to fail. | |
67 // Returns an Extension pointer if the install succeeded, null otherwise. | |
68 const Extension* VerifyCrxInstall(const base::FilePath& path, | |
69 InstallState install_state); | |
70 | |
71 // Verifies the result of a CRX installation. Used by InstallCRX. Set the | |
72 // |install_state| to INSTALL_FAILED if the installation is expected to fail. | |
73 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is | |
74 // non-empty, expects that the existing extension's title was | |
75 // |expected_old_name|. | |
76 // Returns an Extension pointer if the install succeeded, null otherwise. | |
77 const Extension* VerifyCrxInstall(const base::FilePath& path, | |
78 InstallState install_state, | |
79 const std::string& expected_old_name); | |
80 | |
81 enum UpdateState { | |
82 FAILED_SILENTLY, | |
83 FAILED, | |
84 UPDATED, | |
85 INSTALLED, | |
86 DISABLED, | |
87 ENABLED | |
88 }; | |
89 | |
90 void PackCRXAndUpdateExtension(const std::string& id, | |
91 const base::FilePath& dir_path, | |
92 const base::FilePath& pem_path, | |
93 UpdateState expected_state); | |
94 | |
95 void UpdateExtension(const std::string& id, | |
96 const base::FilePath& in_path, | |
97 UpdateState expected_state); | |
98 | |
99 void UninstallExtension(const std::string& id, bool use_helper); | |
100 void UninstallExtension(const std::string& id, | |
101 bool use_helper, | |
102 Extension::State expected_state); | |
103 | |
104 void TerminateExtension(const std::string& id); | |
105 | |
106 // TODO(treib,devlin): Make these private and add accessors as needed. | |
107 extensions::ExtensionList loaded_; | |
108 const Extension* installed_; | |
109 bool was_update_; | |
110 std::string old_name_; | |
111 std::string unloaded_id_; | |
112 UnloadedExtensionInfo::Reason unloaded_reason_; | |
113 | |
114 private: | |
115 void Observe(int type, | |
116 const content::NotificationSource& source, | |
117 const content::NotificationDetails& details) override; | |
118 | |
119 void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags); | |
120 | |
121 content::NotificationRegistrar registrar_; | |
122 size_t expected_extensions_count_; | |
Devlin
2015/10/28 16:15:22
nit: Disallow copy and assign.
Marc Treib
2015/10/29 13:27:57
Done. (Also in ExtensionServiceTestBase)
| |
123 }; | |
124 | |
125 } // namespace extensions | |
126 | |
127 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_TEST_WITH_INSTALL_H_ | |
OLD | NEW |