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

Side by Side 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 unified diff | Download patch
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698