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

Side by Side Diff: chrome/browser/chrome_content_browser_client_unittest.cc

Issue 2697123004: Convert RemoveDataMask from enum to pointers and split it between content and embedder (Closed)
Patch Set: More compilation error fixes. Created 3 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <algorithm>
7 #include <list> 8 #include <list>
8 #include <map> 9 #include <map>
9 #include <memory> 10 #include <memory>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
15 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/field_trial.h" 17 #include "base/metrics/field_trial.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "chrome/browser/browsing_data/browsing_data_helper.h" 21 #include "chrome/browser/browsing_data/browsing_data_helper.h"
21 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 22 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
22 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" 23 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h"
24 #include "chrome/browser/browsing_data/chrome_browsing_data_types.h"
23 #include "chrome/browser/search_engines/template_url_service_factory.h" 25 #include "chrome/browser/search_engines/template_url_service_factory.h"
24 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
25 #include "components/content_settings/core/browser/host_content_settings_map.h" 27 #include "components/content_settings/core/browser/host_content_settings_map.h"
26 #include "components/search_engines/template_url_service.h" 28 #include "components/search_engines/template_url_service.h"
27 #include "components/variations/entropy_provider.h" 29 #include "components/variations/entropy_provider.h"
28 #include "components/variations/variations_associated_data.h" 30 #include "components/variations/variations_associated_data.h"
29 #include "components/version_info/version_info.h" 31 #include "components/version_info/version_info.h"
30 #include "content/public/browser/browsing_data_filter_builder.h" 32 #include "content/public/browser/browsing_data_filter_builder.h"
31 #include "content/public/browser/navigation_controller.h" 33 #include "content/public/browser/navigation_controller.h"
32 #include "content/public/browser/navigation_entry.h" 34 #include "content/public/browser/navigation_entry.h"
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 class MockBrowsingDataRemover : public BrowsingDataRemoverImpl { 353 class MockBrowsingDataRemover : public BrowsingDataRemoverImpl {
352 public: 354 public:
353 explicit MockBrowsingDataRemover(content::BrowserContext* context) 355 explicit MockBrowsingDataRemover(content::BrowserContext* context)
354 : BrowsingDataRemoverImpl(context) {} 356 : BrowsingDataRemoverImpl(context) {}
355 357
356 ~MockBrowsingDataRemover() override { 358 ~MockBrowsingDataRemover() override {
357 DCHECK(!expected_calls_.size()) 359 DCHECK(!expected_calls_.size())
358 << "Expectations were set but not verified."; 360 << "Expectations were set but not verified.";
359 } 361 }
360 362
361 void RemoveInternal(const base::Time& delete_begin, 363 void RemoveInternal(
362 const base::Time& delete_end, 364 const base::Time& delete_begin,
363 int remove_mask, 365 const base::Time& delete_end,
364 int origin_type_mask, 366 const std::set<const content::BrowsingDataType*>& remove_mask,
365 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 367 int origin_type_mask,
366 BrowsingDataRemover::Observer* observer) override { 368 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
369 BrowsingDataRemover::Observer* observer) override {
367 actual_calls_.emplace_back(delete_begin, delete_end, remove_mask, 370 actual_calls_.emplace_back(delete_begin, delete_end, remove_mask,
368 origin_type_mask, std::move(filter_builder), 371 origin_type_mask, std::move(filter_builder),
369 true /* should_compare_filter */); 372 true /* should_compare_filter */);
370 373
371 // |observer| is not recorded in |actual_calls_| to be compared with 374 // |observer| is not recorded in |actual_calls_| to be compared with
372 // expectations, because it's created internally in ClearSiteData() and 375 // expectations, because it's created internally in ClearSiteData() and
373 // it's unknown to this. However, it is tested implicitly, because we use 376 // it's unknown to this. However, it is tested implicitly, because we use
374 // it for the completion callback, so an incorrect |observer| will fail 377 // it for the completion callback, so an incorrect |observer| will fail
375 // the test by waiting for the callback forever. 378 // the test by waiting for the callback forever.
376 DCHECK(observer); 379 DCHECK(observer);
377 observer->OnBrowsingDataRemoverDone(); 380 observer->OnBrowsingDataRemoverDone();
378 } 381 }
379 382
380 void ExpectCall( 383 void ExpectCall(
381 const base::Time& delete_begin, 384 const base::Time& delete_begin,
382 const base::Time& delete_end, 385 const base::Time& delete_end,
383 int remove_mask, 386 const std::set<const content::BrowsingDataType*>& remove_mask,
384 int origin_type_mask, 387 int origin_type_mask,
385 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { 388 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
386 expected_calls_.emplace_back(delete_begin, delete_end, remove_mask, 389 expected_calls_.emplace_back(delete_begin, delete_end, remove_mask,
387 origin_type_mask, std::move(filter_builder), 390 origin_type_mask, std::move(filter_builder),
388 true /* should_compare_filter */); 391 true /* should_compare_filter */);
389 } 392 }
390 393
391 void ExpectCallDontCareAboutFilterBuilder(const base::Time& delete_begin, 394 void ExpectCallDontCareAboutFilterBuilder(
392 const base::Time& delete_end, 395 const base::Time& delete_begin,
393 int remove_mask, 396 const base::Time& delete_end,
394 int origin_type_mask) { 397 const std::set<const content::BrowsingDataType*>& remove_mask,
398 int origin_type_mask) {
395 expected_calls_.emplace_back(delete_begin, delete_end, remove_mask, 399 expected_calls_.emplace_back(delete_begin, delete_end, remove_mask,
396 origin_type_mask, 400 origin_type_mask,
397 std::unique_ptr<BrowsingDataFilterBuilder>(), 401 std::unique_ptr<BrowsingDataFilterBuilder>(),
398 false /* should_compare_filter */); 402 false /* should_compare_filter */);
399 } 403 }
400 404
401 void VerifyAndClearExpectations() { 405 void VerifyAndClearExpectations() {
402 EXPECT_EQ(expected_calls_, actual_calls_); 406 EXPECT_EQ(expected_calls_, actual_calls_);
403 expected_calls_.clear(); 407 expected_calls_.clear();
404 actual_calls_.clear(); 408 actual_calls_.clear();
405 } 409 }
406 410
407 private: 411 private:
408 class CallParameters { 412 class CallParameters {
409 public: 413 public:
410 CallParameters(const base::Time& delete_begin, 414 CallParameters(
411 const base::Time& delete_end, 415 const base::Time& delete_begin,
412 int remove_mask, 416 const base::Time& delete_end,
413 int origin_type_mask, 417 const std::set<const content::BrowsingDataType*>& remove_mask,
414 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 418 int origin_type_mask,
415 bool should_compare_filter) 419 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
420 bool should_compare_filter)
416 : delete_begin_(delete_begin), 421 : delete_begin_(delete_begin),
417 delete_end_(delete_end), 422 delete_end_(delete_end),
418 remove_mask_(remove_mask), 423 remove_mask_(remove_mask),
419 origin_type_mask_(origin_type_mask), 424 origin_type_mask_(origin_type_mask),
420 filter_builder_(std::move(filter_builder)), 425 filter_builder_(std::move(filter_builder)),
421 should_compare_filter_(should_compare_filter) {} 426 should_compare_filter_(should_compare_filter) {}
422 ~CallParameters() {} 427 ~CallParameters() {}
423 428
424 bool operator==(const CallParameters& other) const { 429 bool operator==(const CallParameters& other) const {
425 const CallParameters& a = *this; 430 const CallParameters& a = *this;
426 const CallParameters& b = other; 431 const CallParameters& b = other;
427 432
428 if (a.delete_begin_ != b.delete_begin_ || 433 if (a.delete_begin_ != b.delete_begin_ ||
429 a.delete_end_ != b.delete_end_ || 434 a.delete_end_ != b.delete_end_ ||
430 a.remove_mask_ != b.remove_mask_ || 435 a.remove_mask_ != b.remove_mask_ ||
431 a.origin_type_mask_ != b.origin_type_mask_) { 436 a.origin_type_mask_ != b.origin_type_mask_) {
432 return false; 437 return false;
433 } 438 }
434 439
435 if (!a.should_compare_filter_ || !b.should_compare_filter_) 440 if (!a.should_compare_filter_ || !b.should_compare_filter_)
436 return true; 441 return true;
437 return *a.filter_builder_ == *b.filter_builder_; 442 return *a.filter_builder_ == *b.filter_builder_;
438 } 443 }
439 444
440 private: 445 private:
441 base::Time delete_begin_; 446 base::Time delete_begin_;
442 base::Time delete_end_; 447 base::Time delete_end_;
443 int remove_mask_; 448 std::set<const content::BrowsingDataType*> remove_mask_;
444 int origin_type_mask_; 449 int origin_type_mask_;
445 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_; 450 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_;
446 bool should_compare_filter_; 451 bool should_compare_filter_;
447 }; 452 };
448 453
449 std::list<CallParameters> actual_calls_; 454 std::list<CallParameters> actual_calls_;
450 std::list<CallParameters> expected_calls_; 455 std::list<CallParameters> expected_calls_;
451 }; 456 };
452 457
453 // Tests for ChromeContentBrowserClient::ClearSiteData(). 458 // Tests for ChromeContentBrowserClient::ClearSiteData().
(...skipping 26 matching lines...) Expand all
480 bool finished_; 485 bool finished_;
481 }; 486 };
482 487
483 // Tests that the parameters to ClearBrowsingData() are translated to 488 // Tests that the parameters to ClearBrowsingData() are translated to
484 // the correct BrowsingDataRemover::RemoveInternal() operation. The fourth 489 // the correct BrowsingDataRemover::RemoveInternal() operation. The fourth
485 // parameter, |filter_builder|, is tested in detail in the RegistrableDomains 490 // parameter, |filter_builder|, is tested in detail in the RegistrableDomains
486 // test below. 491 // test below.
487 TEST_F(ChromeContentBrowserClientClearSiteDataTest, Parameters) { 492 TEST_F(ChromeContentBrowserClientClearSiteDataTest, Parameters) {
488 ChromeContentBrowserClient client; 493 ChromeContentBrowserClient client;
489 494
495 // no datatypes
496 std::set<const content::BrowsingDataType*> empty_mask;
497
498 // "cookies"
499 const std::set<const content::BrowsingDataType*> domain_scoped_types = {
500 &kBrowsingDataTypeCookies,
501 &kBrowsingDataTypeChannelIDs,
502 &kBrowsingDataTypePluginData,
503 };
504
505 // "storage"
506 std::set<const content::BrowsingDataType*> storage;
507 std::set_difference(
508 kBrowsingDataTypeSetSiteData.begin(), kBrowsingDataTypeSetSiteData.end(),
509 domain_scoped_types.begin(), domain_scoped_types.end(),
510 std::inserter(storage, storage.begin()));
511
512 // "storage" + "cache"
513 std::set<const content::BrowsingDataType*> storage_and_cache = storage;
514 storage_and_cache.insert(&kBrowsingDataTypeCache);
515
516 // "cookies" + "storage" + "cache"
517 std::set<const content::BrowsingDataType*> all =
518 kBrowsingDataTypeSetSiteData;
519 storage_and_cache.insert(&kBrowsingDataTypeCache);
520
490 struct TestCase { 521 struct TestCase {
491 bool cookies; 522 bool cookies;
492 bool storage; 523 bool storage;
493 bool cache; 524 bool cache;
494 int mask; 525 const std::set<const content::BrowsingDataType*> mask;
495 } test_cases[] = { 526 } test_cases[] = {
496 {false, false, false, 0}, 527 {false, false, false, empty_mask},
497 {true, false, false, BrowsingDataRemover::REMOVE_COOKIES | 528 {true, false, false, { &kBrowsingDataTypeCookies,
498 BrowsingDataRemover::REMOVE_CHANNEL_IDS | 529 &kBrowsingDataTypeChannelIDs,
499 BrowsingDataRemover::REMOVE_PLUGIN_DATA}, 530 &kBrowsingDataTypePluginData }},
500 {false, true, false, BrowsingDataRemover::REMOVE_SITE_DATA & 531 {false, true, false, storage },
501 ~BrowsingDataRemover::REMOVE_COOKIES & 532 {false, false, true, { &kBrowsingDataTypeCache }},
502 ~BrowsingDataRemover::REMOVE_CHANNEL_IDS & 533 {true, true, false, kBrowsingDataTypeSetSiteData},
503 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA}, 534 {true, false, true, { &kBrowsingDataTypeCookies,
504 {false, false, true, BrowsingDataRemover::REMOVE_CACHE}, 535 &kBrowsingDataTypeChannelIDs,
505 {true, true, false, BrowsingDataRemover::REMOVE_SITE_DATA}, 536 &kBrowsingDataTypePluginData,
506 {true, false, true, BrowsingDataRemover::REMOVE_COOKIES | 537 &kBrowsingDataTypeCache }},
507 BrowsingDataRemover::REMOVE_CHANNEL_IDS | 538 {false, true, true, storage_and_cache},
508 BrowsingDataRemover::REMOVE_PLUGIN_DATA | 539 {true, true, true, all},
509 BrowsingDataRemover::REMOVE_CACHE},
510 {false, true, true, BrowsingDataRemover::REMOVE_CACHE |
511 (BrowsingDataRemover::REMOVE_SITE_DATA &
512 ~BrowsingDataRemover::REMOVE_COOKIES &
513 ~BrowsingDataRemover::REMOVE_CHANNEL_IDS &
514 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA)},
515 {true, true, true, BrowsingDataRemover::REMOVE_SITE_DATA |
516 BrowsingDataRemover::REMOVE_CACHE},
517 }; 540 };
518 541
519 for (unsigned int i = 0; i < arraysize(test_cases); ++i) { 542 for (unsigned int i = 0; i < arraysize(test_cases); ++i) {
520 SCOPED_TRACE(base::StringPrintf("Test case %d", i)); 543 SCOPED_TRACE(base::StringPrintf("Test case %d", i));
521 const TestCase& test_case = test_cases[i]; 544 const TestCase& test_case = test_cases[i];
522 545
523 // We always delete data for all time and all origin types. 546 // We always delete data for all time and all origin types.
524 BrowsingDataHelper::OriginTypeMask all_origin_types = 547 BrowsingDataHelper::OriginTypeMask all_origin_types =
525 BrowsingDataHelper::ALL; 548 BrowsingDataHelper::ALL;
526 549
527 // Some data are deleted for the origin and some for the registrable domain. 550 // Some data are deleted for the origin and some for the registrable domain.
528 // Depending on the chosen datatypes, this might result into one or two 551 // Depending on the chosen datatypes, this might result into one or two
529 // calls. In the latter case, the removal mask will be split into two 552 // calls. In the latter case, the removal mask will be split into two
530 // parts - one for the origin deletion and one for the registrable domain. 553 // parts - one for the origin deletion and one for the registrable domain.
531 const int domain_scoped_types = BrowsingDataRemover::REMOVE_COOKIES | 554 std::set<const content::BrowsingDataType*> registrable_domain_deletion_mask;
532 BrowsingDataRemover::REMOVE_CHANNEL_IDS | 555 std::set_intersection(
533 BrowsingDataRemover::REMOVE_PLUGIN_DATA; 556 test_case.mask.begin(), test_case.mask.end(),
534 int registrable_domain_deletion_mask = test_case.mask & domain_scoped_types; 557 domain_scoped_types.begin(), domain_scoped_types.end(),
535 int origin_deletion_mask = test_case.mask & ~domain_scoped_types; 558 std::inserter(registrable_domain_deletion_mask,
559 registrable_domain_deletion_mask.begin()));
536 560
537 if (registrable_domain_deletion_mask) { 561 std::set<const content::BrowsingDataType*> origin_deletion_mask;
562 std::set_difference(
563 test_case.mask.begin(), test_case.mask.end(),
564 domain_scoped_types.begin(), domain_scoped_types.end(),
565 std::inserter(origin_deletion_mask, origin_deletion_mask.begin()));
566
567 if (!registrable_domain_deletion_mask.empty()) {
538 remover()->ExpectCallDontCareAboutFilterBuilder( 568 remover()->ExpectCallDontCareAboutFilterBuilder(
539 base::Time(), base::Time::Max(), 569 base::Time(), base::Time::Max(),
540 registrable_domain_deletion_mask, all_origin_types); 570 registrable_domain_deletion_mask, all_origin_types);
541 } 571 }
542 572
543 if (origin_deletion_mask) { 573 if (!origin_deletion_mask.empty()) {
544 remover()->ExpectCallDontCareAboutFilterBuilder( 574 remover()->ExpectCallDontCareAboutFilterBuilder(
545 base::Time(), base::Time::Max(), 575 base::Time(), base::Time::Max(),
546 origin_deletion_mask, all_origin_types); 576 origin_deletion_mask, all_origin_types);
547 } 577 }
548 578
549 SetClearingFinished(false); 579 SetClearingFinished(false);
550 client.ClearSiteData( 580 client.ClearSiteData(
551 profile(), url::Origin(GURL("https://www.example.com")), 581 profile(), url::Origin(GURL("https://www.example.com")),
552 test_case.cookies, test_case.storage, test_case.cache, 582 test_case.cookies, test_case.storage, test_case.cache,
553 base::Bind( 583 base::Bind(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 for (const TestCase& test_case : test_cases) { 635 for (const TestCase& test_case : test_cases) {
606 SCOPED_TRACE(test_case.origin); 636 SCOPED_TRACE(test_case.origin);
607 637
608 std::unique_ptr<BrowsingDataFilterBuilder> 638 std::unique_ptr<BrowsingDataFilterBuilder>
609 registrable_domain_filter_builder(BrowsingDataFilterBuilder::Create( 639 registrable_domain_filter_builder(BrowsingDataFilterBuilder::Create(
610 BrowsingDataFilterBuilder::WHITELIST)); 640 BrowsingDataFilterBuilder::WHITELIST));
611 registrable_domain_filter_builder->AddRegisterableDomain(test_case.domain); 641 registrable_domain_filter_builder->AddRegisterableDomain(test_case.domain);
612 642
613 remover()->ExpectCall( 643 remover()->ExpectCall(
614 base::Time(), base::Time::Max(), 644 base::Time(), base::Time::Max(),
615 BrowsingDataRemover::REMOVE_COOKIES | 645 { &kBrowsingDataTypeCookies,
616 BrowsingDataRemover::REMOVE_CHANNEL_IDS | 646 &kBrowsingDataTypeChannelIDs,
617 BrowsingDataRemover::REMOVE_PLUGIN_DATA, 647 &kBrowsingDataTypePluginData},
618 BrowsingDataHelper::ALL, std::move(registrable_domain_filter_builder)); 648 BrowsingDataHelper::ALL, std::move(registrable_domain_filter_builder));
619 649
620 std::unique_ptr<BrowsingDataFilterBuilder> origin_filter_builder( 650 std::unique_ptr<BrowsingDataFilterBuilder> origin_filter_builder(
621 BrowsingDataFilterBuilder::Create( 651 BrowsingDataFilterBuilder::Create(
622 BrowsingDataFilterBuilder::WHITELIST)); 652 BrowsingDataFilterBuilder::WHITELIST));
623 origin_filter_builder->AddOrigin(url::Origin(GURL(test_case.origin))); 653 origin_filter_builder->AddOrigin(url::Origin(GURL(test_case.origin)));
624 654
625 remover()->ExpectCall( 655 remover()->ExpectCall(
626 base::Time(), base::Time::Max(), 656 base::Time(), base::Time::Max(),
627 BrowsingDataRemover::REMOVE_CACHE, BrowsingDataHelper::ALL, 657 { &kBrowsingDataTypeCache }, BrowsingDataHelper::ALL,
628 std::move(origin_filter_builder)); 658 std::move(origin_filter_builder));
629 659
630 SetClearingFinished(false); 660 SetClearingFinished(false);
631 client.ClearSiteData( 661 client.ClearSiteData(
632 profile(), url::Origin(GURL(test_case.origin)), true /* cookies */, 662 profile(), url::Origin(GURL(test_case.origin)), true /* cookies */,
633 false /* storage */, true /* cache */, 663 false /* storage */, true /* cache */,
634 base::Bind( 664 base::Bind(
635 &ChromeContentBrowserClientClearSiteDataTest::SetClearingFinished, 665 &ChromeContentBrowserClientClearSiteDataTest::SetClearingFinished,
636 base::Unretained(this), true)); 666 base::Unretained(this), true));
637 EXPECT_TRUE(IsClearingFinished()); 667 EXPECT_TRUE(IsClearingFinished());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 client.ClearSiteData( 711 client.ClearSiteData(
682 profile(), origin, true /* cookies */, false /* storage */, 712 profile(), origin, true /* cookies */, false /* storage */,
683 true /* cache */, 713 true /* cache */,
684 base::Bind( 714 base::Bind(
685 &ChromeContentBrowserClientClearSiteDataTest::SetClearingFinished, 715 &ChromeContentBrowserClientClearSiteDataTest::SetClearingFinished,
686 base::Unretained(this), true)); 716 base::Unretained(this), true));
687 EXPECT_TRUE(IsClearingFinished()); 717 EXPECT_TRUE(IsClearingFinished());
688 } 718 }
689 719
690 } // namespace 720 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698