OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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. |
| 4 |
| 5 #include "net/quic/network_connection.h" |
| 6 |
| 7 #include "net/base/network_change_notifier.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace net { |
| 11 namespace test { |
| 12 |
| 13 class NetworkConnectionPeer { |
| 14 public: |
| 15 static NetworkChangeNotifier::ConnectionType connection_type( |
| 16 const NetworkConnection& network_connection) { |
| 17 return network_connection.connection_type_; |
| 18 } |
| 19 static void set_connection_type(NetworkConnection& network_connection, |
| 20 NetworkChangeNotifier::ConnectionType type) { |
| 21 network_connection.connection_type_ = type; |
| 22 } |
| 23 |
| 24 static const char* connection_description( |
| 25 const NetworkConnection& network_connection) { |
| 26 return network_connection.connection_description_; |
| 27 } |
| 28 static void set_connection_description(NetworkConnection& network_connection, |
| 29 const char* description) { |
| 30 network_connection.connection_description_ = description; |
| 31 } |
| 32 }; |
| 33 |
| 34 // Test NetworkConnection(). |
| 35 class NetworkConnectionTest : public testing::Test { |
| 36 protected: |
| 37 void CheckNetworkConnectionDescription() { |
| 38 NetworkChangeNotifier::ConnectionType type = |
| 39 NetworkChangeNotifier::GetConnectionType(); |
| 40 const char* description = network_connection_.GetDescription(); |
| 41 // Verify GetDescription() updated the cached data. |
| 42 EXPECT_EQ(NetworkConnectionPeer::connection_type(network_connection_), |
| 43 type); |
| 44 EXPECT_EQ( |
| 45 NetworkConnectionPeer::connection_description(network_connection_), |
| 46 description); |
| 47 |
| 48 if (type != NetworkChangeNotifier::CONNECTION_WIFI) |
| 49 EXPECT_EQ(description, |
| 50 NetworkChangeNotifier::ConnectionTypeToString(type)); |
| 51 else |
| 52 EXPECT_NE(nullptr, network_connection_.GetDescription()); |
| 53 } |
| 54 |
| 55 NetworkConnection network_connection_; |
| 56 }; |
| 57 |
| 58 TEST_F(NetworkConnectionTest, GetDescription) { |
| 59 const char* description = network_connection_.GetDescription(); |
| 60 |
| 61 // Set connection description to nullptr. |
| 62 NetworkConnectionPeer::set_connection_description(network_connection_, |
| 63 nullptr); |
| 64 CheckNetworkConnectionDescription(); |
| 65 |
| 66 // Set connection type to a junk value. |
| 67 NetworkConnectionPeer::set_connection_type( |
| 68 network_connection_, NetworkChangeNotifier::CONNECTION_LAST); |
| 69 CheckNetworkConnectionDescription(); |
| 70 |
| 71 EXPECT_EQ(description, network_connection_.GetDescription()); |
| 72 } |
| 73 |
| 74 TEST_F(NetworkConnectionTest, Clear) { |
| 75 CheckNetworkConnectionDescription(); |
| 76 network_connection_.Clear(); |
| 77 CheckNetworkConnectionDescription(); |
| 78 } |
| 79 |
| 80 } // namespace test |
| 81 } // namespace net |
OLD | NEW |