// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/351564777): Remove this and convert code to safer constructs. #pragma allow_unsafe_buffers #endif #include "third_party/blink/renderer/platform/p2p/filtering_network_manager.h" #include <stddef.h> #include <memory> #include <utility> #include <vector> #include "base/check.h" #include "base/memory/raw_ptr_exclusion.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/notreached.h" #include "base/task/single_thread_task_runner.h" #include "base/test/test_simple_task_runner.h" #include "media/base/media_permission.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/renderer/platform/p2p/empty_network_manager.h" #include "third_party/webrtc/rtc_base/ip_address.h" SizeIs; namespace { enum EventType { … }; enum ResultType { … }; struct TestEntry { … }; class EmptyMdnsResponder : public webrtc::MdnsResponderInterface { … }; class MockNetworkManager : public rtc::NetworkManagerBase { … }; class MockMediaPermission : public media::MediaPermission { … }; } // namespace namespace blink { class FilteringNetworkManagerTest : public testing::Test, public sigslot::has_slots<> { … }; // Test that when multiple routes is not requested, SignalNetworksChanged is // fired right after the StartUpdating(). TEST_F(FilteringNetworkManagerTest, MultipleRoutesNotRequested) { … } // Test that multiple routes request is blocked and signaled right after // StartUpdating() since mic/camera permissions are denied. TEST_F(FilteringNetworkManagerTest, BlockMultipleRoutesByStartUpdating) { … } // Test that multiple routes request is blocked and signaled right after // last pending permission check is denied since StartUpdating() has been called // previously. TEST_F(FilteringNetworkManagerTest, BlockMultipleRoutesByPermissionsDenied) { … } // Test that after permissions have been denied, a network change signal from // the internal NetworkManager is still needed before signaling a network // change outwards. This is because even if network enumeration is blocked, // we still want to give time to obtain the default IP addresses. TEST_F(FilteringNetworkManagerTest, BlockMultipleRoutesByNetworksChanged) { … } // Test that multiple routes request is granted and signaled right after // a pending permission check is granted since StartUpdating() has been called // previously. TEST_F(FilteringNetworkManagerTest, AllowMultipleRoutesByPermissionsGranted) { … } // Test that multiple routes request is granted and signaled right after // StartUpdating() since there is at least one media permission granted. TEST_F(FilteringNetworkManagerTest, AllowMultipleRoutesByStartUpdating) { … } // Test that multiple routes request is granted and signaled right after // underneath NetworkManager's SignalNetworksChanged() as at least one // permission is granted and StartUpdating() has been called. TEST_F(FilteringNetworkManagerTest, AllowMultipleRoutesByNetworksChanged) { … } // Test that the networks provided by the GetNetworks() and // GetAnyAddressNetworks() are not associated with an mDNS responder if the // enumeration permission is granted, even if the mDNS obfuscation of local IPs // is allowed (which is by default). TEST_F(FilteringNetworkManagerTest, NullMdnsResponderAfterPermissionGranted) { … } // Test the networks on the default routes given by GetAnyAddressNetworks() are // associated with an mDNS responder if the enumeration is blocked and the mDNS // obfuscation of local IPs is allowed (which is by default). TEST_F(FilteringNetworkManagerTest, ProvideMdnsResponderForDefaultRouteAfterPermissionDenied) { … } // This is a similar test to the previous one but tests that the networks // provided by the GetNetworks() and GetAnyAddressNetworks() are not associated // with an mDNS responder if the mDNS obfuscation of local IPs is not allowed. TEST_F(FilteringNetworkManagerTest, NullMdnsResponderWhenMdnsObfuscationDisallowedAfterPermissionDenied) { … } } // namespace blink