summaryrefslogtreecommitdiff
path: root/chromium/net/quic/quic_server_id_test.cc
blob: 1e08b30d50f8ecb627d876b4f46f8c52f85faf16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/quic/quic_server_id.h"

#include "testing/gtest/include/gtest/gtest.h"

using std::string;

namespace net {

namespace {

TEST(QuicServerIdTest, ToString) {
  HostPortPair google_host_port_pair("google.com", 10);

  QuicServerId google_http_server_id(google_host_port_pair, false,
                                     PRIVACY_MODE_DISABLED);
  string google_http_server_id_str = google_http_server_id.ToString();
  EXPECT_EQ("http://google.com:10", google_http_server_id_str);

  QuicServerId google_https_server_id(google_host_port_pair, true,
                                      PRIVACY_MODE_DISABLED);
  string google_https_server_id_str = google_https_server_id.ToString();
  EXPECT_EQ("https://google.com:10", google_https_server_id_str);

  QuicServerId private_http_server_id(google_host_port_pair, false,
                                      PRIVACY_MODE_ENABLED);
  string private_http_server_id_str = private_http_server_id.ToString();
  EXPECT_EQ("http://google.com:10/private", private_http_server_id_str);

  QuicServerId private_https_server_id(google_host_port_pair, true,
                                       PRIVACY_MODE_ENABLED);
  string private_https_server_id_str = private_https_server_id.ToString();
  EXPECT_EQ("https://google.com:10/private", private_https_server_id_str);
}

TEST(QuicServerIdTest, LessThan) {
  QuicServerId a_10_http(HostPortPair("a.com", 10), false,
                         PRIVACY_MODE_DISABLED);
  QuicServerId a_10_https(HostPortPair("a.com", 10), true,
                          PRIVACY_MODE_DISABLED);
  QuicServerId a_11_http(HostPortPair("a.com", 11), false,
                         PRIVACY_MODE_DISABLED);
  QuicServerId a_11_https(HostPortPair("a.com", 11), true,
                          PRIVACY_MODE_DISABLED);
  QuicServerId b_10_http(HostPortPair("b.com", 10), false,
                         PRIVACY_MODE_DISABLED);
  QuicServerId b_10_https(HostPortPair("b.com", 10), true,
                          PRIVACY_MODE_DISABLED);
  QuicServerId b_11_http(HostPortPair("b.com", 11), false,
                         PRIVACY_MODE_DISABLED);
  QuicServerId b_11_https(HostPortPair("b.com", 11), true,
                          PRIVACY_MODE_DISABLED);

  QuicServerId a_10_http_private(HostPortPair("a.com", 10), false,
                                 PRIVACY_MODE_ENABLED);
  QuicServerId a_10_https_private(HostPortPair("a.com", 10), true,
                                  PRIVACY_MODE_ENABLED);
  QuicServerId a_11_http_private(HostPortPair("a.com", 11), false,
                                 PRIVACY_MODE_ENABLED);
  QuicServerId a_11_https_private(HostPortPair("a.com", 11), true,
                                  PRIVACY_MODE_ENABLED);
  QuicServerId b_10_http_private(HostPortPair("b.com", 10), false,
                                 PRIVACY_MODE_ENABLED);
  QuicServerId b_10_https_private(HostPortPair("b.com", 10), true,
                                  PRIVACY_MODE_ENABLED);
  QuicServerId b_11_http_private(HostPortPair("b.com", 11), false,
                                 PRIVACY_MODE_ENABLED);
  QuicServerId b_11_https_private(HostPortPair("b.com", 11), true,
                                  PRIVACY_MODE_ENABLED);

  // Test combinations of host, port, https and privacy being same on left and
  // right side of less than.
  EXPECT_FALSE(a_10_http  < a_10_http);
  EXPECT_TRUE(a_10_http   < a_10_https);
  EXPECT_FALSE(a_10_https < a_10_http);
  EXPECT_FALSE(a_10_https < a_10_https);

  EXPECT_TRUE(a_10_http   < a_10_http_private);
  EXPECT_TRUE(a_10_http   < a_10_https_private);
  EXPECT_FALSE(a_10_https < a_10_http_private);
  EXPECT_TRUE(a_10_https  < a_10_https_private);

  EXPECT_FALSE(a_10_http_private  < a_10_http);
  EXPECT_TRUE(a_10_http_private   < a_10_https);
  EXPECT_FALSE(a_10_https_private < a_10_http);
  EXPECT_FALSE(a_10_https_private < a_10_https);

  EXPECT_FALSE(a_10_http_private  < a_10_http_private);
  EXPECT_TRUE(a_10_http_private   < a_10_https_private);
  EXPECT_FALSE(a_10_https_private < a_10_http_private);
  EXPECT_FALSE(a_10_https_private < a_10_https_private);

  // Test with either host, port or https being different on left and right side
  // of less than.
  PrivacyMode left_privacy;
  PrivacyMode right_privacy;
  for (int i = 0; i < 4; i++) {
    left_privacy = static_cast<PrivacyMode>(i / 2);
    right_privacy = static_cast<PrivacyMode>(i % 2);
    QuicServerId a_10_http_left_private(HostPortPair("a.com", 10), false,
                                        left_privacy);
    QuicServerId a_10_http_right_private(HostPortPair("a.com", 10), false,
                                         right_privacy);
    QuicServerId a_10_https_left_private(HostPortPair("a.com", 10), true,
                                         left_privacy);
    QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), true,
                                          right_privacy);
    QuicServerId a_11_http_left_private(HostPortPair("a.com", 11), false,
                                        left_privacy);
    QuicServerId a_11_http_right_private(HostPortPair("a.com", 11), false,
                                         right_privacy);
    QuicServerId a_11_https_left_private(HostPortPair("a.com", 11), true,
                                         left_privacy);
    QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), true,
                                          right_privacy);

    QuicServerId b_10_http_left_private(HostPortPair("b.com", 10), false,
                                        left_privacy);
    QuicServerId b_10_http_right_private(HostPortPair("b.com", 10), false,
                                         right_privacy);
    QuicServerId b_10_https_left_private(HostPortPair("b.com", 10), true,
                                         left_privacy);
    QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), true,
                                          right_privacy);
    QuicServerId b_11_http_left_private(HostPortPair("b.com", 11), false,
                                        left_privacy);
    QuicServerId b_11_http_right_private(HostPortPair("b.com", 11), false,
                                         right_privacy);
    QuicServerId b_11_https_left_private(HostPortPair("b.com", 11), true,
                                         left_privacy);
    QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), true,
                                          right_privacy);

    EXPECT_TRUE(a_10_http_left_private  < a_11_http_right_private);
    EXPECT_TRUE(a_10_http_left_private  < a_11_https_right_private);
    EXPECT_TRUE(a_10_https_left_private < a_11_http_right_private);
    EXPECT_TRUE(a_10_https_left_private < a_11_https_right_private);

    EXPECT_TRUE(a_10_http_left_private  < b_10_http_right_private);
    EXPECT_TRUE(a_10_http_left_private  < b_10_https_right_private);
    EXPECT_TRUE(a_10_https_left_private < b_10_http_right_private);
    EXPECT_TRUE(a_10_https_left_private < b_10_https_right_private);

    EXPECT_TRUE(a_10_http_left_private  < b_11_http_right_private);
    EXPECT_TRUE(a_10_http_left_private  < b_11_https_right_private);
    EXPECT_TRUE(a_10_https_left_private < b_11_http_right_private);
    EXPECT_TRUE(a_10_https_left_private < b_11_https_right_private);

    EXPECT_FALSE(a_11_http_left_private  < a_10_http_right_private);
    EXPECT_FALSE(a_11_http_left_private  < a_10_https_right_private);
    EXPECT_FALSE(a_11_https_left_private < a_10_http_right_private);
    EXPECT_FALSE(a_11_https_left_private < a_10_https_right_private);

    EXPECT_FALSE(a_11_http_left_private  < b_10_http_right_private);
    EXPECT_FALSE(a_11_http_left_private  < b_10_https_right_private);
    EXPECT_FALSE(a_11_https_left_private < b_10_http_right_private);
    EXPECT_FALSE(a_11_https_left_private < b_10_https_right_private);

    EXPECT_TRUE(a_11_http_left_private  < b_11_http_right_private);
    EXPECT_TRUE(a_11_http_left_private  < b_11_https_right_private);
    EXPECT_TRUE(a_11_https_left_private < b_11_http_right_private);
    EXPECT_TRUE(a_11_https_left_private < b_11_https_right_private);

    EXPECT_FALSE(b_10_http_left_private  < a_10_http_right_private);
    EXPECT_FALSE(b_10_http_left_private  < a_10_https_right_private);
    EXPECT_FALSE(b_10_https_left_private < a_10_http_right_private);
    EXPECT_FALSE(b_10_https_left_private < a_10_https_right_private);

    EXPECT_TRUE(b_10_http_left_private  < a_11_http_right_private);
    EXPECT_TRUE(b_10_http_left_private  < a_11_https_right_private);
    EXPECT_TRUE(b_10_https_left_private < a_11_http_right_private);
    EXPECT_TRUE(b_10_https_left_private < a_11_https_right_private);

    EXPECT_TRUE(b_10_http_left_private  < b_11_http_right_private);
    EXPECT_TRUE(b_10_http_left_private  < b_11_https_right_private);
    EXPECT_TRUE(b_10_https_left_private < b_11_http_right_private);
    EXPECT_TRUE(b_10_https_left_private < b_11_https_right_private);

    EXPECT_FALSE(b_11_http_left_private  < a_10_http_right_private);
    EXPECT_FALSE(b_11_http_left_private  < a_10_https_right_private);
    EXPECT_FALSE(b_11_https_left_private < a_10_http_right_private);
    EXPECT_FALSE(b_11_https_left_private < a_10_https_right_private);

    EXPECT_FALSE(b_11_http_left_private  < a_11_http_right_private);
    EXPECT_FALSE(b_11_http_left_private  < a_11_https_right_private);
    EXPECT_FALSE(b_11_https_left_private < a_11_http_right_private);
    EXPECT_FALSE(b_11_https_left_private < a_11_https_right_private);

    EXPECT_FALSE(b_11_http_left_private  < b_10_http_right_private);
    EXPECT_FALSE(b_11_http_left_private  < b_10_https_right_private);
    EXPECT_FALSE(b_11_https_left_private < b_10_http_right_private);
    EXPECT_FALSE(b_11_https_left_private < b_10_https_right_private);
  }
}

