OLD | NEW |
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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 BroadcastEventPtr(testing::Pointee(EventServiceListSize( | 369 BroadcastEventPtr(testing::Pointee(EventServiceListSize( |
370 static_cast<size_t>(api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT))))) | 370 static_cast<size_t>(api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT))))) |
371 .Times(1); | 371 .Times(1); |
372 dns_sd_registry()->DispatchMDnsEvent("_testing._tcp.local", services); | 372 dns_sd_registry()->DispatchMDnsEvent("_testing._tcp.local", services); |
373 } | 373 } |
374 | 374 |
375 TEST_F(MDnsAPITest, ExtensionRespectsWhitelist) { | 375 TEST_F(MDnsAPITest, ExtensionRespectsWhitelist) { |
376 scoped_refptr<extensions::Extension> extension = | 376 scoped_refptr<extensions::Extension> extension = |
377 CreateExtension("Dinosaur networker", false, kExtId); | 377 CreateExtension("Dinosaur networker", false, kExtId); |
378 ExtensionRegistry::Get(browser_context())->AddEnabled(extension); | 378 ExtensionRegistry::Get(browser_context())->AddEnabled(extension); |
379 ASSERT_EQ(Manifest::TYPE_EXTENSION, extension.get()->GetType()); | 379 ASSERT_EQ(Manifest::TYPE_EXTENSION, extension->GetType()); |
380 | 380 |
381 // There is a whitelist of mdns service types extensions may access, which | 381 // There is a whitelist of mdns service types extensions may access, which |
382 // includes "_testing._tcp.local" and exludes "_trex._tcp.local" | 382 // includes "_testing._tcp.local" and exludes "_trex._tcp.local" |
383 { | 383 { |
384 base::DictionaryValue filter; | 384 base::DictionaryValue filter; |
385 filter.SetString(kEventFilterServiceTypeKey, "_trex._tcp.local"); | 385 filter.SetString(kEventFilterServiceTypeKey, "_trex._tcp.local"); |
386 | 386 |
387 ASSERT_TRUE(dns_sd_registry()); | 387 ASSERT_TRUE(dns_sd_registry()); |
388 // Test that the extension is able to listen to a non-whitelisted service | 388 // Test that the extension is able to listen to a non-whitelisted service |
389 EXPECT_CALL(*dns_sd_registry(), RegisterDnsSdListener("_trex._tcp.local")) | 389 EXPECT_CALL(*dns_sd_registry(), RegisterDnsSdListener("_trex._tcp.local")) |
(...skipping 29 matching lines...) Expand all Loading... |
419 ->RemoveFilteredEventListener(api::mdns::OnServiceList::kEventName, | 419 ->RemoveFilteredEventListener(api::mdns::OnServiceList::kEventName, |
420 render_process_host(), kExtId, filter, | 420 render_process_host(), kExtId, filter, |
421 false); | 421 false); |
422 } | 422 } |
423 } | 423 } |
424 | 424 |
425 TEST_F(MDnsAPITest, PlatformAppsNotSubjectToWhitelist) { | 425 TEST_F(MDnsAPITest, PlatformAppsNotSubjectToWhitelist) { |
426 scoped_refptr<extensions::Extension> extension = | 426 scoped_refptr<extensions::Extension> extension = |
427 CreateExtension("Dinosaur networker", true, kExtId); | 427 CreateExtension("Dinosaur networker", true, kExtId); |
428 ExtensionRegistry::Get(browser_context())->AddEnabled(extension); | 428 ExtensionRegistry::Get(browser_context())->AddEnabled(extension); |
429 ASSERT_TRUE(extension.get()->is_platform_app()); | 429 ASSERT_TRUE(extension->is_platform_app()); |
430 | 430 |
431 base::DictionaryValue filter; | 431 base::DictionaryValue filter; |
432 filter.SetString(kEventFilterServiceTypeKey, "_trex._tcp.local"); | 432 filter.SetString(kEventFilterServiceTypeKey, "_trex._tcp.local"); |
433 | 433 |
434 ASSERT_TRUE(dns_sd_registry()); | 434 ASSERT_TRUE(dns_sd_registry()); |
435 // Test that the extension is able to listen to a non-whitelisted service | 435 // Test that the extension is able to listen to a non-whitelisted service |
436 EXPECT_CALL(*dns_sd_registry(), RegisterDnsSdListener("_trex._tcp.local")); | 436 EXPECT_CALL(*dns_sd_registry(), RegisterDnsSdListener("_trex._tcp.local")); |
437 EventRouter::Get(browser_context()) | 437 EventRouter::Get(browser_context()) |
438 ->AddFilteredEventListener(api::mdns::OnServiceList::kEventName, | 438 ->AddFilteredEventListener(api::mdns::OnServiceList::kEventName, |
439 render_process_host(), kExtId, filter, false); | 439 render_process_host(), kExtId, filter, false); |
440 | 440 |
441 EXPECT_CALL(*dns_sd_registry(), UnregisterDnsSdListener("_trex._tcp.local")); | 441 EXPECT_CALL(*dns_sd_registry(), UnregisterDnsSdListener("_trex._tcp.local")); |
442 EventRouter::Get(browser_context()) | 442 EventRouter::Get(browser_context()) |
443 ->RemoveFilteredEventListener(api::mdns::OnServiceList::kEventName, | 443 ->RemoveFilteredEventListener(api::mdns::OnServiceList::kEventName, |
444 render_process_host(), kExtId, filter, | 444 render_process_host(), kExtId, filter, |
445 false); | 445 false); |
446 } | 446 } |
447 | 447 |
448 } // namespace extensions | 448 } // namespace extensions |
OLD | NEW |