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

Unified Diff: net/quic/network_connection_unittest.cc

Issue 944883003: QUIC - Cache the connection type and connection description. Make the (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed const char* const as return value to fix ios_rel_device_ninja_ng compile error Created 5 years, 10 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/quic/network_connection_unittest.cc
diff --git a/net/quic/network_connection_unittest.cc b/net/quic/network_connection_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a63438dbcc36b35cea0dd880f79a0d8489dec3e2
--- /dev/null
+++ b/net/quic/network_connection_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright 2015 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/quic/network_connection.h"
+
+#include "net/base/network_change_notifier.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+namespace test {
+
+class NetworkConnectionPeer {
+ public:
+ static NetworkChangeNotifier::ConnectionType connection_type(
+ const NetworkConnection& network_connection) {
+ return network_connection.connection_type_;
+ }
+ static void set_connection_type(NetworkConnection& network_connection,
+ NetworkChangeNotifier::ConnectionType type) {
+ network_connection.connection_type_ = type;
+ }
+
+ static const char* connection_description(
+ const NetworkConnection& network_connection) {
+ return network_connection.connection_description_;
+ }
+ static void set_connection_description(NetworkConnection& network_connection,
+ const char* description) {
+ network_connection.connection_description_ = description;
+ }
+};
+
+// Test NetworkConnection().
+class NetworkConnectionTest : public testing::Test {
+ protected:
+ void CheckNetworkConnectionDescription() {
+ NetworkChangeNotifier::ConnectionType type =
+ NetworkChangeNotifier::GetConnectionType();
+ const char* description = network_connection_.GetDescription();
+ // Verify GetDescription() updated the cached data.
+ EXPECT_EQ(NetworkConnectionPeer::connection_type(network_connection_),
+ type);
+ EXPECT_EQ(
+ NetworkConnectionPeer::connection_description(network_connection_),
+ description);
+
+ if (type != NetworkChangeNotifier::CONNECTION_WIFI)
+ EXPECT_EQ(description,
+ NetworkChangeNotifier::ConnectionTypeToString(type));
+ else
+ EXPECT_NE(nullptr, network_connection_.GetDescription());
+ }
+
+ NetworkConnection network_connection_;
+};
+
+TEST_F(NetworkConnectionTest, GetDescription) {
+ const char* description = network_connection_.GetDescription();
+
+ // Set connection description to nullptr.
+ NetworkConnectionPeer::set_connection_description(network_connection_,
+ nullptr);
+ CheckNetworkConnectionDescription();
+
+ // Set connection type to a junk value.
+ NetworkConnectionPeer::set_connection_type(
+ network_connection_, NetworkChangeNotifier::CONNECTION_LAST);
+ CheckNetworkConnectionDescription();
+
+ EXPECT_EQ(description, network_connection_.GetDescription());
+}
+
+TEST_F(NetworkConnectionTest, Clear) {
+ CheckNetworkConnectionDescription();
+ network_connection_.Clear();
+ CheckNetworkConnectionDescription();
+}
+
+} // namespace test
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698