Include all dupe types (event when value is zero) in scan stats.
[chromium-blink-merge.git] / net / quic / quic_server_id_test.cc
blob1e08b30d50f8ecb627d876b4f46f8c52f85faf16
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"
9 using std::string;
11 namespace net {
13 namespace {
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
97 // of less than.
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,
104 left_privacy);
105 QuicServerId a_10_http_right_private(HostPortPair("a.com", 10), false,
106 right_privacy);
107 QuicServerId a_10_https_left_private(HostPortPair("a.com", 10), true,
108 left_privacy);
109 QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), true,
110 right_privacy);
111 QuicServerId a_11_http_left_private(HostPortPair("a.com", 11), false,
112 left_privacy);
113 QuicServerId a_11_http_right_private(HostPortPair("a.com", 11), false,
114 right_privacy);
115 QuicServerId a_11_https_left_private(HostPortPair("a.com", 11), true,
116 left_privacy);
117 QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), true,
118 right_privacy);
120 QuicServerId b_10_http_left_private(HostPortPair("b.com", 10), false,
121 left_privacy);
122 QuicServerId b_10_http_right_private(HostPortPair("b.com", 10), false,
123 right_privacy);
124 QuicServerId b_10_https_left_private(HostPortPair("b.com", 10), true,
125 left_privacy);
126 QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), true,
127 right_privacy);
128 QuicServerId b_11_http_left_private(HostPortPair("b.com", 11), false,
129 left_privacy);
130 QuicServerId b_11_http_right_private(HostPortPair("b.com", 11), false,
131 right_privacy);
132 QuicServerId b_11_https_left_private(HostPortPair("b.com", 11), true,
133 left_privacy);
134 QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), true,
135 right_privacy);
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,
205 right_privacy);
206 QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), true,
207 right_privacy);
208 QuicServerId a_11_http_right_private(HostPortPair("a.com", 11), false,
209 right_privacy);
210 QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), true,
211 right_privacy);
212 QuicServerId b_10_http_right_private(HostPortPair("b.com", 10), false,
213 right_privacy);
214 QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), true,
215 right_privacy);
216 QuicServerId b_11_http_right_private(HostPortPair("b.com", 11), false,
217 right_privacy);
218 QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), true,
219 right_privacy);
221 QuicServerId new_a_10_http_left_private(HostPortPair("a.com", 10), false,
222 left_privacy);
223 QuicServerId new_a_10_https_left_private(HostPortPair("a.com", 10), true,
224 left_privacy);
225 QuicServerId new_a_11_http_left_private(HostPortPair("a.com", 11), false,
226 left_privacy);
227 QuicServerId new_a_11_https_left_private(HostPortPair("a.com", 11), true,
228 left_privacy);
229 QuicServerId new_b_10_http_left_private(HostPortPair("b.com", 10), false,
230 left_privacy);
231 QuicServerId new_b_10_https_left_private(HostPortPair("b.com", 10), true,
232 left_privacy);
233 QuicServerId new_b_11_http_left_private(HostPortPair("b.com", 11), false,
234 left_privacy);
235 QuicServerId new_b_11_https_left_private(HostPortPair("b.com", 11), true,
236 left_privacy);
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,
251 right_privacy);
252 QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), true,
253 right_privacy);
254 QuicServerId a_11_http_right_private(HostPortPair("a.com", 11), false,
255 right_privacy);
256 QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), true,
257 right_privacy);
258 QuicServerId b_10_http_right_private(HostPortPair("b.com", 10), false,
259 right_privacy);
260 QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), true,
261 right_privacy);
262 QuicServerId b_11_http_right_private(HostPortPair("b.com", 11), false,
263 right_privacy);
264 QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), true,
265 right_privacy);
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);
285 } // namespace
287 } // namespace net