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

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

Issue 196413016: Move CommandLine to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months 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
OLDNEW
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 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/chrome_notification_types.h" 6 #include "chrome/browser/chrome_notification_types.h"
7 #include "chrome/browser/extensions/extension_host.h" 7 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/extensions/extension_install_ui.h" 8 #include "chrome/browser/extensions/extension_install_ui.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/startup_helper.h" 10 #include "chrome/browser/extensions/startup_helper.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 WebstoreStartupInstallerTest() 49 WebstoreStartupInstallerTest()
50 : WebstoreInstallerTest( 50 : WebstoreInstallerTest(
51 kWebstoreDomain, 51 kWebstoreDomain,
52 kTestDataPath, 52 kTestDataPath,
53 kCrxFilename, 53 kCrxFilename,
54 kAppDomain, 54 kAppDomain,
55 kNonAppDomain) {} 55 kNonAppDomain) {}
56 }; 56 };
57 57
58 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, Install) { 58 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, Install) {
59 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 59 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
60 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); 60 switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
61 61
62 ui_test_utils::NavigateToURL( 62 ui_test_utils::NavigateToURL(
63 browser(), GenerateTestServerUrl(kAppDomain, "install.html")); 63 browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
64 64
65 RunTest("runTest"); 65 RunTest("runTest");
66 66
67 const extensions::Extension* extension = browser()->profile()-> 67 const extensions::Extension* extension = browser()->profile()->
68 GetExtensionService()->GetExtensionById(kTestExtensionId, false); 68 GetExtensionService()->GetExtensionById(kTestExtensionId, false);
69 EXPECT_TRUE(extension); 69 EXPECT_TRUE(extension);
70 } 70 }
71 71
72 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, 72 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest,
73 InstallNotAllowedFromNonVerifiedDomains) { 73 InstallNotAllowedFromNonVerifiedDomains) {
74 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 74 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
75 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); 75 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
76 ui_test_utils::NavigateToURL( 76 ui_test_utils::NavigateToURL(
77 browser(), 77 browser(),
78 GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html")); 78 GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html"));
79 79
80 RunTest("runTest1"); 80 RunTest("runTest1");
81 RunTest("runTest2"); 81 RunTest("runTest2");
82 } 82 }
83 83
84 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, FindLink) { 84 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, FindLink) {
85 ui_test_utils::NavigateToURL( 85 ui_test_utils::NavigateToURL(
86 browser(), GenerateTestServerUrl(kAppDomain, "find_link.html")); 86 browser(), GenerateTestServerUrl(kAppDomain, "find_link.html"));
87 87
88 RunTest("runTest"); 88 RunTest("runTest");
89 } 89 }
90 90
91 // Flakes on all platforms: http://crbug.com/95713, http://crbug.com/229947 91 // Flakes on all platforms: http://crbug.com/95713, http://crbug.com/229947
92 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, 92 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest,
93 DISABLED_ArgumentValidation) { 93 DISABLED_ArgumentValidation) {
94 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 94 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
95 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); 95 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
96 96
97 // Each of these tests has to run separately, since one page/tab can 97 // Each of these tests has to run separately, since one page/tab can
98 // only have one in-progress install request. These tests don't all pass 98 // only have one in-progress install request. These tests don't all pass
99 // callbacks to install, so they have no way to wait for the installation 99 // callbacks to install, so they have no way to wait for the installation
100 // to complete before starting the next test. 100 // to complete before starting the next test.
101 bool is_finished = false; 101 bool is_finished = false;
102 for (int i = 0; !is_finished; ++i) { 102 for (int i = 0; !is_finished; ++i) {
103 ui_test_utils::NavigateToURL( 103 ui_test_utils::NavigateToURL(
104 browser(), 104 browser(),
105 GenerateTestServerUrl(kAppDomain, "argument_validation.html")); 105 GenerateTestServerUrl(kAppDomain, "argument_validation.html"));
106 is_finished = !RunIndexedTest("runTest", i); 106 is_finished = !RunIndexedTest("runTest", i);
107 } 107 }
108 } 108 }
109 109
110 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, MultipleInstallCalls) { 110 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, MultipleInstallCalls) {
111 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 111 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
112 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); 112 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
113 113
114 ui_test_utils::NavigateToURL( 114 ui_test_utils::NavigateToURL(
115 browser(), 115 browser(),
116 GenerateTestServerUrl(kAppDomain, "multiple_install_calls.html")); 116 GenerateTestServerUrl(kAppDomain, "multiple_install_calls.html"));
117 RunTest("runTest"); 117 RunTest("runTest");
118 } 118 }
119 119
120 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallNotSupported) { 120 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallNotSupported) {
121 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 121 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
122 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); 122 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
123 ui_test_utils::NavigateToURL( 123 ui_test_utils::NavigateToURL(
124 browser(), 124 browser(),
125 GenerateTestServerUrl(kAppDomain, "install_not_supported.html")); 125 GenerateTestServerUrl(kAppDomain, "install_not_supported.html"));
126 126
127 ui_test_utils::WindowedTabAddedNotificationObserver observer( 127 ui_test_utils::WindowedTabAddedNotificationObserver observer(
128 content::NotificationService::AllSources()); 128 content::NotificationService::AllSources());
129 RunTest("runTest"); 129 RunTest("runTest");
130 observer.Wait(); 130 observer.Wait();
131 131
132 // The inline install should fail, and a store-provided URL should be opened 132 // The inline install should fail, and a store-provided URL should be opened
133 // in a new tab. 133 // in a new tab.
134 WebContents* web_contents = 134 WebContents* web_contents =
135 browser()->tab_strip_model()->GetActiveWebContents(); 135 browser()->tab_strip_model()->GetActiveWebContents();
136 EXPECT_EQ(GURL("http://cws.com/show-me-the-money"), web_contents->GetURL()); 136 EXPECT_EQ(GURL("http://cws.com/show-me-the-money"), web_contents->GetURL());
137 } 137 }
138 138
139 // Regression test for http://crbug.com/144991. 139 // Regression test for http://crbug.com/144991.
140 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallFromHostedApp) { 140 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallFromHostedApp) {
141 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 141 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
142 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); 142 switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
143 143
144 const GURL kInstallUrl = GenerateTestServerUrl(kAppDomain, "install.html"); 144 const GURL kInstallUrl = GenerateTestServerUrl(kAppDomain, "install.html");
145 145
146 // We're forced to construct a hosted app dynamically because we need the 146 // We're forced to construct a hosted app dynamically because we need the
147 // app to run on a declared URL, but we don't know the port ahead of time. 147 // app to run on a declared URL, but we don't know the port ahead of time.
148 scoped_refptr<const Extension> hosted_app = ExtensionBuilder() 148 scoped_refptr<const Extension> hosted_app = ExtensionBuilder()
149 .SetManifest(DictionaryBuilder() 149 .SetManifest(DictionaryBuilder()
150 .Set("name", "hosted app") 150 .Set("name", "hosted app")
151 .Set("version", "1") 151 .Set("version", "1")
(...skipping 16 matching lines...) Expand all
168 168
169 EXPECT_FALSE(extension_service->extensions()->Contains(kTestExtensionId)); 169 EXPECT_FALSE(extension_service->extensions()->Contains(kTestExtensionId));
170 RunTest("runTest"); 170 RunTest("runTest");
171 EXPECT_TRUE(extension_service->extensions()->Contains(kTestExtensionId)); 171 EXPECT_TRUE(extension_service->extensions()->Contains(kTestExtensionId));
172 } 172 }
173 173
174 class WebstoreStartupInstallerManagedUsersTest 174 class WebstoreStartupInstallerManagedUsersTest
175 : public WebstoreStartupInstallerTest { 175 : public WebstoreStartupInstallerTest {
176 public: 176 public:
177 // InProcessBrowserTest overrides: 177 // InProcessBrowserTest overrides:
178 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 178 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE {
179 WebstoreStartupInstallerTest::SetUpCommandLine(command_line); 179 WebstoreStartupInstallerTest::SetUpCommandLine(command_line);
180 command_line->AppendSwitchASCII(switches::kManagedUserId, "asdf"); 180 command_line->AppendSwitchASCII(switches::kManagedUserId, "asdf");
181 } 181 }
182 }; 182 };
183 183
184 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerManagedUsersTest, 184 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerManagedUsersTest,
185 InstallProhibited) { 185 InstallProhibited) {
186 #if defined(OS_WIN) && defined(USE_ASH) 186 #if defined(OS_WIN) && defined(USE_ASH)
187 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 187 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
188 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 188 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
189 switches::kAshBrowserTests))
189 return; 190 return;
190 #endif 191 #endif
191 192
192 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 193 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
193 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); 194 switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
194 195
195 ui_test_utils::NavigateToURL( 196 ui_test_utils::NavigateToURL(
196 browser(), GenerateTestServerUrl(kAppDomain, "install_prohibited.html")); 197 browser(), GenerateTestServerUrl(kAppDomain, "install_prohibited.html"));
197 198
198 RunTest("runTest"); 199 RunTest("runTest");
199 200
200 // No error infobar should show up. 201 // No error infobar should show up.
201 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 202 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
202 InfoBarService* info_bar_service = InfoBarService::FromWebContents(contents); 203 InfoBarService* info_bar_service = InfoBarService::FromWebContents(contents);
203 EXPECT_EQ(info_bar_service->infobar_count(), 0u); 204 EXPECT_EQ(info_bar_service->infobar_count(), 0u);
204 } 205 }
205 206
206 // The unpack failure test needs to use a different install .crx, which is 207 // The unpack failure test needs to use a different install .crx, which is
207 // specified via a command-line flag, so it needs its own test subclass. 208 // specified via a command-line flag, so it needs its own test subclass.
208 class WebstoreStartupInstallUnpackFailureTest 209 class WebstoreStartupInstallUnpackFailureTest
209 : public WebstoreStartupInstallerTest { 210 : public WebstoreStartupInstallerTest {
210 public: 211 public:
211 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 212 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE {
212 WebstoreStartupInstallerTest::SetUpCommandLine(command_line); 213 WebstoreStartupInstallerTest::SetUpCommandLine(command_line);
213 214
214 GURL crx_url = GenerateTestServerUrl( 215 GURL crx_url = GenerateTestServerUrl(
215 kWebstoreDomain, "malformed_extension.crx"); 216 kWebstoreDomain, "malformed_extension.crx");
216 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 217 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
217 switches::kAppsGalleryUpdateURL, crx_url.spec()); 218 switches::kAppsGalleryUpdateURL, crx_url.spec());
218 } 219 }
219 220
220 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 221 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
221 WebstoreStartupInstallerTest::SetUpInProcessBrowserTestFixture(); 222 WebstoreStartupInstallerTest::SetUpInProcessBrowserTestFixture();
222 ExtensionInstallUI::set_disable_failure_ui_for_tests(); 223 ExtensionInstallUI::set_disable_failure_ui_for_tests();
223 } 224 }
224 }; 225 };
225 226
226 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallUnpackFailureTest, 227 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallUnpackFailureTest,
227 WebstoreStartupInstallUnpackFailureTest) { 228 WebstoreStartupInstallUnpackFailureTest) {
228 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 229 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
229 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); 230 switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
230 231
231 ui_test_utils::NavigateToURL(browser(), 232 ui_test_utils::NavigateToURL(browser(),
232 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); 233 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html"));
233 234
234 RunTest("runTest"); 235 RunTest("runTest");
235 } 236 }
236 237
237 class CommandLineWebstoreInstall : public WebstoreStartupInstallerTest, 238 class CommandLineWebstoreInstall : public WebstoreStartupInstallerTest,
238 public content::NotificationObserver { 239 public content::NotificationObserver {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 content::NotificationRegistrar registrar_; 274 content::NotificationRegistrar registrar_;
274 275
275 // Have we seen an installation notification for kTestExtensionId ? 276 // Have we seen an installation notification for kTestExtensionId ?
276 bool saw_install_; 277 bool saw_install_;
277 278
278 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? 279 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen?
279 int browser_open_count_; 280 int browser_open_count_;
280 }; 281 };
281 282
282 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Accept) { 283 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Accept) {
283 CommandLine* command_line = CommandLine::ForCurrentProcess(); 284 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
284 command_line->AppendSwitchASCII( 285 command_line->AppendSwitchASCII(
285 switches::kInstallFromWebstore, kTestExtensionId); 286 switches::kInstallFromWebstore, kTestExtensionId);
286 command_line->AppendSwitchASCII( 287 command_line->AppendSwitchASCII(
287 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); 288 switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
288 extensions::StartupHelper helper; 289 extensions::StartupHelper helper;
289 EXPECT_TRUE(helper.InstallFromWebstore(*command_line, browser()->profile())); 290 EXPECT_TRUE(helper.InstallFromWebstore(*command_line, browser()->profile()));
290 EXPECT_TRUE(saw_install()); 291 EXPECT_TRUE(saw_install());
291 EXPECT_EQ(0, browser_open_count()); 292 EXPECT_EQ(0, browser_open_count());
292 } 293 }
293 294
294 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Cancel) { 295 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Cancel) {
295 CommandLine* command_line = CommandLine::ForCurrentProcess(); 296 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
296 command_line->AppendSwitchASCII( 297 command_line->AppendSwitchASCII(
297 switches::kInstallFromWebstore, kTestExtensionId); 298 switches::kInstallFromWebstore, kTestExtensionId);
298 command_line->AppendSwitchASCII( 299 command_line->AppendSwitchASCII(
299 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); 300 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
300 extensions::StartupHelper helper; 301 extensions::StartupHelper helper;
301 EXPECT_FALSE(helper.InstallFromWebstore(*command_line, browser()->profile())); 302 EXPECT_FALSE(helper.InstallFromWebstore(*command_line, browser()->profile()));
302 EXPECT_FALSE(saw_install()); 303 EXPECT_FALSE(saw_install());
303 EXPECT_EQ(0, browser_open_count()); 304 EXPECT_EQ(0, browser_open_count());
304 } 305 }
305 306
306 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, LimitedAccept) { 307 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, LimitedAccept) {
307 extensions::StartupHelper helper; 308 extensions::StartupHelper helper;
308 309
309 // Small test of "WebStoreIdFromLimitedInstallCmdLine" which made more 310 // Small test of "WebStoreIdFromLimitedInstallCmdLine" which made more
310 // sense together with the rest of the test for "LimitedInstallFromWebstore". 311 // sense together with the rest of the test for "LimitedInstallFromWebstore".
311 CommandLine command_line_test1(CommandLine::NO_PROGRAM); 312 base::CommandLine command_line_test1(base::CommandLine::NO_PROGRAM);
312 command_line_test1.AppendSwitchASCII(switches::kLimitedInstallFromWebstore, 313 command_line_test1.AppendSwitchASCII(switches::kLimitedInstallFromWebstore,
313 "1"); 314 "1");
314 EXPECT_EQ("nckgahadagoaajjgafhacjanaoiihapd", 315 EXPECT_EQ("nckgahadagoaajjgafhacjanaoiihapd",
315 helper.WebStoreIdFromLimitedInstallCmdLine(command_line_test1)); 316 helper.WebStoreIdFromLimitedInstallCmdLine(command_line_test1));
316 317
317 CommandLine command_line_test2(CommandLine::NO_PROGRAM); 318 base::CommandLine command_line_test2(base::CommandLine::NO_PROGRAM);
318 command_line_test1.AppendSwitchASCII(switches::kLimitedInstallFromWebstore, 319 command_line_test1.AppendSwitchASCII(switches::kLimitedInstallFromWebstore,
319 "2"); 320 "2");
320 EXPECT_EQ(kTestExtensionId, 321 EXPECT_EQ(kTestExtensionId,
321 helper.WebStoreIdFromLimitedInstallCmdLine(command_line_test1)); 322 helper.WebStoreIdFromLimitedInstallCmdLine(command_line_test1));
322 323
323 // Now, on to the real test for LimitedInstallFromWebstore. 324 // Now, on to the real test for LimitedInstallFromWebstore.
324 CommandLine* command_line = CommandLine::ForCurrentProcess(); 325 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
325 command_line->AppendSwitchASCII( 326 command_line->AppendSwitchASCII(
326 switches::kLimitedInstallFromWebstore, "2"); 327 switches::kLimitedInstallFromWebstore, "2");
327 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(), 328 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(),
328 base::MessageLoop::QuitWhenIdleClosure()); 329 base::MessageLoop::QuitWhenIdleClosure());
329 base::MessageLoop::current()->Run(); 330 base::MessageLoop::current()->Run();
330 331
331 EXPECT_TRUE(saw_install()); 332 EXPECT_TRUE(saw_install());
332 EXPECT_EQ(0, browser_open_count()); 333 EXPECT_EQ(0, browser_open_count());
333 } 334 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/webstore_installer_test.h ('k') | chrome/browser/first_run/first_run.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698