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

Side by Side Diff: components/domain_reliability/monitor_unittest.cc

Issue 2132563003: Implement origin-based deletion for the domain reliability service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated DomainReliabilityMonitorTest Created 4 years, 5 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 | « components/domain_reliability/monitor.cc ('k') | components/domain_reliability/service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "components/domain_reliability/monitor.h" 5 #include "components/domain_reliability/monitor.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 288
289 // Add a beacon. 289 // Add a beacon.
290 RequestInfo request = MakeRequestInfo(); 290 RequestInfo request = MakeRequestInfo();
291 request.url = GURL("http://example/"); 291 request.url = GURL("http://example/");
292 request.status = net::URLRequestStatus::FromError(net::ERR_CONNECTION_RESET); 292 request.status = net::URLRequestStatus::FromError(net::ERR_CONNECTION_RESET);
293 OnRequestLegComplete(request); 293 OnRequestLegComplete(request);
294 294
295 // Make sure it was added. 295 // Make sure it was added.
296 EXPECT_EQ(1u, CountQueuedBeacons(context)); 296 EXPECT_EQ(1u, CountQueuedBeacons(context));
297 297
298 monitor_.ClearBrowsingData(CLEAR_BEACONS); 298 monitor_.ClearBrowsingData(
299 CLEAR_BEACONS, base::Callback<bool(const GURL&)>());
299 300
300 // Make sure the beacon was cleared, but not the contexts. 301 // Make sure the beacon was cleared, but not the contexts.
301 EXPECT_EQ(1u, monitor_.contexts_size_for_testing()); 302 EXPECT_EQ(1u, monitor_.contexts_size_for_testing());
302 EXPECT_EQ(0u, CountQueuedBeacons(context)); 303 EXPECT_EQ(0u, CountQueuedBeacons(context));
303 } 304 }
304 305
306 TEST_F(DomainReliabilityMonitorTest, ClearBeaconsWithFilter) {
307 // Create two contexts, each with one beacon.
308 GURL origin1("http://example.com/");
309 GURL origin2("http://example.org/");
310
311 DomainReliabilityContext* context1 =
312 CreateAndAddContextForOrigin(origin1, false);
313 RequestInfo request = MakeRequestInfo();
314 request.url = origin1;
315 request.status =
316 net::URLRequestStatus::FromError(net::ERR_CONNECTION_RESET);
317 OnRequestLegComplete(request);
318
319 DomainReliabilityContext* context2 =
320 CreateAndAddContextForOrigin(origin2, false);
321 request = MakeRequestInfo();
322 request.url = origin2;
323 request.status =
324 net::URLRequestStatus::FromError(net::ERR_CONNECTION_RESET);
325 OnRequestLegComplete(request);
326
327 // Delete the beacons for |origin1|.
328 monitor_.ClearBrowsingData(
329 CLEAR_BEACONS,
330 base::Bind(&GURL::operator==, base::Unretained(&origin1)));
331
332 // Beacons for |context1| were cleared. Beacons for |context2| and
333 // the contexts themselves were not.
334 EXPECT_EQ(2u, monitor_.contexts_size_for_testing());
335 EXPECT_EQ(0u, CountQueuedBeacons(context1));
336 EXPECT_EQ(1u, CountQueuedBeacons(context2));
337 }
338
305 TEST_F(DomainReliabilityMonitorTest, ClearContexts) { 339 TEST_F(DomainReliabilityMonitorTest, ClearContexts) {
306 CreateAndAddContext(); 340 CreateAndAddContext();
307 341
308 // Initially the monitor should have just the test context. 342 // Initially the monitor should have just the test context.
309 EXPECT_EQ(1u, monitor_.contexts_size_for_testing()); 343 EXPECT_EQ(1u, monitor_.contexts_size_for_testing());
310 344
311 monitor_.ClearBrowsingData(CLEAR_CONTEXTS); 345 monitor_.ClearBrowsingData(
346 CLEAR_CONTEXTS, base::Callback<bool(const GURL&)>());
312 347
313 // Clearing contexts should leave the monitor with none. 348 // Clearing contexts should leave the monitor with none.
314 EXPECT_EQ(0u, monitor_.contexts_size_for_testing()); 349 EXPECT_EQ(0u, monitor_.contexts_size_for_testing());
315 } 350 }
316 351
352 TEST_F(DomainReliabilityMonitorTest, ClearContextsWithFilter) {
353 GURL origin1("http://example.com/");
354 GURL origin2("http://example.org/");
355
356 CreateAndAddContextForOrigin(origin1, false);
357 CreateAndAddContextForOrigin(origin2, false);
358
359 EXPECT_EQ(2u, monitor_.contexts_size_for_testing());
360
361 // Delete the contexts for |origin1|.
362 monitor_.ClearBrowsingData(
363 CLEAR_CONTEXTS,
364 base::Bind(&GURL::operator==, base::Unretained(&origin1)));
365
366 // Only one of the contexts should have been deleted.
367 EXPECT_EQ(1u, monitor_.contexts_size_for_testing());
368 }
369
317 TEST_F(DomainReliabilityMonitorTest, WildcardMatchesSelf) { 370 TEST_F(DomainReliabilityMonitorTest, WildcardMatchesSelf) {
318 DomainReliabilityContext* context = 371 DomainReliabilityContext* context =
319 CreateAndAddContextForOrigin(GURL("https://wildcard/"), true); 372 CreateAndAddContextForOrigin(GURL("https://wildcard/"), true);
320 373
321 RequestInfo request = MakeRequestInfo(); 374 RequestInfo request = MakeRequestInfo();
322 request.url = GURL("http://wildcard/"); 375 request.url = GURL("http://wildcard/");
323 request.status = net::URLRequestStatus::FromError(net::ERR_CONNECTION_RESET); 376 request.status = net::URLRequestStatus::FromError(net::ERR_CONNECTION_RESET);
324 OnRequestLegComplete(request); 377 OnRequestLegComplete(request);
325 378
326 EXPECT_EQ(1u, CountQueuedBeacons(context)); 379 EXPECT_EQ(1u, CountQueuedBeacons(context));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 request.status = net::URLRequestStatus::FromError(net::ERR_CONNECTION_RESET); 430 request.status = net::URLRequestStatus::FromError(net::ERR_CONNECTION_RESET);
378 OnRequestLegComplete(request); 431 OnRequestLegComplete(request);
379 432
380 EXPECT_EQ(1u, CountQueuedBeacons(context1)); 433 EXPECT_EQ(1u, CountQueuedBeacons(context1));
381 EXPECT_EQ(0u, CountQueuedBeacons(context2)); 434 EXPECT_EQ(0u, CountQueuedBeacons(context2));
382 } 435 }
383 436
384 } // namespace 437 } // namespace
385 438
386 } // namespace domain_reliability 439 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « components/domain_reliability/monitor.cc ('k') | components/domain_reliability/service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698