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

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

Issue 7741037: Add WebstoreInlineInstaller (downloads store data, shows the install UI, and starts the install). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Put webstore response in the right directory. 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"
7 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/extensions/extension_install_dialog.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/webstore_inline_installer.h"
7 #include "chrome/browser/tabs/tab_strip_model.h" 12 #include "chrome/browser/tabs/tab_strip_model.h"
8 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/common/chrome_notification_types.h"
9 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
10 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/browser/tab_contents/tab_contents.h" 18 #include "content/browser/tab_contents/tab_contents.h"
13 #include "content/common/content_notification_types.h" 19 #include "content/common/content_notification_types.h"
14 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
21 #include "net/base/host_port_pair.h"
15 #include "net/base/mock_host_resolver.h" 22 #include "net/base/mock_host_resolver.h"
16 23
24 const char kWebstoreDomain[] = "cws.com";
25 const char kAppDomain[] = "app.com";
26
17 class WebstoreInlineInstallTest : public InProcessBrowserTest { 27 class WebstoreInlineInstallTest : public InProcessBrowserTest {
18 public: 28 public:
19 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 29 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
20 EnableDOMAutomation(); 30 EnableDOMAutomation();
21 31
32 // We start the test server now instead of in
33 // SetUpInProcessBrowserTestFixture so that we can get its port number.
34 ASSERT_TRUE(test_server()->Start());
35
22 InProcessBrowserTest::SetUpCommandLine(command_line); 36 InProcessBrowserTest::SetUpCommandLine(command_line);
37
38 net::HostPortPair host_port = test_server()->host_port_pair();
39 test_gallery_url_ = base::StringPrintf(
40 "http://%s:%d/files/extensions/api_test/webstore_inline_install",
41 kWebstoreDomain, host_port.port());
23 command_line->AppendSwitchASCII( 42 command_line->AppendSwitchASCII(
24 switches::kAppsGalleryURL, "http://cws.com"); 43 switches::kAppsGalleryURL, test_gallery_url_);
44
45 GURL crx_url = GenerateTestServerUrl(kWebstoreDomain, "extension.crx");
46 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
47 switches::kAppsGalleryUpdateURL, crx_url.spec());
48
25 command_line->AppendSwitch(switches::kEnableInlineWebstoreInstall); 49 command_line->AppendSwitch(switches::kEnableInlineWebstoreInstall);
26 } 50 }
27 51
28 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 52 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
29 host_resolver()->AddRule("cws.com", "127.0.0.1"); 53 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1");
30 host_resolver()->AddRule("app.com", "127.0.0.1"); 54 host_resolver()->AddRule(kAppDomain, "127.0.0.1");
31 ASSERT_TRUE(test_server()->Start());
32 } 55 }
33 56
34 protected: 57 protected:
35 GURL GetPageUrl(const std::string& page_filename) { 58 GURL GenerateTestServerUrl(const std::string& domain,
59 const std::string& page_filename) {
36 GURL page_url = test_server()->GetURL( 60 GURL page_url = test_server()->GetURL(
37 "files/extensions/api_test/webstore_inline_install/" + page_filename); 61 "files/extensions/api_test/webstore_inline_install/" + page_filename);
38 62
39 GURL::Replacements replace_host; 63 GURL::Replacements replace_host;
40 std::string host_str("app.com"); 64 replace_host.SetHostStr(domain);
41 replace_host.SetHostStr(host_str);
42 return page_url.ReplaceComponents(replace_host); 65 return page_url.ReplaceComponents(replace_host);
43 } 66 }
67
68 std::string test_gallery_url_;
44 }; 69 };
45 70
46 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, Install) { 71 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, Install) {
47 ui_test_utils::NavigateToURL(browser(), GetPageUrl("install.html")); 72 SetExtensionInstallDialogForManifestAutoConfirmForTests(true);
73
74 ui_test_utils::WindowedNotificationObserver load_signal(
75 chrome::NOTIFICATION_EXTENSION_LOADED,
76 Source<Profile>(browser()->profile()));
77
78 ui_test_utils::NavigateToURL(
79 browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
48 80
49 bool result = false; 81 bool result = false;
82 std::string script = StringPrintf("runTest('%s')", test_gallery_url_.c_str());
50 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 83 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
51 browser()->GetSelectedTabContents()->render_view_host(), L"", 84 browser()->GetSelectedTabContents()->render_view_host(), L"",
52 L"runTest()", &result)); 85 UTF8ToWide(script), &result));
53 EXPECT_TRUE(result); 86 EXPECT_TRUE(result);
54 87
55 // The "inline" UI right now is just the store entry in a new tab. 88 load_signal.Wait();
56 if (browser()->tabstrip_model()->count() == 1) {
57 ui_test_utils::WaitForNewTab(browser());
58 }
59 89
60 TabContents* tab_contents = browser()->GetSelectedTabContents(); 90 const Extension* extension = browser()->profile()->GetExtensionService()->
61 EXPECT_EQ( 91 GetExtensionById("ecglahbcnmdpdciemllbhojghbkagdje", false);
62 GURL("http://cws.com/detail/mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"), 92 EXPECT_TRUE(extension != NULL);
63 tab_contents->GetURL());
64 } 93 }
65 94
66 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, FindLink) { 95 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, FindLink) {
67 ui_test_utils::NavigateToURL(browser(), GetPageUrl("find_link.html")); 96 ui_test_utils::NavigateToURL(
97 browser(), GenerateTestServerUrl(kAppDomain, "find_link.html"));
68 98
69 bool result = false; 99 bool result = false;
100 std::string script = StringPrintf("runTest('%s')", test_gallery_url_.c_str());
70 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 101 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
71 browser()->GetSelectedTabContents()->render_view_host(), L"", 102 browser()->GetSelectedTabContents()->render_view_host(), L"",
72 L"runTest()", &result)); 103 UTF8ToWide(script), &result));
73 EXPECT_TRUE(result); 104 EXPECT_TRUE(result);
74 } 105 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_webstore_private_apitest.cc ('k') | chrome/browser/extensions/webstore_inline_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698