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