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 #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 namespace extensions { |
20 class Extension; | 21 class Extension; |
| 22 } |
21 | 23 |
22 // Base class for extension browser tests. Provides utilities for loading, | 24 // Base class for extension browser tests. Provides utilities for loading, |
23 // unloading, and installing extensions. | 25 // unloading, and installing extensions. |
24 class ExtensionBrowserTest | 26 class ExtensionBrowserTest |
25 : public InProcessBrowserTest, public content::NotificationObserver { | 27 : public InProcessBrowserTest, public content::NotificationObserver { |
26 protected: | 28 protected: |
27 ExtensionBrowserTest(); | 29 ExtensionBrowserTest(); |
28 virtual ~ExtensionBrowserTest(); | 30 virtual ~ExtensionBrowserTest(); |
29 | 31 |
30 // InProcessBrowserTest | 32 // InProcessBrowserTest |
31 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; | 33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; |
32 | 34 |
33 const Extension* LoadExtension(const FilePath& path); | 35 const extensions::Extension* LoadExtension(const FilePath& path); |
34 | 36 |
35 // Same as above, but enables the extension in incognito mode first. | 37 // Same as above, but enables the extension in incognito mode first. |
36 const Extension* LoadExtensionIncognito(const FilePath& path); | 38 const extensions::Extension* LoadExtensionIncognito(const FilePath& path); |
37 | 39 |
38 const Extension* LoadExtensionWithOptions(const FilePath& path, | 40 const extensions::Extension* LoadExtensionWithOptions(const FilePath& path, |
39 bool incognito_enabled, | 41 bool incognito_enabled, |
40 bool fileaccess_enabled); | 42 bool fileaccess_enabled); |
41 | 43 |
42 // Loads extension and imitates that it is a component extension. | 44 // Loads extension and imitates that it is a component extension. |
43 const Extension* LoadExtensionAsComponent(const FilePath& path); | 45 const extensions::Extension* LoadExtensionAsComponent(const FilePath& path); |
44 | 46 |
45 // Pack the extension in |dir_path| into a crx file and return its path. | 47 // Pack the extension in |dir_path| into a crx file and return its path. |
46 // Return an empty FilePath if there were errors. | 48 // Return an empty FilePath if there were errors. |
47 FilePath PackExtension(const FilePath& dir_path); | 49 FilePath PackExtension(const FilePath& dir_path); |
48 | 50 |
49 // Pack the extension in |dir_path| into a crx file at |crx_path|, using the | 51 // Pack the extension in |dir_path| into a crx file at |crx_path|, using the |
50 // key |pem_path|. If |pem_path| does not exist, create a new key at | 52 // key |pem_path|. If |pem_path| does not exist, create a new key at |
51 // |pem_out_path|. | 53 // |pem_out_path|. |
52 // Return the path to the crx file, or an empty FilePath if there were errors. | 54 // Return the path to the crx file, or an empty FilePath if there were errors. |
53 FilePath PackExtensionWithOptions(const FilePath& dir_path, | 55 FilePath PackExtensionWithOptions(const FilePath& dir_path, |
54 const FilePath& crx_path, | 56 const FilePath& crx_path, |
55 const FilePath& pem_path, | 57 const FilePath& pem_path, |
56 const FilePath& pem_out_path); | 58 const FilePath& pem_out_path); |
57 | 59 |
58 // |expected_change| indicates how many extensions should be installed (or | 60 // |expected_change| indicates how many extensions should be installed (or |
59 // disabled, if negative). | 61 // disabled, if negative). |
60 // 1 means you expect a new install, 0 means you expect an upgrade, -1 means | 62 // 1 means you expect a new install, 0 means you expect an upgrade, -1 means |
61 // you expect a failed upgrade. | 63 // you expect a failed upgrade. |
62 const Extension* InstallExtension(const FilePath& path, int expected_change) { | 64 const extensions::Extension* InstallExtension(const FilePath& path, |
| 65 int expected_change) { |
63 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE, | 66 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE, |
64 expected_change); | 67 expected_change); |
65 } | 68 } |
66 | 69 |
67 // Installs extension as if it came from the Chrome Webstore. | 70 // Installs extension as if it came from the Chrome Webstore. |
68 const Extension* InstallExtensionFromWebstore( | 71 const extensions::Extension* InstallExtensionFromWebstore( |
69 const FilePath& path, int expected_change); | 72 const FilePath& path, int expected_change); |
70 | 73 |
71 // Same as above but passes an id to CrxInstaller and does not allow a | 74 // Same as above but passes an id to CrxInstaller and does not allow a |
72 // privilege increase. | 75 // privilege increase. |
73 const Extension* UpdateExtension(const std::string& id, const FilePath& path, | 76 const extensions::Extension* UpdateExtension(const std::string& id, |
| 77 const FilePath& path, |
74 int expected_change) { | 78 int expected_change) { |
75 return InstallOrUpdateExtension(id, path, INSTALL_UI_TYPE_NONE, | 79 return InstallOrUpdateExtension(id, path, INSTALL_UI_TYPE_NONE, |
76 expected_change); | 80 expected_change); |
77 } | 81 } |
78 | 82 |
79 // Same as |InstallExtension| but with the normal extension UI showing up | 83 // Same as |InstallExtension| but with the normal extension UI showing up |
80 // (for e.g. info bar on success). | 84 // (for e.g. info bar on success). |
81 const Extension* InstallExtensionWithUI(const FilePath& path, | 85 const extensions::Extension* InstallExtensionWithUI(const FilePath& path, |
82 int expected_change) { | 86 int expected_change) { |
83 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NORMAL, | 87 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NORMAL, |
84 expected_change); | 88 expected_change); |
85 } | 89 } |
86 const Extension* InstallExtensionWithUIAutoConfirm(const FilePath& path, | 90 |
87 int expected_change, | 91 const extensions::Extension* InstallExtensionWithUIAutoConfirm( |
88 Profile* profile) { | 92 const FilePath& path, |
| 93 int expected_change, |
| 94 Profile* profile) { |
89 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_AUTO_CONFIRM, | 95 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_AUTO_CONFIRM, |
90 expected_change, profile, false); | 96 expected_change, profile, false); |
91 } | 97 } |
92 | 98 |
93 // Begins install process but simulates a user cancel. | 99 // Begins install process but simulates a user cancel. |
94 const Extension* StartInstallButCancel(const FilePath& path) { | 100 const extensions::Extension* StartInstallButCancel(const FilePath& path) { |
95 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_CANCEL, 0); | 101 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_CANCEL, 0); |
96 } | 102 } |
97 | 103 |
98 void ReloadExtension(const std::string& extension_id); | 104 void ReloadExtension(const std::string& extension_id); |
99 | 105 |
100 void UnloadExtension(const std::string& extension_id); | 106 void UnloadExtension(const std::string& extension_id); |
101 | 107 |
102 void UninstallExtension(const std::string& extension_id); | 108 void UninstallExtension(const std::string& extension_id); |
103 | 109 |
104 void DisableExtension(const std::string& extension_id); | 110 void DisableExtension(const std::string& extension_id); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 156 |
151 // Specifies the type of UI (if any) to show during installation and what | 157 // Specifies the type of UI (if any) to show during installation and what |
152 // user action to simulate. | 158 // user action to simulate. |
153 enum InstallUIType { | 159 enum InstallUIType { |
154 INSTALL_UI_TYPE_NONE, | 160 INSTALL_UI_TYPE_NONE, |
155 INSTALL_UI_TYPE_CANCEL, | 161 INSTALL_UI_TYPE_CANCEL, |
156 INSTALL_UI_TYPE_NORMAL, | 162 INSTALL_UI_TYPE_NORMAL, |
157 INSTALL_UI_TYPE_AUTO_CONFIRM, | 163 INSTALL_UI_TYPE_AUTO_CONFIRM, |
158 }; | 164 }; |
159 | 165 |
160 const Extension* InstallOrUpdateExtension(const std::string& id, | 166 const extensions::Extension* InstallOrUpdateExtension(const std::string& id, |
161 const FilePath& path, | 167 const FilePath& path, |
162 InstallUIType ui_type, | 168 InstallUIType ui_type, |
163 int expected_change); | 169 int expected_change); |
164 const Extension* InstallOrUpdateExtension(const std::string& id, | 170 const extensions::Extension* InstallOrUpdateExtension(const std::string& id, |
165 const FilePath& path, | 171 const FilePath& path, |
166 InstallUIType ui_type, | 172 InstallUIType ui_type, |
167 int expected_change, | 173 int expected_change, |
168 Profile* profile, | 174 Profile* profile, |
169 bool from_webstore); | 175 bool from_webstore); |
170 | 176 |
171 bool WaitForExtensionViewsToLoad(); | 177 bool WaitForExtensionViewsToLoad(); |
172 | 178 |
173 // When waiting for page action count to change, we wait until it reaches this | 179 // When waiting for page action count to change, we wait until it reaches this |
174 // value. | 180 // value. |
175 int target_page_action_count_; | 181 int target_page_action_count_; |
176 | 182 |
177 // When waiting for visible page action count to change, we wait until it | 183 // When waiting for visible page action count to change, we wait until it |
178 // reaches this value. | 184 // reaches this value. |
179 int target_visible_page_action_count_; | 185 int target_visible_page_action_count_; |
180 }; | 186 }; |
181 | 187 |
182 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_ | 188 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_ |
OLD | NEW |