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