Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Unified Diff: net/base/network_change_notifier_unittest.cc

Issue 298023005: Infer network connection type from network interface type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add tests Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/network_change_notifier_unittest.cc
diff --git a/net/base/network_change_notifier_unittest.cc b/net/base/network_change_notifier_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..db6301763999491cbc2e557213847572981c14e8
--- /dev/null
+++ b/net/base/network_change_notifier_unittest.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/base/net_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+class NetworkChangeNotifierTest : public testing::Test {
+ public:
+ NetworkChangeNotifierTest() {}
+ virtual ~NetworkChangeNotifierTest() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierTest);
+};
+
+TEST_F(NetworkChangeNotifierTest, InterfacesToConnectionType) {
+ NetworkInterfaceList list;
+
+ // Test empty list.
+ EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list),
+ NetworkChangeNotifier::CONNECTION_UNKNOWN);
+
+ NetworkInterface interface;
+ for (int i = NetworkChangeNotifier::CONNECTION_UNKNOWN;
+ i < NetworkChangeNotifier::CONNECTION_LAST;
+ i++) {
+ // Check individual types.
+ list.clear();
+ interface.type = static_cast<NetworkChangeNotifier::ConnectionType>(i);
+ 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);
+ }
+ }
+
+#if defined(OS_WIN)
+ // Ignore fake teredo interface.
+ list.clear();
+ interface.type = NetworkChangeNotifier::CONNECTION_4G;
+ interface.friendly_name = "Teredo Tunneling Pseudo-Interface";
+ list.push_back(interface);
+ EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list),
+ NetworkChangeNotifier::CONNECTION_UNKNOWN);
+ interface.type = NetworkChangeNotifier::CONNECTION_3G;
+ interface.friendly_name = "";
+ list.push_back(interface);
+ EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list),
+ NetworkChangeNotifier::CONNECTION_3G);
+ list.reverse();
+ EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list),
+ NetworkChangeNotifier::CONNECTION_3G);
+#endif
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698