| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 405 |
| 406 base::MessageLoop::current()->RunUntilIdle(); | 406 base::MessageLoop::current()->RunUntilIdle(); |
| 407 } | 407 } |
| 408 | 408 |
| 409 | 409 |
| 410 class ServiceResolverTest : public ServiceDiscoveryTest { | 410 class ServiceResolverTest : public ServiceDiscoveryTest { |
| 411 public: | 411 public: |
| 412 ServiceResolverTest() { | 412 ServiceResolverTest() { |
| 413 metadata_expected_.push_back("hello"); | 413 metadata_expected_.push_back("hello"); |
| 414 address_expected_ = net::HostPortPair("myhello.local", 8888); | 414 address_expected_ = net::HostPortPair("myhello.local", 8888); |
| 415 ip_address_expected_.push_back(1); | 415 EXPECT_TRUE( |
| 416 ip_address_expected_.push_back(2); | 416 net::IPAddress::FromIPLiteral("1.2.3.4", &ip_address_expected_)); |
| 417 ip_address_expected_.push_back(3); | |
| 418 ip_address_expected_.push_back(4); | |
| 419 } | 417 } |
| 420 | 418 |
| 421 ~ServiceResolverTest() { | 419 ~ServiceResolverTest() { |
| 422 } | 420 } |
| 423 | 421 |
| 424 void SetUp() { | 422 void SetUp() { |
| 425 resolver_ = service_discovery_client_.CreateServiceResolver( | 423 resolver_ = service_discovery_client_.CreateServiceResolver( |
| 426 "hello._privet._tcp.local", | 424 "hello._privet._tcp.local", |
| 427 base::Bind(&ServiceResolverTest::OnFinishedResolving, | 425 base::Bind(&ServiceResolverTest::OnFinishedResolving, |
| 428 base::Unretained(this))); | 426 base::Unretained(this))); |
| 429 } | 427 } |
| 430 | 428 |
| 431 void OnFinishedResolving(ServiceResolver::RequestStatus request_status, | 429 void OnFinishedResolving(ServiceResolver::RequestStatus request_status, |
| 432 const ServiceDescription& service_description) { | 430 const ServiceDescription& service_description) { |
| 433 OnFinishedResolvingInternal(request_status, | 431 OnFinishedResolvingInternal(request_status, |
| 434 service_description.address.ToString(), | 432 service_description.address.ToString(), |
| 435 service_description.metadata, | 433 service_description.metadata, |
| 436 service_description.ip_address); | 434 service_description.ip_address); |
| 437 } | 435 } |
| 438 | 436 |
| 439 MOCK_METHOD4(OnFinishedResolvingInternal, | 437 MOCK_METHOD4(OnFinishedResolvingInternal, |
| 440 void(ServiceResolver::RequestStatus, | 438 void(ServiceResolver::RequestStatus, |
| 441 const std::string&, | 439 const std::string&, |
| 442 const std::vector<std::string>&, | 440 const std::vector<std::string>&, |
| 443 const net::IPAddressNumber&)); | 441 const net::IPAddress&)); |
| 444 | 442 |
| 445 protected: | 443 protected: |
| 446 scoped_ptr<ServiceResolver> resolver_; | 444 scoped_ptr<ServiceResolver> resolver_; |
| 447 net::IPAddressNumber ip_address_; | 445 net::IPAddress ip_address_; |
| 448 net::HostPortPair address_expected_; | 446 net::HostPortPair address_expected_; |
| 449 std::vector<std::string> metadata_expected_; | 447 std::vector<std::string> metadata_expected_; |
| 450 net::IPAddressNumber ip_address_expected_; | 448 net::IPAddress ip_address_expected_; |
| 451 }; | 449 }; |
| 452 | 450 |
| 453 TEST_F(ServiceResolverTest, TxtAndSrvButNoA) { | 451 TEST_F(ServiceResolverTest, TxtAndSrvButNoA) { |
| 454 EXPECT_CALL(socket_factory_, OnSendTo(_)).Times(4); | 452 EXPECT_CALL(socket_factory_, OnSendTo(_)).Times(4); |
| 455 | 453 |
| 456 resolver_->StartResolving(); | 454 resolver_->StartResolving(); |
| 457 | 455 |
| 458 socket_factory_.SimulateReceive(kSamplePacketSRV, sizeof(kSamplePacketSRV)); | 456 socket_factory_.SimulateReceive(kSamplePacketSRV, sizeof(kSamplePacketSRV)); |
| 459 | 457 |
| 460 base::MessageLoop::current()->RunUntilIdle(); | 458 base::MessageLoop::current()->RunUntilIdle(); |
| 461 | 459 |
| 462 EXPECT_CALL(*this, | 460 EXPECT_CALL( |
| 463 OnFinishedResolvingInternal(ServiceResolver::STATUS_SUCCESS, | 461 *this, OnFinishedResolvingInternal(ServiceResolver::STATUS_SUCCESS, |
| 464 address_expected_.ToString(), | 462 address_expected_.ToString(), |
| 465 metadata_expected_, | 463 metadata_expected_, net::IPAddress())); |
| 466 net::IPAddressNumber())); | |
| 467 | 464 |
| 468 socket_factory_.SimulateReceive(kSamplePacketTXT, sizeof(kSamplePacketTXT)); | 465 socket_factory_.SimulateReceive(kSamplePacketTXT, sizeof(kSamplePacketTXT)); |
| 469 } | 466 } |
| 470 | 467 |
| 471 TEST_F(ServiceResolverTest, TxtSrvAndA) { | 468 TEST_F(ServiceResolverTest, TxtSrvAndA) { |
| 472 EXPECT_CALL(socket_factory_, OnSendTo(_)).Times(4); | 469 EXPECT_CALL(socket_factory_, OnSendTo(_)).Times(4); |
| 473 | 470 |
| 474 resolver_->StartResolving(); | 471 resolver_->StartResolving(); |
| 475 | 472 |
| 476 EXPECT_CALL(*this, | 473 EXPECT_CALL(*this, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 ServiceResolver::STATUS_REQUEST_TIMEOUT, _, _, _)); | 508 ServiceResolver::STATUS_REQUEST_TIMEOUT, _, _, _)); |
| 512 | 509 |
| 513 // TODO(noamsml): When NSEC record support is added, change this to use an | 510 // TODO(noamsml): When NSEC record support is added, change this to use an |
| 514 // NSEC record. | 511 // NSEC record. |
| 515 RunFor(base::TimeDelta::FromSeconds(4)); | 512 RunFor(base::TimeDelta::FromSeconds(4)); |
| 516 } | 513 } |
| 517 | 514 |
| 518 } // namespace | 515 } // namespace |
| 519 | 516 |
| 520 } // namespace local_discovery | 517 } // namespace local_discovery |
| OLD | NEW |