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

Side by Side Diff: net/dns/single_request_host_resolver_unittest.cc

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/single_request_host_resolver.h" 5 #include "net/dns/single_request_host_resolver.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "net/base/address_list.h" 8 #include "net/base/address_list.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/base/test_completion_callback.h" 10 #include "net/base/test_completion_callback.h"
11 #include "net/dns/mock_host_resolver.h" 11 #include "net/dns/mock_host_resolver.h"
12 #include "net/log/net_log.h" 12 #include "net/log/net_log.h"
13 #include "net/test/gtest_util.h"
14 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
17 using net::test::IsError;
18 using net::test::IsOk;
19
15 namespace net { 20 namespace net {
16 21
17 namespace { 22 namespace {
18 23
19 // Helper class used by SingleRequestHostResolverTest.Cancel test. 24 // Helper class used by SingleRequestHostResolverTest.Cancel test.
20 // It checks that only one request is outstanding at a time, and that 25 // It checks that only one request is outstanding at a time, and that
21 // it is cancelled before the class is destroyed. 26 // it is cancelled before the class is destroyed.
22 class HangingHostResolver : public HostResolver { 27 class HangingHostResolver : public HostResolver {
23 public: 28 public:
24 HangingHostResolver() : outstanding_request_(NULL) {} 29 HangingHostResolver() : outstanding_request_(NULL) {}
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 resolver.rules()->AddIPLiteralRule("watsup", "199.188.1.166", std::string()); 76 resolver.rules()->AddIPLiteralRule("watsup", "199.188.1.166", std::string());
72 77
73 SingleRequestHostResolver single_request_resolver(&resolver); 78 SingleRequestHostResolver single_request_resolver(&resolver);
74 79
75 // Resolve "watsup:90" using our SingleRequestHostResolver. 80 // Resolve "watsup:90" using our SingleRequestHostResolver.
76 AddressList addrlist; 81 AddressList addrlist;
77 TestCompletionCallback callback; 82 TestCompletionCallback callback;
78 HostResolver::RequestInfo request(HostPortPair("watsup", 90)); 83 HostResolver::RequestInfo request(HostPortPair("watsup", 90));
79 int rv = single_request_resolver.Resolve( 84 int rv = single_request_resolver.Resolve(
80 request, DEFAULT_PRIORITY, &addrlist, callback.callback(), BoundNetLog()); 85 request, DEFAULT_PRIORITY, &addrlist, callback.callback(), BoundNetLog());
81 EXPECT_EQ(ERR_IO_PENDING, rv); 86 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
82 EXPECT_EQ(OK, callback.WaitForResult()); 87 EXPECT_THAT(callback.WaitForResult(), IsOk());
83 88
84 // Verify that the result is what we specified in the MockHostResolver. 89 // Verify that the result is what we specified in the MockHostResolver.
85 ASSERT_FALSE(addrlist.empty()); 90 ASSERT_FALSE(addrlist.empty());
86 EXPECT_EQ("199.188.1.166", addrlist.front().ToStringWithoutPort()); 91 EXPECT_EQ("199.188.1.166", addrlist.front().ToStringWithoutPort());
87 } 92 }
88 93
89 // Test that the Cancel() method cancels any outstanding request. 94 // Test that the Cancel() method cancels any outstanding request.
90 TEST(SingleRequestHostResolverTest, Cancel) { 95 TEST(SingleRequestHostResolverTest, Cancel) {
91 HangingHostResolver resolver; 96 HangingHostResolver resolver;
92 97
93 { 98 {
94 SingleRequestHostResolver single_request_resolver(&resolver); 99 SingleRequestHostResolver single_request_resolver(&resolver);
95 100
96 // Resolve "watsup:90" using our SingleRequestHostResolver. 101 // Resolve "watsup:90" using our SingleRequestHostResolver.
97 AddressList addrlist; 102 AddressList addrlist;
98 TestCompletionCallback callback; 103 TestCompletionCallback callback;
99 HostResolver::RequestInfo request(HostPortPair("watsup", 90)); 104 HostResolver::RequestInfo request(HostPortPair("watsup", 90));
100 int rv = single_request_resolver.Resolve(request, 105 int rv = single_request_resolver.Resolve(request,
101 DEFAULT_PRIORITY, 106 DEFAULT_PRIORITY,
102 &addrlist, 107 &addrlist,
103 callback.callback(), 108 callback.callback(),
104 BoundNetLog()); 109 BoundNetLog());
105 EXPECT_EQ(ERR_IO_PENDING, rv); 110 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
106 EXPECT_TRUE(resolver.has_outstanding_request()); 111 EXPECT_TRUE(resolver.has_outstanding_request());
107 } 112 }
108 113
109 // Now that the SingleRequestHostResolver has been destroyed, the 114 // Now that the SingleRequestHostResolver has been destroyed, the
110 // in-progress request should have been aborted. 115 // in-progress request should have been aborted.
111 EXPECT_FALSE(resolver.has_outstanding_request()); 116 EXPECT_FALSE(resolver.has_outstanding_request());
112 } 117 }
113 118
114 // Test that the Cancel() method is a no-op when there is no outstanding 119 // Test that the Cancel() method is a no-op when there is no outstanding
115 // request. 120 // request.
116 TEST(SingleRequestHostResolverTest, CancelWhileNoPendingRequest) { 121 TEST(SingleRequestHostResolverTest, CancelWhileNoPendingRequest) {
117 HangingHostResolver resolver; 122 HangingHostResolver resolver;
118 SingleRequestHostResolver single_request_resolver(&resolver); 123 SingleRequestHostResolver single_request_resolver(&resolver);
119 single_request_resolver.Cancel(); 124 single_request_resolver.Cancel();
120 125
121 // To pass, HangingHostResolver should not have received a cancellation 126 // To pass, HangingHostResolver should not have received a cancellation
122 // request (since there is nothing to cancel). If it does, it will crash. 127 // request (since there is nothing to cancel). If it does, it will crash.
123 } 128 }
124 129
125 } // namespace 130 } // namespace
126 131
127 } // namespace net 132 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/mojo_host_resolver_impl_unittest.cc ('k') | net/ftp/ftp_ctrl_response_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698