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