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
);