| 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_transaction.h" | 5 #include "net/dns/dns_transaction.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 const char* data, | 235 const char* data, |
| 236 size_t data_length) { | 236 size_t data_length) { |
| 237 CHECK(socket_factory_.get()); | 237 CHECK(socket_factory_.get()); |
| 238 DnsQuery* query = new DnsQuery(id, DomainFromDot(dotted_name), qtype); | 238 DnsQuery* query = new DnsQuery(id, DomainFromDot(dotted_name), qtype); |
| 239 queries_.push_back(query); | 239 queries_.push_back(query); |
| 240 | 240 |
| 241 // The response is only used to hold the IOBuffer. | 241 // The response is only used to hold the IOBuffer. |
| 242 DnsResponse* response = new DnsResponse(data, data_length, 0); | 242 DnsResponse* response = new DnsResponse(data, data_length, 0); |
| 243 responses_.push_back(response); | 243 responses_.push_back(response); |
| 244 | 244 |
| 245 writes_.push_back(MockWrite(true, | 245 writes_.push_back(MockWrite(ASYNC, |
| 246 query->io_buffer()->data(), | 246 query->io_buffer()->data(), |
| 247 query->io_buffer()->size())); | 247 query->io_buffer()->size())); |
| 248 reads_.push_back(MockRead(true, | 248 reads_.push_back(MockRead(ASYNC, |
| 249 response->io_buffer()->data(), | 249 response->io_buffer()->data(), |
| 250 data_length)); | 250 data_length)); |
| 251 | 251 |
| 252 transaction_ids_.push_back(id); | 252 transaction_ids_.push_back(id); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Add expected query of |dotted_name| and |qtype| and no response. | 255 // Add expected query of |dotted_name| and |qtype| and no response. |
| 256 void AddTimeout(const char* dotted_name, uint16 qtype) { | 256 void AddTimeout(const char* dotted_name, uint16 qtype) { |
| 257 CHECK(socket_factory_.get()); | 257 CHECK(socket_factory_.get()); |
| 258 uint16 id = base::RandInt(0, kuint16max); | 258 uint16 id = base::RandInt(0, kuint16max); |
| 259 DnsQuery* query = new DnsQuery(id, DomainFromDot(dotted_name), qtype); | 259 DnsQuery* query = new DnsQuery(id, DomainFromDot(dotted_name), qtype); |
| 260 queries_.push_back(query); | 260 queries_.push_back(query); |
| 261 | 261 |
| 262 writes_.push_back(MockWrite(true, | 262 writes_.push_back(MockWrite(ASYNC, |
| 263 query->io_buffer()->data(), | 263 query->io_buffer()->data(), |
| 264 query->io_buffer()->size())); | 264 query->io_buffer()->size())); |
| 265 // Empty MockRead indicates no data. | 265 // Empty MockRead indicates no data. |
| 266 reads_.push_back(MockRead()); | 266 reads_.push_back(MockRead()); |
| 267 transaction_ids_.push_back(id); | 267 transaction_ids_.push_back(id); |
| 268 } | 268 } |
| 269 | 269 |
| 270 // Add expected query of |dotted_name| and |qtype| and response with no answer | 270 // Add expected query of |dotted_name| and |qtype| and response with no answer |
| 271 // and rcode set to |rcode|. | 271 // and rcode set to |rcode|. |
| 272 void AddRcode(const char* dotted_name, uint16 qtype, int rcode) { | 272 void AddRcode(const char* dotted_name, uint16 qtype, int rcode) { |
| 273 CHECK(socket_factory_.get()); | 273 CHECK(socket_factory_.get()); |
| 274 CHECK_NE(dns_protocol::kRcodeNOERROR, rcode); | 274 CHECK_NE(dns_protocol::kRcodeNOERROR, rcode); |
| 275 uint16 id = base::RandInt(0, kuint16max); | 275 uint16 id = base::RandInt(0, kuint16max); |
| 276 DnsQuery* query = new DnsQuery(id, DomainFromDot(dotted_name), qtype); | 276 DnsQuery* query = new DnsQuery(id, DomainFromDot(dotted_name), qtype); |
| 277 queries_.push_back(query); | 277 queries_.push_back(query); |
| 278 | 278 |
| 279 DnsResponse* response = new DnsResponse(query->io_buffer()->data(), | 279 DnsResponse* response = new DnsResponse(query->io_buffer()->data(), |
| 280 query->io_buffer()->size(), | 280 query->io_buffer()->size(), |
| 281 0); | 281 0); |
| 282 dns_protocol::Header* header = | 282 dns_protocol::Header* header = |
| 283 reinterpret_cast<dns_protocol::Header*>(response->io_buffer()->data()); | 283 reinterpret_cast<dns_protocol::Header*>(response->io_buffer()->data()); |
| 284 header->flags |= htons(dns_protocol::kFlagResponse | rcode); | 284 header->flags |= htons(dns_protocol::kFlagResponse | rcode); |
| 285 responses_.push_back(response); | 285 responses_.push_back(response); |
| 286 | 286 |
| 287 writes_.push_back(MockWrite(true, | 287 writes_.push_back(MockWrite(ASYNC, |
| 288 query->io_buffer()->data(), | 288 query->io_buffer()->data(), |
| 289 query->io_buffer()->size())); | 289 query->io_buffer()->size())); |
| 290 reads_.push_back(MockRead(true, | 290 reads_.push_back(MockRead(ASYNC, |
| 291 response->io_buffer()->data(), | 291 response->io_buffer()->data(), |
| 292 query->io_buffer()->size())); | 292 query->io_buffer()->size())); |
| 293 transaction_ids_.push_back(id); | 293 transaction_ids_.push_back(id); |
| 294 } | 294 } |
| 295 | 295 |
| 296 // Call after all Add* calls to prepare data for |socket_factory_|. | 296 // Call after all Add* calls to prepare data for |socket_factory_|. |
| 297 // This separation is necessary because the |reads_| and |writes_| vectors | 297 // This separation is necessary because the |reads_| and |writes_| vectors |
| 298 // could reallocate their data during those calls. | 298 // could reallocate their data during those calls. |
| 299 void PrepareSockets() { | 299 void PrepareSockets() { |
| 300 CHECK_EQ(writes_.size(), reads_.size()); | 300 CHECK_EQ(writes_.size(), reads_.size()); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 TransactionHelper helper2("x", | 675 TransactionHelper helper2("x", |
| 676 dns_protocol::kTypeA, | 676 dns_protocol::kTypeA, |
| 677 ERR_NAME_NOT_RESOLVED); | 677 ERR_NAME_NOT_RESOLVED); |
| 678 EXPECT_TRUE(helper2.Run(transaction_factory_.get())); | 678 EXPECT_TRUE(helper2.Run(transaction_factory_.get())); |
| 679 } | 679 } |
| 680 | 680 |
| 681 } // namespace | 681 } // namespace |
| 682 | 682 |
| 683 } // namespace net | 683 } // namespace net |
| 684 | 684 |
| OLD | NEW |