OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 EXPECT_TRUE_WAIT(callback_called_, 1000); | 933 EXPECT_TRUE_WAIT(callback_called_, 1000); |
934 | 934 |
935 // Network manager is stopped; the network monitor is removed. | 935 // Network manager is stopped; the network monitor is removed. |
936 manager.StopUpdating(); | 936 manager.StopUpdating(); |
937 EXPECT_TRUE(GetNetworkMonitor(manager) == nullptr); | 937 EXPECT_TRUE(GetNetworkMonitor(manager) == nullptr); |
938 | 938 |
939 NetworkMonitorFactory::ReleaseFactory(factory); | 939 NetworkMonitorFactory::ReleaseFactory(factory); |
940 } | 940 } |
941 | 941 |
942 TEST_F(NetworkTest, DefaultLocalAddress) { | 942 TEST_F(NetworkTest, DefaultLocalAddress) { |
| 943 IPAddress ip; |
943 TestBasicNetworkManager manager; | 944 TestBasicNetworkManager manager; |
| 945 manager.SignalNetworksChanged.connect(static_cast<NetworkTest*>(this), |
| 946 &NetworkTest::OnNetworksChanged); |
| 947 FakeNetworkMonitorFactory* factory = new FakeNetworkMonitorFactory(); |
| 948 NetworkMonitorFactory::SetFactory(factory); |
944 manager.StartUpdating(); | 949 manager.StartUpdating(); |
945 IPAddress ip; | 950 EXPECT_TRUE_WAIT(callback_called_, 1000); |
946 | |
947 // GetDefaultLocalAddress should return false when not set. | |
948 EXPECT_FALSE(manager.GetDefaultLocalAddress(AF_INET, &ip)); | |
949 EXPECT_FALSE(manager.GetDefaultLocalAddress(AF_INET6, &ip)); | |
950 | 951 |
951 // Make sure we can query default local address when an address for such | 952 // Make sure we can query default local address when an address for such |
952 // address family exists. | 953 // address family exists. |
953 std::vector<Network*> networks; | 954 std::vector<Network*> networks; |
954 manager.GetNetworks(&networks); | 955 manager.GetNetworks(&networks); |
| 956 EXPECT_TRUE(!networks.empty()); |
955 for (auto& network : networks) { | 957 for (auto& network : networks) { |
956 if (network->GetBestIP().family() == AF_INET) { | 958 if (network->GetBestIP().family() == AF_INET) { |
957 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET) != IPAddress()); | 959 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET) != IPAddress()); |
958 } else if (network->GetBestIP().family() == AF_INET6) { | 960 } else if (network->GetBestIP().family() == AF_INET6 && |
| 961 !IPIsLoopback(network->GetBestIP())) { |
| 962 // Existence of an IPv6 loopback address doesn't mean it has IPv6 network |
| 963 // enabled. |
959 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET6) != IPAddress()); | 964 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET6) != IPAddress()); |
960 } | 965 } |
961 } | 966 } |
962 | 967 |
963 // GetDefaultLocalAddress should return the valid default address after set. | 968 // GetDefaultLocalAddress should return the valid default address after set. |
964 manager.set_default_local_addresses(GetLoopbackIP(AF_INET), | 969 manager.set_default_local_addresses(GetLoopbackIP(AF_INET), |
965 GetLoopbackIP(AF_INET6)); | 970 GetLoopbackIP(AF_INET6)); |
966 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET, &ip)); | 971 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET, &ip)); |
967 EXPECT_EQ(ip, GetLoopbackIP(AF_INET)); | 972 EXPECT_EQ(ip, GetLoopbackIP(AF_INET)); |
968 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip)); | 973 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip)); |
969 EXPECT_EQ(ip, GetLoopbackIP(AF_INET6)); | 974 EXPECT_EQ(ip, GetLoopbackIP(AF_INET6)); |
970 manager.StopUpdating(); | 975 manager.StopUpdating(); |
971 } | 976 } |
972 | 977 |
973 } // namespace rtc | 978 } // namespace rtc |
OLD | NEW |