Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: net/reporting/reporting_cache_unittest.cc

Issue 2779983002: Reporting: Properly support endpoints with includeSubdomains. (Closed)
Patch Set: Make requested changes. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/reporting/reporting_cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/reporting/reporting_cache.h" 5 #include "net/reporting/reporting_cache.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 EXPECT_EQ(2, observer()->cache_update_count()); 289 EXPECT_EQ(2, observer()->cache_update_count());
290 290
291 cache()->RemoveAllClients(); 291 cache()->RemoveAllClients();
292 EXPECT_EQ(3, observer()->cache_update_count()); 292 EXPECT_EQ(3, observer()->cache_update_count());
293 293
294 std::vector<const ReportingClient*> clients; 294 std::vector<const ReportingClient*> clients;
295 cache()->GetClients(&clients); 295 cache()->GetClients(&clients);
296 EXPECT_TRUE(clients.empty()); 296 EXPECT_TRUE(clients.empty());
297 } 297 }
298 298
299 TEST_F(ReportingCacheTest, ExcludeSubdomainsDifferentPort) {
300 const url::Origin kOrigin(GURL("https://example/"));
301 const url::Origin kDifferentPortOrigin(GURL("https://example:444/"));
302
303 cache()->SetClient(kDifferentPortOrigin, kEndpoint1_,
304 ReportingClient::Subdomains::EXCLUDE, kGroup1_,
305 kExpires1_);
306
307 std::vector<const ReportingClient*> clients;
308 cache()->GetClientsForOriginAndGroup(kOrigin, kGroup1_, &clients);
309 EXPECT_TRUE(clients.empty());
310 }
311
312 TEST_F(ReportingCacheTest, ExcludeSubdomainsSuperdomain) {
313 const url::Origin kOrigin(GURL("https://foo.example/"));
314 const url::Origin kSuperOrigin(GURL("https://example/"));
315
316 cache()->SetClient(kSuperOrigin, kEndpoint1_,
317 ReportingClient::Subdomains::EXCLUDE, kGroup1_,
318 kExpires1_);
319
320 std::vector<const ReportingClient*> clients;
321 cache()->GetClientsForOriginAndGroup(kOrigin, kGroup1_, &clients);
322 EXPECT_TRUE(clients.empty());
323 }
324
325 TEST_F(ReportingCacheTest, IncludeSubdomainsDifferentPort) {
326 const url::Origin kOrigin(GURL("https://example/"));
327 const url::Origin kDifferentPortOrigin(GURL("https://example:444/"));
328
329 cache()->SetClient(kDifferentPortOrigin, kEndpoint1_,
330 ReportingClient::Subdomains::INCLUDE, kGroup1_,
331 kExpires1_);
332
333 std::vector<const ReportingClient*> clients;
334 cache()->GetClientsForOriginAndGroup(kOrigin, kGroup1_, &clients);
335 ASSERT_EQ(1u, clients.size());
336 EXPECT_EQ(kDifferentPortOrigin, clients[0]->origin);
337 }
338
339 TEST_F(ReportingCacheTest, IncludeSubdomainsSuperdomain) {
340 const url::Origin kOrigin(GURL("https://foo.example/"));
341 const url::Origin kSuperOrigin(GURL("https://example/"));
342
343 cache()->SetClient(kSuperOrigin, kEndpoint1_,
344 ReportingClient::Subdomains::INCLUDE, kGroup1_,
345 kExpires1_);
346
347 std::vector<const ReportingClient*> clients;
348 cache()->GetClientsForOriginAndGroup(kOrigin, kGroup1_, &clients);
349 ASSERT_EQ(1u, clients.size());
350 EXPECT_EQ(kSuperOrigin, clients[0]->origin);
351 }
352
353 TEST_F(ReportingCacheTest, IncludeSubdomainsPreferOriginToDifferentPort) {
354 const url::Origin kOrigin(GURL("https://foo.example/"));
355 const url::Origin kDifferentPortOrigin(GURL("https://example:444/"));
356
357 cache()->SetClient(kOrigin, kEndpoint1_, ReportingClient::Subdomains::INCLUDE,
358 kGroup1_, kExpires1_);
359 cache()->SetClient(kDifferentPortOrigin, kEndpoint1_,
360 ReportingClient::Subdomains::INCLUDE, kGroup1_,
361 kExpires1_);
362
363 std::vector<const ReportingClient*> clients;
364 cache()->GetClientsForOriginAndGroup(kOrigin, kGroup1_, &clients);
365 ASSERT_EQ(1u, clients.size());
366 EXPECT_EQ(kOrigin, clients[0]->origin);
367 }
368
369 TEST_F(ReportingCacheTest, IncludeSubdomainsPreferOriginToSuperdomain) {
370 const url::Origin kOrigin(GURL("https://foo.example/"));
371 const url::Origin kSuperOrigin(GURL("https://example/"));
372
373 cache()->SetClient(kOrigin, kEndpoint1_, ReportingClient::Subdomains::INCLUDE,
374 kGroup1_, kExpires1_);
375 cache()->SetClient(kSuperOrigin, kEndpoint1_,
376 ReportingClient::Subdomains::INCLUDE, kGroup1_,
377 kExpires1_);
378
379 std::vector<const ReportingClient*> clients;
380 cache()->GetClientsForOriginAndGroup(kOrigin, kGroup1_, &clients);
381 ASSERT_EQ(1u, clients.size());
382 EXPECT_EQ(kOrigin, clients[0]->origin);
383 }
384
385 TEST_F(ReportingCacheTest, IncludeSubdomainsPreferMoreSpecificSuperdomain) {
386 const url::Origin kOrigin(GURL("https://foo.bar.example/"));
387 const url::Origin kSuperOrigin(GURL("https://bar.example/"));
388 const url::Origin kSuperSuperOrigin(GURL("https://example/"));
389
390 cache()->SetClient(kSuperOrigin, kEndpoint1_,
391 ReportingClient::Subdomains::INCLUDE, kGroup1_,
392 kExpires1_);
393 cache()->SetClient(kSuperSuperOrigin, kEndpoint1_,
394 ReportingClient::Subdomains::INCLUDE, kGroup1_,
395 kExpires1_);
396
397 std::vector<const ReportingClient*> clients;
398 cache()->GetClientsForOriginAndGroup(kOrigin, kGroup1_, &clients);
399 ASSERT_EQ(1u, clients.size());
400 EXPECT_EQ(kSuperOrigin, clients[0]->origin);
401 }
402
299 } // namespace 403 } // namespace
300 } // namespace net 404 } // namespace net
OLDNEW
« no previous file with comments | « net/reporting/reporting_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698