We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / net / base / network_change_notifier_unittest.cc
blobcb4e7745560ff516c6bec5df3731f78e71352db4
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"
10 namespace net {
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
21 // unknown.
22 if (max_bandwidth == std::numeric_limits<double>::infinity()) {
23 EXPECT_NE(NetworkChangeNotifier::CONNECTION_NONE, connection_type);
24 return;
27 switch (connection_type) {
28 case NetworkChangeNotifier::CONNECTION_UNKNOWN:
29 EXPECT_EQ(std::numeric_limits<double>::infinity(), max_bandwidth);
30 break;
31 case NetworkChangeNotifier::CONNECTION_ETHERNET:
32 EXPECT_GE(10.0, max_bandwidth);
33 EXPECT_LE(10000.0, max_bandwidth);
34 break;
35 case NetworkChangeNotifier::CONNECTION_WIFI:
36 EXPECT_GE(1.0, max_bandwidth);
37 EXPECT_LE(7000.0, max_bandwidth);
38 break;
39 case NetworkChangeNotifier::CONNECTION_2G:
40 EXPECT_GE(0.01, max_bandwidth);
41 EXPECT_LE(0.384, max_bandwidth);
42 break;
43 case NetworkChangeNotifier::CONNECTION_3G:
44 EXPECT_GE(2.0, max_bandwidth);
45 EXPECT_LE(42.0, max_bandwidth);
46 break;
47 case NetworkChangeNotifier::CONNECTION_4G:
48 EXPECT_GE(100.0, max_bandwidth);
49 EXPECT_LE(100.0, max_bandwidth);
50 break;
51 case NetworkChangeNotifier::CONNECTION_NONE:
52 EXPECT_EQ(0.0, max_bandwidth);
53 break;
54 case NetworkChangeNotifier::CONNECTION_BLUETOOTH:
55 EXPECT_GE(1.0, max_bandwidth);
56 EXPECT_LE(24.0, max_bandwidth);
57 break;
61 TEST(NetworkChangeNotifierTest, ConnectionTypeFromInterfaceList) {
62 NetworkInterfaceList list;
64 // Test empty 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);
73 list.clear();
74 list.push_back(interface);
75 EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list), i);
76 // Check two types.
77 for (int j = NetworkChangeNotifier::CONNECTION_UNKNOWN;
78 j <= NetworkChangeNotifier::CONNECTION_LAST; j++) {
79 list.clear();
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 } // namespace net