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 3 // found in the LICENSE file. 4 5 #include "base/strings/string_util.h" 6 #include "base/strings/utf_string_conversions.h" 7 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" 9 #include "chrome/test/base/in_process_browser_test.h" 10 #include "chrome/test/base/ui_test_utils.h" 11 #include "content/public/test/browser_test_utils.h" 12 #include "net/base/test_data_directory.h" 13 #include "net/test/spawned_test_server/spawned_test_server.h" 14 15 namespace { 16 17 class WebSocketBrowserTest : public InProcessBrowserTest { 18 public: 19 WebSocketBrowserTest() 20 : ws_server_(net::SpawnedTestServer::TYPE_WS, 21 net::SpawnedTestServer::kLocalhost, 22 net::GetWebSocketTestDataDirectory()), 23 wss_server_(net::SpawnedTestServer::TYPE_WSS, 24 SSLOptions(SSLOptions::CERT_OK), 25 net::GetWebSocketTestDataDirectory()) { 26 } 27 28 protected: 29 net::SpawnedTestServer ws_server_; 30 net::SpawnedTestServer wss_server_; 31 32 private: 33 typedef net::SpawnedTestServer::SSLOptions SSLOptions; 34 35 DISALLOW_COPY_AND_ASSIGN(WebSocketBrowserTest); 36 }; 37 38 // Test that the browser can handle a WebSocket frame split into multiple TCP 39 // segments. 40 IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, WebSocketSplitSegments) { 41 // Launch a WebSocket server. 42 ASSERT_TRUE(ws_server_.Start()); 43 44 // Setup page title observer. 45 content::WebContents* tab = 46 browser()->tab_strip_model()->GetActiveWebContents(); 47 content::TitleWatcher watcher(tab, base::ASCIIToUTF16("PASS")); 48 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); 49 50 // Visit a HTTP page for testing. 51 std::string scheme("http"); 52 GURL::Replacements replacements; 53 replacements.SetSchemeStr(scheme); 54 ui_test_utils::NavigateToURL( 55 browser(), 56 ws_server_.GetURL( 57 "split_packet_check.html").ReplaceComponents(replacements)); 58 59 const base::string16 result = watcher.WaitAndGetTitle(); 60 EXPECT_TRUE(EqualsASCII(result, "PASS")); 61 } 62 63 IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, SecureWebSocketSplitRecords) { 64 // Launch a secure WebSocket server. 65 ASSERT_TRUE(wss_server_.Start()); 66 67 // Setup page title observer. 68 content::WebContents* tab = 69 browser()->tab_strip_model()->GetActiveWebContents(); 70 content::TitleWatcher watcher(tab, base::ASCIIToUTF16("PASS")); 71 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); 72 73 // Visit a HTTPS page for testing. 74 std::string scheme("https"); 75 GURL::Replacements replacements; 76 replacements.SetSchemeStr(scheme); 77 ui_test_utils::NavigateToURL( 78 browser(), 79 wss_server_.GetURL( 80 "split_packet_check.html").ReplaceComponents(replacements)); 81 82 const base::string16 result = watcher.WaitAndGetTitle(); 83 EXPECT_TRUE(EqualsASCII(result, "PASS")); 84 } 85 86 } // namespace 87