Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: chrome/browser/extensions/api/mdns/mdns_api_unittest.cc

Issue 2876703002: [mDns] Move dns_sd_registry from extension/api/mdns to media/router/discovery/mdns (Closed)
Patch Set: rebase with master Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/extensions/api/mdns/mdns_api.h" 5 #include "chrome/browser/extensions/api/mdns/mdns_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return base::MakeUnique<extensions::EventRouter>( 84 return base::MakeUnique<extensions::EventRouter>(
85 context, ExtensionPrefs::Get(context)); 85 context, ExtensionPrefs::Get(context));
86 } 86 }
87 87
88 // For ExtensionService interface when it requires a path that is not used. 88 // For ExtensionService interface when it requires a path that is not used.
89 base::FilePath bogus_file_pathname(const std::string& name) { 89 base::FilePath bogus_file_pathname(const std::string& name) {
90 return base::FilePath(FILE_PATH_LITERAL("//foobar_nonexistent")) 90 return base::FilePath(FILE_PATH_LITERAL("//foobar_nonexistent"))
91 .AppendASCII(name); 91 .AppendASCII(name);
92 } 92 }
93 93
94 class MockDnsSdRegistry : public DnsSdRegistry { 94 class MockDnsSdRegistry : public media_router::DnsSdRegistry {
95 public: 95 public:
96 explicit MockDnsSdRegistry(extensions::MDnsAPI* api) : api_(api) {} 96 explicit MockDnsSdRegistry(extensions::MDnsAPI* api) : api_(api) {}
97 virtual ~MockDnsSdRegistry() {} 97 virtual ~MockDnsSdRegistry() {}
98 98
99 MOCK_METHOD1(AddObserver, void(DnsSdObserver* observer)); 99 MOCK_METHOD1(AddObserver, void(DnsSdObserver* observer));
100 MOCK_METHOD1(RemoveObserver, void(DnsSdObserver* observer)); 100 MOCK_METHOD1(RemoveObserver, void(DnsSdObserver* observer));
101 MOCK_METHOD1(RegisterDnsSdListener, void(const std::string& service_type)); 101 MOCK_METHOD1(RegisterDnsSdListener, void(const std::string& service_type));
102 MOCK_METHOD1(UnregisterDnsSdListener, void(const std::string& service_type)); 102 MOCK_METHOD1(UnregisterDnsSdListener, void(const std::string& service_type));
103 MOCK_METHOD1(Publish, void(const std::string&)); 103 MOCK_METHOD1(Publish, void(const std::string&));
104 MOCK_METHOD0(ForceDiscovery, void(void)); 104 MOCK_METHOD0(ForceDiscovery, void(void));
105 105
106 void DispatchMDnsEvent(const std::string& service_type, 106 void DispatchMDnsEvent(const std::string& service_type,
107 const DnsSdServiceList& services) { 107 const DnsSdServiceList& services) {
108 api_->OnDnsSdEvent(service_type, services); 108 api_->OnDnsSdEvent(service_type, services);
109 } 109 }
110 110
111 private: 111 private:
112 extensions::DnsSdRegistry::DnsSdObserver* api_; 112 media_router::DnsSdRegistry::DnsSdObserver* api_;
113 }; 113 };
114 114
115 class MockEventRouter : public EventRouter { 115 class MockEventRouter : public EventRouter {
116 public: 116 public:
117 explicit MockEventRouter(content::BrowserContext* browser_context, 117 explicit MockEventRouter(content::BrowserContext* browser_context,
118 ExtensionPrefs* extension_prefs) 118 ExtensionPrefs* extension_prefs)
119 : EventRouter(browser_context, extension_prefs) {} 119 : EventRouter(browser_context, extension_prefs) {}
120 virtual ~MockEventRouter() {} 120 virtual ~MockEventRouter() {}
121 121
122 virtual void BroadcastEvent(std::unique_ptr<Event> event) { 122 virtual void BroadcastEvent(std::unique_ptr<Event> event) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 202
203 // Do some sanity checking 203 // Do some sanity checking
204 ASSERT_TRUE(MDnsAPI::Get(browser_context())); // constructs MDnsAPI 204 ASSERT_TRUE(MDnsAPI::Get(browser_context())); // constructs MDnsAPI
205 ASSERT_TRUE(EventRouter::Get(browser_context())); // constructs EventRouter 205 ASSERT_TRUE(EventRouter::Get(browser_context())); // constructs EventRouter
206 206
207 registry_ = new MockDnsSdRegistry(MDnsAPI::Get(browser_context())); 207 registry_ = new MockDnsSdRegistry(MDnsAPI::Get(browser_context()));
208 EXPECT_CALL(*dns_sd_registry(), 208 EXPECT_CALL(*dns_sd_registry(),
209 AddObserver(MDnsAPI::Get(browser_context()))) 209 AddObserver(MDnsAPI::Get(browser_context())))
210 .Times(1); 210 .Times(1);
211 MDnsAPI::Get(browser_context()) 211 MDnsAPI::Get(browser_context())
212 ->SetDnsSdRegistryForTesting(std::unique_ptr<DnsSdRegistry>(registry_)); 212 ->SetDnsSdRegistryForTesting(
213 std::unique_ptr<media_router::DnsSdRegistry>(registry_));
213 214
214 render_process_host_.reset( 215 render_process_host_.reset(
215 new content::MockRenderProcessHost(browser_context())); 216 new content::MockRenderProcessHost(browser_context()));
216 } 217 }
217 218
218 // Returns the mDNS API factory function (mock vs. real) to use for the test. 219 // Returns the mDNS API factory function (mock vs. real) to use for the test.
219 virtual BrowserContextKeyedServiceFactory::TestingFactoryFunction 220 virtual BrowserContextKeyedServiceFactory::TestingFactoryFunction
220 GetMDnsFactory() { 221 GetMDnsFactory() {
221 return MDnsAPITestingFactoryFunction; 222 return MDnsAPITestingFactoryFunction;
222 } 223 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 TEST_F(MDnsAPIMaxServicesTest, OnServiceListDoesNotExceedLimit) { 352 TEST_F(MDnsAPIMaxServicesTest, OnServiceListDoesNotExceedLimit) {
352 EventRouterFactory::GetInstance()->SetTestingFactory( 353 EventRouterFactory::GetInstance()->SetTestingFactory(
353 browser_context(), &MockEventRouterFactoryFunction); 354 browser_context(), &MockEventRouterFactoryFunction);
354 355
355 // This check should change when the [value=2048] changes in the IDL file. 356 // This check should change when the [value=2048] changes in the IDL file.
356 EXPECT_EQ(2048, api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT); 357 EXPECT_EQ(2048, api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT);
357 358
358 // Dispatch an mDNS event with more service instances than the max, and ensure 359 // Dispatch an mDNS event with more service instances than the max, and ensure
359 // that the list is truncated by inspecting the argument to MockEventRouter's 360 // that the list is truncated by inspecting the argument to MockEventRouter's
360 // BroadcastEvent method. 361 // BroadcastEvent method.
361 DnsSdRegistry::DnsSdServiceList services; 362 media_router::DnsSdRegistry::DnsSdServiceList services;
362 for (int i = 0; i < api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT + 10; ++i) { 363 for (int i = 0; i < api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT + 10; ++i) {
363 services.push_back(DnsSdService()); 364 services.push_back(media_router::DnsSdService());
364 } 365 }
365 EXPECT_CALL( 366 EXPECT_CALL(
366 *event_router(), 367 *event_router(),
367 BroadcastEventPtr(testing::Pointee(EventServiceListSize( 368 BroadcastEventPtr(testing::Pointee(EventServiceListSize(
368 static_cast<size_t>(api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT))))) 369 static_cast<size_t>(api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT)))))
369 .Times(1); 370 .Times(1);
370 dns_sd_registry()->DispatchMDnsEvent("_testing._tcp.local", services); 371 dns_sd_registry()->DispatchMDnsEvent("_testing._tcp.local", services);
371 } 372 }
372 373
373 TEST_F(MDnsAPITest, ExtensionRespectsWhitelist) { 374 TEST_F(MDnsAPITest, ExtensionRespectsWhitelist) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 render_process_host(), kExtId, filter, false); 438 render_process_host(), kExtId, filter, false);
438 439
439 EXPECT_CALL(*dns_sd_registry(), UnregisterDnsSdListener("_trex._tcp.local")); 440 EXPECT_CALL(*dns_sd_registry(), UnregisterDnsSdListener("_trex._tcp.local"));
440 EventRouter::Get(browser_context()) 441 EventRouter::Get(browser_context())
441 ->RemoveFilteredEventListener(api::mdns::OnServiceList::kEventName, 442 ->RemoveFilteredEventListener(api::mdns::OnServiceList::kEventName,
442 render_process_host(), kExtId, filter, 443 render_process_host(), kExtId, filter,
443 false); 444 false);
444 } 445 }
445 446
446 } // namespace extensions 447 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/mdns/mdns_api.cc ('k') | chrome/browser/extensions/api/mdns/mdns_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698