| OLD | NEW |
| 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/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 20 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 21 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 21 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 22 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" | 22 #include "chrome/browser/browsing_data/mock_browsing_data_remover.h" |
| 23 #include "chrome/browser/search_engines/template_url_service_factory.h" | 23 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 24 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
| 25 #include "components/content_settings/core/browser/host_content_settings_map.h" | 25 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 26 #include "components/search_engines/template_url_service.h" | 26 #include "components/search_engines/template_url_service.h" |
| 27 #include "components/variations/entropy_provider.h" | 27 #include "components/variations/entropy_provider.h" |
| 28 #include "components/variations/variations_associated_data.h" | 28 #include "components/variations/variations_associated_data.h" |
| 29 #include "components/version_info/version_info.h" | 29 #include "components/version_info/version_info.h" |
| 30 #include "content/public/browser/browsing_data_filter_builder.h" | 30 #include "content/public/browser/browsing_data_filter_builder.h" |
| 31 #include "content/public/browser/navigation_controller.h" | 31 #include "content/public/browser/navigation_controller.h" |
| 32 #include "content/public/browser/navigation_entry.h" | 32 #include "content/public/browser/navigation_entry.h" |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 ASSERT_TRUE(entry != NULL); | 336 ASSERT_TRUE(entry != NULL); |
| 337 EXPECT_EQ(url_rewritten, entry->GetURL()); | 337 EXPECT_EQ(url_rewritten, entry->GetURL()); |
| 338 EXPECT_EQ(url_original, entry->GetVirtualURL()); | 338 EXPECT_EQ(url_original, entry->GetVirtualURL()); |
| 339 } | 339 } |
| 340 | 340 |
| 341 } // namespace content | 341 } // namespace content |
| 342 #endif // !defined(OS_ANDROID) | 342 #endif // !defined(OS_ANDROID) |
| 343 | 343 |
| 344 namespace { | 344 namespace { |
| 345 | 345 |
| 346 // A BrowsingDataRemover that only records calls. | |
| 347 // TODO(msramek): Once BrowsingDataRemoverImpl moves to content/ (non-public), | |
| 348 // it will not be possible to inherit from it here. However, at that time | |
| 349 // this functionality will become redundant, as it will no longer be necessary | |
| 350 // to call to chrome/ to perform deletion. Remove it then. | |
| 351 class MockBrowsingDataRemover : public BrowsingDataRemoverImpl { | |
| 352 public: | |
| 353 explicit MockBrowsingDataRemover(content::BrowserContext* context) | |
| 354 : BrowsingDataRemoverImpl(context) {} | |
| 355 | |
| 356 ~MockBrowsingDataRemover() override { | |
| 357 DCHECK(!expected_calls_.size()) | |
| 358 << "Expectations were set but not verified."; | |
| 359 } | |
| 360 | |
| 361 void RemoveInternal(const base::Time& delete_begin, | |
| 362 const base::Time& delete_end, | |
| 363 int remove_mask, | |
| 364 int origin_type_mask, | |
| 365 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, | |
| 366 BrowsingDataRemover::Observer* observer) override { | |
| 367 actual_calls_.emplace_back(delete_begin, delete_end, remove_mask, | |
| 368 origin_type_mask, std::move(filter_builder), | |
| 369 true /* should_compare_filter */); | |
| 370 | |
| 371 // |observer| is not recorded in |actual_calls_| to be compared with | |
| 372 // expectations, because it's created internally in ClearSiteData() and | |
| 373 // 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 | |
| 375 // the test by waiting for the callback forever. | |
| 376 DCHECK(observer); | |
| 377 observer->OnBrowsingDataRemoverDone(); | |
| 378 } | |
| 379 | |
| 380 void ExpectCall( | |
| 381 const base::Time& delete_begin, | |
| 382 const base::Time& delete_end, | |
| 383 int remove_mask, | |
| 384 int origin_type_mask, | |
| 385 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { | |
| 386 expected_calls_.emplace_back(delete_begin, delete_end, remove_mask, | |
| 387 origin_type_mask, std::move(filter_builder), | |
| 388 true /* should_compare_filter */); | |
| 389 } | |
| 390 | |
| 391 void ExpectCallDontCareAboutFilterBuilder(const base::Time& delete_begin, | |
| 392 const base::Time& delete_end, | |
| 393 int remove_mask, | |
| 394 int origin_type_mask) { | |
| 395 expected_calls_.emplace_back(delete_begin, delete_end, remove_mask, | |
| 396 origin_type_mask, | |
| 397 std::unique_ptr<BrowsingDataFilterBuilder>(), | |
| 398 false /* should_compare_filter */); | |
| 399 } | |
| 400 | |
| 401 void VerifyAndClearExpectations() { | |
| 402 EXPECT_EQ(expected_calls_, actual_calls_); | |
| 403 expected_calls_.clear(); | |
| 404 actual_calls_.clear(); | |
| 405 } | |
| 406 | |
| 407 private: | |
| 408 class CallParameters { | |
| 409 public: | |
| 410 CallParameters(const base::Time& delete_begin, | |
| 411 const base::Time& delete_end, | |
| 412 int remove_mask, | |
| 413 int origin_type_mask, | |
| 414 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, | |
| 415 bool should_compare_filter) | |
| 416 : delete_begin_(delete_begin), | |
| 417 delete_end_(delete_end), | |
| 418 remove_mask_(remove_mask), | |
| 419 origin_type_mask_(origin_type_mask), | |
| 420 filter_builder_(std::move(filter_builder)), | |
| 421 should_compare_filter_(should_compare_filter) {} | |
| 422 ~CallParameters() {} | |
| 423 | |
| 424 bool operator==(const CallParameters& other) const { | |
| 425 const CallParameters& a = *this; | |
| 426 const CallParameters& b = other; | |
| 427 | |
| 428 if (a.delete_begin_ != b.delete_begin_ || | |
| 429 a.delete_end_ != b.delete_end_ || | |
| 430 a.remove_mask_ != b.remove_mask_ || | |
| 431 a.origin_type_mask_ != b.origin_type_mask_) { | |
| 432 return false; | |
| 433 } | |
| 434 | |
| 435 if (!a.should_compare_filter_ || !b.should_compare_filter_) | |
| 436 return true; | |
| 437 return *a.filter_builder_ == *b.filter_builder_; | |
| 438 } | |
| 439 | |
| 440 private: | |
| 441 base::Time delete_begin_; | |
| 442 base::Time delete_end_; | |
| 443 int remove_mask_; | |
| 444 int origin_type_mask_; | |
| 445 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_; | |
| 446 bool should_compare_filter_; | |
| 447 }; | |
| 448 | |
| 449 std::list<CallParameters> actual_calls_; | |
| 450 std::list<CallParameters> expected_calls_; | |
| 451 }; | |
| 452 | |
| 453 // Tests for ChromeContentBrowserClient::ClearSiteData(). | 346 // Tests for ChromeContentBrowserClient::ClearSiteData(). |
| 454 class ChromeContentBrowserClientClearSiteDataTest : public testing::Test { | 347 class ChromeContentBrowserClientClearSiteDataTest : public testing::Test { |
| 455 public: | 348 public: |
| 456 void SetUp() override { | 349 void SetUp() override { |
| 457 BrowsingDataRemoverFactory::GetInstance()->SetTestingFactoryAndUse( | 350 BrowsingDataRemoverFactory::GetInstance()->SetTestingFactoryAndUse( |
| 458 &profile_, &ChromeContentBrowserClientClearSiteDataTest::GetRemover); | 351 &profile_, &ChromeContentBrowserClientClearSiteDataTest::GetRemover); |
| 459 } | 352 } |
| 460 | 353 |
| 461 content::BrowserContext* profile() { return &profile_; } | 354 content::BrowserContext* profile() { return &profile_; } |
| 462 | 355 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 client.ClearSiteData( | 574 client.ClearSiteData( |
| 682 profile(), origin, true /* cookies */, false /* storage */, | 575 profile(), origin, true /* cookies */, false /* storage */, |
| 683 true /* cache */, | 576 true /* cache */, |
| 684 base::Bind( | 577 base::Bind( |
| 685 &ChromeContentBrowserClientClearSiteDataTest::SetClearingFinished, | 578 &ChromeContentBrowserClientClearSiteDataTest::SetClearingFinished, |
| 686 base::Unretained(this), true)); | 579 base::Unretained(this), true)); |
| 687 EXPECT_TRUE(IsClearingFinished()); | 580 EXPECT_TRUE(IsClearingFinished()); |
| 688 } | 581 } |
| 689 | 582 |
| 690 } // namespace | 583 } // namespace |
| OLD | NEW |