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

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

Issue 1007323003: DNS Prefetch fix: renderer shouldn't send long hostnames to browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: explicitly test long string not requested Created 5 years, 9 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
« no previous file with comments | « no previous file | chrome/test/data/predictor/dns_prefetch.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/predictor_browsertest.cc
diff --git a/chrome/browser/net/predictor_browsertest.cc b/chrome/browser/net/predictor_browsertest.cc
index 94d389ff2ac4065dbbc1863dafd942c65d8286ae..6255237a3c546459c05765349b236d3a681f2743 100644
--- a/chrome/browser/net/predictor_browsertest.cc
+++ b/chrome/browser/net/predictor_browsertest.cc
@@ -30,6 +30,11 @@ namespace {
const char kBlinkPreconnectFeature[] = "LinkPreconnect";
const char kChromiumHostname[] = "chromium.org";
+const char kInvalidLongHostname[] = "illegally-long-hostname-over-255-"
+ "characters-should-not-send-an-ipc-message-to-the-browser-"
+ "0000000000000000000000000000000000000000000000000000000000000000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000.org";
// Records a history of all hostnames for which resolving has been requested,
// and immediately fails the resolution requests themselves.
@@ -54,7 +59,11 @@ class HostResolutionRequestRecorder : public net::HostResolverProc {
return net::ERR_NAME_NOT_RESOLVED;
}
- bool HasHostBeenRequested(const std::string& hostname) {
+ int RequestedHostnameCount() const {
+ return requested_hostnames_.size();
+ }
+
+ bool HasHostBeenRequested(const std::string& hostname) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
return std::find(requested_hostnames_.begin(),
requested_hostnames_.end(),
@@ -210,10 +219,18 @@ class PredictorBrowserTest : public InProcessBrowserTest {
serializer.Serialize(*list_value);
}
+ bool HasHostBeenRequested(const std::string& hostname) const {
+ return host_resolution_request_recorder_->HasHostBeenRequested(hostname);
+ }
+
void WaitUntilHostHasBeenRequested(const std::string& hostname) {
host_resolution_request_recorder_->WaitUntilHostHasBeenRequested(hostname);
}
+ int RequestedHostnameCount() const {
+ return host_resolution_request_recorder_->RequestedHostnameCount();
+ }
+
const GURL startup_url_;
const GURL referring_url_;
const GURL target_url_;
@@ -254,10 +271,13 @@ IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, ShutdownStartupCycle) {
IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, DnsPrefetch) {
ASSERT_TRUE(test_server()->Start());
+ int hostnames_requested_before_load = RequestedHostnameCount();
ui_test_utils::NavigateToURL(
browser(),
GURL(test_server()->GetURL("files/predictor/dns_prefetch.html")));
WaitUntilHostHasBeenRequested(kChromiumHostname);
+ ASSERT_FALSE(HasHostBeenRequested(kInvalidLongHostname));
+ ASSERT_EQ(hostnames_requested_before_load + 1, RequestedHostnameCount());
}
IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, Preconnect) {
« no previous file with comments | « no previous file | chrome/test/data/predictor/dns_prefetch.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698