QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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/third_party/quiche/src/quic/core/quic_server_id.h" |
| 6 | |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 7 | #include <string> |
| 8 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | #include "net/third_party/quiche/src/quic/platform/api/quic_estimate_memory_usage.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
| 11 | |
| 12 | namespace quic { |
| 13 | |
| 14 | namespace { |
| 15 | |
| 16 | class QuicServerIdTest : public QuicTest {}; |
| 17 | |
| 18 | TEST_F(QuicServerIdTest, Constructor) { |
| 19 | QuicServerId google_server_id("google.com", 10, false); |
| 20 | EXPECT_EQ("google.com", google_server_id.host()); |
| 21 | EXPECT_EQ(10, google_server_id.port()); |
| 22 | EXPECT_FALSE(google_server_id.privacy_mode_enabled()); |
| 23 | |
| 24 | QuicServerId private_server_id("mail.google.com", 12, true); |
| 25 | EXPECT_EQ("mail.google.com", private_server_id.host()); |
| 26 | EXPECT_EQ(12, private_server_id.port()); |
| 27 | EXPECT_TRUE(private_server_id.privacy_mode_enabled()); |
| 28 | } |
| 29 | |
| 30 | TEST_F(QuicServerIdTest, LessThan) { |
| 31 | QuicServerId a_10_https("a.com", 10, false); |
| 32 | QuicServerId a_11_https("a.com", 11, false); |
| 33 | QuicServerId b_10_https("b.com", 10, false); |
| 34 | QuicServerId b_11_https("b.com", 11, false); |
| 35 | |
| 36 | QuicServerId a_10_https_private("a.com", 10, true); |
| 37 | QuicServerId a_11_https_private("a.com", 11, true); |
| 38 | QuicServerId b_10_https_private("b.com", 10, true); |
| 39 | QuicServerId b_11_https_private("b.com", 11, true); |
| 40 | |
| 41 | // Test combinations of host, port, and privacy being same on left and |
| 42 | // right side of less than. |
| 43 | EXPECT_FALSE(a_10_https < a_10_https); |
| 44 | EXPECT_TRUE(a_10_https < a_10_https_private); |
| 45 | EXPECT_FALSE(a_10_https_private < a_10_https); |
| 46 | EXPECT_FALSE(a_10_https_private < a_10_https_private); |
| 47 | |
| 48 | // Test with either host, port or https being different on left and right side |
| 49 | // of less than. |
| 50 | bool left_privacy; |
| 51 | bool right_privacy; |
| 52 | for (int i = 0; i < 4; i++) { |
| 53 | left_privacy = (i / 2 == 0); |
| 54 | right_privacy = (i % 2 == 0); |
| 55 | QuicServerId a_10_https_left_private("a.com", 10, left_privacy); |
| 56 | QuicServerId a_10_https_right_private("a.com", 10, right_privacy); |
| 57 | QuicServerId a_11_https_left_private("a.com", 11, left_privacy); |
| 58 | QuicServerId a_11_https_right_private("a.com", 11, right_privacy); |
| 59 | |
| 60 | QuicServerId b_10_https_left_private("b.com", 10, left_privacy); |
| 61 | QuicServerId b_10_https_right_private("b.com", 10, right_privacy); |
| 62 | QuicServerId b_11_https_left_private("b.com", 11, left_privacy); |
| 63 | QuicServerId b_11_https_right_private("b.com", 11, right_privacy); |
| 64 | |
| 65 | EXPECT_TRUE(a_10_https_left_private < a_11_https_right_private); |
| 66 | EXPECT_TRUE(a_10_https_left_private < b_10_https_right_private); |
| 67 | EXPECT_TRUE(a_10_https_left_private < b_11_https_right_private); |
| 68 | EXPECT_FALSE(a_11_https_left_private < a_10_https_right_private); |
| 69 | EXPECT_FALSE(a_11_https_left_private < b_10_https_right_private); |
| 70 | EXPECT_TRUE(a_11_https_left_private < b_11_https_right_private); |
| 71 | EXPECT_FALSE(b_10_https_left_private < a_10_https_right_private); |
| 72 | EXPECT_TRUE(b_10_https_left_private < a_11_https_right_private); |
| 73 | EXPECT_TRUE(b_10_https_left_private < b_11_https_right_private); |
| 74 | EXPECT_FALSE(b_11_https_left_private < a_10_https_right_private); |
| 75 | EXPECT_FALSE(b_11_https_left_private < a_11_https_right_private); |
| 76 | EXPECT_FALSE(b_11_https_left_private < b_10_https_right_private); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | TEST_F(QuicServerIdTest, Equals) { |
| 81 | bool left_privacy; |
| 82 | bool right_privacy; |
| 83 | for (int i = 0; i < 2; i++) { |
| 84 | left_privacy = right_privacy = (i == 0); |
| 85 | QuicServerId a_10_https_right_private("a.com", 10, right_privacy); |
| 86 | QuicServerId a_11_https_right_private("a.com", 11, right_privacy); |
| 87 | QuicServerId b_10_https_right_private("b.com", 10, right_privacy); |
| 88 | QuicServerId b_11_https_right_private("b.com", 11, right_privacy); |
| 89 | |
| 90 | QuicServerId new_a_10_https_left_private("a.com", 10, left_privacy); |
| 91 | QuicServerId new_a_11_https_left_private("a.com", 11, left_privacy); |
| 92 | QuicServerId new_b_10_https_left_private("b.com", 10, left_privacy); |
| 93 | QuicServerId new_b_11_https_left_private("b.com", 11, left_privacy); |
| 94 | |
| 95 | EXPECT_EQ(new_a_10_https_left_private, a_10_https_right_private); |
| 96 | EXPECT_EQ(new_a_11_https_left_private, a_11_https_right_private); |
| 97 | EXPECT_EQ(new_b_10_https_left_private, b_10_https_right_private); |
| 98 | EXPECT_EQ(new_b_11_https_left_private, b_11_https_right_private); |
| 99 | } |
| 100 | |
| 101 | for (int i = 0; i < 2; i++) { |
| 102 | right_privacy = (i == 0); |
| 103 | QuicServerId a_10_https_right_private("a.com", 10, right_privacy); |
| 104 | QuicServerId a_11_https_right_private("a.com", 11, right_privacy); |
| 105 | QuicServerId b_10_https_right_private("b.com", 10, right_privacy); |
| 106 | QuicServerId b_11_https_right_private("b.com", 11, right_privacy); |
| 107 | |
| 108 | QuicServerId new_a_10_https_left_private("a.com", 10, false); |
| 109 | |
| 110 | EXPECT_FALSE(new_a_10_https_left_private == a_11_https_right_private); |
| 111 | EXPECT_FALSE(new_a_10_https_left_private == b_10_https_right_private); |
| 112 | EXPECT_FALSE(new_a_10_https_left_private == b_11_https_right_private); |
| 113 | } |
| 114 | QuicServerId a_10_https_private("a.com", 10, true); |
| 115 | QuicServerId new_a_10_https_no_private("a.com", 10, false); |
| 116 | EXPECT_FALSE(new_a_10_https_no_private == a_10_https_private); |
| 117 | } |
| 118 | |
| 119 | TEST_F(QuicServerIdTest, EstimateMemoryUsage) { |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 120 | std::string host = "this is a rather very quite long hostname"; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 121 | uint16_t port = 10; |
| 122 | bool privacy_mode_enabled = true; |
| 123 | QuicServerId server_id(host, port, privacy_mode_enabled); |
| 124 | EXPECT_EQ(QuicEstimateMemoryUsage(host), QuicEstimateMemoryUsage(server_id)); |
| 125 | } |
| 126 | |
| 127 | } // namespace |
| 128 | |
| 129 | } // namespace quic |