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