Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/public/test/browser_test_utils.h" | |
| 6 #include "content/public/test/content_browser_test.h" | |
| 7 #include "content/public/test/content_browser_test_utils.h" | |
| 8 #include "content/shell/browser/shell.h" | |
| 9 #include "net/dns/host_resolver_proc.h" | |
| 10 #include "net/dns/mock_host_resolver.h" | |
| 11 #include "testing/gmock/include/gmock/gmock.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 using ::testing::_; | |
| 17 | |
| 18 class MockHostResolverProc : public net::HostResolverProc { | |
| 19 public: | |
| 20 MockHostResolverProc() : net::HostResolverProc(nullptr) {} | |
| 21 | |
| 22 MOCK_METHOD5(Resolve, | |
| 23 int(const std::string& host, | |
| 24 net::AddressFamily address_family, | |
| 25 net::HostResolverFlags flags, | |
| 26 net::AddressList* addresses, | |
| 27 int* os_error)); | |
| 28 | |
| 29 private: | |
| 30 ~MockHostResolverProc() override {} | |
| 31 }; | |
| 32 | |
| 33 class ResourceHintsBrowserTest : public ContentBrowserTest { | |
| 34 public: | |
| 35 ResourceHintsBrowserTest() | |
| 36 : mock_host_resolver_proc_(new MockHostResolverProc), | |
| 37 scoped_host_resolver_proc_(nullptr) {} | |
| 38 | |
| 39 protected: | |
| 40 scoped_refptr<MockHostResolverProc> mock_host_resolver_proc_; | |
| 41 std::unique_ptr<net::ScopedDefaultHostResolverProc> | |
| 42 scoped_host_resolver_proc_; | |
| 43 }; | |
| 44 | |
| 45 IN_PROC_BROWSER_TEST_F(ResourceHintsBrowserTest, DnsPrefetch) { | |
| 46 scoped_host_resolver_proc_.reset( | |
| 47 new net::ScopedDefaultHostResolverProc(mock_host_resolver_proc_.get())); | |
| 48 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 49 | |
| 50 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
| |
| 51 .Times(1); | |
| 52 EXPECT_CALL(*mock_host_resolver_proc_, | |
| 53 Resolve(testing::Ne("chromium.org"), _, _, _, _)) | |
| 54 .Times(0); | |
| 55 EXPECT_TRUE(NavigateToURL(shell(), embedded_test_server()->GetURL( | |
| 56 "/resource_hints/dns_prefetch.html"))); | |
| 57 EXPECT_TRUE( | |
| 58 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"))); | |
| 59 scoped_host_resolver_proc_.reset(); | |
| 60 } | |
| 61 | |
| 62 } // namespace content | |
| OLD | NEW |