| Index: content/browser/loader/resource_hints_browsertest.cc
|
| diff --git a/content/browser/loader/resource_hints_browsertest.cc b/content/browser/loader/resource_hints_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a7ba00ad2011e5eeac2d31a753a020f02d2d4aaa
|
| --- /dev/null
|
| +++ b/content/browser/loader/resource_hints_browsertest.cc
|
| @@ -0,0 +1,89 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <algorithm>
|
| +
|
| +#include "content/public/test/browser_test_utils.h"
|
| +#include "content/public/test/content_browser_test.h"
|
| +#include "content/public/test/content_browser_test_utils.h"
|
| +#include "content/shell/browser/shell.h"
|
| +#include "net/dns/host_resolver_proc.h"
|
| +#include "net/dns/mock_host_resolver.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace content {
|
| +
|
| +class MockHostResolverProc : public net::HostResolverProc {
|
| + public:
|
| + MockHostResolverProc() : net::HostResolverProc(nullptr) {}
|
| +
|
| + int Resolve(const std::string& host,
|
| + net::AddressFamily address_family,
|
| + net::HostResolverFlags flags,
|
| + net::AddressList* addresses,
|
| + int* os_error) override {
|
| + requests_.push_back(host);
|
| + return 0;
|
| + }
|
| +
|
| + size_t num_requests() { return requests_.size(); }
|
| +
|
| + bool host_requested(std::string host) {
|
| + return std::find(requests_.begin(), requests_.end(), host) !=
|
| + requests_.end();
|
| + }
|
| +
|
| + private:
|
| + ~MockHostResolverProc() override {}
|
| +
|
| + std::vector<std::string> requests_;
|
| +};
|
| +
|
| +class ResourceHintsBrowserTest : public ContentBrowserTest {
|
| + public:
|
| + ResourceHintsBrowserTest()
|
| + : mock_host_resolver_proc_(new MockHostResolverProc),
|
| + scoped_host_resolver_proc_(nullptr) {}
|
| +
|
| + protected:
|
| + scoped_refptr<MockHostResolverProc> mock_host_resolver_proc_;
|
| + std::unique_ptr<net::ScopedDefaultHostResolverProc>
|
| + scoped_host_resolver_proc_;
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ResourceHintsBrowserTest, DnsPrefetch) {
|
| + scoped_host_resolver_proc_.reset(
|
| + new net::ScopedDefaultHostResolverProc(mock_host_resolver_proc_.get()));
|
| + ASSERT_TRUE(embedded_test_server()->Start());
|
| +
|
| + EXPECT_TRUE(NavigateToURL(shell(), embedded_test_server()->GetURL(
|
| + "/resource_hints/dns_prefetch.html")));
|
| + EXPECT_TRUE(
|
| + NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")));
|
| +
|
| + EXPECT_EQ(mock_host_resolver_proc_->num_requests(), 1u);
|
| + EXPECT_TRUE(mock_host_resolver_proc_->host_requested("chromium.org"));
|
| + scoped_host_resolver_proc_.reset();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ResourceHintsBrowserTest, DnsPrefetchMany) {
|
| + scoped_host_resolver_proc_.reset(
|
| + new net::ScopedDefaultHostResolverProc(mock_host_resolver_proc_.get()));
|
| + ASSERT_TRUE(embedded_test_server()->Start());
|
| +
|
| + EXPECT_TRUE(
|
| + NavigateToURL(shell(), embedded_test_server()->GetURL(
|
| + "/resource_hints/dns_prefetch_many.html")));
|
| + EXPECT_TRUE(
|
| + NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")));
|
| +
|
| + EXPECT_EQ(mock_host_resolver_proc_->num_requests(), 4u);
|
| + EXPECT_TRUE(mock_host_resolver_proc_->host_requested("chromium1.org"));
|
| + EXPECT_TRUE(mock_host_resolver_proc_->host_requested("chromium2.org"));
|
| + EXPECT_TRUE(mock_host_resolver_proc_->host_requested("chromium3.org"));
|
| + EXPECT_TRUE(mock_host_resolver_proc_->host_requested("chromium4.org"));
|
| + scoped_host_resolver_proc_.reset();
|
| +}
|
| +
|
| +} // namespace content
|
|
|