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

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

Issue 10907104: Support an --install-from-webstore command line switch (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebased Created 8 years, 3 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 "base/stringprintf.h" 6 #include "base/stringprintf.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/extensions/extension_install_dialog.h" 9 #include "chrome/browser/extensions/extension_install_dialog.h"
10 #include "chrome/browser/extensions/extension_install_ui.h" 10 #include "chrome/browser/extensions/extension_install_ui.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/startup_helper.h"
12 #include "chrome/browser/extensions/webstore_inline_installer.h" 13 #include "chrome/browser/extensions/webstore_inline_installer.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_tabstrip.h" 15 #include "chrome/browser/ui/browser_tabstrip.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.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"
21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/browser_test_utils.h" 25 #include "content/public/test/browser_test_utils.h"
23 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
24 #include "net/base/host_port_pair.h" 27 #include "net/base/host_port_pair.h"
25 #include "net/base/mock_host_resolver.h" 28 #include "net/base/mock_host_resolver.h"
26 29
27 using content::WebContents; 30 using content::WebContents;
31 using extensions::Extension;
28 32
29 const char kWebstoreDomain[] = "cws.com"; 33 const char kWebstoreDomain[] = "cws.com";
30 const char kAppDomain[] = "app.com"; 34 const char kAppDomain[] = "app.com";
31 const char kNonAppDomain[] = "nonapp.com"; 35 const char kNonAppDomain[] = "nonapp.com";
36 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje";
32 37
33 class WebstoreInlineInstallTest : public InProcessBrowserTest { 38 class WebstoreInlineInstallTest : public InProcessBrowserTest {
34 public: 39 public:
35 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 40 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
36 // We start the test server now instead of in 41 // We start the test server now instead of in
37 // SetUpInProcessBrowserTestFixture so that we can get its port number. 42 // SetUpInProcessBrowserTestFixture so that we can get its port number.
38 ASSERT_TRUE(test_server()->Start()); 43 ASSERT_TRUE(test_server()->Start());
39 44
40 net::HostPortPair host_port = test_server()->host_port_pair(); 45 net::HostPortPair host_port = test_server()->host_port_pair();
41 test_gallery_url_ = base::StringPrintf( 46 test_gallery_url_ = base::StringPrintf(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, Install) { 91 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, Install) {
87 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 92 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
88 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); 93 switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
89 94
90 ui_test_utils::NavigateToURL( 95 ui_test_utils::NavigateToURL(
91 browser(), GenerateTestServerUrl(kAppDomain, "install.html")); 96 browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
92 97
93 RunInlineInstallTest("runTest"); 98 RunInlineInstallTest("runTest");
94 99
95 const extensions::Extension* extension = browser()->profile()-> 100 const extensions::Extension* extension = browser()->profile()->
96 GetExtensionService()->GetExtensionById( 101 GetExtensionService()->GetExtensionById(kTestExtensionId, false);
97 "ecglahbcnmdpdciemllbhojghbkagdje", false);
98 EXPECT_TRUE(extension); 102 EXPECT_TRUE(extension);
99 } 103 }
100 104
101 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, 105 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest,
102 InstallNotAllowedFromNonVerifiedDomains) { 106 InstallNotAllowedFromNonVerifiedDomains) {
103 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 107 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
104 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); 108 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
105 ui_test_utils::NavigateToURL( 109 ui_test_utils::NavigateToURL(
106 browser(), 110 browser(),
107 GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html")); 111 GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html"));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallUnpackFailureTest, 171 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallUnpackFailureTest,
168 WebstoreInlineInstallUnpackFailureTest) { 172 WebstoreInlineInstallUnpackFailureTest) {
169 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 173 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
170 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); 174 switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
171 175
172 ui_test_utils::NavigateToURL(browser(), 176 ui_test_utils::NavigateToURL(browser(),
173 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); 177 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html"));
174 178
175 RunInlineInstallTest("runTest"); 179 RunInlineInstallTest("runTest");
176 } 180 }
181
182 class CommandLineWebstoreInstall : public WebstoreInlineInstallTest,
183 public content::NotificationObserver {
184 public:
185 CommandLineWebstoreInstall() : saw_install_(false) {}
186 virtual ~CommandLineWebstoreInstall() {}
187
188 virtual void SetUpOnMainThread() OVERRIDE {
189 WebstoreInlineInstallTest::SetUpOnMainThread();
190 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
191 content::NotificationService::AllSources());
192 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
193 switches::kInstallFromWebstore, kTestExtensionId);
194 }
195
196 bool saw_install() { return saw_install_; }
197
198 protected:
199 // NotificationObserver interface.
200 virtual void Observe(int type,
201 const content::NotificationSource& source,
202 const content::NotificationDetails& details) OVERRIDE {
203 ASSERT_EQ(chrome::NOTIFICATION_EXTENSION_INSTALLED, type);
204 const Extension* extension = content::Details<Extension>(details).ptr();
205 ASSERT_TRUE(extension != NULL);
206 EXPECT_EQ(extension->id(), kTestExtensionId);
207 saw_install_ = true;
208 }
209
210 content::NotificationRegistrar registrar_;
211
212 // Have we seen an installation notification for kTestExtensionId ?
213 bool saw_install_;
214 };
215
216 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Accept) {
217 CommandLine* command_line = CommandLine::ForCurrentProcess();
218 command_line->AppendSwitchASCII(
219 switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
220 extensions::StartupHelper helper;
221 EXPECT_TRUE(helper.InstallFromWebstore(*command_line, browser()->profile()));
222 EXPECT_TRUE(saw_install());
223 }
224
225 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Cancel) {
226 CommandLine* command_line = CommandLine::ForCurrentProcess();
227 command_line->AppendSwitchASCII(
228 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
229 extensions::StartupHelper helper;
230 EXPECT_FALSE(helper.InstallFromWebstore(*command_line, browser()->profile()));
231 EXPECT_FALSE(saw_install());
232 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/tab_helper.cc ('k') | chrome/browser/extensions/webstore_inline_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698