Shivani Sharma | d81bdd4 | 2019-05-23 17:19:56 | [diff] [blame] | 1 | // Copyright 2019 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/base/network_isolation_key.h" |
| 6 | |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 7 | #include "base/stl_util.h" |
Eric Robinson | fc7de10 | 2019-06-21 15:27:10 | [diff] [blame] | 8 | #include "base/test/scoped_feature_list.h" |
Matt Menke | 2fa4599 | 2019-08-06 23:07:35 | [diff] [blame^] | 9 | #include "base/values.h" |
Eric Robinson | fc7de10 | 2019-06-21 15:27:10 | [diff] [blame] | 10 | #include "net/base/features.h" |
Shivani Sharma | d81bdd4 | 2019-05-23 17:19:56 | [diff] [blame] | 11 | #include "testing/gtest/include/gtest/gtest.h" |
| 12 | #include "url/gurl.h" |
| 13 | #include "url/origin.h" |
| 14 | |
| 15 | namespace net { |
| 16 | |
| 17 | TEST(NetworkIsolationKeyTest, EmptyKey) { |
| 18 | NetworkIsolationKey key; |
| 19 | EXPECT_FALSE(key.IsFullyPopulated()); |
| 20 | EXPECT_EQ(std::string(), key.ToString()); |
| 21 | EXPECT_TRUE(key.IsTransient()); |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 22 | EXPECT_EQ("null", key.ToDebugString()); |
Shivani Sharma | d81bdd4 | 2019-05-23 17:19:56 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | TEST(NetworkIsolationKeyTest, NonEmptyKey) { |
| 26 | url::Origin origin = url::Origin::Create(GURL("http://a.test/")); |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 27 | NetworkIsolationKey key(origin, origin); |
Shivani Sharma | d81bdd4 | 2019-05-23 17:19:56 | [diff] [blame] | 28 | EXPECT_TRUE(key.IsFullyPopulated()); |
| 29 | EXPECT_EQ(origin.Serialize(), key.ToString()); |
| 30 | EXPECT_FALSE(key.IsTransient()); |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 31 | EXPECT_EQ("http://a.test", key.ToDebugString()); |
Shivani Sharma | d81bdd4 | 2019-05-23 17:19:56 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | TEST(NetworkIsolationKeyTest, OpaqueOriginKey) { |
| 35 | url::Origin origin_data = |
| 36 | url::Origin::Create(GURL("data:text/html,<body>Hello World</body>")); |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 37 | NetworkIsolationKey key(origin_data, origin_data); |
Shivani Sharma | d81bdd4 | 2019-05-23 17:19:56 | [diff] [blame] | 38 | EXPECT_TRUE(key.IsFullyPopulated()); |
| 39 | EXPECT_EQ(std::string(), key.ToString()); |
| 40 | EXPECT_TRUE(key.IsTransient()); |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 41 | |
| 42 | // Create another opaque origin, and make sure it has a different debug |
| 43 | // string. |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 44 | const auto kOriginNew = origin_data.DeriveNewOpaqueOrigin(); |
| 45 | EXPECT_NE(key.ToDebugString(), |
| 46 | NetworkIsolationKey(kOriginNew, kOriginNew).ToDebugString()); |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | TEST(NetworkIsolationKeyTest, Operators) { |
| 50 | // These are in ascending order. |
| 51 | const NetworkIsolationKey kKeys[] = { |
| 52 | NetworkIsolationKey(), |
| 53 | // Unique origins are still sorted by scheme, so data is before file, and |
| 54 | // file before http. |
| 55 | NetworkIsolationKey( |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 56 | url::Origin::Create(GURL("data:text/html,<body>Hello World</body>")), |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 57 | url::Origin::Create(GURL("data:text/html,<body>Hello World</body>"))), |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 58 | NetworkIsolationKey(url::Origin::Create(GURL("file:///foo")), |
| 59 | url::Origin::Create(GURL("file:///foo"))), |
| 60 | NetworkIsolationKey(url::Origin::Create(GURL("http://a.test/")), |
| 61 | url::Origin::Create(GURL("http://a.test/"))), |
| 62 | NetworkIsolationKey(url::Origin::Create(GURL("http://b.test/")), |
| 63 | url::Origin::Create(GURL("http://b.test/"))), |
| 64 | NetworkIsolationKey(url::Origin::Create(GURL("https://a.test/")), |
| 65 | url::Origin::Create(GURL("https://a.test/"))), |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | for (size_t first = 0; first < base::size(kKeys); ++first) { |
| 69 | NetworkIsolationKey key1 = kKeys[first]; |
| 70 | SCOPED_TRACE(key1.ToDebugString()); |
| 71 | |
| 72 | EXPECT_TRUE(key1 == key1); |
| 73 | EXPECT_FALSE(key1 < key1); |
| 74 | |
| 75 | // Make sure that copying a key doesn't change the results of any operation. |
| 76 | // This check is a bit more interesting with unique origins. |
| 77 | NetworkIsolationKey key1_copy = key1; |
| 78 | EXPECT_TRUE(key1 == key1_copy); |
| 79 | EXPECT_FALSE(key1 < key1_copy); |
| 80 | EXPECT_FALSE(key1_copy < key1); |
| 81 | |
| 82 | for (size_t second = first + 1; second < base::size(kKeys); ++second) { |
| 83 | NetworkIsolationKey key2 = kKeys[second]; |
| 84 | SCOPED_TRACE(key2.ToDebugString()); |
| 85 | |
| 86 | EXPECT_TRUE(key1 < key2); |
| 87 | EXPECT_FALSE(key2 < key1); |
| 88 | EXPECT_FALSE(key1 == key2); |
| 89 | EXPECT_FALSE(key2 == key1); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | TEST(NetworkIsolationKeyTest, UniqueOriginOperators) { |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 95 | const auto kOrigin1 = |
| 96 | url::Origin::Create(GURL("data:text/html,<body>Hello World</body>")); |
| 97 | const auto kOrigin2 = |
| 98 | url::Origin::Create(GURL("data:text/html,<body>Hello World</body>")); |
| 99 | NetworkIsolationKey key1(kOrigin1, kOrigin1); |
| 100 | NetworkIsolationKey key2(kOrigin2, kOrigin2); |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 101 | |
| 102 | EXPECT_TRUE(key1 == key1); |
| 103 | EXPECT_TRUE(key2 == key2); |
| 104 | |
| 105 | // Creating copies shouldn't affect comparison result. |
| 106 | EXPECT_TRUE(NetworkIsolationKey(key1) == NetworkIsolationKey(key1)); |
| 107 | EXPECT_TRUE(NetworkIsolationKey(key2) == NetworkIsolationKey(key2)); |
| 108 | |
| 109 | EXPECT_FALSE(key1 == key2); |
| 110 | EXPECT_FALSE(key2 == key1); |
| 111 | |
| 112 | // Order of Nonces isn't predictable, but they should have an ordering. |
| 113 | EXPECT_TRUE(key1 < key2 || key2 < key1); |
| 114 | EXPECT_TRUE(!(key1 < key2) || !(key2 < key1)); |
Shivani Sharma | d81bdd4 | 2019-05-23 17:19:56 | [diff] [blame] | 115 | } |
| 116 | |
Yao Xiao | 6924a36a | 2019-07-12 16:55:19 | [diff] [blame] | 117 | TEST(NetworkIsolationKeyTest, WithFrameOrigin) { |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 118 | const auto kOriginA = url::Origin::Create(GURL("http://a.test")); |
| 119 | const auto kOriginB = url::Origin::Create(GURL("http://b.test")); |
| 120 | NetworkIsolationKey key1(kOriginB, kOriginB); |
| 121 | NetworkIsolationKey key2(kOriginB, kOriginA); |
Eric Robinson | fc7de10 | 2019-06-21 15:27:10 | [diff] [blame] | 122 | EXPECT_TRUE(key2.IsFullyPopulated()); |
| 123 | EXPECT_FALSE(key2.IsTransient()); |
| 124 | EXPECT_EQ("http://b.test", key2.ToString()); |
| 125 | EXPECT_EQ("http://b.test", key2.ToDebugString()); |
| 126 | |
| 127 | EXPECT_TRUE(key1 == key2); |
| 128 | EXPECT_FALSE(key1 != key2); |
| 129 | EXPECT_FALSE(key1 < key2); |
| 130 | EXPECT_FALSE(key2 < key1); |
| 131 | } |
| 132 | |
Yao Xiao | 6924a36a | 2019-07-12 16:55:19 | [diff] [blame] | 133 | TEST(NetworkIsolationKeyTest, OpaqueOriginKeyWithFrameOrigin) { |
Eric Robinson | fc7de10 | 2019-06-21 15:27:10 | [diff] [blame] | 134 | url::Origin origin_data = |
| 135 | url::Origin::Create(GURL("data:text/html,<body>Hello World</body>")); |
| 136 | |
| 137 | NetworkIsolationKey key1(url::Origin::Create(GURL("http://a.test")), |
| 138 | origin_data); |
| 139 | EXPECT_TRUE(key1.IsFullyPopulated()); |
| 140 | EXPECT_FALSE(key1.IsTransient()); |
| 141 | EXPECT_EQ("http://a.test", key1.ToString()); |
| 142 | EXPECT_EQ("http://a.test", key1.ToDebugString()); |
| 143 | |
| 144 | NetworkIsolationKey key2(origin_data, |
| 145 | url::Origin::Create(GURL("http://a.test"))); |
| 146 | EXPECT_TRUE(key2.IsFullyPopulated()); |
| 147 | EXPECT_TRUE(key2.IsTransient()); |
| 148 | EXPECT_EQ("", key2.ToString()); |
| 149 | EXPECT_EQ(origin_data.GetDebugString(), key2.ToDebugString()); |
| 150 | EXPECT_NE(origin_data.DeriveNewOpaqueOrigin().GetDebugString(), |
| 151 | key2.ToDebugString()); |
| 152 | } |
| 153 | |
Matt Menke | 2fa4599 | 2019-08-06 23:07:35 | [diff] [blame^] | 154 | TEST(NetworkIsolationKeyTest, ValueRoundTripEmpty) { |
| 155 | const url::Origin kJunkOrigin = |
| 156 | url::Origin::Create(GURL("data:text/html,junk")); |
| 157 | |
| 158 | // Convert empty key to value and back, expecting the same value. |
| 159 | NetworkIsolationKey no_frame_origin_key; |
| 160 | base::Value no_frame_origin_value; |
| 161 | ASSERT_TRUE(no_frame_origin_key.ToValue(&no_frame_origin_value)); |
| 162 | |
| 163 | // Fill initial value with junk data, to make sure it's overwritten. |
| 164 | NetworkIsolationKey out_key(kJunkOrigin, kJunkOrigin); |
| 165 | EXPECT_TRUE(NetworkIsolationKey::FromValue(no_frame_origin_value, &out_key)); |
| 166 | EXPECT_EQ(no_frame_origin_key, out_key); |
| 167 | |
| 168 | // Perform same checks when frame origins are enabled. |
| 169 | |
| 170 | base::test::ScopedFeatureList feature_list; |
| 171 | feature_list.InitAndEnableFeature( |
| 172 | net::features::kAppendFrameOriginToNetworkIsolationKey); |
| 173 | |
| 174 | NetworkIsolationKey frame_origin_key; |
| 175 | base::Value frame_origin_value; |
| 176 | ASSERT_TRUE(frame_origin_key.ToValue(&frame_origin_value)); |
| 177 | |
| 178 | // Fill initial value with junk data, to make sure it's overwritten. |
| 179 | out_key = NetworkIsolationKey(kJunkOrigin, kJunkOrigin); |
| 180 | EXPECT_TRUE(NetworkIsolationKey::FromValue(frame_origin_value, &out_key)); |
| 181 | EXPECT_EQ(frame_origin_key, out_key); |
| 182 | |
| 183 | // The Values should also be the same in both cases. |
| 184 | EXPECT_EQ(no_frame_origin_key, frame_origin_key); |
| 185 | } |
| 186 | |
| 187 | TEST(NetworkIsolationKeyTest, ValueRoundTripNoFrameOrigin) { |
| 188 | const url::Origin kJunkOrigin = |
| 189 | url::Origin::Create(GURL("data:text/html,junk")); |
| 190 | |
| 191 | NetworkIsolationKey key1(url::Origin::Create(GURL("https://foo.test/")), |
| 192 | kJunkOrigin); |
| 193 | base::Value value; |
| 194 | ASSERT_TRUE(key1.ToValue(&value)); |
| 195 | |
| 196 | // Fill initial value with junk data, to make sure it's overwritten. |
| 197 | NetworkIsolationKey key2(kJunkOrigin, kJunkOrigin); |
| 198 | EXPECT_TRUE(NetworkIsolationKey::FromValue(value, &key2)); |
| 199 | EXPECT_EQ(key1, key2); |
| 200 | |
| 201 | base::test::ScopedFeatureList feature_list; |
| 202 | feature_list.InitAndEnableFeature( |
| 203 | net::features::kAppendFrameOriginToNetworkIsolationKey); |
| 204 | |
| 205 | // Loading should fail when frame origins are enabled. |
| 206 | EXPECT_FALSE(NetworkIsolationKey::FromValue(value, &key2)); |
| 207 | } |
| 208 | |
| 209 | TEST(NetworkIsolationKeyTest, ValueRoundTripFrameOrigin) { |
| 210 | const url::Origin kJunkOrigin = |
| 211 | url::Origin::Create(GURL("data:text/html,junk")); |
| 212 | |
| 213 | base::test::ScopedFeatureList feature_list; |
| 214 | feature_list.InitAndEnableFeature( |
| 215 | net::features::kAppendFrameOriginToNetworkIsolationKey); |
| 216 | |
| 217 | NetworkIsolationKey key1(url::Origin::Create(GURL("https://foo.test/")), |
| 218 | url::Origin::Create(GURL("https://foo.test/"))); |
| 219 | base::Value value; |
| 220 | ASSERT_TRUE(key1.ToValue(&value)); |
| 221 | |
| 222 | // Fill initial value with junk data, to make sure it's overwritten. |
| 223 | NetworkIsolationKey key2(kJunkOrigin, kJunkOrigin); |
| 224 | EXPECT_TRUE(NetworkIsolationKey::FromValue(value, &key2)); |
| 225 | EXPECT_EQ(key1, key2); |
| 226 | |
| 227 | feature_list.Reset(); |
| 228 | |
| 229 | // Loading should fail when frame origins are disabled. |
| 230 | EXPECT_FALSE(NetworkIsolationKey::FromValue(value, &key2)); |
| 231 | } |
| 232 | |
| 233 | TEST(NetworkIsolationKeyTest, ToValueTransientOrigin) { |
| 234 | const url::Origin kTransientOrigin = |
| 235 | url::Origin::Create(GURL("data:text/html,transient")); |
| 236 | |
| 237 | for (bool use_frame_origins : {false, true}) { |
| 238 | SCOPED_TRACE(use_frame_origins); |
| 239 | base::test::ScopedFeatureList feature_list; |
| 240 | if (use_frame_origins) { |
| 241 | feature_list.InitAndEnableFeature( |
| 242 | net::features::kAppendFrameOriginToNetworkIsolationKey); |
| 243 | } |
| 244 | |
| 245 | NetworkIsolationKey key1(kTransientOrigin, kTransientOrigin); |
| 246 | EXPECT_TRUE(key1.IsTransient()); |
| 247 | base::Value value; |
| 248 | EXPECT_FALSE(key1.ToValue(&value)); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | TEST(NetworkIsolationKeyTest, FromValueBadData) { |
| 253 | // Can't create these inline, since vector initialization lists require a |
| 254 | // copy, and base::Value has no copy operator, only move. |
| 255 | base::Value::ListStorage not_a_url_list; |
| 256 | not_a_url_list.emplace_back(base::Value("not-a-url")); |
| 257 | |
| 258 | base::Value::ListStorage transient_origin_list; |
| 259 | transient_origin_list.emplace_back(base::Value("data:text/html,transient")); |
| 260 | |
| 261 | base::Value::ListStorage too_many_origins_list; |
| 262 | too_many_origins_list.emplace_back(base::Value("https://too/")); |
| 263 | too_many_origins_list.emplace_back(base::Value("https://many/")); |
| 264 | too_many_origins_list.emplace_back(base::Value("https://origins/")); |
| 265 | |
| 266 | const base::Value kTestCases[] = { |
| 267 | base::Value(base::Value::Type::STRING), |
| 268 | base::Value(base::Value::Type::DICTIONARY), |
| 269 | base::Value(std::move(not_a_url_list)), |
| 270 | base::Value(std::move(transient_origin_list)), |
| 271 | base::Value(std::move(too_many_origins_list)), |
| 272 | }; |
| 273 | |
| 274 | for (bool use_frame_origins : {false, true}) { |
| 275 | SCOPED_TRACE(use_frame_origins); |
| 276 | base::test::ScopedFeatureList feature_list; |
| 277 | if (use_frame_origins) { |
| 278 | feature_list.InitAndEnableFeature( |
| 279 | net::features::kAppendFrameOriginToNetworkIsolationKey); |
| 280 | } |
| 281 | |
| 282 | for (const auto& test_case : kTestCases) { |
| 283 | NetworkIsolationKey key; |
| 284 | // Write the value on failure. |
| 285 | EXPECT_FALSE(NetworkIsolationKey::FromValue(test_case, &key)) |
| 286 | << test_case; |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
Yao Xiao | 6924a36a | 2019-07-12 16:55:19 | [diff] [blame] | 291 | class NetworkIsolationKeyWithFrameOriginTest : public testing::Test { |
Eric Robinson | fc7de10 | 2019-06-21 15:27:10 | [diff] [blame] | 292 | public: |
Yao Xiao | 6924a36a | 2019-07-12 16:55:19 | [diff] [blame] | 293 | NetworkIsolationKeyWithFrameOriginTest() { |
Eric Robinson | fc7de10 | 2019-06-21 15:27:10 | [diff] [blame] | 294 | feature_list_.InitAndEnableFeature( |
Yao Xiao | 6924a36a | 2019-07-12 16:55:19 | [diff] [blame] | 295 | net::features::kAppendFrameOriginToNetworkIsolationKey); |
Eric Robinson | fc7de10 | 2019-06-21 15:27:10 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | private: |
| 299 | base::test::ScopedFeatureList feature_list_; |
| 300 | }; |
| 301 | |
Yao Xiao | 6924a36a | 2019-07-12 16:55:19 | [diff] [blame] | 302 | TEST_F(NetworkIsolationKeyWithFrameOriginTest, WithFrameOrigin) { |
Eric Robinson | fc7de10 | 2019-06-21 15:27:10 | [diff] [blame] | 303 | NetworkIsolationKey key(url::Origin::Create(GURL("http://b.test")), |
| 304 | url::Origin::Create(GURL("http://a.test/"))); |
| 305 | EXPECT_TRUE(key.IsFullyPopulated()); |
| 306 | EXPECT_FALSE(key.IsTransient()); |
| 307 | EXPECT_EQ("http://b.test http://a.test", key.ToString()); |
| 308 | EXPECT_EQ("http://b.test http://a.test", key.ToDebugString()); |
| 309 | |
| 310 | EXPECT_TRUE(key == key); |
| 311 | EXPECT_FALSE(key != key); |
| 312 | EXPECT_FALSE(key < key); |
| 313 | } |
| 314 | |
Yao Xiao | 6924a36a | 2019-07-12 16:55:19 | [diff] [blame] | 315 | TEST_F(NetworkIsolationKeyWithFrameOriginTest, OpaqueOriginKey) { |
Eric Robinson | fc7de10 | 2019-06-21 15:27:10 | [diff] [blame] | 316 | url::Origin origin_data = |
| 317 | url::Origin::Create(GURL("data:text/html,<body>Hello World</body>")); |
| 318 | |
| 319 | NetworkIsolationKey key1(url::Origin::Create(GURL("http://a.test")), |
| 320 | origin_data); |
| 321 | EXPECT_TRUE(key1.IsFullyPopulated()); |
| 322 | EXPECT_TRUE(key1.IsTransient()); |
| 323 | EXPECT_EQ("", key1.ToString()); |
| 324 | EXPECT_EQ("http://a.test " + origin_data.GetDebugString(), |
| 325 | key1.ToDebugString()); |
| 326 | EXPECT_NE( |
| 327 | "http://a.test " + origin_data.DeriveNewOpaqueOrigin().GetDebugString(), |
| 328 | key1.ToDebugString()); |
| 329 | |
| 330 | NetworkIsolationKey key2(origin_data, |
| 331 | url::Origin::Create(GURL("http://a.test"))); |
| 332 | EXPECT_TRUE(key2.IsFullyPopulated()); |
| 333 | EXPECT_TRUE(key2.IsTransient()); |
| 334 | EXPECT_EQ("", key2.ToString()); |
| 335 | EXPECT_EQ(origin_data.GetDebugString() + " http://a.test", |
| 336 | key2.ToDebugString()); |
| 337 | EXPECT_NE( |
| 338 | origin_data.DeriveNewOpaqueOrigin().GetDebugString() + " http://a.test", |
| 339 | key2.ToDebugString()); |
| 340 | } |
| 341 | |
Yao Xiao | 6924a36a | 2019-07-12 16:55:19 | [diff] [blame] | 342 | TEST_F(NetworkIsolationKeyWithFrameOriginTest, OpaqueOriginKeyBoth) { |
Eric Robinson | fc7de10 | 2019-06-21 15:27:10 | [diff] [blame] | 343 | url::Origin origin_data_1 = |
| 344 | url::Origin::Create(GURL("data:text/html,<body>Hello World</body>")); |
| 345 | url::Origin origin_data_2 = |
| 346 | url::Origin::Create(GURL("data:text/html,<body>Hello Universe</body>")); |
| 347 | url::Origin origin_data_3 = |
| 348 | url::Origin::Create(GURL("data:text/html,<body>Hello Cosmos</body>")); |
| 349 | |
| 350 | NetworkIsolationKey key1(origin_data_1, origin_data_2); |
| 351 | NetworkIsolationKey key2(origin_data_1, origin_data_2); |
| 352 | NetworkIsolationKey key3(origin_data_1, origin_data_3); |
| 353 | |
| 354 | // All the keys should be fully populated and transient. |
| 355 | EXPECT_TRUE(key1.IsFullyPopulated()); |
| 356 | EXPECT_TRUE(key2.IsFullyPopulated()); |
| 357 | EXPECT_TRUE(key3.IsFullyPopulated()); |
| 358 | EXPECT_TRUE(key1.IsTransient()); |
| 359 | EXPECT_TRUE(key2.IsTransient()); |
| 360 | EXPECT_TRUE(key3.IsTransient()); |
| 361 | |
| 362 | // Test the equality/comparisons of the various keys |
| 363 | EXPECT_TRUE(key1 == key2); |
| 364 | EXPECT_FALSE(key1 == key3); |
| 365 | EXPECT_FALSE(key1 < key2 || key2 < key1); |
| 366 | EXPECT_TRUE(key1 < key3 || key3 < key1); |
| 367 | |
| 368 | // Test the ToString and ToDebugString |
| 369 | EXPECT_EQ(key1.ToDebugString(), key2.ToDebugString()); |
| 370 | EXPECT_NE(key1.ToDebugString(), key3.ToDebugString()); |
| 371 | EXPECT_EQ("", key1.ToString()); |
| 372 | EXPECT_EQ("", key2.ToString()); |
| 373 | EXPECT_EQ("", key3.ToString()); |
| 374 | } |
| 375 | |
Shivani Sharma | d81bdd4 | 2019-05-23 17:19:56 | [diff] [blame] | 376 | } // namespace net |