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..156c8ccdcdd346dbfeb3b4f6eb9ee48be4cae8ff |
--- /dev/null |
+++ b/content/browser/loader/resource_hints_browsertest.cc |
@@ -0,0 +1,62 @@ |
+// 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 "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/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace content { |
+ |
+using ::testing::_; |
+ |
+class MockHostResolverProc : public net::HostResolverProc { |
+ public: |
+ MockHostResolverProc() : net::HostResolverProc(nullptr) {} |
+ |
+ MOCK_METHOD5(Resolve, |
+ int(const std::string& host, |
+ net::AddressFamily address_family, |
+ net::HostResolverFlags flags, |
+ net::AddressList* addresses, |
+ int* os_error)); |
+ |
+ private: |
+ ~MockHostResolverProc() override {} |
+}; |
+ |
+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_CALL(*mock_host_resolver_proc_, Resolve("chromium.org", _, _, _, _)) |
mmenke
2016/06/17 20:05:36
I'd recommend against using Gmock - it reduces the
Charlie Harrison
2016/06/19 11:01:56
Hm. I think I disagree with you. To extend these t
|
+ .Times(1); |
+ EXPECT_CALL(*mock_host_resolver_proc_, |
+ Resolve(testing::Ne("chromium.org"), _, _, _, _)) |
+ .Times(0); |
+ EXPECT_TRUE(NavigateToURL(shell(), embedded_test_server()->GetURL( |
+ "/resource_hints/dns_prefetch.html"))); |
+ EXPECT_TRUE( |
+ NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"))); |
+ scoped_host_resolver_proc_.reset(); |
+} |
+ |
+} // namespace content |