Revert of Move fetching logic out of ApplicationManager, eliminate url mappings....
[chromium-blink-merge.git] / net / quic / network_connection_unittest.cc
bloba63438dbcc36b35cea0dd880f79a0d8489dec3e2
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.
5 #include "net/quic/network_connection.h"
7 #include "net/base/network_change_notifier.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace net {
11 namespace test {
13 class NetworkConnectionPeer {
14 public:
15 static NetworkChangeNotifier::ConnectionType connection_type(
16 const NetworkConnection& network_connection) {
17 return network_connection.connection_type_;
19 static void set_connection_type(NetworkConnection& network_connection,
20 NetworkChangeNotifier::ConnectionType type) {
21 network_connection.connection_type_ = type;
24 static const char* connection_description(
25 const NetworkConnection& network_connection) {
26 return network_connection.connection_description_;
28 static void set_connection_description(NetworkConnection& network_connection,
29 const char* description) {
30 network_connection.connection_description_ = description;
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);
48 if (type != NetworkChangeNotifier::CONNECTION_WIFI)
49 EXPECT_EQ(description,
50 NetworkChangeNotifier::ConnectionTypeToString(type));
51 else
52 EXPECT_NE(nullptr, network_connection_.GetDescription());
55 NetworkConnection network_connection_;
58 TEST_F(NetworkConnectionTest, GetDescription) {
59 const char* description = network_connection_.GetDescription();
61 // Set connection description to nullptr.
62 NetworkConnectionPeer::set_connection_description(network_connection_,
63 nullptr);
64 CheckNetworkConnectionDescription();
66 // Set connection type to a junk value.
67 NetworkConnectionPeer::set_connection_type(
68 network_connection_, NetworkChangeNotifier::CONNECTION_LAST);
69 CheckNetworkConnectionDescription();
71 EXPECT_EQ(description, network_connection_.GetDescription());
74 TEST_F(NetworkConnectionTest, Clear) {
75 CheckNetworkConnectionDescription();
76 network_connection_.Clear();
77 CheckNetworkConnectionDescription();
80 } // namespace test
81 } // namespace net