Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: chrome/browser/extensions/extension_startup_browsertest.cc

Issue 8898025: Extend --load-extension commandline to accept multiple (comma-separated) extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a test Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/string_util.h"
11 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/user_script_master.h" 13 #include "chrome/browser/extensions/user_script_master.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
18 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
19 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
(...skipping 19 matching lines...) Expand all
40 FilePath profile_dir; 41 FilePath profile_dir;
41 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); 42 PathService::Get(chrome::DIR_USER_DATA, &profile_dir);
42 profile_dir = profile_dir.AppendASCII("Default"); 43 profile_dir = profile_dir.AppendASCII("Default");
43 file_util::CreateDirectory(profile_dir); 44 file_util::CreateDirectory(profile_dir);
44 45
45 preferences_file_ = profile_dir.AppendASCII("Preferences"); 46 preferences_file_ = profile_dir.AppendASCII("Preferences");
46 user_scripts_dir_ = profile_dir.AppendASCII("User Scripts"); 47 user_scripts_dir_ = profile_dir.AppendASCII("User Scripts");
47 extensions_dir_ = profile_dir.AppendASCII("Extensions"); 48 extensions_dir_ = profile_dir.AppendASCII("Extensions");
48 49
49 if (enable_extensions_) { 50 if (enable_extensions_) {
50 if (load_extension_.empty()) { 51 if (load_extensions_.empty()) {
51 FilePath src_dir; 52 FilePath src_dir;
52 PathService::Get(chrome::DIR_TEST_DATA, &src_dir); 53 PathService::Get(chrome::DIR_TEST_DATA, &src_dir);
53 src_dir = src_dir.AppendASCII("extensions").AppendASCII("good"); 54 src_dir = src_dir.AppendASCII("extensions").AppendASCII("good");
54 55
55 file_util::CopyFile(src_dir.AppendASCII("Preferences"), 56 file_util::CopyFile(src_dir.AppendASCII("Preferences"),
56 preferences_file_); 57 preferences_file_);
57 file_util::CopyDirectory(src_dir.AppendASCII("Extensions"), 58 file_util::CopyDirectory(src_dir.AppendASCII("Extensions"),
58 profile_dir, true); // recursive 59 profile_dir, true); // recursive
59 } 60 }
60 } else { 61 } else {
61 command_line->AppendSwitch(switches::kDisableExtensions); 62 command_line->AppendSwitch(switches::kDisableExtensions);
62 } 63 }
63 64
64 if (!load_extension_.empty()) { 65 if (!load_extensions_.empty()) {
65 command_line->AppendSwitchPath(switches::kLoadExtension, load_extension_); 66 FilePath::StringType paths = JoinString(load_extensions_, ',');
67 command_line->AppendSwitchNative(switches::kLoadExtension,
68 paths);
66 command_line->AppendSwitch(switches::kDisableExtensionsFileAccessCheck); 69 command_line->AppendSwitch(switches::kDisableExtensionsFileAccessCheck);
67 } 70 }
68 } 71 }
69 72
70 virtual void TearDown() { 73 virtual void TearDown() {
71 EXPECT_TRUE(file_util::Delete(preferences_file_, false)); 74 EXPECT_TRUE(file_util::Delete(preferences_file_, false));
72 75
73 // TODO(phajdan.jr): Check return values of the functions below, carefully. 76 // TODO(phajdan.jr): Check return values of the functions below, carefully.
74 file_util::Delete(user_scripts_dir_, true); 77 file_util::Delete(user_scripts_dir_, true);
75 file_util::Delete(extensions_dir_, true); 78 file_util::Delete(extensions_dir_, true);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 browser()->GetSelectedTabContents()->render_view_host(), L"", 127 browser()->GetSelectedTabContents()->render_view_host(), L"",
125 L"window.domAutomationController.send(document.title == 'Modified')", 128 L"window.domAutomationController.send(document.title == 'Modified')",
126 &result)); 129 &result));
127 EXPECT_EQ(expect_script, result); 130 EXPECT_EQ(expect_script, result);
128 } 131 }
129 132
130 FilePath preferences_file_; 133 FilePath preferences_file_;
131 FilePath extensions_dir_; 134 FilePath extensions_dir_;
132 FilePath user_scripts_dir_; 135 FilePath user_scripts_dir_;
133 bool enable_extensions_; 136 bool enable_extensions_;
134 FilePath load_extension_; 137 // Extensions to load from the command line.
138 std::vector<FilePath::StringType> load_extensions_;
135 139
136 int num_expected_extensions_; 140 int num_expected_extensions_;
137 }; 141 };
138 142
139 143
140 // ExtensionsStartupTest 144 // ExtensionsStartupTest
141 // Ensures that we can startup the browser with --enable-extensions and some 145 // Ensures that we can startup the browser with --enable-extensions and some
142 // extensions installed and see them run and do basic things. 146 // extensions installed and see them run and do basic things.
143 147
144 class ExtensionsStartupTest : public ExtensionStartupTestBase { 148 class ExtensionsStartupTest : public ExtensionStartupTestBase {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 193 }
190 194
191 // ExtensionsLoadTest 195 // ExtensionsLoadTest
192 // Ensures that we can startup the browser with --load-extension and see them 196 // Ensures that we can startup the browser with --load-extension and see them
193 // run. 197 // run.
194 198
195 class ExtensionsLoadTest : public ExtensionStartupTestBase { 199 class ExtensionsLoadTest : public ExtensionStartupTestBase {
196 public: 200 public:
197 ExtensionsLoadTest() { 201 ExtensionsLoadTest() {
198 enable_extensions_ = true; 202 enable_extensions_ = true;
199 PathService::Get(chrome::DIR_TEST_DATA, &load_extension_); 203 FilePath one_extension_path;
200 load_extension_ = load_extension_ 204 PathService::Get(chrome::DIR_TEST_DATA, &one_extension_path);
205 one_extension_path = one_extension_path
201 .AppendASCII("extensions") 206 .AppendASCII("extensions")
202 .AppendASCII("good") 207 .AppendASCII("good")
203 .AppendASCII("Extensions") 208 .AppendASCII("Extensions")
204 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 209 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
205 .AppendASCII("1.0.0.0"); 210 .AppendASCII("1.0.0.0");
211 load_extensions_.push_back(one_extension_path.value());
206 } 212 }
207 }; 213 };
208 214
209 // Fails inconsistently on Linux x64. http://crbug.com/80961 215 // Fails inconsistently on Linux x64. http://crbug.com/80961
210 #if defined(OS_LINUX) && defined(ARCH_CPU_64_BITS) 216 #if defined(OS_LINUX) && defined(ARCH_CPU_64_BITS)
211 #define Maybe_Test FLAKY_Test 217 #define Maybe_Test FLAKY_Test
212 #else 218 #else
213 #define Maybe_Test Test 219 #define Maybe_Test Test
214 #endif 220 #endif
215 221
216 IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Maybe_Test) { 222 IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Maybe_Test) {
217 WaitForServicesToStart(1, true); 223 WaitForServicesToStart(1, true);
218 TestInjection(true, true); 224 TestInjection(true, true);
219 } 225 }
226
227 // ExtensionsLoadMultipleTest
228 // Ensures that we can startup the browser with multiple extensions
229 // via --load-extension=X1,X2
230
asargent_no_longer_on_chrome 2011/12/14 17:52:53 nit: remove space here
231 class ExtensionsLoadMultipleTest : public ExtensionStartupTestBase {
232 public:
233 ExtensionsLoadMultipleTest() {
234 enable_extensions_ = true;
235 FilePath one_extension_path;
236 PathService::Get(chrome::DIR_TEST_DATA, &one_extension_path);
237 one_extension_path = one_extension_path
238 .AppendASCII("extensions")
239 .AppendASCII("good")
240 .AppendASCII("Extensions")
241 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
242 .AppendASCII("1.0.0.0");
243 load_extensions_.push_back(one_extension_path.value());
244
245 FilePath second_extension_path;
246 PathService::Get(chrome::DIR_TEST_DATA, &second_extension_path);
247 second_extension_path = second_extension_path
248 .AppendASCII("extensions")
249 .AppendASCII("app");
250 load_extensions_.push_back(second_extension_path.value());
251
252 FilePath third_extension_path;
253 PathService::Get(chrome::DIR_TEST_DATA, &third_extension_path);
254 third_extension_path = third_extension_path
255 .AppendASCII("extensions")
256 .AppendASCII("app1");
257 load_extensions_.push_back(third_extension_path.value());
258
259 FilePath fourth_extension_path;
260 PathService::Get(chrome::DIR_TEST_DATA, &fourth_extension_path);
261 fourth_extension_path = fourth_extension_path
262 .AppendASCII("extensions")
263 .AppendASCII("app2");
264 load_extensions_.push_back(fourth_extension_path.value());
265 }
266 };
267
268 IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) {
269 WaitForServicesToStart(4, true);
270 TestInjection(true, true);
271 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698