| OLD | NEW |
| 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 "net/base/address_list.h" | 7 #include "net/base/address_list.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "net/base/net_log.h" | 9 #include "net/base/net_log.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 "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Helper class used by SingleRequestHostResolverTest.Cancel test. | 18 // Helper class used by SingleRequestHostResolverTest.Cancel test. |
| 19 // It checks that only one request is outstanding at a time, and that | 19 // It checks that only one request is outstanding at a time, and that |
| 20 // it is cancelled before the class is destroyed. | 20 // it is cancelled before the class is destroyed. |
| 21 class HangingHostResolver : public HostResolver { | 21 class HangingHostResolver : public HostResolver { |
| 22 public: | 22 public: |
| 23 HangingHostResolver() : outstanding_request_(NULL) {} | 23 HangingHostResolver() : outstanding_request_(NULL) {} |
| 24 | 24 |
| 25 virtual ~HangingHostResolver() { | 25 virtual ~HangingHostResolver() { EXPECT_TRUE(!has_outstanding_request()); } |
| 26 EXPECT_TRUE(!has_outstanding_request()); | |
| 27 } | |
| 28 | 26 |
| 29 bool has_outstanding_request() const { | 27 bool has_outstanding_request() const { return outstanding_request_ != NULL; } |
| 30 return outstanding_request_ != NULL; | |
| 31 } | |
| 32 | 28 |
| 33 virtual int Resolve(const RequestInfo& info, | 29 virtual int Resolve(const RequestInfo& info, |
| 34 RequestPriority priority, | 30 RequestPriority priority, |
| 35 AddressList* addresses, | 31 AddressList* addresses, |
| 36 const CompletionCallback& callback, | 32 const CompletionCallback& callback, |
| 37 RequestHandle* out_req, | 33 RequestHandle* out_req, |
| 38 const BoundNetLog& net_log) OVERRIDE { | 34 const BoundNetLog& net_log) OVERRIDE { |
| 39 EXPECT_FALSE(has_outstanding_request()); | 35 EXPECT_FALSE(has_outstanding_request()); |
| 40 outstanding_request_ = reinterpret_cast<RequestHandle>(0x1234); | 36 outstanding_request_ = reinterpret_cast<RequestHandle>(0x1234); |
| 41 *out_req = outstanding_request_; | 37 *out_req = outstanding_request_; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // request. | 112 // request. |
| 117 TEST(SingleRequestHostResolverTest, CancelWhileNoPendingRequest) { | 113 TEST(SingleRequestHostResolverTest, CancelWhileNoPendingRequest) { |
| 118 HangingHostResolver resolver; | 114 HangingHostResolver resolver; |
| 119 SingleRequestHostResolver single_request_resolver(&resolver); | 115 SingleRequestHostResolver single_request_resolver(&resolver); |
| 120 single_request_resolver.Cancel(); | 116 single_request_resolver.Cancel(); |
| 121 | 117 |
| 122 // To pass, HangingHostResolver should not have received a cancellation | 118 // To pass, HangingHostResolver should not have received a cancellation |
| 123 // request (since there is nothing to cancel). If it does, it will crash. | 119 // request (since there is nothing to cancel). If it does, it will crash. |
| 124 } | 120 } |
| 125 | 121 |
| 126 } // namespace | 122 } // namespace |
| 127 | 123 |
| 128 } // namespace net | 124 } // namespace net |
| OLD | NEW |