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

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

Issue 922533003: Eliminated the logic that accumulated multiple preconnect requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added browser test Created 5 years, 10 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 | components/network_hints/renderer/renderer_preconnect.h » ('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 307c61c25604fb0f7ceb9c9982de881fc264bf9c..b8eab4eef9b8f1232c5cc2e9ce497ac797b22afc 100644
--- a/chrome/browser/net/predictor_browsertest.cc
+++ b/chrome/browser/net/predictor_browsertest.cc
@@ -2,8 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/base64.h"
+#include "base/command_line.h"
#include "base/json/json_string_value_serializer.h"
#include "base/prefs/pref_service.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/predictor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
@@ -11,7 +15,9 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/test_utils.h"
+#include "net/base/capturing_net_log_observer.h"
#include "net/base/net_errors.h"
+#include "net/base/net_log.h"
#include "net/dns/host_resolver_proc.h"
#include "net/dns/mock_host_resolver.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -21,6 +27,9 @@ using testing::HasSubstr;
namespace {
+const char kEnablePreconnect[] = "--enable-blink-features=LinkPreconnect";
+const char kEnableExperimentalWebPlatformFeatures[] =
+ "--enable-experimental-web-platform-features";
const char kChromiumHostname[] = "chromium.org";
// Records a history of all hostnames for which resolving has been requested,
@@ -111,6 +120,11 @@ class PredictorBrowserTest : public InProcessBrowserTest {
InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
}
+ void SetUpCommandLine(base::CommandLine* command_line) override {
+ command_line->AppendSwitch(kEnablePreconnect);
+ command_line->AppendSwitch(kEnableExperimentalWebPlatformFeatures);
+ }
+
void TearDownInProcessBrowserTestFixture() override {
InProcessBrowserTest::TearDownInProcessBrowserTestFixture();
scoped_host_resolver_proc_.reset();
@@ -200,5 +214,42 @@ IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, DnsPrefetch) {
WaitUntilHostHasBeenRequested(kChromiumHostname);
}
+IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, Preconnect) {
+ ASSERT_TRUE(test_server()->Start());
+
+ net::CapturingNetLogObserver net_log;
mmenke 2015/02/13 16:42:17 Calling a NetLogObserver net_log is a little confu
Pat Meenan 2015/02/13 20:45:26 Done.
+ g_browser_process->net_log()->AddThreadSafeObserver(&net_log,
+ net::NetLog::LOG_ALL_BUT_BYTES);
mmenke 2015/02/13 16:42:16 nit: Should indent 4, and move &net_log on to the
Pat Meenan 2015/02/13 20:45:26 Done.
+
+ // Create a HTML preconnect reference to the local server in the form
+ // <link rel="preconnect" href="http://test-server/">
+ // and navigate to it as a data URI. The only netlog activity to the test
+ // server will be as a result of parsing and making the preconnect request.
mmenke 2015/02/13 16:42:17 Claiming "The only netlog activity" is anything is
Pat Meenan 2015/02/13 20:45:26 Done.
+ std::string preconnect_url = test_server()->GetURL("").spec();
+ std::string preconnect_content = "<link rel=\"preconnect\" href=\"";
+ preconnect_content += preconnect_url + "\">";
+ std::string data_uri = "data:text/html;base64,";
+ std::string encoded;
+ base::Base64Encode(preconnect_content, &encoded);
+ data_uri += encoded;
mmenke 2015/02/13 16:42:17 nit: Suggest merging this line with the one where
mmenke 2015/02/13 16:42:17 optional: Do we have to base64 encode it? "data:
Pat Meenan 2015/02/13 20:45:26 We either need to base64 encode or URL encode it.
+
+ ui_test_utils::NavigateToURL(browser(), GURL(data_uri));
mmenke 2015/02/13 16:42:16 For this to be non-racy, we're depending on the pr
Pat Meenan 2015/02/13 20:45:26 My original implementation had a custom observer w
mmenke 2015/02/13 20:55:05 I must be missing something...Why doesn't this wor
+
+ // Look through the recorded netlog events for the URL that we specified
mmenke 2015/02/13 16:42:17 nit: netlog -> NetLog
Pat Meenan 2015/02/13 20:45:26 Done.
+ // in the preconnect request.
+ bool saw_preconnect_request = false;
+ g_browser_process->net_log()->RemoveThreadSafeObserver(&net_log);
mmenke 2015/02/13 16:42:17 nit: This should probably go above this code bloc
Pat Meenan 2015/02/13 20:45:26 Done.
+ net::CapturedNetLogEntry::List list;
+ net_log.GetEntries(&list);
+ for (const auto& entry : list) {
+ if (entry.GetParamsJson().find(preconnect_url)) {
+ saw_preconnect_request = true;
+ break;
+ }
+ }
+
+ ASSERT_TRUE(saw_preconnect_request);
mmenke 2015/02/13 16:42:16 nit: EXPECT_TRUE?
Pat Meenan 2015/02/13 20:45:26 Done.
+}
+
} // namespace chrome_browser_net
« no previous file with comments | « no previous file | components/network_hints/renderer/renderer_preconnect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698