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

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

Issue 7795032: Add link URL and success/failure callback parameters to chrome.webstore.install() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback Created 9 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) 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 "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_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/webstore_inline_installer.h" 11 #include "chrome/browser/extensions/webstore_inline_installer.h"
12 #include "chrome/browser/tabs/tab_strip_model.h" 12 #include "chrome/browser/tabs/tab_strip_model.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/browser/tab_contents/tab_contents.h" 18 #include "content/browser/tab_contents/tab_contents.h"
19 #include "content/common/content_notification_types.h" 19 #include "content/common/content_notification_types.h"
20 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
21 #include "net/base/host_port_pair.h" 21 #include "net/base/host_port_pair.h"
22 #include "net/base/mock_host_resolver.h" 22 #include "net/base/mock_host_resolver.h"
23 23
24 const char kWebstoreDomain[] = "cws.com"; 24 const char kWebstoreDomain[] = "cws.com";
25 const char kAppDomain[] = "app.com"; 25 const char kAppDomain[] = "app.com";
26 const char kNonAppDomain[] = "nonapp.com";
26 27
27 class WebstoreInlineInstallTest : public InProcessBrowserTest { 28 class WebstoreInlineInstallTest : public InProcessBrowserTest {
28 public: 29 public:
29 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 30 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
30 EnableDOMAutomation(); 31 EnableDOMAutomation();
31 32
32 // We start the test server now instead of in 33 // We start the test server now instead of in
33 // SetUpInProcessBrowserTestFixture so that we can get its port number. 34 // SetUpInProcessBrowserTestFixture so that we can get its port number.
34 ASSERT_TRUE(test_server()->Start()); 35 ASSERT_TRUE(test_server()->Start());
35 36
36 InProcessBrowserTest::SetUpCommandLine(command_line); 37 InProcessBrowserTest::SetUpCommandLine(command_line);
37 38
38 net::HostPortPair host_port = test_server()->host_port_pair(); 39 net::HostPortPair host_port = test_server()->host_port_pair();
39 test_gallery_url_ = base::StringPrintf( 40 test_gallery_url_ = base::StringPrintf(
40 "http://%s:%d/files/extensions/api_test/webstore_inline_install", 41 "http://%s:%d/files/extensions/api_test/webstore_inline_install",
41 kWebstoreDomain, host_port.port()); 42 kWebstoreDomain, host_port.port());
42 command_line->AppendSwitchASCII( 43 command_line->AppendSwitchASCII(
43 switches::kAppsGalleryURL, test_gallery_url_); 44 switches::kAppsGalleryURL, test_gallery_url_);
44 45
45 GURL crx_url = GenerateTestServerUrl(kWebstoreDomain, "extension.crx"); 46 GURL crx_url = GenerateTestServerUrl(kWebstoreDomain, "extension.crx");
46 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 47 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
47 switches::kAppsGalleryUpdateURL, crx_url.spec()); 48 switches::kAppsGalleryUpdateURL, crx_url.spec());
48 49
49 command_line->AppendSwitch(switches::kEnableInlineWebstoreInstall); 50 command_line->AppendSwitch(switches::kEnableInlineWebstoreInstall);
50 } 51 }
51 52
52 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 53 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
53 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1"); 54 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1");
54 host_resolver()->AddRule(kAppDomain, "127.0.0.1"); 55 host_resolver()->AddRule(kAppDomain, "127.0.0.1");
56 host_resolver()->AddRule(kNonAppDomain, "127.0.0.1");
55 } 57 }
56 58
57 protected: 59 protected:
58 GURL GenerateTestServerUrl(const std::string& domain, 60 GURL GenerateTestServerUrl(const std::string& domain,
59 const std::string& page_filename) { 61 const std::string& page_filename) {
60 GURL page_url = test_server()->GetURL( 62 GURL page_url = test_server()->GetURL(
61 "files/extensions/api_test/webstore_inline_install/" + page_filename); 63 "files/extensions/api_test/webstore_inline_install/" + page_filename);
62 64
63 GURL::Replacements replace_host; 65 GURL::Replacements replace_host;
64 replace_host.SetHostStr(domain); 66 replace_host.SetHostStr(domain);
65 return page_url.ReplaceComponents(replace_host); 67 return page_url.ReplaceComponents(replace_host);
66 } 68 }
67 69
70 void RunInlineInstallTest() {
71 bool result = false;
72 std::string script =
73 StringPrintf("runTest('%s')", test_gallery_url_.c_str());
74 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
75 browser()->GetSelectedTabContents()->render_view_host(), L"",
76 UTF8ToWide(script), &result));
77 EXPECT_TRUE(result);
78 }
79
68 std::string test_gallery_url_; 80 std::string test_gallery_url_;
69 }; 81 };
70 82
71 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, Install) { 83 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, Install) {
72 SetExtensionInstallDialogForManifestAutoConfirmForTests(true); 84 SetExtensionInstallDialogForManifestAutoConfirmForTests(true);
73 85
74 ui_test_utils::WindowedNotificationObserver load_signal( 86 ui_test_utils::WindowedNotificationObserver load_signal(
75 chrome::NOTIFICATION_EXTENSION_LOADED, 87 chrome::NOTIFICATION_EXTENSION_LOADED,
76 Source<Profile>(browser()->profile())); 88 Source<Profile>(browser()->profile()));
77 89
78 ui_test_utils::NavigateToURL( 90 ui_test_utils::NavigateToURL(
79 browser(), GenerateTestServerUrl(kAppDomain, "install.html")); 91 browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
80 92
81 bool result = false; 93 RunInlineInstallTest();
82 std::string script = StringPrintf("runTest('%s')", test_gallery_url_.c_str());
83 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
84 browser()->GetSelectedTabContents()->render_view_host(), L"",
85 UTF8ToWide(script), &result));
86 EXPECT_TRUE(result);
87 94
88 load_signal.Wait(); 95 load_signal.Wait();
89 96
90 const Extension* extension = browser()->profile()->GetExtensionService()-> 97 const Extension* extension = browser()->profile()->GetExtensionService()->
91 GetExtensionById("ecglahbcnmdpdciemllbhojghbkagdje", false); 98 GetExtensionById("ecglahbcnmdpdciemllbhojghbkagdje", false);
92 EXPECT_TRUE(extension != NULL); 99 EXPECT_TRUE(extension != NULL);
93 } 100 }
94 101
102 IN_PROC_BROWSER_TEST_F(
103 WebstoreInlineInstallTest, InstallNotAllowedFromNonVerifiedDomains) {
104 SetExtensionInstallDialogForManifestAutoConfirmForTests(false);
105 ui_test_utils::NavigateToURL(
106 browser(),
107 GenerateTestServerUrl(kNonAppDomain, "install-non-verified-domain.html"));
108
109 RunInlineInstallTest();
110 }
111
95 // Flakily fails on Linux. http://crbug.com/95280 112 // Flakily fails on Linux. http://crbug.com/95280
96 #if defined(OS_LINUX) 113 #if defined(OS_LINUX)
97 #define MAYBE_FindLink FLAKY_FindLink 114 #define MAYBE_FindLink FLAKY_FindLink
98 #else 115 #else
99 #define MAYBE_FindLink FindLink 116 #define MAYBE_FindLink FindLink
100 #endif 117 #endif
101 118
102 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, MAYBE_FindLink) { 119 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, MAYBE_FindLink) {
103 ui_test_utils::NavigateToURL( 120 ui_test_utils::NavigateToURL(
104 browser(), GenerateTestServerUrl(kAppDomain, "find_link.html")); 121 browser(), GenerateTestServerUrl(kAppDomain, "find_link.html"));
105 122
106 bool result = false; 123 RunInlineInstallTest();
107 std::string script = StringPrintf("runTest('%s')", test_gallery_url_.c_str());
108 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
109 browser()->GetSelectedTabContents()->render_view_host(), L"",
110 UTF8ToWide(script), &result));
111 EXPECT_TRUE(result);
112 } 124 }
125
126 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, ArgumentValidation) {
127 SetExtensionInstallDialogForManifestAutoConfirmForTests(false);
128 ui_test_utils::NavigateToURL(
129 browser(), GenerateTestServerUrl(kAppDomain, "argument_validation.html"));
130
131 RunInlineInstallTest();
132 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_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