| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 void NavigateToHTTPS(const std::string& path) { | 48 void NavigateToHTTPS(const std::string& path) { |
| 49 // Visit a HTTPS page for testing. | 49 // Visit a HTTPS page for testing. |
| 50 std::string scheme("https"); | 50 std::string scheme("https"); |
| 51 GURL::Replacements replacements; | 51 GURL::Replacements replacements; |
| 52 replacements.SetSchemeStr(scheme); | 52 replacements.SetSchemeStr(scheme); |
| 53 ui_test_utils::NavigateToURL( | 53 ui_test_utils::NavigateToURL( |
| 54 browser(), wss_server_.GetURL(path).ReplaceComponents(replacements)); | 54 browser(), wss_server_.GetURL(path).ReplaceComponents(replacements)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Prepare the title watcher. | 57 // Prepare the title watcher. |
| 58 virtual void SetUpOnMainThread() OVERRIDE { | 58 virtual void SetUpOnMainThread() override { |
| 59 watcher_.reset(new content::TitleWatcher( | 59 watcher_.reset(new content::TitleWatcher( |
| 60 browser()->tab_strip_model()->GetActiveWebContents(), | 60 browser()->tab_strip_model()->GetActiveWebContents(), |
| 61 base::ASCIIToUTF16("PASS"))); | 61 base::ASCIIToUTF16("PASS"))); |
| 62 watcher_->AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); | 62 watcher_->AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
| 63 } | 63 } |
| 64 | 64 |
| 65 virtual void TearDownOnMainThread() OVERRIDE { watcher_.reset(); } | 65 virtual void TearDownOnMainThread() override { watcher_.reset(); } |
| 66 | 66 |
| 67 std::string WaitAndGetTitle() { | 67 std::string WaitAndGetTitle() { |
| 68 return base::UTF16ToUTF8(watcher_->WaitAndGetTitle()); | 68 return base::UTF16ToUTF8(watcher_->WaitAndGetTitle()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 net::SpawnedTestServer ws_server_; | 71 net::SpawnedTestServer ws_server_; |
| 72 net::SpawnedTestServer wss_server_; | 72 net::SpawnedTestServer wss_server_; |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 typedef net::SpawnedTestServer::SSLOptions SSLOptions; | 75 typedef net::SpawnedTestServer::SSLOptions SSLOptions; |
| 76 scoped_ptr<content::TitleWatcher> watcher_; | 76 scoped_ptr<content::TitleWatcher> watcher_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(WebSocketBrowserTest); | 78 DISALLOW_COPY_AND_ASSIGN(WebSocketBrowserTest); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // Framework for tests using the connect_to.html page served by a separate HTTP | 81 // Framework for tests using the connect_to.html page served by a separate HTTP |
| 82 // server. | 82 // server. |
| 83 class WebSocketBrowserConnectToTest : public WebSocketBrowserTest { | 83 class WebSocketBrowserConnectToTest : public WebSocketBrowserTest { |
| 84 protected: | 84 protected: |
| 85 WebSocketBrowserConnectToTest() | 85 WebSocketBrowserConnectToTest() |
| 86 : http_server_(net::SpawnedTestServer::TYPE_HTTP, | 86 : http_server_(net::SpawnedTestServer::TYPE_HTTP, |
| 87 net::SpawnedTestServer::kLocalhost, | 87 net::SpawnedTestServer::kLocalhost, |
| 88 net::GetWebSocketTestDataDirectory()) {} | 88 net::GetWebSocketTestDataDirectory()) {} |
| 89 | 89 |
| 90 // The title watcher and HTTP server are set up automatically by the test | 90 // The title watcher and HTTP server are set up automatically by the test |
| 91 // framework. Each test case still needs to configure and start the | 91 // framework. Each test case still needs to configure and start the |
| 92 // WebSocket server(s) it needs. | 92 // WebSocket server(s) it needs. |
| 93 virtual void SetUpOnMainThread() OVERRIDE { | 93 virtual void SetUpOnMainThread() override { |
| 94 WebSocketBrowserTest::SetUpOnMainThread(); | 94 WebSocketBrowserTest::SetUpOnMainThread(); |
| 95 ASSERT_TRUE(http_server_.StartInBackground()); | 95 ASSERT_TRUE(http_server_.StartInBackground()); |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Supply a ws: or wss: URL to connect to. | 98 // Supply a ws: or wss: URL to connect to. |
| 99 void ConnectTo(GURL url) { | 99 void ConnectTo(GURL url) { |
| 100 ASSERT_TRUE(http_server_.BlockUntilStarted()); | 100 ASSERT_TRUE(http_server_.BlockUntilStarted()); |
| 101 std::string query("url=" + url.spec()); | 101 std::string query("url=" + url.spec()); |
| 102 GURL::Replacements replacements; | 102 GURL::Replacements replacements; |
| 103 replacements.SetQueryStr(query); | 103 replacements.SetQueryStr(query); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 122 logged_in_(false) { | 122 logged_in_(false) { |
| 123 registrar_.Add( | 123 registrar_.Add( |
| 124 this, | 124 this, |
| 125 chrome::NOTIFICATION_AUTH_NEEDED, | 125 chrome::NOTIFICATION_AUTH_NEEDED, |
| 126 content::Source<content::NavigationController>(navigation_controller)); | 126 content::Source<content::NavigationController>(navigation_controller)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // NotificationObserver implementation | 129 // NotificationObserver implementation |
| 130 virtual void Observe(int type, | 130 virtual void Observe(int type, |
| 131 const content::NotificationSource& source, | 131 const content::NotificationSource& source, |
| 132 const content::NotificationDetails& details) OVERRIDE { | 132 const content::NotificationDetails& details) override { |
| 133 DCHECK_EQ(chrome::NOTIFICATION_AUTH_NEEDED, type); | 133 DCHECK_EQ(chrome::NOTIFICATION_AUTH_NEEDED, type); |
| 134 scoped_refptr<LoginHandler> login_handler = | 134 scoped_refptr<LoginHandler> login_handler = |
| 135 content::Details<LoginNotificationDetails>(details)->handler(); | 135 content::Details<LoginNotificationDetails>(details)->handler(); |
| 136 login_handler->SetAuth(username_, password_); | 136 login_handler->SetAuth(username_, password_); |
| 137 logged_in_ = true; | 137 logged_in_ = true; |
| 138 } | 138 } |
| 139 | 139 |
| 140 bool logged_in() const { return logged_in_; } | 140 bool logged_in() const { return logged_in_; } |
| 141 | 141 |
| 142 private: | 142 private: |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // Blink layout tests, and browser tests are expensive to run. | 294 // Blink layout tests, and browser tests are expensive to run. |
| 295 IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, SSLConnectionLimit) { | 295 IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, SSLConnectionLimit) { |
| 296 ASSERT_TRUE(wss_server_.Start()); | 296 ASSERT_TRUE(wss_server_.Start()); |
| 297 | 297 |
| 298 NavigateToHTTPS("multiple-connections.html"); | 298 NavigateToHTTPS("multiple-connections.html"); |
| 299 | 299 |
| 300 EXPECT_EQ("PASS", WaitAndGetTitle()); | 300 EXPECT_EQ("PASS", WaitAndGetTitle()); |
| 301 } | 301 } |
| 302 | 302 |
| 303 } // namespace | 303 } // namespace |
| OLD | NEW |