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.
5 #include "net/base/network_change_notifier.h"
7 #include "net/base/net_util.h"
8 #include "testing/gtest/include/gtest/gtest.h"
12 // Note: This test is subject to the host's OS and network connection. This test
13 // is not future-proof. New standards will come about necessitating the need to
14 // alter the ranges of these tests.
15 TEST(NetworkChangeNotifierTest
, NetMaxBandwidthRange
) {
16 NetworkChangeNotifier::ConnectionType connection_type
=
17 NetworkChangeNotifier::GetConnectionType();
18 double max_bandwidth
= NetworkChangeNotifier::GetMaxBandwidth();
20 // Always accept infinity as it's the default value if the bandwidth is
22 if (max_bandwidth
== std::numeric_limits
<double>::infinity()) {
23 EXPECT_NE(NetworkChangeNotifier::CONNECTION_NONE
, connection_type
);
27 switch (connection_type
) {
28 case NetworkChangeNotifier::CONNECTION_UNKNOWN
:
29 EXPECT_EQ(std::numeric_limits
<double>::infinity(), max_bandwidth
);
31 case NetworkChangeNotifier::CONNECTION_ETHERNET
:
32 EXPECT_GE(10.0, max_bandwidth
);
33 EXPECT_LE(10000.0, max_bandwidth
);
35 case NetworkChangeNotifier::CONNECTION_WIFI
:
36 EXPECT_GE(1.0, max_bandwidth
);
37 EXPECT_LE(7000.0, max_bandwidth
);
39 case NetworkChangeNotifier::CONNECTION_2G
:
40 EXPECT_GE(0.01, max_bandwidth
);
41 EXPECT_LE(0.384, max_bandwidth
);
43 case NetworkChangeNotifier::CONNECTION_3G
:
44 EXPECT_GE(2.0, max_bandwidth
);
45 EXPECT_LE(42.0, max_bandwidth
);
47 case NetworkChangeNotifier::CONNECTION_4G
:
48 EXPECT_GE(100.0, max_bandwidth
);
49 EXPECT_LE(100.0, max_bandwidth
);
51 case NetworkChangeNotifier::CONNECTION_NONE
:
52 EXPECT_EQ(0.0, max_bandwidth
);
54 case NetworkChangeNotifier::CONNECTION_BLUETOOTH
:
55 EXPECT_GE(1.0, max_bandwidth
);
56 EXPECT_LE(24.0, max_bandwidth
);
61 TEST(NetworkChangeNotifierTest
, ConnectionTypeFromInterfaceList
) {
62 NetworkInterfaceList list
;
65 EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list
),
66 NetworkChangeNotifier::CONNECTION_NONE
);
68 for (int i
= NetworkChangeNotifier::CONNECTION_UNKNOWN
;
69 i
<= NetworkChangeNotifier::CONNECTION_LAST
; i
++) {
70 // Check individual types.
71 NetworkInterface interface
;
72 interface
.type
= static_cast<NetworkChangeNotifier::ConnectionType
>(i
);
74 list
.push_back(interface
);
75 EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list
), i
);
77 for (int j
= NetworkChangeNotifier::CONNECTION_UNKNOWN
;
78 j
<= NetworkChangeNotifier::CONNECTION_LAST
; j
++) {
80 interface
.type
= static_cast<NetworkChangeNotifier::ConnectionType
>(i
);
81 list
.push_back(interface
);
82 interface
.type
= static_cast<NetworkChangeNotifier::ConnectionType
>(j
);
83 list
.push_back(interface
);
84 EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list
),
85 i
== j
? i
: NetworkChangeNotifier::CONNECTION_UNKNOWN
);
90 TEST(NetworkChangeNotifierTest
, IgnoreTeredoOnWindows
) {
91 NetworkInterfaceList list
;
92 NetworkInterface interface_teredo
;
93 interface_teredo
.type
= NetworkChangeNotifier::CONNECTION_ETHERNET
;
94 interface_teredo
.friendly_name
= "Teredo Tunneling Pseudo-Interface";
95 list
.push_back(interface_teredo
);
98 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE
,
99 NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list
));
101 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_ETHERNET
,
102 NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list
));
106 TEST(NetworkChangeNotifierTest
, IgnoreVMInterfaces
) {
107 NetworkInterfaceList list
;
108 NetworkInterface interface_vmnet_linux
;
109 interface_vmnet_linux
.type
= NetworkChangeNotifier::CONNECTION_ETHERNET
;
110 interface_vmnet_linux
.name
= "vmnet1";
111 interface_vmnet_linux
.friendly_name
= "vmnet1";
112 list
.push_back(interface_vmnet_linux
);
114 NetworkInterface interface_vmnet_win
;
115 interface_vmnet_win
.type
= NetworkChangeNotifier::CONNECTION_ETHERNET
;
116 interface_vmnet_win
.name
= "virtualdevice";
117 interface_vmnet_win
.friendly_name
= "VMware Network Adapter VMnet1";
118 list
.push_back(interface_vmnet_win
);
120 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE
,
121 NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list
));