Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3324)

Unified Diff: chrome/browser/net/predictor_browsertest.cc

Issue 1131293004: Add cross origin to Blink-driven preconnect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added more tests and fixed a test bug Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698