OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "network_change_notifier.h" |
| 6 |
| 7 #include "net/base/net_util.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace net { |
| 11 |
| 12 TEST(NetworkChangeNotifierTest, InterfacesToConnectionType) { |
| 13 NetworkInterfaceList list; |
| 14 |
| 15 // Test empty list. |
| 16 EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list), |
| 17 NetworkChangeNotifier::CONNECTION_UNKNOWN); |
| 18 |
| 19 NetworkInterface interface; |
| 20 for (int i = NetworkChangeNotifier::CONNECTION_UNKNOWN; |
| 21 i < NetworkChangeNotifier::CONNECTION_LAST; |
| 22 i++) { |
| 23 // Check individual types. |
| 24 list.clear(); |
| 25 interface.type = static_cast<NetworkChangeNotifier::ConnectionType>(i); |
| 26 list.push_back(interface); |
| 27 EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list), i); |
| 28 // Check two types. |
| 29 for (int j = NetworkChangeNotifier::CONNECTION_UNKNOWN; |
| 30 j < NetworkChangeNotifier::CONNECTION_LAST; |
| 31 j++) { |
| 32 list.clear(); |
| 33 interface.type = static_cast<NetworkChangeNotifier::ConnectionType>(i); |
| 34 list.push_back(interface); |
| 35 interface.type = static_cast<NetworkChangeNotifier::ConnectionType>(j); |
| 36 list.push_back(interface); |
| 37 EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list), |
| 38 i == j ? i : NetworkChangeNotifier::CONNECTION_UNKNOWN); |
| 39 } |
| 40 } |
| 41 |
| 42 #if defined(OS_WIN) |
| 43 // Ignore fake Teredo interface. |
| 44 list.clear(); |
| 45 interface.type = NetworkChangeNotifier::CONNECTION_4G; |
| 46 interface.friendly_name = "Teredo Tunneling Pseudo-Interface"; |
| 47 list.push_back(interface); |
| 48 // Verify Teredo interface type ignored. |
| 49 EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list), |
| 50 NetworkChangeNotifier::CONNECTION_UNKNOWN); |
| 51 // Verify type of non-Teredo interface used. |
| 52 interface.type = NetworkChangeNotifier::CONNECTION_3G; |
| 53 interface.friendly_name = ""; |
| 54 list.push_back(interface); |
| 55 EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list), |
| 56 NetworkChangeNotifier::CONNECTION_3G); |
| 57 // Reverse elements. |
| 58 list.push_back(list[0]); |
| 59 list.erase(list.begin()); |
| 60 EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list), |
| 61 NetworkChangeNotifier::CONNECTION_3G); |
| 62 #endif |
| 63 } |
| 64 |
| 65 } // namespace net |
OLD | NEW |