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

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

Issue 2827523003: Move BrowsingDataRemover to content/ (Closed)
Patch Set: Rebase over codereview.chromium.org/2815913005 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
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 <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "chrome/browser/browsing_data/browsing_data_helper.h" 21 #include "chrome/browser/browsing_data/browsing_data_helper.h"
22 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
23 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" 22 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
24 #include "chrome/browser/browsing_data/mock_browsing_data_remover_delegate.h" 23 #include "chrome/browser/browsing_data/mock_browsing_data_remover_delegate.h"
25 #include "chrome/browser/search_engines/template_url_service_factory.h" 24 #include "chrome/browser/search_engines/template_url_service_factory.h"
26 #include "chrome/test/base/testing_profile.h" 25 #include "chrome/test/base/testing_profile.h"
27 #include "components/content_settings/core/browser/host_content_settings_map.h" 26 #include "components/content_settings/core/browser/host_content_settings_map.h"
28 #include "components/search_engines/template_url_service.h" 27 #include "components/search_engines/template_url_service.h"
29 #include "components/variations/entropy_provider.h" 28 #include "components/variations/entropy_provider.h"
30 #include "components/variations/variations_associated_data.h" 29 #include "components/variations/variations_associated_data.h"
31 #include "components/version_info/version_info.h" 30 #include "components/version_info/version_info.h"
32 #include "content/public/browser/browsing_data_filter_builder.h" 31 #include "content/public/browser/browsing_data_filter_builder.h"
32 #include "content/public/browser/browsing_data_remover.h"
33 #include "content/public/browser/navigation_controller.h" 33 #include "content/public/browser/navigation_controller.h"
34 #include "content/public/browser/navigation_entry.h" 34 #include "content/public/browser/navigation_entry.h"
35 #include "content/public/browser/storage_partition.h" 35 #include "content/public/browser/storage_partition.h"
36 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
37 #include "content/public/common/content_switches.h" 37 #include "content/public/common/content_switches.h"
38 #include "content/public/test/test_browser_thread_bundle.h" 38 #include "content/public/test/test_browser_thread_bundle.h"
39 #include "media/media_features.h" 39 #include "media/media_features.h"
40 #include "testing/gmock/include/gmock/gmock.h" 40 #include "testing/gmock/include/gmock/gmock.h"
41 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
42 #include "url/gurl.h" 42 #include "url/gurl.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 343
344 } // namespace content 344 } // namespace content
345 #endif // !defined(OS_ANDROID) 345 #endif // !defined(OS_ANDROID)
346 346
347 namespace { 347 namespace {
348 348
349 // Tests for ChromeContentBrowserClient::ClearSiteData(). 349 // Tests for ChromeContentBrowserClient::ClearSiteData().
350 class ChromeContentBrowserClientClearSiteDataTest : public testing::Test { 350 class ChromeContentBrowserClientClearSiteDataTest : public testing::Test {
351 public: 351 public:
352 void SetUp() override { 352 void SetUp() override {
353 BrowsingDataRemoverFactory::GetForBrowserContext(profile()) 353 content::BrowserContext::GetBrowsingDataRemover(profile())
354 ->SetEmbedderDelegate( 354 ->SetEmbedderDelegate(&mock_delegate_);
355 base::MakeUnique<MockBrowsingDataRemoverDelegate>());
356 run_loop_.reset(new base::RunLoop()); 355 run_loop_.reset(new base::RunLoop());
357 } 356 }
358 357
359 content::BrowserContext* profile() { return &profile_; } 358 content::BrowserContext* profile() { return &profile_; }
360 359
361 MockBrowsingDataRemoverDelegate* delegate() { 360 MockBrowsingDataRemoverDelegate* delegate() { return &mock_delegate_; }
362 return static_cast<MockBrowsingDataRemoverDelegate*>(
363 BrowsingDataRemoverFactory::GetForBrowserContext(profile())
364 ->GetEmbedderDelegate());
365 }
366 361
367 void OnClearingFinished() { run_loop_->Quit(); } 362 void OnClearingFinished() { run_loop_->Quit(); }
368 363
369 void WaitForClearingFinished() { 364 void WaitForClearingFinished() {
370 run_loop_->Run(); 365 run_loop_->Run();
371 run_loop_.reset(new base::RunLoop()); 366 run_loop_.reset(new base::RunLoop());
372 } 367 }
373 368
374 private: 369 private:
375 std::unique_ptr<base::RunLoop> run_loop_; 370 std::unique_ptr<base::RunLoop> run_loop_;
371 MockBrowsingDataRemoverDelegate mock_delegate_;
376 content::TestBrowserThreadBundle thread_bundle_; 372 content::TestBrowserThreadBundle thread_bundle_;
377 TestingProfile profile_; 373 TestingProfile profile_;
378 }; 374 };
379 375
380 // Tests that the parameters to ClearBrowsingData() are translated to 376 // Tests that the parameters to ClearBrowsingData() are translated to
381 // the correct BrowsingDataRemover::RemoveInternal() operation. The fourth 377 // the correct BrowsingDataRemover::RemoveInternal() operation. The fourth
382 // parameter, |filter_builder|, is tested in detail in the RegistrableDomains 378 // parameter, |filter_builder|, is tested in detail in the RegistrableDomains
383 // test below. 379 // test below.
384 TEST_F(ChromeContentBrowserClientClearSiteDataTest, Parameters) { 380 TEST_F(ChromeContentBrowserClientClearSiteDataTest, Parameters) {
385 ChromeContentBrowserClient client; 381 ChromeContentBrowserClient client;
386 382
387 struct TestCase { 383 struct TestCase {
388 bool cookies; 384 bool cookies;
389 bool storage; 385 bool storage;
390 bool cache; 386 bool cache;
391 int mask; 387 int mask;
392 } test_cases[] = { 388 } test_cases[] = {
393 {false, false, false, 0}, 389 {false, false, false, 0},
394 {true, false, false, 390 {true, false, false,
395 BrowsingDataRemover::DATA_TYPE_COOKIES | 391 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
396 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS | 392 content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
397 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA}, 393 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA},
398 {false, true, false, BrowsingDataRemover::DATA_TYPE_DOM_STORAGE}, 394 {false, true, false, content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE},
399 {false, false, true, BrowsingDataRemover::DATA_TYPE_CACHE}, 395 {false, false, true, content::BrowsingDataRemover::DATA_TYPE_CACHE},
400 {true, true, false, 396 {true, true, false,
401 BrowsingDataRemover::DATA_TYPE_COOKIES | 397 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
402 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS | 398 content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
403 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA | 399 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA |
404 BrowsingDataRemover::DATA_TYPE_DOM_STORAGE}, 400 content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE},
405 {true, false, true, 401 {true, false, true,
406 BrowsingDataRemover::DATA_TYPE_COOKIES | 402 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
407 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS | 403 content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
408 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA | 404 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA |
409 BrowsingDataRemover::DATA_TYPE_CACHE}, 405 content::BrowsingDataRemover::DATA_TYPE_CACHE},
410 {false, true, true, 406 {false, true, true,
411 BrowsingDataRemover::DATA_TYPE_DOM_STORAGE | 407 content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE |
412 BrowsingDataRemover::DATA_TYPE_CACHE}, 408 content::BrowsingDataRemover::DATA_TYPE_CACHE},
413 {true, true, true, 409 {true, true, true,
414 BrowsingDataRemover::DATA_TYPE_COOKIES | 410 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
415 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS | 411 content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
416 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA | 412 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA |
417 BrowsingDataRemover::DATA_TYPE_DOM_STORAGE | 413 content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE |
418 BrowsingDataRemover::DATA_TYPE_CACHE}, 414 content::BrowsingDataRemover::DATA_TYPE_CACHE},
419 }; 415 };
420 416
421 for (unsigned int i = 0; i < arraysize(test_cases); ++i) { 417 for (unsigned int i = 0; i < arraysize(test_cases); ++i) {
422 SCOPED_TRACE(base::StringPrintf("Test case %d", i)); 418 SCOPED_TRACE(base::StringPrintf("Test case %d", i));
423 const TestCase& test_case = test_cases[i]; 419 const TestCase& test_case = test_cases[i];
424 420
425 // We always delete data for all time and all origin types. 421 // We always delete data for all time and all origin types.
426 int all_origin_types = ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES; 422 int all_origin_types = ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES;
427 423
428 // Some data are deleted for the origin and some for the registrable domain. 424 // Some data are deleted for the origin and some for the registrable domain.
429 // Depending on the chosen datatypes, this might result into one or two 425 // Depending on the chosen datatypes, this might result into one or two
430 // calls. In the latter case, the removal mask will be split into two 426 // calls. In the latter case, the removal mask will be split into two
431 // parts - one for the origin deletion and one for the registrable domain. 427 // parts - one for the origin deletion and one for the registrable domain.
432 const int domain_scoped_types = 428 const int domain_scoped_types =
433 BrowsingDataRemover::DATA_TYPE_COOKIES | 429 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
434 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS | 430 content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
435 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA; 431 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA;
436 int registrable_domain_deletion_mask = test_case.mask & domain_scoped_types; 432 int registrable_domain_deletion_mask = test_case.mask & domain_scoped_types;
437 int origin_deletion_mask = test_case.mask & ~domain_scoped_types; 433 int origin_deletion_mask = test_case.mask & ~domain_scoped_types;
438 434
439 if (registrable_domain_deletion_mask) { 435 if (registrable_domain_deletion_mask) {
440 delegate()->ExpectCallDontCareAboutFilterBuilder( 436 delegate()->ExpectCallDontCareAboutFilterBuilder(
441 base::Time(), base::Time::Max(), registrable_domain_deletion_mask, 437 base::Time(), base::Time::Max(), registrable_domain_deletion_mask,
442 all_origin_types); 438 all_origin_types);
443 } 439 }
444 440
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 for (const TestCase& test_case : test_cases) { 502 for (const TestCase& test_case : test_cases) {
507 SCOPED_TRACE(test_case.origin); 503 SCOPED_TRACE(test_case.origin);
508 504
509 std::unique_ptr<BrowsingDataFilterBuilder> 505 std::unique_ptr<BrowsingDataFilterBuilder>
510 registrable_domain_filter_builder(BrowsingDataFilterBuilder::Create( 506 registrable_domain_filter_builder(BrowsingDataFilterBuilder::Create(
511 BrowsingDataFilterBuilder::WHITELIST)); 507 BrowsingDataFilterBuilder::WHITELIST));
512 registrable_domain_filter_builder->AddRegisterableDomain(test_case.domain); 508 registrable_domain_filter_builder->AddRegisterableDomain(test_case.domain);
513 509
514 delegate()->ExpectCall( 510 delegate()->ExpectCall(
515 base::Time(), base::Time::Max(), 511 base::Time(), base::Time::Max(),
516 BrowsingDataRemover::DATA_TYPE_COOKIES | 512 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
517 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS | 513 content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
518 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA, 514 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA,
519 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES, 515 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES,
520 *registrable_domain_filter_builder); 516 *registrable_domain_filter_builder);
521 517
522 std::unique_ptr<BrowsingDataFilterBuilder> origin_filter_builder( 518 std::unique_ptr<BrowsingDataFilterBuilder> origin_filter_builder(
523 BrowsingDataFilterBuilder::Create( 519 BrowsingDataFilterBuilder::Create(
524 BrowsingDataFilterBuilder::WHITELIST)); 520 BrowsingDataFilterBuilder::WHITELIST));
525 origin_filter_builder->AddOrigin(url::Origin(GURL(test_case.origin))); 521 origin_filter_builder->AddOrigin(url::Origin(GURL(test_case.origin)));
526 522
527 delegate()->ExpectCall(base::Time(), base::Time::Max(), 523 delegate()->ExpectCall(base::Time(), base::Time::Max(),
528 BrowsingDataRemover::DATA_TYPE_CACHE, 524 content::BrowsingDataRemover::DATA_TYPE_CACHE,
529 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES, 525 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES,
530 *origin_filter_builder); 526 *origin_filter_builder);
531 527
532 client.ClearSiteData( 528 client.ClearSiteData(
533 profile(), url::Origin(GURL(test_case.origin)), true /* cookies */, 529 profile(), url::Origin(GURL(test_case.origin)), true /* cookies */,
534 false /* storage */, true /* cache */, 530 false /* storage */, true /* cache */,
535 base::Bind( 531 base::Bind(
536 &ChromeContentBrowserClientClearSiteDataTest::OnClearingFinished, 532 &ChromeContentBrowserClientClearSiteDataTest::OnClearingFinished,
537 base::Unretained(this))); 533 base::Unretained(this)));
538 WaitForClearingFinished(); 534 WaitForClearingFinished();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 client.ClearSiteData( 574 client.ClearSiteData(
579 profile(), origin, true /* cookies */, false /* storage */, 575 profile(), origin, true /* cookies */, false /* storage */,
580 true /* cache */, 576 true /* cache */,
581 base::Bind( 577 base::Bind(
582 &ChromeContentBrowserClientClearSiteDataTest::OnClearingFinished, 578 &ChromeContentBrowserClientClearSiteDataTest::OnClearingFinished,
583 base::Unretained(this))); 579 base::Unretained(this)));
584 WaitForClearingFinished(); 580 WaitForClearingFinished();
585 } 581 }
586 582
587 } // namespace 583 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/chromeos/profiles/profile_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698