Index: chrome/browser/net/websocket_browsertest.cc |
diff --git a/chrome/browser/net/websocket_browsertest.cc b/chrome/browser/net/websocket_browsertest.cc |
index 58605de17472bd041be93ceaeb05db77567c0670..a0a65b82e90b36a24384eeb81b5428ea898c0411 100644 |
--- a/chrome/browser/net/websocket_browsertest.cc |
+++ b/chrome/browser/net/websocket_browsertest.cc |
@@ -2,6 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include <string> |
+ |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/ui/browser.h" |
@@ -11,21 +13,39 @@ |
#include "content/public/test/browser_test_utils.h" |
#include "net/base/test_data_directory.h" |
#include "net/test/spawned_test_server/spawned_test_server.h" |
+#include "url/gurl.h" |
namespace { |
class WebSocketBrowserTest : public InProcessBrowserTest { |
public: |
WebSocketBrowserTest() |
- : ws_server_(net::SpawnedTestServer::TYPE_WS, |
- net::SpawnedTestServer::kLocalhost, |
- net::GetWebSocketTestDataDirectory()), |
- wss_server_(net::SpawnedTestServer::TYPE_WSS, |
- SSLOptions(SSLOptions::CERT_OK), |
- net::GetWebSocketTestDataDirectory()) { |
- } |
+ : ws_server_(net::SpawnedTestServer::TYPE_WS, |
+ net::SpawnedTestServer::kLocalhost, |
+ net::GetWebSocketTestDataDirectory()), |
+ wss_server_(net::SpawnedTestServer::TYPE_WSS, |
+ SSLOptions(SSLOptions::CERT_OK), |
+ net::GetWebSocketTestDataDirectory()) {} |
protected: |
+ void NavigateToHTTP(const std::string& path) { |
+ // Visit a HTTP page for testing. |
+ std::string scheme("http"); |
+ GURL::Replacements replacements; |
+ replacements.SetSchemeStr(scheme); |
+ ui_test_utils::NavigateToURL( |
+ browser(), ws_server_.GetURL(path).ReplaceComponents(replacements)); |
+ } |
+ |
+ void NavigateToHTTPS(const std::string& path) { |
+ // Visit a HTTPS page for testing. |
+ std::string scheme("https"); |
+ GURL::Replacements replacements; |
+ replacements.SetSchemeStr(scheme); |
+ ui_test_utils::NavigateToURL( |
+ browser(), wss_server_.GetURL(path).ReplaceComponents(replacements)); |
+ } |
+ |
net::SpawnedTestServer ws_server_; |
net::SpawnedTestServer wss_server_; |
@@ -47,17 +67,10 @@ IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, WebSocketSplitSegments) { |
content::TitleWatcher watcher(tab, base::ASCIIToUTF16("PASS")); |
watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
- // Visit a HTTP page for testing. |
- std::string scheme("http"); |
- GURL::Replacements replacements; |
- replacements.SetSchemeStr(scheme); |
- ui_test_utils::NavigateToURL( |
- browser(), |
- ws_server_.GetURL( |
- "split_packet_check.html").ReplaceComponents(replacements)); |
+ NavigateToHTTP("split_packet_check.html"); |
const base::string16 result = watcher.WaitAndGetTitle(); |
- EXPECT_TRUE(EqualsASCII(result, "PASS")); |
+ EXPECT_EQ(base::ASCIIToUTF16("PASS"), result); |
} |
IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, SecureWebSocketSplitRecords) { |
@@ -70,17 +83,43 @@ IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, SecureWebSocketSplitRecords) { |
content::TitleWatcher watcher(tab, base::ASCIIToUTF16("PASS")); |
watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
- // Visit a HTTPS page for testing. |
- std::string scheme("https"); |
- GURL::Replacements replacements; |
- replacements.SetSchemeStr(scheme); |
- ui_test_utils::NavigateToURL( |
- browser(), |
- wss_server_.GetURL( |
- "split_packet_check.html").ReplaceComponents(replacements)); |
+ NavigateToHTTPS("split_packet_check.html"); |
const base::string16 result = watcher.WaitAndGetTitle(); |
- EXPECT_TRUE(EqualsASCII(result, "PASS")); |
+ EXPECT_EQ(base::ASCIIToUTF16("PASS"), result); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, SendCloseFrameWhenTabIsClosed) { |
+ // Launch a WebSocket server. |
+ ASSERT_TRUE(ws_server_.Start()); |
+ |
+ content::WebContents* tab = |
+ browser()->tab_strip_model()->GetActiveWebContents(); |
+ { |
+ // Create a new tab, establish a WebSocket connection and close the tab. |
+ content::WebContents* new_tab = content::WebContents::Create( |
+ content::WebContents::CreateParams(tab->GetBrowserContext())); |
+ browser()->tab_strip_model()->AppendWebContents(new_tab, true); |
+ ASSERT_EQ(new_tab, browser()->tab_strip_model()->GetWebContentsAt(1)); |
+ |
+ content::TitleWatcher connected_title_watcher( |
+ new_tab, base::ASCIIToUTF16("CONNECTED")); |
+ connected_title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("CLOSED")); |
+ NavigateToHTTP("counted_connection.html"); |
+ const base::string16 result = connected_title_watcher.WaitAndGetTitle(); |
+ EXPECT_TRUE(EqualsASCII(result, "CONNECTED")); |
+ |
+ content::WebContentsDestroyedWatcher destroyed_watcher(new_tab); |
+ browser()->tab_strip_model()->CloseWebContentsAt(1, 0); |
+ destroyed_watcher.Wait(); |
+ } |
+ |
+ content::TitleWatcher title_watcher(tab, base::ASCIIToUTF16("PASS")); |
+ title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
+ |
+ NavigateToHTTP("count_connection.html"); |
+ const base::string16 result = title_watcher.WaitAndGetTitle(); |
+ EXPECT_EQ(base::ASCIIToUTF16("PASS"), result); |
} |
} // namespace |