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

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: Fix win build (no std::vector.reverse) 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
« no previous file with comments | « net/base/network_change_notifier.cc ('k') | net/base/network_change_notifier_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..db6e18102d87f4e5ec1e6eb78935161844b7f185
--- /dev/null
+++ b/net/base/network_change_notifier_unittest.cc
@@ -0,0 +1,72 @@
+// 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.
+
mmenke 2014/06/20 15:18:57 nit: #include "network_change_notifier.h", one li
pauljensen 2014/06/20 19:22:31 Done.
+#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) {
mmenke 2014/06/20 15:18:57 nit: Can we get rid of the test fixture, and just
pauljensen 2014/06/20 19:22:32 Done. I forgot you could friend functions.
+ 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.
mmenke 2014/06/20 15:18:57 nit: I believe Teredo should be capitalized.
pauljensen 2014/06/20 19:22:32 Done.
+ list.clear();
+ interface.type = NetworkChangeNotifier::CONNECTION_4G;
+ interface.friendly_name = "Teredo Tunneling Pseudo-Interface";
+ list.push_back(interface);
+ // Verify we ignore teredo element type.
mmenke 2014/06/20 15:18:57 nit: Don't use "we" in comments.
pauljensen 2014/06/20 19:22:32 Done.
+ EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list),
+ NetworkChangeNotifier::CONNECTION_UNKNOWN);
+ // Verify we take type of non-teredo element.
mmenke 2014/06/20 15:18:57 nit: Don't use "we" in comments.
pauljensen 2014/06/20 19:22:32 Done.
+ interface.type = NetworkChangeNotifier::CONNECTION_3G;
+ interface.friendly_name = "";
+ list.push_back(interface);
+ EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list),
+ NetworkChangeNotifier::CONNECTION_3G);
+ // Reverse elements.
+ list[2] = list[0];
+ list.erase(list.begin());
+ EXPECT_EQ(NetworkChangeNotifier::ConnectionTypeFromInterfaceList(list),
+ NetworkChangeNotifier::CONNECTION_3G);
+#endif
+}
+
+} // namespace net
« no previous file with comments | « net/base/network_change_notifier.cc ('k') | net/base/network_change_notifier_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698