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.
5 #include "net/quic/quic_server_id.h"
7 #include "testing/gtest/include/gtest/gtest.h"
15 TEST(QuicServerIdTest
, ToString
) {
16 HostPortPair
google_host_port_pair("google.com", 10);
18 QuicServerId
google_http_server_id(google_host_port_pair
, false,
19 PRIVACY_MODE_DISABLED
);
20 string google_http_server_id_str
= google_http_server_id
.ToString();
21 EXPECT_EQ("http://google.com:10", google_http_server_id_str
);
23 QuicServerId
google_https_server_id(google_host_port_pair
, true,
24 PRIVACY_MODE_DISABLED
);
25 string google_https_server_id_str
= google_https_server_id
.ToString();
26 EXPECT_EQ("https://google.com:10", google_https_server_id_str
);
28 QuicServerId
private_http_server_id(google_host_port_pair
, false,
29 PRIVACY_MODE_ENABLED
);
30 string private_http_server_id_str
= private_http_server_id
.ToString();
31 EXPECT_EQ("http://google.com:10/private", private_http_server_id_str
);
33 QuicServerId
private_https_server_id(google_host_port_pair
, true,
34 PRIVACY_MODE_ENABLED
);
35 string private_https_server_id_str
= private_https_server_id
.ToString();
36 EXPECT_EQ("https://google.com:10/private", private_https_server_id_str
);
39 TEST(QuicServerIdTest
, LessThan
) {
40 QuicServerId
a_10_http(HostPortPair("a.com", 10), false,
41 PRIVACY_MODE_DISABLED
);
42 QuicServerId
a_10_https(HostPortPair("a.com", 10), true,
43 PRIVACY_MODE_DISABLED
);
44 QuicServerId
a_11_http(HostPortPair("a.com", 11), false,
45 PRIVACY_MODE_DISABLED
);
46 QuicServerId
a_11_https(HostPortPair("a.com", 11), true,
47 PRIVACY_MODE_DISABLED
);
48 QuicServerId
b_10_http(HostPortPair("b.com", 10), false,
49 PRIVACY_MODE_DISABLED
);
50 QuicServerId
b_10_https(HostPortPair("b.com", 10), true,
51 PRIVACY_MODE_DISABLED
);
52 QuicServerId
b_11_http(HostPortPair("b.com", 11), false,
53 PRIVACY_MODE_DISABLED
);
54 QuicServerId
b_11_https(HostPortPair("b.com", 11), true,
55 PRIVACY_MODE_DISABLED
);
57 QuicServerId
a_10_http_private(HostPortPair("a.com", 10), false,
58 PRIVACY_MODE_ENABLED
);
59 QuicServerId
a_10_https_private(HostPortPair("a.com", 10), true,
60 PRIVACY_MODE_ENABLED
);
61 QuicServerId
a_11_http_private(HostPortPair("a.com", 11), false,
62 PRIVACY_MODE_ENABLED
);
63 QuicServerId
a_11_https_private(HostPortPair("a.com", 11), true,
64 PRIVACY_MODE_ENABLED
);
65 QuicServerId
b_10_http_private(HostPortPair("b.com", 10), false,
66 PRIVACY_MODE_ENABLED
);
67 QuicServerId
b_10_https_private(HostPortPair("b.com", 10), true,
68 PRIVACY_MODE_ENABLED
);
69 QuicServerId
b_11_http_private(HostPortPair("b.com", 11), false,
70 PRIVACY_MODE_ENABLED
);
71 QuicServerId
b_11_https_private(HostPortPair("b.com", 11), true,
72 PRIVACY_MODE_ENABLED
);
74 // Test combinations of host, port, https and privacy being same on left and
75 // right side of less than.
76 EXPECT_FALSE(a_10_http
< a_10_http
);
77 EXPECT_TRUE(a_10_http
< a_10_https
);
78 EXPECT_FALSE(a_10_https
< a_10_http
);
79 EXPECT_FALSE(a_10_https
< a_10_https
);
81 EXPECT_TRUE(a_10_http
< a_10_http_private
);
82 EXPECT_TRUE(a_10_http
< a_10_https_private
);
83 EXPECT_FALSE(a_10_https
< a_10_http_private
);
84 EXPECT_TRUE(a_10_https
< a_10_https_private
);
86 EXPECT_FALSE(a_10_http_private
< a_10_http
);
87 EXPECT_TRUE(a_10_http_private
< a_10_https
);
88 EXPECT_FALSE(a_10_https_private
< a_10_http
);
89 EXPECT_FALSE(a_10_https_private
< a_10_https
);
91 EXPECT_FALSE(a_10_http_private
< a_10_http_private
);
92 EXPECT_TRUE(a_10_http_private
< a_10_https_private
);
93 EXPECT_FALSE(a_10_https_private
< a_10_http_private
);
94 EXPECT_FALSE(a_10_https_private
< a_10_https_private
);
96 // Test with either host, port or https being different on left and right side
98 PrivacyMode left_privacy
;
99 PrivacyMode right_privacy
;
100 for (int i
= 0; i
< 4; i
++) {
101 left_privacy
= static_cast<PrivacyMode
>(i
/ 2);
102 right_privacy
= static_cast<PrivacyMode
>(i
% 2);
103 QuicServerId
a_10_http_left_private(HostPortPair("a.com", 10), false,
105 QuicServerId
a_10_http_right_private(HostPortPair("a.com", 10), false,
107 QuicServerId
a_10_https_left_private(HostPortPair("a.com", 10), true,
109 QuicServerId
a_10_https_right_private(HostPortPair("a.com", 10), true,
111 QuicServerId
a_11_http_left_private(HostPortPair("a.com", 11), false,
113 QuicServerId
a_11_http_right_private(HostPortPair("a.com", 11), false,
115 QuicServerId
a_11_https_left_private(HostPortPair("a.com", 11), true,
117 QuicServerId
a_11_https_right_private(HostPortPair("a.com", 11), true,
120 QuicServerId
b_10_http_left_private(HostPortPair("b.com", 10), false,
122 QuicServerId
b_10_http_right_private(HostPortPair("b.com", 10), false,
124 QuicServerId
b_10_https_left_private(HostPortPair("b.com", 10), true,
126 QuicServerId
b_10_https_right_private(HostPortPair("b.com", 10), true,
128 QuicServerId
b_11_http_left_private(HostPortPair("b.com", 11), false,
130 QuicServerId
b_11_http_right_private(HostPortPair("b.com", 11), false,
132 QuicServerId
b_11_https_left_private(HostPortPair("b.com", 11), true,
134 QuicServerId
b_11_https_right_private(HostPortPair("b.com", 11), true,
137 EXPECT_TRUE(a_10_http_left_private
< a_11_http_right_private
);
138 EXPECT_TRUE(a_10_http_left_private
< a_11_https_right_private
);
139 EXPECT_TRUE(a_10_https_left_private
< a_11_http_right_private
);
140 EXPECT_TRUE(a_10_https_left_private
< a_11_https_right_private
);
142 EXPECT_TRUE(a_10_http_left_private
< b_10_http_right_private
);
143 EXPECT_TRUE(a_10_http_left_private
< b_10_https_right_private
);
144 EXPECT_TRUE(a_10_https_left_private
< b_10_http_right_private
);
145 EXPECT_TRUE(a_10_https_left_private
< b_10_https_right_private
);
147 EXPECT_TRUE(a_10_http_left_private
< b_11_http_right_private
);
148 EXPECT_TRUE(a_10_http_left_private
< b_11_https_right_private
);
149 EXPECT_TRUE(a_10_https_left_private
< b_11_http_right_private
);
150 EXPECT_TRUE(a_10_https_left_private
< b_11_https_right_private
);
152 EXPECT_FALSE(a_11_http_left_private
< a_10_http_right_private
);
153 EXPECT_FALSE(a_11_http_left_private
< a_10_https_right_private
);
154 EXPECT_FALSE(a_11_https_left_private
< a_10_http_right_private
);
155 EXPECT_FALSE(a_11_https_left_private
< a_10_https_right_private
);
157 EXPECT_FALSE(a_11_http_left_private
< b_10_http_right_private
);
158 EXPECT_FALSE(a_11_http_left_private
< b_10_https_right_private
);
159 EXPECT_FALSE(a_11_https_left_private
< b_10_http_right_private
);
160 EXPECT_FALSE(a_11_https_left_private
< b_10_https_right_private
);
162 EXPECT_TRUE(a_11_http_left_private
< b_11_http_right_private
);
163 EXPECT_TRUE(a_11_http_left_private
< b_11_https_right_private
);
164 EXPECT_TRUE(a_11_https_left_private
< b_11_http_right_private
);
165 EXPECT_TRUE(a_11_https_left_private
< b_11_https_right_private
);
167 EXPECT_FALSE(b_10_http_left_private
< a_10_http_right_private
);
168 EXPECT_FALSE(b_10_http_left_private
< a_10_https_right_private
);
169 EXPECT_FALSE(b_10_https_left_private
< a_10_http_right_private
);
170 EXPECT_FALSE(b_10_https_left_private
< a_10_https_right_private
);
172 EXPECT_TRUE(b_10_http_left_private
< a_11_http_right_private
);
173 EXPECT_TRUE(b_10_http_left_private
< a_11_https_right_private
);
174 EXPECT_TRUE(b_10_https_left_private
< a_11_http_right_private
);
175 EXPECT_TRUE(b_10_https_left_private
< a_11_https_right_private
);
177 EXPECT_TRUE(b_10_http_left_private
< b_11_http_right_private
);
178 EXPECT_TRUE(b_10_http_left_private
< b_11_https_right_private
);
179 EXPECT_TRUE(b_10_https_left_private
< b_11_http_right_private
);
180 EXPECT_TRUE(b_10_https_left_private
< b_11_https_right_private
);
182 EXPECT_FALSE(b_11_http_left_private
< a_10_http_right_private
);
183 EXPECT_FALSE(b_11_http_left_private
< a_10_https_right_private
);
184 EXPECT_FALSE(b_11_https_left_private
< a_10_http_right_private
);
185 EXPECT_FALSE(b_11_https_left_private
< a_10_https_right_private
);
187 EXPECT_FALSE(b_11_http_left_private
< a_11_http_right_private
);
188 EXPECT_FALSE(b_11_http_left_private
< a_11_https_right_private
);
189 EXPECT_FALSE(b_11_https_left_private
< a_11_http_right_private
);
190 EXPECT_FALSE(b_11_https_left_private
< a_11_https_right_private
);
192 EXPECT_FALSE(b_11_http_left_private
< b_10_http_right_private
);
193 EXPECT_FALSE(b_11_http_left_private
< b_10_https_right_private
);
194 EXPECT_FALSE(b_11_https_left_private
< b_10_http_right_private
);
195 EXPECT_FALSE(b_11_https_left_private
< b_10_https_right_private
);
199 TEST(QuicServerIdTest
, Equals
) {
200 PrivacyMode left_privacy
;
201 PrivacyMode right_privacy
;
202 for (int i
= 0; i
< 2; i
++) {
203 left_privacy
= right_privacy
= static_cast<PrivacyMode
>(i
);
204 QuicServerId
a_10_http_right_private(HostPortPair("a.com", 10), false,
206 QuicServerId
a_10_https_right_private(HostPortPair("a.com", 10), true,
208 QuicServerId
a_11_http_right_private(HostPortPair("a.com", 11), false,
210 QuicServerId
a_11_https_right_private(HostPortPair("a.com", 11), true,
212 QuicServerId
b_10_http_right_private(HostPortPair("b.com", 10), false,
214 QuicServerId
b_10_https_right_private(HostPortPair("b.com", 10), true,
216 QuicServerId
b_11_http_right_private(HostPortPair("b.com", 11), false,
218 QuicServerId
b_11_https_right_private(HostPortPair("b.com", 11), true,
221 QuicServerId
new_a_10_http_left_private(HostPortPair("a.com", 10), false,
223 QuicServerId
new_a_10_https_left_private(HostPortPair("a.com", 10), true,
225 QuicServerId
new_a_11_http_left_private(HostPortPair("a.com", 11), false,
227 QuicServerId
new_a_11_https_left_private(HostPortPair("a.com", 11), true,
229 QuicServerId
new_b_10_http_left_private(HostPortPair("b.com", 10), false,
231 QuicServerId
new_b_10_https_left_private(HostPortPair("b.com", 10), true,
233 QuicServerId
new_b_11_http_left_private(HostPortPair("b.com", 11), false,
235 QuicServerId
new_b_11_https_left_private(HostPortPair("b.com", 11), true,
238 EXPECT_EQ(new_a_10_http_left_private
, a_10_http_right_private
);
239 EXPECT_EQ(new_a_10_https_left_private
, a_10_https_right_private
);
240 EXPECT_EQ(new_a_11_http_left_private
, a_11_http_right_private
);
241 EXPECT_EQ(new_a_11_https_left_private
, a_11_https_right_private
);
242 EXPECT_EQ(new_b_10_http_left_private
, b_10_http_right_private
);
243 EXPECT_EQ(new_b_10_https_left_private
, b_10_https_right_private
);
244 EXPECT_EQ(new_b_11_http_left_private
, b_11_http_right_private
);
245 EXPECT_EQ(new_b_11_https_left_private
, b_11_https_right_private
);
248 for (int i
= 0; i
< 2; i
++) {
249 right_privacy
= static_cast<PrivacyMode
>(i
);
250 QuicServerId
a_10_http_right_private(HostPortPair("a.com", 10), false,
252 QuicServerId
a_10_https_right_private(HostPortPair("a.com", 10), true,
254 QuicServerId
a_11_http_right_private(HostPortPair("a.com", 11), false,
256 QuicServerId
a_11_https_right_private(HostPortPair("a.com", 11), true,
258 QuicServerId
b_10_http_right_private(HostPortPair("b.com", 10), false,
260 QuicServerId
b_10_https_right_private(HostPortPair("b.com", 10), true,
262 QuicServerId
b_11_http_right_private(HostPortPair("b.com", 11), false,
264 QuicServerId
b_11_https_right_private(HostPortPair("b.com", 11), true,
267 QuicServerId
new_a_10_http_left_private(HostPortPair("a.com", 10), false,
268 PRIVACY_MODE_DISABLED
);
270 EXPECT_FALSE(new_a_10_http_left_private
== a_10_https_right_private
);
271 EXPECT_FALSE(new_a_10_http_left_private
== a_11_http_right_private
);
272 EXPECT_FALSE(new_a_10_http_left_private
== b_10_http_right_private
);
273 EXPECT_FALSE(new_a_10_http_left_private
== a_11_https_right_private
);
274 EXPECT_FALSE(new_a_10_http_left_private
== b_10_https_right_private
);
275 EXPECT_FALSE(new_a_10_http_left_private
== b_11_http_right_private
);
276 EXPECT_FALSE(new_a_10_http_left_private
== b_11_https_right_private
);
278 QuicServerId
a_10_http_private(HostPortPair("a.com", 10), false,
279 PRIVACY_MODE_ENABLED
);
280 QuicServerId
new_a_10_http_no_private(HostPortPair("a.com", 10), false,
281 PRIVACY_MODE_DISABLED
);
282 EXPECT_FALSE(new_a_10_http_no_private
== a_10_http_private
);