OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
19 | 19 |
20 class Extension; | 20 class Extension; |
21 | 21 |
22 // Base class for extension browser tests. Provides utilities for loading, | 22 // Base class for extension browser tests. Provides utilities for loading, |
23 // unloading, and installing extensions. | 23 // unloading, and installing extensions. |
24 class ExtensionBrowserTest | 24 class ExtensionBrowserTest |
25 : public InProcessBrowserTest, public content::NotificationObserver { | 25 : public InProcessBrowserTest, public content::NotificationObserver { |
26 protected: | 26 protected: |
27 ExtensionBrowserTest(); | 27 ExtensionBrowserTest(); |
28 | 28 |
29 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; | 29 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; |
| 30 |
30 const Extension* LoadExtension(const FilePath& path); | 31 const Extension* LoadExtension(const FilePath& path); |
31 | 32 |
32 // Same as above, but enables the extension in incognito mode first. | 33 // Same as above, but enables the extension in incognito mode first. |
33 const Extension* LoadExtensionIncognito(const FilePath& path); | 34 const Extension* LoadExtensionIncognito(const FilePath& path); |
34 | 35 |
35 const Extension* LoadExtensionWithOptions(const FilePath& path, | 36 const Extension* LoadExtensionWithOptions(const FilePath& path, |
36 bool incognito_enabled, | 37 bool incognito_enabled, |
37 bool fileaccess_enabled); | 38 bool fileaccess_enabled); |
38 | 39 |
39 // Loads extension and imitates that it is a component extension. | 40 // Loads extension and imitates that it is a component extension. |
40 bool LoadExtensionAsComponent(const FilePath& path); | 41 bool LoadExtensionAsComponent(const FilePath& path); |
41 | 42 |
42 // Pack the extension in |dir_path| into a crx file and return its path. | 43 // Pack the extension in |dir_path| into a crx file and return its path. |
43 // Return an empty FilePath if there were errors. | 44 // Return an empty FilePath if there were errors. |
44 FilePath PackExtension(const FilePath& dir_path); | 45 FilePath PackExtension(const FilePath& dir_path); |
45 | 46 |
46 // Pack the extension in |dir_path| into a crx file at |crx_path|, using the | 47 // Pack the extension in |dir_path| into a crx file at |crx_path|, using the |
47 // key |pem_path|. If |pem_path| does not exist, create a new key at | 48 // key |pem_path|. If |pem_path| does not exist, create a new key at |
48 // |pem_out_path|. | 49 // |pem_out_path|. |
49 // Return the path to the crx file, or an empty FilePath if there were errors. | 50 // Return the path to the crx file, or an empty FilePath if there were errors. |
50 FilePath PackExtensionWithOptions(const FilePath& dir_path, | 51 FilePath PackExtensionWithOptions(const FilePath& dir_path, |
51 const FilePath& crx_path, | 52 const FilePath& crx_path, |
52 const FilePath& pem_path, | 53 const FilePath& pem_path, |
53 const FilePath& pem_out_path); | 54 const FilePath& pem_out_path); |
54 | 55 |
55 // |expected_change| indicates how many extensions should be installed (or | 56 // |expected_change| indicates how many extensions should be installed (or |
56 // disabled, if negative). | 57 // disabled, if negative). |
57 // 1 means you expect a new install, 0 means you expect an upgrade, -1 means | 58 // 1 means you expect a new install, 0 means you expect an upgrade, -1 means |
58 // you expect a failed upgrade. | 59 // you expect a failed upgrade. |
59 bool InstallExtension(const FilePath& path, int expected_change) { | 60 const Extension* InstallExtension(const FilePath& path, int expected_change) { |
60 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE, | 61 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE, |
61 expected_change); | 62 expected_change); |
62 } | 63 } |
63 | 64 |
64 // Installs extension as if it came from the Chrome Webstore. | 65 // Installs extension as if it came from the Chrome Webstore. |
65 bool InstallExtensionFromWebstore(const FilePath& path, int expected_change); | 66 const Extension* InstallExtensionFromWebstore( |
| 67 const FilePath& path, int expected_change); |
66 | 68 |
67 // Same as above but passes an id to CrxInstaller and does not allow a | 69 // Same as above but passes an id to CrxInstaller and does not allow a |
68 // privilege increase. | 70 // privilege increase. |
69 bool UpdateExtension(const std::string& id, const FilePath& path, | 71 const Extension* UpdateExtension(const std::string& id, const FilePath& path, |
70 int expected_change) { | 72 int expected_change) { |
71 return InstallOrUpdateExtension(id, path, INSTALL_UI_TYPE_NONE, | 73 return InstallOrUpdateExtension(id, path, INSTALL_UI_TYPE_NONE, |
72 expected_change); | 74 expected_change); |
73 } | 75 } |
74 | 76 |
75 // Same as |InstallExtension| but with the normal extension UI showing up | 77 // Same as |InstallExtension| but with the normal extension UI showing up |
76 // (for e.g. info bar on success). | 78 // (for e.g. info bar on success). |
77 bool InstallExtensionWithUI(const FilePath& path, int expected_change) { | 79 const Extension* InstallExtensionWithUI(const FilePath& path, |
| 80 int expected_change) { |
78 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NORMAL, | 81 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NORMAL, |
79 expected_change); | 82 expected_change); |
80 } | 83 } |
81 bool InstallExtensionWithUIAutoConfirm(const FilePath& path, | 84 const Extension* InstallExtensionWithUIAutoConfirm(const FilePath& path, |
82 int expected_change, | 85 int expected_change, |
83 Profile* profile) { | 86 Profile* profile) { |
84 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_AUTO_CONFIRM, | 87 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_AUTO_CONFIRM, |
85 expected_change, profile, false); | 88 expected_change, profile, false); |
86 } | 89 } |
87 | 90 |
88 // Begins install process but simulates a user cancel. | 91 // Begins install process but simulates a user cancel. |
89 bool StartInstallButCancel(const FilePath& path) { | 92 const Extension* StartInstallButCancel(const FilePath& path) { |
90 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_CANCEL, 0); | 93 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_CANCEL, 0); |
91 } | 94 } |
92 | 95 |
93 void ReloadExtension(const std::string& extension_id); | 96 void ReloadExtension(const std::string& extension_id); |
94 | 97 |
95 void UnloadExtension(const std::string& extension_id); | 98 void UnloadExtension(const std::string& extension_id); |
96 | 99 |
97 void UninstallExtension(const std::string& extension_id); | 100 void UninstallExtension(const std::string& extension_id); |
98 | 101 |
99 void DisableExtension(const std::string& extension_id); | 102 void DisableExtension(const std::string& extension_id); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 143 |
141 // Specifies the type of UI (if any) to show during installation and what | 144 // Specifies the type of UI (if any) to show during installation and what |
142 // user action to simulate. | 145 // user action to simulate. |
143 enum InstallUIType { | 146 enum InstallUIType { |
144 INSTALL_UI_TYPE_NONE, | 147 INSTALL_UI_TYPE_NONE, |
145 INSTALL_UI_TYPE_CANCEL, | 148 INSTALL_UI_TYPE_CANCEL, |
146 INSTALL_UI_TYPE_NORMAL, | 149 INSTALL_UI_TYPE_NORMAL, |
147 INSTALL_UI_TYPE_AUTO_CONFIRM, | 150 INSTALL_UI_TYPE_AUTO_CONFIRM, |
148 }; | 151 }; |
149 | 152 |
150 bool InstallOrUpdateExtension(const std::string& id, const FilePath& path, | 153 const Extension* InstallOrUpdateExtension(const std::string& id, |
151 InstallUIType ui_type, | 154 const FilePath& path, |
152 int expected_change); | 155 InstallUIType ui_type, |
153 bool InstallOrUpdateExtension(const std::string& id, const FilePath& path, | 156 int expected_change); |
154 InstallUIType ui_type, | 157 const Extension* InstallOrUpdateExtension(const std::string& id, |
155 int expected_change, | 158 const FilePath& path, |
156 Profile* profile, | 159 InstallUIType ui_type, |
157 bool from_webstore); | 160 int expected_change, |
| 161 Profile* profile, |
| 162 bool from_webstore); |
158 | 163 |
159 bool WaitForExtensionHostsToLoad(); | 164 bool WaitForExtensionHostsToLoad(); |
160 | 165 |
161 // When waiting for page action count to change, we wait until it reaches this | 166 // When waiting for page action count to change, we wait until it reaches this |
162 // value. | 167 // value. |
163 int target_page_action_count_; | 168 int target_page_action_count_; |
164 | 169 |
165 // When waiting for visible page action count to change, we wait until it | 170 // When waiting for visible page action count to change, we wait until it |
166 // reaches this value. | 171 // reaches this value. |
167 int target_visible_page_action_count_; | 172 int target_visible_page_action_count_; |
168 }; | 173 }; |
169 | 174 |
170 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_ | 175 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_ |
OLD | NEW |