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

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

Issue 1148323007: [Extensions] Introduce a ScopedExtensionDialogAutoConfirm (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 5 years, 6 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
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 "base/scoped_observer.h" 6 #include "base/scoped_observer.h"
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/extension_install_prompt.h"
9 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/startup_helper.h" 9 #include "chrome/browser/extensions/startup_helper.h"
11 #include "chrome/browser/extensions/webstore_installer_test.h" 10 #include "chrome/browser/extensions/webstore_installer_test.h"
12 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/test_switches.h" 17 #include "chrome/test/base/test_switches.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 WebstoreStartupInstallerTest() 49 WebstoreStartupInstallerTest()
51 : WebstoreInstallerTest( 50 : WebstoreInstallerTest(
52 kWebstoreDomain, 51 kWebstoreDomain,
53 kTestDataPath, 52 kTestDataPath,
54 kCrxFilename, 53 kCrxFilename,
55 kAppDomain, 54 kAppDomain,
56 kNonAppDomain) {} 55 kNonAppDomain) {}
57 }; 56 };
58 57
59 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, Install) { 58 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, Install) {
60 ExtensionInstallPrompt::g_auto_confirm_for_tests = 59 AutoAcceptInstall();
61 ExtensionInstallPrompt::ACCEPT;
62 60
63 ui_test_utils::NavigateToURL( 61 ui_test_utils::NavigateToURL(
64 browser(), GenerateTestServerUrl(kAppDomain, "install.html")); 62 browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
65 63
66 RunTest("runTest"); 64 RunTest("runTest");
67 65
68 extensions::ExtensionRegistry* registry = 66 extensions::ExtensionRegistry* registry =
69 extensions::ExtensionRegistry::Get(browser()->profile()); 67 extensions::ExtensionRegistry::Get(browser()->profile());
70 const extensions::Extension* extension = 68 const extensions::Extension* extension =
71 registry->enabled_extensions().GetByID(kTestExtensionId); 69 registry->enabled_extensions().GetByID(kTestExtensionId);
72 EXPECT_TRUE(extension); 70 EXPECT_TRUE(extension);
73 } 71 }
74 72
75 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, 73 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest,
76 InstallNotAllowedFromNonVerifiedDomains) { 74 InstallNotAllowedFromNonVerifiedDomains) {
77 ExtensionInstallPrompt::g_auto_confirm_for_tests = 75 AutoCancelInstall();
78 ExtensionInstallPrompt::CANCEL;
79 ui_test_utils::NavigateToURL( 76 ui_test_utils::NavigateToURL(
80 browser(), 77 browser(),
81 GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html")); 78 GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html"));
82 79
83 RunTest("runTest1"); 80 RunTest("runTest1");
84 RunTest("runTest2"); 81 RunTest("runTest2");
85 } 82 }
86 83
87 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, FindLink) { 84 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, FindLink) {
88 ui_test_utils::NavigateToURL( 85 ui_test_utils::NavigateToURL(
89 browser(), GenerateTestServerUrl(kAppDomain, "find_link.html")); 86 browser(), GenerateTestServerUrl(kAppDomain, "find_link.html"));
90 87
91 RunTest("runTest"); 88 RunTest("runTest");
92 } 89 }
93 90
94 // 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
95 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, 92 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest,
96 DISABLED_ArgumentValidation) { 93 DISABLED_ArgumentValidation) {
97 ExtensionInstallPrompt::g_auto_confirm_for_tests = 94 AutoCancelInstall();
98 ExtensionInstallPrompt::CANCEL;
99 95
100 // Each of these tests has to run separately, since one page/tab can 96 // Each of these tests has to run separately, since one page/tab can
101 // only have one in-progress install request. These tests don't all pass 97 // only have one in-progress install request. These tests don't all pass
102 // callbacks to install, so they have no way to wait for the installation 98 // callbacks to install, so they have no way to wait for the installation
103 // to complete before starting the next test. 99 // to complete before starting the next test.
104 bool is_finished = false; 100 bool is_finished = false;
105 for (int i = 0; !is_finished; ++i) { 101 for (int i = 0; !is_finished; ++i) {
106 ui_test_utils::NavigateToURL( 102 ui_test_utils::NavigateToURL(
107 browser(), 103 browser(),
108 GenerateTestServerUrl(kAppDomain, "argument_validation.html")); 104 GenerateTestServerUrl(kAppDomain, "argument_validation.html"));
109 is_finished = !RunIndexedTest("runTest", i); 105 is_finished = !RunIndexedTest("runTest", i);
110 } 106 }
111 } 107 }
112 108
113 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, MultipleInstallCalls) { 109 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, MultipleInstallCalls) {
114 ExtensionInstallPrompt::g_auto_confirm_for_tests = 110 AutoCancelInstall();
115 ExtensionInstallPrompt::CANCEL;
116 111
117 ui_test_utils::NavigateToURL( 112 ui_test_utils::NavigateToURL(
118 browser(), 113 browser(),
119 GenerateTestServerUrl(kAppDomain, "multiple_install_calls.html")); 114 GenerateTestServerUrl(kAppDomain, "multiple_install_calls.html"));
120 RunTest("runTest"); 115 RunTest("runTest");
121 } 116 }
122 117
123 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallNotSupported) { 118 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallNotSupported) {
124 ExtensionInstallPrompt::g_auto_confirm_for_tests = 119 AutoCancelInstall();
125 ExtensionInstallPrompt::CANCEL;
126 ui_test_utils::NavigateToURL( 120 ui_test_utils::NavigateToURL(
127 browser(), 121 browser(),
128 GenerateTestServerUrl(kAppDomain, "install_not_supported.html")); 122 GenerateTestServerUrl(kAppDomain, "install_not_supported.html"));
129 123
130 ui_test_utils::WindowedTabAddedNotificationObserver observer( 124 ui_test_utils::WindowedTabAddedNotificationObserver observer(
131 content::NotificationService::AllSources()); 125 content::NotificationService::AllSources());
132 RunTest("runTest"); 126 RunTest("runTest");
133 observer.Wait(); 127 observer.Wait();
134 128
135 // The inline install should fail, and a store-provided URL should be opened 129 // The inline install should fail, and a store-provided URL should be opened
136 // in a new tab. 130 // in a new tab.
137 WebContents* web_contents = 131 WebContents* web_contents =
138 browser()->tab_strip_model()->GetActiveWebContents(); 132 browser()->tab_strip_model()->GetActiveWebContents();
139 EXPECT_EQ(GURL("http://cws.com/show-me-the-money"), web_contents->GetURL()); 133 EXPECT_EQ(GURL("http://cws.com/show-me-the-money"), web_contents->GetURL());
140 } 134 }
141 135
142 // Regression test for http://crbug.com/144991. 136 // Regression test for http://crbug.com/144991.
143 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallFromHostedApp) { 137 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallFromHostedApp) {
144 ExtensionInstallPrompt::g_auto_confirm_for_tests = 138 AutoAcceptInstall();
145 ExtensionInstallPrompt::ACCEPT;
146 139
147 const GURL kInstallUrl = GenerateTestServerUrl(kAppDomain, "install.html"); 140 const GURL kInstallUrl = GenerateTestServerUrl(kAppDomain, "install.html");
148 141
149 // We're forced to construct a hosted app dynamically because we need the 142 // We're forced to construct a hosted app dynamically because we need the
150 // app to run on a declared URL, but we don't know the port ahead of time. 143 // app to run on a declared URL, but we don't know the port ahead of time.
151 scoped_refptr<const Extension> hosted_app = ExtensionBuilder() 144 scoped_refptr<const Extension> hosted_app = ExtensionBuilder()
152 .SetManifest(DictionaryBuilder() 145 .SetManifest(DictionaryBuilder()
153 .Set("name", "hosted app") 146 .Set("name", "hosted app")
154 .Set("version", "1") 147 .Set("version", "1")
155 .Set("app", DictionaryBuilder() 148 .Set("app", DictionaryBuilder()
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 181
189 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerSupervisedUsersTest, 182 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerSupervisedUsersTest,
190 InstallProhibited) { 183 InstallProhibited) {
191 #if defined(OS_WIN) && defined(USE_ASH) 184 #if defined(OS_WIN) && defined(USE_ASH)
192 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 185 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
193 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 186 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
194 switches::kAshBrowserTests)) 187 switches::kAshBrowserTests))
195 return; 188 return;
196 #endif 189 #endif
197 190
198 ExtensionInstallPrompt::g_auto_confirm_for_tests = 191 AutoAcceptInstall();
199 ExtensionInstallPrompt::ACCEPT;
200 192
201 ui_test_utils::NavigateToURL( 193 ui_test_utils::NavigateToURL(
202 browser(), GenerateTestServerUrl(kAppDomain, "install_prohibited.html")); 194 browser(), GenerateTestServerUrl(kAppDomain, "install_prohibited.html"));
203 195
204 RunTest("runTest"); 196 RunTest("runTest");
205 197
206 // No error infobar should show up. 198 // No error infobar should show up.
207 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 199 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
208 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); 200 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
209 EXPECT_EQ(0u, infobar_service->infobar_count()); 201 EXPECT_EQ(0u, infobar_service->infobar_count());
(...skipping 14 matching lines...) Expand all
224 } 216 }
225 217
226 void SetUpInProcessBrowserTestFixture() override { 218 void SetUpInProcessBrowserTestFixture() override {
227 WebstoreStartupInstallerTest::SetUpInProcessBrowserTestFixture(); 219 WebstoreStartupInstallerTest::SetUpInProcessBrowserTestFixture();
228 extensions::ExtensionInstallUI::set_disable_failure_ui_for_tests(); 220 extensions::ExtensionInstallUI::set_disable_failure_ui_for_tests();
229 } 221 }
230 }; 222 };
231 223
232 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallUnpackFailureTest, 224 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallUnpackFailureTest,
233 WebstoreStartupInstallUnpackFailureTest) { 225 WebstoreStartupInstallUnpackFailureTest) {
234 ExtensionInstallPrompt::g_auto_confirm_for_tests = 226 AutoAcceptInstall();
235 ExtensionInstallPrompt::ACCEPT;
236 227
237 ui_test_utils::NavigateToURL(browser(), 228 ui_test_utils::NavigateToURL(browser(),
238 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); 229 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html"));
239 230
240 RunTest("runTest"); 231 RunTest("runTest");
241 } 232 }
242 233
243 class CommandLineWebstoreInstall 234 class CommandLineWebstoreInstall
244 : public WebstoreStartupInstallerTest, 235 : public WebstoreStartupInstallerTest,
245 public content::NotificationObserver, 236 public content::NotificationObserver,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 bool saw_install_; 279 bool saw_install_;
289 280
290 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? 281 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen?
291 int browser_open_count_; 282 int browser_open_count_;
292 }; 283 };
293 284
294 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, CannotInstallNonEphemeral) { 285 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, CannotInstallNonEphemeral) {
295 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 286 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
296 command_line->AppendSwitchASCII( 287 command_line->AppendSwitchASCII(
297 switches::kInstallEphemeralAppFromWebstore, kTestExtensionId); 288 switches::kInstallEphemeralAppFromWebstore, kTestExtensionId);
298 ExtensionInstallPrompt::g_auto_confirm_for_tests = 289 AutoAcceptInstall();
299 ExtensionInstallPrompt::ACCEPT;
300 extensions::StartupHelper helper; 290 extensions::StartupHelper helper;
301 EXPECT_FALSE(helper.InstallEphemeralApp(*command_line, browser()->profile())); 291 EXPECT_FALSE(helper.InstallEphemeralApp(*command_line, browser()->profile()));
302 EXPECT_FALSE(saw_install()); 292 EXPECT_FALSE(saw_install());
303 EXPECT_EQ(0, browser_open_count()); 293 EXPECT_EQ(0, browser_open_count());
304 } 294 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/webstore_installer_test.cc ('k') | chrome/browser/infobars/infobars_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698