TEST(QuicServerIdTest, Equals) {
  PrivacyMode left_privacy;
  PrivacyMode right_privacy;
  for (int i = 0; i < 2; i++) {
    left_privacy = right_privacy = static_cast<PrivacyMode>(i);
    QuicServerId a_10_http_right_private(HostPortPair("a.com", 10), false,
                                         right_privacy);
    QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), true,
                                          right_privacy);
    QuicServerId a_11_http_right_private(HostPortPair("a.com", 11), false,
                                         right_privacy);
    QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), true,
                                          right_privacy);
    QuicServerId b_10_http_right_private(HostPortPair("b.com", 10), false,
                                         right_privacy);
    QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), true,
                                          right_privacy);
    QuicServerId b_11_http_right_private(HostPortPair("b.com", 11), false,
                                         right_privacy);
    QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), true,
                                          right_privacy);

    QuicServerId new_a_10_http_left_private(HostPortPair("a.com", 10), false,
                                            left_privacy);
    QuicServerId new_a_10_https_left_private(HostPortPair("a.com", 10), true,
                                             left_privacy);
    QuicServerId new_a_11_http_left_private(HostPortPair("a.com", 11), false,
                                            left_privacy);
    QuicServerId new_a_11_https_left_private(HostPortPair("a.com", 11), true,
                                             left_privacy);
    QuicServerId new_b_10_http_left_private(HostPortPair("b.com", 10), false,
                                            left_privacy);
    QuicServerId new_b_10_https_left_private(HostPortPair("b.com", 10), true,
                                             left_privacy);
    QuicServerId new_b_11_http_left_private(HostPortPair("b.com", 11), false,
                                            left_privacy);
    QuicServerId new_b_11_https_left_private(HostPortPair("b.com", 11), true,
                                             left_privacy);

    EXPECT_EQ(new_a_10_http_left_private,  a_10_http_right_private);
    EXPECT_EQ(new_a_10_https_left_private, a_10_https_right_private);
    EXPECT_EQ(new_a_11_http_left_private,  a_11_http_right_private);
    EXPECT_EQ(new_a_11_https_left_private, a_11_https_right_private);
    EXPECT_EQ(new_b_10_http_left_private,  b_10_http_right_private);
    EXPECT_EQ(new_b_10_https_left_private, b_10_https_right_private);
    EXPECT_EQ(new_b_11_http_left_private,  b_11_http_right_private);
    EXPECT_EQ(new_b_11_https_left_private, b_11_https_right_private);
  }

  for (int i = 0; i < 2; i++) {
    right_privacy = static_cast<PrivacyMode>(i);
    QuicServerId a_10_http_right_private(HostPortPair("a.com", 10), false,
                                         right_privacy);
    QuicServerId a_10_https_right_private(HostPortPair("a.com", 10), true,
                                          right_privacy);
    QuicServerId a_11_http_right_private(HostPortPair("a.com", 11), false,
                                         right_privacy);
    QuicServerId a_11_https_right_private(HostPortPair("a.com", 11), true,
                                          right_privacy);
    QuicServerId b_10_http_right_private(HostPortPair("b.com", 10), false,
                                         right_privacy);
    QuicServerId b_10_https_right_private(HostPortPair("b.com", 10), true,
                                          right_privacy);
    QuicServerId b_11_http_right_private(HostPortPair("b.com", 11), false,
                                         right_privacy);
    QuicServerId b_11_https_right_private(HostPortPair("b.com", 11), true,
                                          right_privacy);

    QuicServerId new_a_10_http_left_private(HostPortPair("a.com", 10), false,
                                            PRIVACY_MODE_DISABLED);

    EXPECT_FALSE(new_a_10_http_left_private == a_10_https_right_private);
    EXPECT_FALSE(new_a_10_http_left_private == a_11_http_right_private);
    EXPECT_FALSE(new_a_10_http_left_private == b_10_http_right_private);
    EXPECT_FALSE(new_a_10_http_left_private == a_11_https_right_private);
    EXPECT_FALSE(new_a_10_http_left_private == b_10_https_right_private);
    EXPECT_FALSE(new_a_10_http_left_private == b_11_http_right_private);
    EXPECT_FALSE(new_a_10_http_left_private == b_11_https_right_private);
  }
  QuicServerId a_10_http_private(HostPortPair("a.com", 10), false,
                                 PRIVACY_MODE_ENABLED);
  QuicServerId new_a_10_http_no_private(HostPortPair("a.com", 10), false,
                                        PRIVACY_MODE_DISABLED);
  EXPECT_FALSE(new_a_10_http_no_private == a_10_http_private);
}

}  // namespace

}  // namespace net