| OLD | NEW |
| 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/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 #if defined(OS_CHROMEOS) | 78 #if defined(OS_CHROMEOS) |
| 79 // We bypass manually installed proxy for localhost on chromeos. | 79 // We bypass manually installed proxy for localhost on chromeos. |
| 80 #define MAYBE_BasicAuthWSConnect DISABLED_BasicAuthWSConnect | 80 #define MAYBE_BasicAuthWSConnect DISABLED_BasicAuthWSConnect |
| 81 #else | 81 #else |
| 82 #define MAYBE_BasicAuthWSConnect BasicAuthWSConnect | 82 #define MAYBE_BasicAuthWSConnect BasicAuthWSConnect |
| 83 #endif | 83 #endif |
| 84 // Test that the browser can establish a WebSocket connection via a proxy | 84 // Test that the browser can establish a WebSocket connection via a proxy |
| 85 // that requires basic authentication. | 85 // that requires basic authentication. |
| 86 IN_PROC_BROWSER_TEST_F(ProxyBrowserTest, MAYBE_BasicAuthWSConnect) { | 86 IN_PROC_BROWSER_TEST_F(ProxyBrowserTest, MAYBE_BasicAuthWSConnect) { |
| 87 // Launch WebSocket server. | 87 // Launch WebSocket server. |
| 88 content::TestWebSocketServer ws_server; | 88 net::TestServer ws_server(net::TestServer::TYPE_WS, |
| 89 int port = ws_server.UseRandomPort(); | 89 net::TestServer::kLocalhost, |
| 90 FilePath ws_root_dir; | 90 FilePath(FILE_PATH_LITERAL("net/data/websocket"))); |
| 91 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &ws_root_dir)); | 91 ASSERT_TRUE(ws_server.Start()); |
| 92 ASSERT_TRUE(ws_server.Start(ws_root_dir)); | |
| 93 | 92 |
| 94 content::WebContents* tab = chrome::GetActiveWebContents(browser()); | 93 content::WebContents* tab = chrome::GetActiveWebContents(browser()); |
| 95 content::NavigationController* controller = &tab->GetController(); | 94 content::NavigationController* controller = &tab->GetController(); |
| 96 content::NotificationRegistrar registrar; | 95 content::NotificationRegistrar registrar; |
| 97 // The proxy server will request basic authentication. | 96 // The proxy server will request basic authentication. |
| 98 // |observer| supplies the credential. | 97 // |observer| supplies the credential. |
| 99 LoginPromptObserver observer; | 98 LoginPromptObserver observer; |
| 100 registrar.Add(&observer, chrome::NOTIFICATION_AUTH_NEEDED, | 99 registrar.Add(&observer, chrome::NOTIFICATION_AUTH_NEEDED, |
| 101 content::Source<content::NavigationController>(controller)); | 100 content::Source<content::NavigationController>(controller)); |
| 102 | 101 |
| 103 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); | 102 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); |
| 104 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 103 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
| 105 | 104 |
| 106 // Visit a page that tries to establish WebSocket connection. The title | 105 // Visit a page that tries to establish WebSocket connection. The title |
| 107 // of the page will be 'PASS' on success. | 106 // of the page will be 'PASS' on success. |
| 108 // TODO(bashi): Add TestWebSocketServer::GetURL() instead creating url here. | 107 std::string scheme("http"); |
| 109 std::string url_path = | 108 GURL::Replacements replacements; |
| 110 StringPrintf("%s%d%s", "http://localhost:", port, "/ws.html"); | 109 replacements.SetSchemeStr(scheme); |
| 111 ui_test_utils::NavigateToURL(browser(), GURL(url_path)); | 110 ui_test_utils::NavigateToURL( |
| 111 browser(), |
| 112 ws_server.GetURL("connect_check.html").ReplaceComponents(replacements)); |
| 112 | 113 |
| 113 const string16 result = watcher.WaitAndGetTitle(); | 114 const string16 result = watcher.WaitAndGetTitle(); |
| 114 EXPECT_TRUE(EqualsASCII(result, "PASS")); | 115 EXPECT_TRUE(EqualsASCII(result, "PASS")); |
| 115 EXPECT_TRUE(observer.auth_handled()); | 116 EXPECT_TRUE(observer.auth_handled()); |
| 116 } | 117 } |
| 117 | 118 |
| 118 } // namespace | 119 } // namespace |
| OLD | NEW |