OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
14 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
15 #include "chrome/common/extensions/extension.h" | |
15 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 | 21 |
21 namespace extensions { | |
22 class Extension; | |
23 } | |
24 | |
25 // Base class for extension browser tests. Provides utilities for loading, | 22 // Base class for extension browser tests. Provides utilities for loading, |
26 // unloading, and installing extensions. | 23 // unloading, and installing extensions. |
27 class ExtensionBrowserTest : virtual public InProcessBrowserTest, | 24 class ExtensionBrowserTest : virtual public InProcessBrowserTest, |
28 public content::NotificationObserver { | 25 public content::NotificationObserver { |
29 protected: | 26 protected: |
30 ExtensionBrowserTest(); | 27 ExtensionBrowserTest(); |
31 virtual ~ExtensionBrowserTest(); | 28 virtual ~ExtensionBrowserTest(); |
32 | 29 |
33 // InProcessBrowserTest | 30 // InProcessBrowserTest |
34 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; | 31 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; |
35 | 32 |
36 const extensions::Extension* LoadExtension(const FilePath& path); | 33 const extensions::Extension* LoadExtension(const FilePath& path); |
37 | 34 |
38 // Same as above, but enables the extension in incognito mode first. | 35 // Same as above, but enables the extension in incognito mode first. |
39 const extensions::Extension* LoadExtensionIncognito(const FilePath& path); | 36 const extensions::Extension* LoadExtensionIncognito(const FilePath& path); |
40 | 37 |
41 const extensions::Extension* LoadExtensionWithOptions(const FilePath& path, | 38 const extensions::Extension* LoadExtensionWithOptions( |
42 bool incognito_enabled, | 39 const FilePath& path, |
43 bool fileaccess_enabled); | 40 bool incognito_enabled, |
41 bool fileaccess_enabled); | |
44 | 42 |
45 // Loads extension and imitates that it is a component extension. | 43 // Loads extension and imitates that it is a component extension. |
46 const extensions::Extension* LoadExtensionAsComponent(const FilePath& path); | 44 const extensions::Extension* LoadExtensionAsComponent(const FilePath& path); |
47 | 45 |
48 // Pack the extension in |dir_path| into a crx file and return its path. | 46 // Pack the extension in |dir_path| into a crx file and return its path. |
49 // Return an empty FilePath if there were errors. | 47 // Return an empty FilePath if there were errors. |
50 FilePath PackExtension(const FilePath& dir_path); | 48 FilePath PackExtension(const FilePath& dir_path); |
51 | 49 |
52 // Pack the extension in |dir_path| into a crx file at |crx_path|, using the | 50 // Pack the extension in |dir_path| into a crx file at |crx_path|, using the |
53 // key |pem_path|. If |pem_path| does not exist, create a new key at | 51 // key |pem_path|. If |pem_path| does not exist, create a new key at |
54 // |pem_out_path|. | 52 // |pem_out_path|. |
55 // Return the path to the crx file, or an empty FilePath if there were errors. | 53 // Return the path to the crx file, or an empty FilePath if there were errors. |
56 FilePath PackExtensionWithOptions(const FilePath& dir_path, | 54 FilePath PackExtensionWithOptions(const FilePath& dir_path, |
57 const FilePath& crx_path, | 55 const FilePath& crx_path, |
58 const FilePath& pem_path, | 56 const FilePath& pem_path, |
59 const FilePath& pem_out_path); | 57 const FilePath& pem_out_path); |
60 | 58 |
61 // |expected_change| indicates how many extensions should be installed (or | 59 // |expected_change| indicates how many extensions should be installed (or |
62 // disabled, if negative). | 60 // disabled, if negative). |
63 // 1 means you expect a new install, 0 means you expect an upgrade, -1 means | 61 // 1 means you expect a new install, 0 means you expect an upgrade, -1 means |
64 // you expect a failed upgrade. | 62 // you expect a failed upgrade. |
65 const extensions::Extension* InstallExtension(const FilePath& path, | 63 const extensions::Extension* InstallExtension(const FilePath& path, |
66 int expected_change) { | 64 int expected_change) { |
67 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE, | 65 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE, |
68 expected_change); | 66 expected_change); |
69 } | 67 } |
70 | 68 |
69 // Same as above, but an install source other than Extension::INTERNAL can be | |
70 // specified. Intended to be used only in tests. | |
asargent_no_longer_on_chrome
2012/08/02 21:28:07
nit: You probably don't need to mention that it's
mitchellwrosen
2012/08/02 21:31:04
Sure thing.
| |
71 const extensions::Extension* InstallExtension( | |
72 const FilePath& path, | |
73 int expected_change, | |
74 extensions::Extension::Location install_source) { | |
75 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE, | |
76 expected_change, install_source); | |
77 } | |
78 | |
71 // Installs extension as if it came from the Chrome Webstore. | 79 // Installs extension as if it came from the Chrome Webstore. |
72 const extensions::Extension* InstallExtensionFromWebstore( | 80 const extensions::Extension* InstallExtensionFromWebstore( |
73 const FilePath& path, int expected_change); | 81 const FilePath& path, int expected_change); |
74 | 82 |
75 // Same as above but passes an id to CrxInstaller and does not allow a | 83 // Same as above but passes an id to CrxInstaller and does not allow a |
76 // privilege increase. | 84 // privilege increase. |
77 const extensions::Extension* UpdateExtension(const std::string& id, | 85 const extensions::Extension* UpdateExtension(const std::string& id, |
78 const FilePath& path, | 86 const FilePath& path, |
79 int expected_change) { | 87 int expected_change) { |
80 return InstallOrUpdateExtension(id, path, INSTALL_UI_TYPE_NONE, | 88 return InstallOrUpdateExtension(id, path, INSTALL_UI_TYPE_NONE, |
81 expected_change); | 89 expected_change); |
82 } | 90 } |
83 | 91 |
84 // Same as |InstallExtension| but with the normal extension UI showing up | 92 // Same as |InstallExtension| but with the normal extension UI showing up |
85 // (for e.g. info bar on success). | 93 // (for e.g. info bar on success). |
86 const extensions::Extension* InstallExtensionWithUI(const FilePath& path, | 94 const extensions::Extension* InstallExtensionWithUI(const FilePath& path, |
87 int expected_change) { | 95 int expected_change) { |
88 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NORMAL, | 96 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NORMAL, |
89 expected_change); | 97 expected_change); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 const extensions::Extension* InstallOrUpdateExtension(const std::string& id, | 197 const extensions::Extension* InstallOrUpdateExtension(const std::string& id, |
190 const FilePath& path, | 198 const FilePath& path, |
191 InstallUIType ui_type, | 199 InstallUIType ui_type, |
192 int expected_change); | 200 int expected_change); |
193 const extensions::Extension* InstallOrUpdateExtension(const std::string& id, | 201 const extensions::Extension* InstallOrUpdateExtension(const std::string& id, |
194 const FilePath& path, | 202 const FilePath& path, |
195 InstallUIType ui_type, | 203 InstallUIType ui_type, |
196 int expected_change, | 204 int expected_change, |
197 Browser* browser, | 205 Browser* browser, |
198 bool from_webstore); | 206 bool from_webstore); |
207 const extensions::Extension* InstallOrUpdateExtension( | |
208 const std::string& id, | |
209 const FilePath& path, | |
210 InstallUIType ui_type, | |
211 int expected_change, | |
212 extensions::Extension::Location install_source); | |
213 const extensions::Extension* InstallOrUpdateExtension( | |
214 const std::string& id, | |
215 const FilePath& path, | |
216 InstallUIType ui_type, | |
217 int expected_change, | |
218 extensions::Extension::Location install_source, | |
219 Browser* browser, | |
220 bool from_webstore); | |
199 | 221 |
200 bool WaitForExtensionViewsToLoad(); | 222 bool WaitForExtensionViewsToLoad(); |
201 | 223 |
202 // When waiting for page action count to change, we wait until it reaches this | 224 // When waiting for page action count to change, we wait until it reaches this |
203 // value. | 225 // value. |
204 int target_page_action_count_; | 226 int target_page_action_count_; |
205 | 227 |
206 // When waiting for visible page action count to change, we wait until it | 228 // When waiting for visible page action count to change, we wait until it |
207 // reaches this value. | 229 // reaches this value. |
208 int target_visible_page_action_count_; | 230 int target_visible_page_action_count_; |
209 }; | 231 }; |
210 | 232 |
211 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_ | 233 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_ |
OLD | NEW |