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

Side by Side Diff: chrome/browser/net/predictor_browsertest.cc

Issue 2043753002: Declarative resource hints go through mojo IPC to //content Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove gmocking + add another browser test Created 4 years, 6 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 unified diff | Download patch
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 18 matching lines...) Expand all
29 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
30 #include "chrome/test/base/in_process_browser_test.h" 30 #include "chrome/test/base/in_process_browser_test.h"
31 #include "chrome/test/base/ui_test_utils.h" 31 #include "chrome/test/base/ui_test_utils.h"
32 #include "components/prefs/pref_service.h" 32 #include "components/prefs/pref_service.h"
33 #include "content/public/common/content_switches.h" 33 #include "content/public/common/content_switches.h"
34 #include "content/public/test/browser_test_utils.h" 34 #include "content/public/test/browser_test_utils.h"
35 #include "content/public/test/test_utils.h" 35 #include "content/public/test/test_utils.h"
36 #include "net/base/host_port_pair.h" 36 #include "net/base/host_port_pair.h"
37 #include "net/base/ip_endpoint.h" 37 #include "net/base/ip_endpoint.h"
38 #include "net/base/net_errors.h" 38 #include "net/base/net_errors.h"
39 #include "net/dns/host_resolver_proc.h"
40 #include "net/dns/mock_host_resolver.h" 39 #include "net/dns/mock_host_resolver.h"
41 #include "net/http/http_transaction_factory.h" 40 #include "net/http/http_transaction_factory.h"
42 #include "net/socket/stream_socket.h" 41 #include "net/socket/stream_socket.h"
43 #include "net/test/embedded_test_server/embedded_test_server.h" 42 #include "net/test/embedded_test_server/embedded_test_server.h"
44 #include "net/test/embedded_test_server/embedded_test_server_connection_listener .h" 43 #include "net/test/embedded_test_server/embedded_test_server_connection_listener .h"
45 #include "net/test/embedded_test_server/http_request.h" 44 #include "net/test/embedded_test_server/http_request.h"
46 #include "net/test/embedded_test_server/http_response.h" 45 #include "net/test/embedded_test_server/http_response.h"
47 #include "net/test/url_request/url_request_failed_job.h" 46 #include "net/test/url_request/url_request_failed_job.h"
48 #include "net/url_request/url_request_context.h" 47 #include "net/url_request/url_request_context.h"
49 #include "net/url_request/url_request_context_getter.h" 48 #include "net/url_request/url_request_context_getter.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 if (request.GetURL().path() != path) 90 if (request.GetURL().path() != path)
92 return nullptr; 91 return nullptr;
93 std::unique_ptr<net::test_server::BasicHttpResponse> response( 92 std::unique_ptr<net::test_server::BasicHttpResponse> response(
94 new net::test_server::BasicHttpResponse); 93 new net::test_server::BasicHttpResponse);
95 response->set_code(net::HTTP_MOVED_PERMANENTLY); 94 response->set_code(net::HTTP_MOVED_PERMANENTLY);
96 response->AddCustomHeader("Location", redirect_url.spec()); 95 response->AddCustomHeader("Location", redirect_url.spec());
97 return std::move(response); 96 return std::move(response);
98 } 97 }
99 98
100 const char kBlinkPreconnectFeature[] = "LinkPreconnect"; 99 const char kBlinkPreconnectFeature[] = "LinkPreconnect";
101 const char kChromiumUrl[] = "http://chromium.org";
102 const char kInvalidLongUrl[] =
103 "http://"
104 "illegally-long-hostname-over-255-characters-should-not-send-an-ipc-"
105 "message-to-the-browser-"
106 "00000000000000000000000000000000000000000000000000000000000000000000000000"
107 "00000000000000000000000000000000000000000000000000000000000000000000000000"
108 "0000000000000000000000000000000000000000000000000000.org";
109 100
110 // Gets notified by the EmbeddedTestServer on incoming connections being 101 // Gets notified by the EmbeddedTestServer on incoming connections being
111 // accepted or read from, keeps track of them and exposes that info to 102 // accepted or read from, keeps track of them and exposes that info to
112 // the tests. 103 // the tests.
113 // A port being reused is currently considered an error. If a test 104 // A port being reused is currently considered an error. If a test
114 // needs to verify multiple connections are opened in sequence, that will need 105 // needs to verify multiple connections are opened in sequence, that will need
115 // to be changed. 106 // to be changed.
116 class ConnectionListener 107 class ConnectionListener
117 : public net::test_server::EmbeddedTestServerConnectionListener { 108 : public net::test_server::EmbeddedTestServerConnectionListener {
118 public: 109 public:
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 // inspecting that the Predictor starts making the expected hostname requests. 1369 // inspecting that the Predictor starts making the expected hostname requests.
1379 PrepareFrameSubresources(referring_url_); 1370 PrepareFrameSubresources(referring_url_);
1380 observer()->WaitUntilHostLookedUp(target_url_); 1371 observer()->WaitUntilHostLookedUp(target_url_);
1381 1372
1382 // Verify that both urls were requested by the predictor. Note that the 1373 // Verify that both urls were requested by the predictor. Note that the
1383 // startup URL may be requested before the observer attaches itself. 1374 // startup URL may be requested before the observer attaches itself.
1384 ExpectUrlRequestedFromPredictor(startup_url_); 1375 ExpectUrlRequestedFromPredictor(startup_url_);
1385 EXPECT_FALSE(observer()->HostFound(target_url_)); 1376 EXPECT_FALSE(observer()->HostFound(target_url_));
1386 } 1377 }
1387 1378
1388 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, DnsPrefetch) {
1389 // Navigate once to make sure all initial hostnames are requested.
1390 ui_test_utils::NavigateToURL(browser(),
1391 embedded_test_server()->GetURL("/title1.html"));
1392
1393 size_t hosts_looked_up_before_load = observer()->TotalHostsLookedUp();
1394
1395 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(
1396 "/predictor/dns_prefetch.html"));
1397 observer()->WaitUntilHostLookedUp(GURL(kChromiumUrl));
1398 ASSERT_FALSE(observer()->HasHostBeenLookedUp(GURL(kInvalidLongUrl)));
1399
1400 EXPECT_FALSE(observer()->HostFound(GURL(kChromiumUrl)));
1401 ASSERT_EQ(hosts_looked_up_before_load + 1, observer()->TotalHostsLookedUp());
1402 }
1403
1404 // Tests that preconnect warms up a socket connection to a test server. 1379 // Tests that preconnect warms up a socket connection to a test server.
1405 // Note: This test uses a data URI to serve the preconnect hint, to make sure 1380 // Note: This test uses a data URI to serve the preconnect hint, to make sure
1406 // that the network stack doesn't just re-use its connection to the test server. 1381 // that the network stack doesn't just re-use its connection to the test server.
1382 // TODO(csharrison): Move these tests to //content/browser/loader. Now that
1383 // resource hints have migrated to live there. This might require sharing the
1384 // preconnect test harness logic.
1407 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectNonCORS) { 1385 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectNonCORS) {
1408 GURL preconnect_url = embedded_test_server()->base_url(); 1386 GURL preconnect_url = embedded_test_server()->base_url();
1409 std::string preconnect_content = 1387 std::string preconnect_content =
1410 "<link rel=\"preconnect\" href=\"" + preconnect_url.spec() + "\">"; 1388 "<link rel=\"preconnect\" href=\"" + preconnect_url.spec() + "\">";
1411 NavigateToDataURLWithContent(preconnect_content); 1389 NavigateToDataURLWithContent(preconnect_content);
1412 connection_listener_->WaitUntilFirstConnectionAccepted(); 1390 connection_listener_->WaitUntilFirstConnectionAccepted();
1413 EXPECT_EQ(1u, connection_listener_->GetAcceptedSocketCount()); 1391 EXPECT_EQ(1u, connection_listener_->GetAcceptedSocketCount());
1414 EXPECT_EQ(0u, connection_listener_->GetReadSocketCount()); 1392 EXPECT_EQ(0u, connection_listener_->GetReadSocketCount());
1415 } 1393 }
1416 1394
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 // Second navigation to content with an img. 1480 // Second navigation to content with an img.
1503 std::string img_content = 1481 std::string img_content =
1504 "<img src=\"" + preconnect_url.spec() + "test.gif\">"; 1482 "<img src=\"" + preconnect_url.spec() + "test.gif\">";
1505 NavigateToDataURLWithContent(img_content); 1483 NavigateToDataURLWithContent(img_content);
1506 connection_listener_->WaitUntilFirstConnectionRead(); 1484 connection_listener_->WaitUntilFirstConnectionRead();
1507 EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount()); 1485 EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount());
1508 EXPECT_EQ(1u, connection_listener_->GetReadSocketCount()); 1486 EXPECT_EQ(1u, connection_listener_->GetReadSocketCount());
1509 } 1487 }
1510 1488
1511 } // namespace chrome_browser_net 1489 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698