| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/media/router/discovery/mdns/dns_sd_registry.h" | 5 #include "chrome/browser/media/router/discovery/mdns/dns_sd_registry.h" |
| 6 #include "chrome/browser/media/router/discovery/mdns/dns_sd_delegate.h" | 6 #include "chrome/browser/media/router/discovery/mdns/dns_sd_delegate.h" |
| 7 #include "chrome/browser/media/router/discovery/mdns/dns_sd_device_lister.h" | 7 #include "chrome/browser/media/router/discovery/mdns/dns_sd_device_lister.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace media_router { | 11 namespace media_router { |
| 12 | 12 |
| 13 class MockDnsSdDeviceLister : public DnsSdDeviceLister { | 13 class MockDnsSdDeviceLister : public DnsSdDeviceLister { |
| 14 public: | 14 public: |
| 15 MockDnsSdDeviceLister() : DnsSdDeviceLister(NULL, NULL, "") {} | 15 MockDnsSdDeviceLister() : DnsSdDeviceLister(NULL, NULL, "") {} |
| 16 ~MockDnsSdDeviceLister() override {} | 16 ~MockDnsSdDeviceLister() override {} |
| 17 | 17 |
| 18 MOCK_METHOD1(Discover, void(bool force_update)); | 18 MOCK_METHOD0(Discover, void()); |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 class TestDnsSdRegistry : public DnsSdRegistry { | 21 class TestDnsSdRegistry : public DnsSdRegistry { |
| 22 public: | 22 public: |
| 23 TestDnsSdRegistry() : DnsSdRegistry(NULL), delegate_(NULL) {} | 23 TestDnsSdRegistry() : DnsSdRegistry(NULL), delegate_(NULL) {} |
| 24 ~TestDnsSdRegistry() override {} | 24 ~TestDnsSdRegistry() override {} |
| 25 | 25 |
| 26 MockDnsSdDeviceLister* GetListerForService(const std::string& service_type) { | 26 MockDnsSdDeviceLister* GetListerForService(const std::string& service_type) { |
| 27 return listers_[service_type]; | 27 return listers_[service_type]; |
| 28 } | 28 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 EXPECT_CALL(observer_, | 109 EXPECT_CALL(observer_, |
| 110 OnDnsSdEvent(service_type1, DnsSdRegistry::DnsSdServiceList())); | 110 OnDnsSdEvent(service_type1, DnsSdRegistry::DnsSdServiceList())); |
| 111 EXPECT_CALL(observer_, | 111 EXPECT_CALL(observer_, |
| 112 OnDnsSdEvent(service_type2, DnsSdRegistry::DnsSdServiceList())); | 112 OnDnsSdEvent(service_type2, DnsSdRegistry::DnsSdServiceList())); |
| 113 | 113 |
| 114 registry_->RegisterDnsSdListener(service_type1); | 114 registry_->RegisterDnsSdListener(service_type1); |
| 115 registry_->RegisterDnsSdListener(service_type2); | 115 registry_->RegisterDnsSdListener(service_type2); |
| 116 EXPECT_EQ(1, registry_->GetServiceListenerCount(service_type1)); | 116 EXPECT_EQ(1, registry_->GetServiceListenerCount(service_type1)); |
| 117 EXPECT_EQ(1, registry_->GetServiceListenerCount(service_type2)); | 117 EXPECT_EQ(1, registry_->GetServiceListenerCount(service_type2)); |
| 118 | 118 |
| 119 EXPECT_CALL(*registry_->GetLister(service_type1), Discover(false)); | 119 EXPECT_CALL(*registry_->GetLister(service_type1), Discover()); |
| 120 EXPECT_CALL(*registry_->GetLister(service_type2), Discover(false)); | 120 EXPECT_CALL(*registry_->GetLister(service_type2), Discover()); |
| 121 registry_->ForceDiscovery(); | 121 registry_->ForceDiscovery(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Tests registering a listener and receiving an added and updated event. | 124 // Tests registering a listener and receiving an added and updated event. |
| 125 TEST_F(DnsSdRegistryTest, AddAndUpdate) { | 125 TEST_F(DnsSdRegistryTest, AddAndUpdate) { |
| 126 const std::string service_type = "_testing._tcp.local"; | 126 const std::string service_type = "_testing._tcp.local"; |
| 127 const std::string ip_address1 = "192.168.0.100"; | 127 const std::string ip_address1 = "192.168.0.100"; |
| 128 const std::string ip_address2 = "192.168.0.101"; | 128 const std::string ip_address2 = "192.168.0.101"; |
| 129 | 129 |
| 130 DnsSdService service; | 130 DnsSdService service; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 service.ip_address = "192.168.0.100"; | 255 service.ip_address = "192.168.0.100"; |
| 256 registry_->GetDelegate()->ServiceChanged(service_type, true, service); | 256 registry_->GetDelegate()->ServiceChanged(service_type, true, service); |
| 257 // Update with changed ip address. | 257 // Update with changed ip address. |
| 258 service.ip_address = "192.168.0.101"; | 258 service.ip_address = "192.168.0.101"; |
| 259 registry_->GetDelegate()->ServiceChanged(service_type, false, service); | 259 registry_->GetDelegate()->ServiceChanged(service_type, false, service); |
| 260 // Update with no changes to the service. | 260 // Update with no changes to the service. |
| 261 registry_->GetDelegate()->ServiceChanged(service_type, false, service); | 261 registry_->GetDelegate()->ServiceChanged(service_type, false, service); |
| 262 } | 262 } |
| 263 | 263 |
| 264 } // namespace media_router | 264 } // namespace media_router |
| OLD | NEW |