| 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/dns_test_util.h" | 5 #include "net/dns/dns_test_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/big_endian.h" | 9 #include "base/big_endian.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/sys_byteorder.h" | 13 #include "base/sys_byteorder.h" |
| 14 #include "net/base/dns_util.h" | 14 #include "net/base/dns_util.h" |
| 15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/dns/address_sorter.h" | 17 #include "net/dns/address_sorter.h" |
| 18 #include "net/dns/dns_query.h" | 18 #include "net/dns/dns_query.h" |
| 19 #include "net/dns/dns_response.h" | 19 #include "net/dns/dns_response.h" |
| 20 #include "net/dns/dns_transaction.h" | 20 #include "net/dns/dns_transaction.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 class MockAddressSorter : public AddressSorter { | 26 class MockAddressSorter : public AddressSorter { |
| 27 public: | 27 public: |
| 28 virtual ~MockAddressSorter() {} | 28 ~MockAddressSorter() override {} |
| 29 virtual void Sort(const AddressList& list, | 29 void Sort(const AddressList& list, |
| 30 const CallbackType& callback) const override { | 30 const CallbackType& callback) const override { |
| 31 // Do nothing. | 31 // Do nothing. |
| 32 callback.Run(true, list); | 32 callback.Run(true, list); |
| 33 } | 33 } |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 // A DnsTransaction which uses MockDnsClientRuleList to determine the response. | 36 // A DnsTransaction which uses MockDnsClientRuleList to determine the response. |
| 37 class MockTransaction : public DnsTransaction, | 37 class MockTransaction : public DnsTransaction, |
| 38 public base::SupportsWeakPtr<MockTransaction> { | 38 public base::SupportsWeakPtr<MockTransaction> { |
| 39 public: | 39 public: |
| 40 MockTransaction(const MockDnsClientRuleList& rules, | 40 MockTransaction(const MockDnsClientRuleList& rules, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 }; | 159 }; |
| 160 | 160 |
| 161 } // namespace | 161 } // namespace |
| 162 | 162 |
| 163 // A DnsTransactionFactory which creates MockTransaction. | 163 // A DnsTransactionFactory which creates MockTransaction. |
| 164 class MockTransactionFactory : public DnsTransactionFactory { | 164 class MockTransactionFactory : public DnsTransactionFactory { |
| 165 public: | 165 public: |
| 166 explicit MockTransactionFactory(const MockDnsClientRuleList& rules) | 166 explicit MockTransactionFactory(const MockDnsClientRuleList& rules) |
| 167 : rules_(rules) {} | 167 : rules_(rules) {} |
| 168 | 168 |
| 169 virtual ~MockTransactionFactory() {} | 169 ~MockTransactionFactory() override {} |
| 170 | 170 |
| 171 virtual scoped_ptr<DnsTransaction> CreateTransaction( | 171 scoped_ptr<DnsTransaction> CreateTransaction( |
| 172 const std::string& hostname, | 172 const std::string& hostname, |
| 173 uint16 qtype, | 173 uint16 qtype, |
| 174 const DnsTransactionFactory::CallbackType& callback, | 174 const DnsTransactionFactory::CallbackType& callback, |
| 175 const BoundNetLog&) override { | 175 const BoundNetLog&) override { |
| 176 MockTransaction* transaction = | 176 MockTransaction* transaction = |
| 177 new MockTransaction(rules_, hostname, qtype, callback); | 177 new MockTransaction(rules_, hostname, qtype, callback); |
| 178 if (transaction->delayed()) | 178 if (transaction->delayed()) |
| 179 delayed_transactions_.push_back(transaction->AsWeakPtr()); | 179 delayed_transactions_.push_back(transaction->AsWeakPtr()); |
| 180 return scoped_ptr<DnsTransaction>(transaction); | 180 return scoped_ptr<DnsTransaction>(transaction); |
| 181 } | 181 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 220 |
| 221 AddressSorter* MockDnsClient::GetAddressSorter() { | 221 AddressSorter* MockDnsClient::GetAddressSorter() { |
| 222 return address_sorter_.get(); | 222 return address_sorter_.get(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void MockDnsClient::CompleteDelayedTransactions() { | 225 void MockDnsClient::CompleteDelayedTransactions() { |
| 226 factory_->CompleteDelayedTransactions(); | 226 factory_->CompleteDelayedTransactions(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace net | 229 } // namespace net |
| OLD | NEW |