Index: chrome/browser/net/predictor_browsertest.cc |
diff --git a/chrome/browser/net/predictor_browsertest.cc b/chrome/browser/net/predictor_browsertest.cc |
index c4ebc559fd76ea783fa357a164c99dbea33be3f7..6abe98fad846c13feb795f0ffc7386451e6ab466 100644 |
--- a/chrome/browser/net/predictor_browsertest.cc |
+++ b/chrome/browser/net/predictor_browsertest.cc |
@@ -61,6 +61,7 @@ class ConnectionListener |
const net::test_server::StreamListenSocket& connection) override { |
base::AutoLock lock(lock_); |
uint16_t socket = GetPort(connection); |
+ printf("Socket %d\n", socket); |
Ryan Sleevi
2015/07/10 09:46:45
*cough* :P
Yoav Weiss
2015/07/10 10:03:40
Doh! I got accustomed to Blink's cl upload hooks y
|
EXPECT_TRUE(sockets_.find(socket) == sockets_.end()); |
sockets_[socket] = SOCKET_ACCEPTED; |
@@ -104,7 +105,7 @@ class ConnectionListener |
static uint16_t GetPort( |
const net::test_server::StreamListenSocket& connection) { |
net::IPEndPoint address; |
- EXPECT_EQ(net::OK, connection.GetLocalAddress(&address)); |
+ EXPECT_EQ(net::OK, connection.GetPeerAddress(&address)); |
Ryan Sleevi
2015/07/10 09:46:45
Wait, what? Why this change?
Connections are a tu
Yoav Weiss
2015/07/10 10:03:40
GetLocal gives me the port number of the local lis
Ryan Sleevi
2015/07/10 10:09:35
Right, that's basically what I was assuming, but w
|
return address.port(); |
} |
@@ -350,7 +351,7 @@ IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, MAYBE_DnsPrefetch) { |
// Tests that preconnect warms up a socket connection to a test server. |
// Note: This test uses a data URI to serve the preconnect hint, to make sure |
// that the network stack doesn't just re-use its connection to the test server. |
-IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, Preconnect) { |
+IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectNonCORS) { |
GURL preconnect_url = embedded_test_server()->base_url(); |
std::string preconnect_content = |
"<link rel=\"preconnect\" href=\"" + preconnect_url.spec() + "\">"; |
@@ -364,7 +365,7 @@ IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, Preconnect) { |
// and that that socket is later used when fetching a resource. |
// Note: This test uses a data URI to serve the preconnect hint, to make sure |
// that the network stack doesn't just re-use its connection to the test server. |
-IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectAndUse) { |
+IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectAndFetchNonCORS) { |
GURL preconnect_url = embedded_test_server()->base_url(); |
// First navigation to content with a preconnect hint. |
std::string preconnect_content = |
@@ -383,5 +384,76 @@ IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectAndUse) { |
EXPECT_EQ(1u, connection_listener_->GetReadSocketCount()); |
} |
+// Tests that preconnect warms up a CORS connection to a test |
+// server, and that socket is later used when fetching a CORS resource. |
+// Note: This test uses a data URI to serve the preconnect hint, to make sure |
+// that the network stack doesn't just re-use its connection to the test server. |
+IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectAndFetchCORS) { |
+ GURL preconnect_url = embedded_test_server()->base_url(); |
+ // First navigation to content with a preconnect hint. |
+ std::string preconnect_content = "<link rel=\"preconnect\" href=\"" + |
+ preconnect_url.spec() + "\" crossorigin>"; |
+ NavigateToDataURLWithContent(preconnect_content); |
+ connection_listener_->WaitUntilFirstConnectionAccepted(); |
+ EXPECT_EQ(1u, connection_listener_->GetAcceptedSocketCount()); |
+ EXPECT_EQ(0u, connection_listener_->GetReadSocketCount()); |
+ |
+ // Second navigation to content with a font. |
+ std::string font_content = "<script>var font = new FontFace('FontA', 'url(" + |
+ preconnect_url.spec() + |
+ "test.woff2)');font.load();</script>"; |
+ NavigateToDataURLWithContent(font_content); |
+ connection_listener_->WaitUntilFirstConnectionRead(); |
+ EXPECT_EQ(1u, connection_listener_->GetAcceptedSocketCount()); |
+ EXPECT_EQ(1u, connection_listener_->GetReadSocketCount()); |
+} |
+ |
+// Tests that preconnect warms up a non-CORS connection to a test |
+// server, but that socket is not used when fetching a CORS resource. |
+// Note: This test uses a data URI to serve the preconnect hint, to make sure |
+// that the network stack doesn't just re-use its connection to the test server. |
+IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectNonCORSAndFetchCORS) { |
+ GURL preconnect_url = embedded_test_server()->base_url(); |
+ // First navigation to content with a preconnect hint. |
+ std::string preconnect_content = |
+ "<link rel=\"preconnect\" href=\"" + preconnect_url.spec() + "\">"; |
+ NavigateToDataURLWithContent(preconnect_content); |
+ connection_listener_->WaitUntilFirstConnectionAccepted(); |
+ EXPECT_EQ(1u, connection_listener_->GetAcceptedSocketCount()); |
+ EXPECT_EQ(0u, connection_listener_->GetReadSocketCount()); |
+ |
+ // Second navigation to content with a font. |
+ std::string font_content = "<script>var font = new FontFace('FontA', 'url(" + |
+ preconnect_url.spec() + |
+ "test.woff2)');font.load();</script>"; |
+ NavigateToDataURLWithContent(font_content); |
+ connection_listener_->WaitUntilFirstConnectionRead(); |
+ EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount()); |
+ EXPECT_EQ(1u, connection_listener_->GetReadSocketCount()); |
+} |
+ |
+// Tests that preconnect warms up a CORS connection to a test server, |
+// but that socket is not used when fetching a non-CORS resource. |
+// Note: This test uses a data URI to serve the preconnect hint, to make sure |
+// that the network stack doesn't just re-use its connection to the test server. |
+IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectCORSAndFetchNonCORS) { |
+ GURL preconnect_url = embedded_test_server()->base_url(); |
+ // First navigation to content with a preconnect hint. |
+ std::string preconnect_content = "<link rel=\"preconnect\" href=\"" + |
+ preconnect_url.spec() + "\" crossorigin>"; |
+ NavigateToDataURLWithContent(preconnect_content); |
+ connection_listener_->WaitUntilFirstConnectionAccepted(); |
+ EXPECT_EQ(1u, connection_listener_->GetAcceptedSocketCount()); |
+ EXPECT_EQ(0u, connection_listener_->GetReadSocketCount()); |
+ |
+ // Second navigation to content with an img. |
+ std::string img_content = |
+ "<img src=\"" + preconnect_url.spec() + "test.gif\">"; |
+ NavigateToDataURLWithContent(img_content); |
+ connection_listener_->WaitUntilFirstConnectionRead(); |
+ EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount()); |
+ EXPECT_EQ(1u, connection_listener_->GetReadSocketCount()); |
+} |
+ |
} // namespace chrome_browser_net |