Chromium Code Reviews| 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/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 net::GetWebSocketTestDataDirectory()), | 22 net::GetWebSocketTestDataDirectory()), |
| 23 wss_server_(net::SpawnedTestServer::TYPE_WSS, | 23 wss_server_(net::SpawnedTestServer::TYPE_WSS, |
| 24 SSLOptions(SSLOptions::CERT_OK), | 24 SSLOptions(SSLOptions::CERT_OK), |
| 25 net::GetWebSocketTestDataDirectory()) { | 25 net::GetWebSocketTestDataDirectory()) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 protected: | 28 protected: |
| 29 net::SpawnedTestServer ws_server_; | 29 net::SpawnedTestServer ws_server_; |
| 30 net::SpawnedTestServer wss_server_; | 30 net::SpawnedTestServer wss_server_; |
| 31 | 31 |
| 32 void NavigateToHTTP(const std::string& path) { | |
| 33 // Visit a HTTP page for testing. | |
| 34 std::string scheme("http"); | |
| 35 GURL::Replacements replacements; | |
| 36 replacements.SetSchemeStr(scheme); | |
| 37 ui_test_utils::NavigateToURL( | |
| 38 browser(), | |
| 39 ws_server_.GetURL(path).ReplaceComponents(replacements)); | |
| 40 } | |
| 41 | |
| 42 void NavigateToHTTPS(const std::string& path) { | |
| 43 // Visit a HTTPS page for testing. | |
| 44 std::string scheme("https"); | |
| 45 GURL::Replacements replacements; | |
| 46 replacements.SetSchemeStr(scheme); | |
| 47 ui_test_utils::NavigateToURL( | |
| 48 browser(), | |
| 49 wss_server_.GetURL(path).ReplaceComponents(replacements)); | |
| 50 } | |
| 51 | |
| 32 private: | 52 private: |
| 33 typedef net::SpawnedTestServer::SSLOptions SSLOptions; | 53 typedef net::SpawnedTestServer::SSLOptions SSLOptions; |
| 34 | 54 |
| 35 DISALLOW_COPY_AND_ASSIGN(WebSocketBrowserTest); | 55 DISALLOW_COPY_AND_ASSIGN(WebSocketBrowserTest); |
| 36 }; | 56 }; |
| 37 | 57 |
| 38 // Test that the browser can handle a WebSocket frame split into multiple TCP | 58 // Test that the browser can handle a WebSocket frame split into multiple TCP |
| 39 // segments. | 59 // segments. |
| 40 IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, WebSocketSplitSegments) { | 60 IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, WebSocketSplitSegments) { |
| 41 // Launch a WebSocket server. | 61 // Launch a WebSocket server. |
| 42 ASSERT_TRUE(ws_server_.Start()); | 62 ASSERT_TRUE(ws_server_.Start()); |
| 43 | 63 |
| 44 // Setup page title observer. | 64 // Setup page title observer. |
| 45 content::WebContents* tab = | 65 content::WebContents* tab = |
| 46 browser()->tab_strip_model()->GetActiveWebContents(); | 66 browser()->tab_strip_model()->GetActiveWebContents(); |
| 47 content::TitleWatcher watcher(tab, base::ASCIIToUTF16("PASS")); | 67 content::TitleWatcher watcher(tab, base::ASCIIToUTF16("PASS")); |
| 48 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); | 68 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
| 49 | 69 |
| 50 // Visit a HTTP page for testing. | 70 NavigateToHTTP("split_packet_check.html"); |
| 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 | 71 |
| 59 const base::string16 result = watcher.WaitAndGetTitle(); | 72 const base::string16 result = watcher.WaitAndGetTitle(); |
| 60 EXPECT_TRUE(EqualsASCII(result, "PASS")); | 73 EXPECT_TRUE(EqualsASCII(result, "PASS")); |
| 61 } | 74 } |
| 62 | 75 |
| 63 IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, SecureWebSocketSplitRecords) { | 76 IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, SecureWebSocketSplitRecords) { |
| 64 // Launch a secure WebSocket server. | 77 // Launch a secure WebSocket server. |
| 65 ASSERT_TRUE(wss_server_.Start()); | 78 ASSERT_TRUE(wss_server_.Start()); |
| 66 | 79 |
| 67 // Setup page title observer. | 80 // Setup page title observer. |
| 68 content::WebContents* tab = | 81 content::WebContents* tab = |
| 69 browser()->tab_strip_model()->GetActiveWebContents(); | 82 browser()->tab_strip_model()->GetActiveWebContents(); |
| 70 content::TitleWatcher watcher(tab, base::ASCIIToUTF16("PASS")); | 83 content::TitleWatcher watcher(tab, base::ASCIIToUTF16("PASS")); |
| 71 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); | 84 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
| 72 | 85 |
| 73 // Visit a HTTPS page for testing. | 86 NavigateToHTTPS("split_packet_check.html"); |
| 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 | 87 |
| 82 const base::string16 result = watcher.WaitAndGetTitle(); | 88 const base::string16 result = watcher.WaitAndGetTitle(); |
| 83 EXPECT_TRUE(EqualsASCII(result, "PASS")); | 89 EXPECT_TRUE(EqualsASCII(result, "PASS")); |
| 84 } | 90 } |
| 85 | 91 |
| 92 IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, SendCloseFrameWhenTabIsClosed) { | |
| 93 // Launch a secure WebSocket server. | |
|
Adam Rice
2014/07/14 10:17:20
Remove the word "secure".
yhirano
2014/07/14 11:24:35
Done.
| |
| 94 ASSERT_TRUE(ws_server_.Start()); | |
| 95 | |
| 96 content::WebContents* tab = | |
| 97 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 98 { | |
| 99 // Create a new tab, establish a WebSocket connection and close the tab. | |
| 100 content::WebContents* newTab = | |
| 101 content::WebContents::Create( | |
| 102 content::WebContents::CreateParams(tab->GetBrowserContext())); | |
| 103 browser()->tab_strip_model()->AppendWebContents(newTab, true); | |
| 104 ASSERT_EQ(newTab, browser()->tab_strip_model()->GetWebContentsAt(1)); | |
| 105 content::TitleWatcher title_watcher(newTab, | |
| 106 base::ASCIIToUTF16("CONNECTED")); | |
| 107 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("CLOSED")); | |
| 108 content::WebContentsDestroyedWatcher destroyed_watcher(newTab); | |
| 109 | |
| 110 NavigateToHTTP("connect.html"); | |
|
Adam Rice
2014/07/14 10:31:30
The name "connect.html" is too generic. How about
yhirano
2014/07/14 11:24:35
Done.
| |
| 111 const base::string16 result = title_watcher.WaitAndGetTitle(); | |
| 112 EXPECT_TRUE(EqualsASCII(result, "CONNECTED")); | |
| 113 browser()->tab_strip_model()->CloseWebContentsAt(1, 0); | |
| 114 destroyed_watcher.Wait(); | |
| 115 } | |
| 116 | |
| 117 content::TitleWatcher title_watcher(tab, base::ASCIIToUTF16("PASS")); | |
| 118 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); | |
| 119 | |
| 120 NavigateToHTTP("count-connection.html"); | |
| 121 const base::string16 result = title_watcher.WaitAndGetTitle(); | |
| 122 EXPECT_TRUE(EqualsASCII(result, "PASS")); | |
| 123 } | |
| 124 | |
| 86 } // namespace | 125 } // namespace |
| OLD | NEW |