| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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/quic_server_id.h" | |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 using std::string; | |
| 10 | |
| 11 namespace net { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 TEST(QuicServerIdTest, ToString) { | |
| 16 HostPortPair google_host_port_pair("google.com", 10); | |
| 17 | |
| 18 QuicServerId google_server_id(google_host_port_pair, PRIVACY_MODE_DISABLED); | |
| 19 string google_server_id_str = google_server_id.ToString(); | |
| 20 EXPECT_EQ("https://google.com:10", google_server_id_str); | |
| 21 | |
| 22 QuicServerId private_server_id(google_host_port_pair, PRIVACY_MODE_ENABLED); | |
| 23 string private_server_id_str = private_server_id.ToString(); | |
| 24 EXPECT_EQ("https://google.com:10/private", private_server_id_str); | |
| 25 } | |
| 26 | |
| 27 TEST(QuicServerIdTest, LessThan) { | |
| 28 QuicServerId a_10_https(HostPortPair("a.com", 10), PRIVACY_MODE_DISABLED); | |
| 29 QuicServerId a_11_https(HostPortPair("a.com", 11), PRIVACY_MODE_DISABLED); | |
| 30 QuicServerId b_10_https(HostPortPair("b.com", 10), PRIVACY_MODE_DISABLED); | |
| 31 QuicServerId b_11_https(HostPortPair("b.com", 11), PRIVACY_MODE_DISABLED); | |
| 32 | |
| 33 QuicServerId a_10_https_private(HostPortPair("a.com", 10), | |
| 34 PRIVACY_MODE_ENABLED); | |
| 35 QuicServerId a_11_https_private(HostPortPair("a.com", 11), | |
| 36 PRIVACY_MODE_ENABLED); | |
| 37 QuicServerId b_10_https_private(HostPortPair("b.com", 10), | |
| 38 PRIVACY_MODE_ENABLED); | |
| 39 QuicServerId b_11_https_private(HostPortPair("b.com", 11), | |
| 40 PRIVACY_MODE_ENABLED); | |
| 41 | |
| 42 // Test combinations of host, port, and privacy being same on left and | |
| 43 // right side of less than. | |
| 44 EXPECT_FALSE(a_10_https < a_10_https); | |
| 45 EXPECT_TRUE(a_10_https < a_10_https_private); | |
| 46 EXPECT_FALSE(a_10_https_private < a_10_https); | |
| 47 EXPECT_FALSE(a_10_https_private < a_10_https_private); | |
| 48 | |
| 49 // Test with either host, port or https being different on left and right side | |
| 50 // of less than. | |
| 51 PrivacyMode left_privacy; | |
| 52 PrivacyMode right_privacy; | |
| 53 for (int i = 0; i < 4; i++) { | |
| 54 left_privacy = static_cast<PrivacyMode>(i / 2); | |
| 55 right_privacy = static_cast<PrivacyMode>(i % 2); | |
| 56 QuicServerId a_10_https_left_private(HostPortPair("a.com", 10), | |
| 57 left_privacy); | |
| 58 QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), | |
| 59 right_privacy); | |
| 60 QuicServerId a_11_https_left_private(HostPortPair("a.com", 11), | |
| 61 left_privacy); | |
| 62 QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), | |
| 63 right_privacy); | |
| 64 | |
| 65 QuicServerId b_10_https_left_private(HostPortPair("b.com", 10), | |
| 66 left_privacy); | |
| 67 QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), | |
| 68 right_privacy); | |
| 69 QuicServerId b_11_https_left_private(HostPortPair("b.com", 11), | |
| 70 left_privacy); | |
| 71 QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), | |
| 72 right_privacy); | |
| 73 | |
| 74 EXPECT_TRUE(a_10_https_left_private < a_11_https_right_private); | |
| 75 EXPECT_TRUE(a_10_https_left_private < b_10_https_right_private); | |
| 76 EXPECT_TRUE(a_10_https_left_private < b_11_https_right_private); | |
| 77 EXPECT_FALSE(a_11_https_left_private < a_10_https_right_private); | |
| 78 EXPECT_FALSE(a_11_https_left_private < b_10_https_right_private); | |
| 79 EXPECT_TRUE(a_11_https_left_private < b_11_https_right_private); | |
| 80 EXPECT_FALSE(b_10_https_left_private < a_10_https_right_private); | |
| 81 EXPECT_TRUE(b_10_https_left_private < a_11_https_right_private); | |
| 82 EXPECT_TRUE(b_10_https_left_private < b_11_https_right_private); | |
| 83 EXPECT_FALSE(b_11_https_left_private < a_10_https_right_private); | |
| 84 EXPECT_FALSE(b_11_https_left_private < a_11_https_right_private); | |
| 85 EXPECT_FALSE(b_11_https_left_private < b_10_https_right_private); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 TEST(QuicServerIdTest, Equals) { | |
| 90 PrivacyMode left_privacy; | |
| 91 PrivacyMode right_privacy; | |
| 92 for (int i = 0; i < 2; i++) { | |
| 93 left_privacy = right_privacy = static_cast<PrivacyMode>(i); | |
| 94 QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), | |
| 95 right_privacy); | |
| 96 QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), | |
| 97 right_privacy); | |
| 98 QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), | |
| 99 right_privacy); | |
| 100 QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), | |
| 101 right_privacy); | |
| 102 | |
| 103 QuicServerId new_a_10_https_left_private(HostPortPair("a.com", 10), | |
| 104 left_privacy); | |
| 105 QuicServerId new_a_11_https_left_private(HostPortPair("a.com", 11), | |
| 106 left_privacy); | |
| 107 QuicServerId new_b_10_https_left_private(HostPortPair("b.com", 10), | |
| 108 left_privacy); | |
| 109 QuicServerId new_b_11_https_left_private(HostPortPair("b.com", 11), | |
| 110 left_privacy); | |
| 111 | |
| 112 EXPECT_EQ(new_a_10_https_left_private, a_10_https_right_private); | |
| 113 EXPECT_EQ(new_a_11_https_left_private, a_11_https_right_private); | |
| 114 EXPECT_EQ(new_b_10_https_left_private, b_10_https_right_private); | |
| 115 EXPECT_EQ(new_b_11_https_left_private, b_11_https_right_private); | |
| 116 } | |
| 117 | |
| 118 for (int i = 0; i < 2; i++) { | |
| 119 right_privacy = static_cast<PrivacyMode>(i); | |
| 120 QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), | |
| 121 right_privacy); | |
| 122 QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), | |
| 123 right_privacy); | |
| 124 QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), | |
| 125 right_privacy); | |
| 126 QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), | |
| 127 right_privacy); | |
| 128 | |
| 129 QuicServerId new_a_10_https_left_private(HostPortPair("a.com", 10), | |
| 130 PRIVACY_MODE_DISABLED); | |
| 131 | |
| 132 EXPECT_FALSE(new_a_10_https_left_private == a_11_https_right_private); | |
| 133 EXPECT_FALSE(new_a_10_https_left_private == b_10_https_right_private); | |
| 134 EXPECT_FALSE(new_a_10_https_left_private == b_11_https_right_private); | |
| 135 } | |
| 136 QuicServerId a_10_https_private(HostPortPair("a.com", 10), | |
| 137 PRIVACY_MODE_ENABLED); | |
| 138 QuicServerId new_a_10_https_no_private(HostPortPair("a.com", 10), | |
| 139 PRIVACY_MODE_DISABLED); | |
| 140 EXPECT_FALSE(new_a_10_https_no_private == a_10_https_private); | |
| 141 } | |
| 142 | |
| 143 } // namespace | |
| 144 | |
| 145 } // namespace net | |
| OLD | NEW |