| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "chrome/browser/extensions/api/mdns/mdns_api.h" | 8 #include "chrome/browser/extensions/api/mdns/mdns_api.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/media/router/discovery/mdns/mock_dns_sd_registry.h" |
| 11 #include "chrome/common/extensions/api/mdns.h" | 12 #include "chrome/common/extensions/api/mdns.h" |
| 12 #include "extensions/common/switches.h" | 13 #include "extensions/common/switches.h" |
| 13 #include "extensions/test/result_catcher.h" | 14 #include "extensions/test/result_catcher.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 15 | 16 |
| 16 using ::testing::_; | 17 using ::testing::_; |
| 17 using ::testing::A; | 18 using ::testing::A; |
| 18 using DnsSdRegistry = media_router::DnsSdRegistry; | 19 using media_router::DnsSdRegistry; |
| 19 | 20 |
| 20 namespace api = extensions::api; | 21 namespace api = extensions::api; |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 class MockDnsSdRegistry : public DnsSdRegistry { | |
| 25 public: | |
| 26 explicit MockDnsSdRegistry(extensions::MDnsAPI* api) : api_(api) {} | |
| 27 virtual ~MockDnsSdRegistry() {} | |
| 28 | |
| 29 MOCK_METHOD1(AddObserver, void(DnsSdObserver* observer)); | |
| 30 MOCK_METHOD1(RemoveObserver, void(DnsSdObserver* observer)); | |
| 31 MOCK_METHOD1(RegisterDnsSdListener, void(const std::string& service_type)); | |
| 32 MOCK_METHOD1(UnregisterDnsSdListener, void(const std::string& service_type)); | |
| 33 MOCK_METHOD0(ForceDiscovery, void(void)); | |
| 34 | |
| 35 void DispatchMDnsEvent(const std::string& service_type, | |
| 36 const DnsSdServiceList& services) { | |
| 37 api_->OnDnsSdEvent(service_type, services); | |
| 38 } | |
| 39 | |
| 40 private: | |
| 41 DnsSdRegistry::DnsSdObserver* api_; | |
| 42 }; | |
| 43 | |
| 44 class MDnsAPITest : public ExtensionApiTest { | 25 class MDnsAPITest : public ExtensionApiTest { |
| 45 public: | 26 public: |
| 46 MDnsAPITest() {} | 27 MDnsAPITest() {} |
| 47 | 28 |
| 48 void SetUpCommandLine(base::CommandLine* command_line) override { | 29 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 49 ExtensionApiTest::SetUpCommandLine(command_line); | 30 ExtensionApiTest::SetUpCommandLine(command_line); |
| 50 command_line->AppendSwitchASCII( | 31 command_line->AppendSwitchASCII( |
| 51 extensions::switches::kWhitelistedExtensionID, | 32 extensions::switches::kWhitelistedExtensionID, |
| 52 "ddchlicdkolnonkihahngkmmmjnjlkkf"); | 33 "ddchlicdkolnonkihahngkmmmjnjlkkf"); |
| 53 } | 34 } |
| 54 | 35 |
| 55 void SetUpTestDnsSdRegistry() { | 36 void SetUpTestDnsSdRegistry() { |
| 56 extensions::MDnsAPI* api = extensions::MDnsAPI::Get(profile()); | 37 extensions::MDnsAPI* api = extensions::MDnsAPI::Get(profile()); |
| 57 dns_sd_registry_ = new MockDnsSdRegistry(api); | 38 dns_sd_registry_ = base::MakeUnique<media_router::MockDnsSdRegistry>(api); |
| 58 EXPECT_CALL(*dns_sd_registry_, AddObserver(api)) | 39 EXPECT_CALL(*dns_sd_registry_, AddObserver(api)) |
| 59 .Times(1); | 40 .Times(1); |
| 60 // Transfers ownership of the registry instance. | 41 api->SetDnsSdRegistryForTesting(dns_sd_registry_.get()); |
| 61 api->SetDnsSdRegistryForTesting( | |
| 62 base::WrapUnique<DnsSdRegistry>(dns_sd_registry_)); | |
| 63 } | 42 } |
| 64 | 43 |
| 65 protected: | 44 protected: |
| 66 MockDnsSdRegistry* dns_sd_registry_; | 45 std::unique_ptr<media_router::MockDnsSdRegistry> dns_sd_registry_; |
| 67 }; | 46 }; |
| 68 | 47 |
| 69 } // namespace | 48 } // namespace |
| 70 | 49 |
| 71 // TODO(justinlin): Win Dbg has a workaround that makes RunExtensionSubtest | 50 // TODO(justinlin): Win Dbg has a workaround that makes RunExtensionSubtest |
| 72 // always return true without actually running the test. Remove when fixed. | 51 // always return true without actually running the test. Remove when fixed. |
| 73 #if defined(OS_WIN) && !defined(NDEBUG) | 52 #if defined(OS_WIN) && !defined(NDEBUG) |
| 74 #define MAYBE_RegisterListener DISABLED_RegisterListener | 53 #define MAYBE_RegisterListener DISABLED_RegisterListener |
| 75 #else | 54 #else |
| 76 #define MAYBE_RegisterListener RegisterListener | 55 #define MAYBE_RegisterListener RegisterListener |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 #define MAYBE_MaxServiceInstancesPerEventConst \ | 186 #define MAYBE_MaxServiceInstancesPerEventConst \ |
| 208 DISABLED_MaxServiceInstancesPerEventConst | 187 DISABLED_MaxServiceInstancesPerEventConst |
| 209 #else | 188 #else |
| 210 #define MAYBE_MaxServiceInstancesPerEventConst MaxServiceInstancesPerEventConst | 189 #define MAYBE_MaxServiceInstancesPerEventConst MaxServiceInstancesPerEventConst |
| 211 #endif | 190 #endif |
| 212 // Test loading extension and registering multiple listeners. | 191 // Test loading extension and registering multiple listeners. |
| 213 IN_PROC_BROWSER_TEST_F(MDnsAPITest, MAYBE_MaxServiceInstancesPerEventConst) { | 192 IN_PROC_BROWSER_TEST_F(MDnsAPITest, MAYBE_MaxServiceInstancesPerEventConst) { |
| 214 EXPECT_TRUE(RunExtensionSubtest("mdns/api", | 193 EXPECT_TRUE(RunExtensionSubtest("mdns/api", |
| 215 "get_max_service_instances.html")); | 194 "get_max_service_instances.html")); |
| 216 } | 195 } |
| OLD | NEW |