Determine connection type in NetworkChangeNotifierLinux.
Check interface for wireless extensions to determine if it is a wifi connection. Check SIOCETHTOOL for ethernet. GetCurrentConnectionType will return the CONNECTION_UNKNOWN unless all connections are the same type.
[email protected]
BUG=160537
Review URL: https://codereview.chromium.org/739983005
Cr-Commit-Position: refs/heads/master@{#314042}
diff --git a/net/base/network_change_notifier_unittest.cc b/net/base/network_change_notifier_unittest.cc
index b8310fa..cb4e774 100644
--- a/net/base/network_change_notifier_unittest.cc
+++ b/net/base/network_change_notifier_unittest.cc
@@ -4,6 +4,7 @@
#include "net/base/network_change_notifier.h"
+#include "net/base/net_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
@@ -57,4 +58,33 @@
}
}
+TEST(NetworkChangeNotifierTest, ConnectionTypeFromInterfaceList) {
+ NetworkInterfaceList list;
+
+ // Test empty list.
+ EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list),
+ NetworkChangeNotifier::CONNECTION_NONE);
+
+ for (int i = NetworkChangeNotifier::CONNECTION_UNKNOWN;
+ i <= NetworkChangeNotifier::CONNECTION_LAST; i++) {
+ // Check individual types.
+ NetworkInterface interface;
+ interface.type = static_cast<NetworkChangeNotifier::ConnectionType>(i);
+ list.clear();
+ list.push_back(interface);
+ EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list), i);
+ // Check two types.
+ for (int j = NetworkChangeNotifier::CONNECTION_UNKNOWN;
+ j <= NetworkChangeNotifier::CONNECTION_LAST; j++) {
+ list.clear();
+ interface.type = static_cast<NetworkChangeNotifier::ConnectionType>(i);
+ list.push_back(interface);
+ interface.type = static_cast<NetworkChangeNotifier::ConnectionType>(j);
+ list.push_back(interface);
+ EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list),
+ i == j ? i : NetworkChangeNotifier::CONNECTION_UNKNOWN);
+ }
+ }
+}
+
} // namespace net