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

Unified Diff: chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_unittest.cc

Issue 2641853002: Split BrowsingDataRemoverTest into two tests for Impl and Delegate. (Closed)
Patch Set: Updated year Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover_unittest.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_unittest.cc
diff --git a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_unittest.cc
similarity index 50%
rename from chrome/browser/browsing_data/browsing_data_remover_unittest.cc
rename to chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_unittest.cc
index 446d9b8dcc46bc05fbc277f2cbc7bd73ec575377..eeab98a9dd4aaa862ee9c2f8dd0fda43f5522192 100644
--- a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
+++ b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_unittest.cc
@@ -1,37 +1,15 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <stddef.h>
-#include <stdint.h>
-
-#include <list>
-#include <memory>
-#include <set>
-#include <string>
-#include <utility>
-#include <vector>
+#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
#include "base/guid.h"
-#include "base/location.h"
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/memory/ptr_util.h"
-#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
-#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/task/cancelable_task_tracker.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "build/build_config.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
-#include "chrome/browser/browsing_data/browsing_data_filter_builder.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
@@ -75,31 +53,15 @@
#include "components/password_manager/core/browser/password_manager_test_utils.h"
#include "components/password_manager/core/browser/password_store_consumer.h"
#include "components/prefs/testing_pref_service.h"
-#include "content/public/browser/browser_context.h"
-#include "content/public/browser/cookie_store_factory.h"
-#include "content/public/browser/dom_storage_context.h"
-#include "content/public/browser/local_storage_usage_info.h"
-#include "content/public/browser/permission_type.h"
-#include "content/public/browser/storage_partition.h"
#include "content/public/test/mock_download_manager.h"
-#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h"
-#include "extensions/features/features.h"
#include "net/cookies/cookie_store.h"
-#include "net/http/http_network_session.h"
#include "net/http/http_transaction_factory.h"
-#include "net/ssl/channel_id_service.h"
-#include "net/ssl/channel_id_store.h"
-#include "net/ssl/ssl_client_cert_type.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
-#include "ppapi/features/features.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/favicon_size.h"
-#include "url/origin.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/webapps/webapp_registry.h"
@@ -115,18 +77,10 @@
#include "components/signin/core/account_id/account_id.h"
#endif
-#if BUILDFLAG(ENABLE_EXTENSIONS)
-#include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
-#endif
-
#if BUILDFLAG(ENABLE_PLUGINS)
#include "chrome/browser/browsing_data/mock_browsing_data_flash_lso_helper.h"
#endif
-class MockExtensionSpecialStoragePolicy;
-
-using content::BrowserThread;
-using content::StoragePartition;
using domain_reliability::CLEAR_BEACONS;
using domain_reliability::CLEAR_CONTEXTS;
using domain_reliability::DomainReliabilityClearMode;
@@ -155,173 +109,19 @@ const char kTestOrigin2[] = "http://host2.com:1/";
const char kTestOrigin3[] = "http://host3.com:1/";
const char kTestRegisterableDomain3[] = "host3.com";
const char kTestOrigin4[] = "https://host3.com:1/";
-const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
-const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
-
-// For Autofill.
-const char kWebOrigin[] = "https://www.example.com/";
// For HTTP auth.
const char kTestRealm[] = "TestRealm";
+// For Autofill.
+const char kWebOrigin[] = "https://www.example.com/";
+
const GURL kOrigin1(kTestOrigin1);
const GURL kOrigin2(kTestOrigin2);
const GURL kOrigin3(kTestOrigin3);
const GURL kOrigin4(kTestOrigin4);
-const GURL kOriginExt(kTestOriginExt);
-const GURL kOriginDevTools(kTestOriginDevTools);
-
-const base::FilePath::CharType kDomStorageOrigin1[] =
- FILE_PATH_LITERAL("http_host1_1.localstorage");
-
-const base::FilePath::CharType kDomStorageOrigin2[] =
- FILE_PATH_LITERAL("http_host2_1.localstorage");
-
-const base::FilePath::CharType kDomStorageOrigin3[] =
- FILE_PATH_LITERAL("http_host3_1.localstorage");
-
-const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL(
- "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage");
-
-#if defined(OS_CHROMEOS)
-void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true));
-}
-#endif
-
-struct StoragePartitionRemovalData {
- uint32_t remove_mask = 0;
- uint32_t quota_storage_remove_mask = 0;
- base::Time remove_begin;
- base::Time remove_end;
- StoragePartition::OriginMatcherFunction origin_matcher;
- StoragePartition::CookieMatcherFunction cookie_matcher;
-
- StoragePartitionRemovalData() {}
-};
-
-net::CanonicalCookie CreateCookieWithHost(const GURL& source) {
- std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create(
- source, "A", "1", std::string(), "/", base::Time::Now(),
- base::Time::Now(), false, false, net::CookieSameSite::DEFAULT_MODE, false,
- net::COOKIE_PRIORITY_MEDIUM));
- EXPECT_TRUE(cookie);
- return *cookie;
-}
-
-class TestStoragePartition : public StoragePartition {
- public:
- TestStoragePartition() {}
- ~TestStoragePartition() override {}
-
- // content::StoragePartition implementation.
- base::FilePath GetPath() override { return base::FilePath(); }
- net::URLRequestContextGetter* GetURLRequestContext() override {
- return nullptr;
- }
- net::URLRequestContextGetter* GetMediaURLRequestContext() override {
- return nullptr;
- }
- storage::QuotaManager* GetQuotaManager() override { return nullptr; }
- content::AppCacheService* GetAppCacheService() override { return nullptr; }
- storage::FileSystemContext* GetFileSystemContext() override {
- return nullptr;
- }
- storage::DatabaseTracker* GetDatabaseTracker() override { return nullptr; }
- content::DOMStorageContext* GetDOMStorageContext() override {
- return nullptr;
- }
- content::IndexedDBContext* GetIndexedDBContext() override { return nullptr; }
- content::ServiceWorkerContext* GetServiceWorkerContext() override {
- return nullptr;
- }
- content::CacheStorageContext* GetCacheStorageContext() override {
- return nullptr;
- }
- content::PlatformNotificationContext* GetPlatformNotificationContext()
- override {
- return nullptr;
- }
- content::HostZoomMap* GetHostZoomMap() override { return nullptr; }
- content::HostZoomLevelContext* GetHostZoomLevelContext() override {
- return nullptr;
- }
- content::ZoomLevelDelegate* GetZoomLevelDelegate() override {
- return nullptr;
- }
-
- void ClearDataForOrigin(uint32_t remove_mask,
- uint32_t quota_storage_remove_mask,
- const GURL& storage_origin,
- net::URLRequestContextGetter* rq_context,
- const base::Closure& callback) override {
- BrowserThread::PostTask(BrowserThread::UI,
- FROM_HERE,
- base::Bind(&TestStoragePartition::AsyncRunCallback,
- base::Unretained(this),
- callback));
- }
-
- void ClearData(uint32_t remove_mask,
- uint32_t quota_storage_remove_mask,
- const GURL& storage_origin,
- const OriginMatcherFunction& origin_matcher,
- const base::Time begin,
- const base::Time end,
- const base::Closure& callback) override {
- // Store stuff to verify parameters' correctness later.
- storage_partition_removal_data_.remove_mask = remove_mask;
- storage_partition_removal_data_.quota_storage_remove_mask =
- quota_storage_remove_mask;
- storage_partition_removal_data_.remove_begin = begin;
- storage_partition_removal_data_.remove_end = end;
- storage_partition_removal_data_.origin_matcher = origin_matcher;
-
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- base::Bind(&TestStoragePartition::AsyncRunCallback,
- base::Unretained(this), callback));
- }
-
- void ClearData(uint32_t remove_mask,
- uint32_t quota_storage_remove_mask,
- const OriginMatcherFunction& origin_matcher,
- const CookieMatcherFunction& cookie_matcher,
- const base::Time begin,
- const base::Time end,
- const base::Closure& callback) override {
- // Store stuff to verify parameters' correctness later.
- storage_partition_removal_data_.remove_mask = remove_mask;
- storage_partition_removal_data_.quota_storage_remove_mask =
- quota_storage_remove_mask;
- storage_partition_removal_data_.remove_begin = begin;
- storage_partition_removal_data_.remove_end = end;
- storage_partition_removal_data_.origin_matcher = origin_matcher;
- storage_partition_removal_data_.cookie_matcher = cookie_matcher;
-
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&TestStoragePartition::AsyncRunCallback,
- base::Unretained(this), callback));
- }
-
- void Flush() override {}
- StoragePartitionRemovalData GetStoragePartitionRemovalData() {
- return storage_partition_removal_data_;
- }
-
- private:
- void AsyncRunCallback(const base::Closure& callback) {
- callback.Run();
- }
-
- StoragePartitionRemovalData storage_partition_removal_data_;
-
- DISALLOW_COPY_AND_ASSIGN(TestStoragePartition);
-};
+// Testers --------------------------------------------------------------------
#if defined(OS_ANDROID)
class TestWebappRegistry : public WebappRegistry {
@@ -340,74 +140,13 @@ class TestWebappRegistry : public WebappRegistry {
};
#endif
-// Custom matcher to test the equivalence of two URL filters. Since those are
-// blackbox predicates, we can only approximate the equivalence by testing
-// whether the filter give the same answer for several URLs. This is currently
-// good enough for our testing purposes, to distinguish whitelists
-// and blacklists, empty and non-empty filters and such.
-// TODO(msramek): BrowsingDataRemover and some of its backends support URL
-// filters, but its constructor currently only takes a single URL and constructs
-// its own url filter. If an url filter was directly passed to
-// BrowsingDataRemover (what should eventually be the case), we can use the same
-// instance in the test as well, and thus simply test base::Callback::Equals()
-// in this matcher.
-class ProbablySameFilterMatcher
- : public MatcherInterface<const base::Callback<bool(const GURL&)>&> {
- public:
- explicit ProbablySameFilterMatcher(
- const base::Callback<bool(const GURL&)>& filter)
- : to_match_(filter) {
- }
-
- virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter,
- MatchResultListener* listener) const {
- if (filter.is_null() && to_match_.is_null())
- return true;
- if (filter.is_null() != to_match_.is_null())
- return false;
-
- const GURL urls_to_test_[] =
- {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")};
- for (GURL url : urls_to_test_) {
- if (filter.Run(url) != to_match_.Run(url)) {
- if (listener)
- *listener << "The filters differ on the URL " << url;
- return false;
- }
- }
- return true;
- }
-
- virtual void DescribeTo(::std::ostream* os) const {
- *os << "is probably the same url filter as " << &to_match_;
- }
-
- virtual void DescribeNegationTo(::std::ostream* os) const {
- *os << "is definitely NOT the same url filter as " << &to_match_;
- }
-
- private:
- const base::Callback<bool(const GURL&)>& to_match_;
-};
-
-inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter(
- const base::Callback<bool(const GURL&)>& filter) {
- return MakeMatcher(new ProbablySameFilterMatcher(filter));
-}
-
-bool ProbablySameFilters(
- const base::Callback<bool(const GURL&)>& filter1,
- const base::Callback<bool(const GURL&)>& filter2) {
- return ProbablySameFilter(filter1).MatchAndExplain(filter2, nullptr);
-}
-
-base::Time AnHourAgo() {
- return base::Time::Now() - base::TimeDelta::FromHours(1);
+#if defined(OS_CHROMEOS)
+void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true));
}
-
-} // namespace
-
-// Testers -------------------------------------------------------------------
+#endif
class RemoveCookieTester {
public:
@@ -507,68 +246,6 @@ class RemoveSafeBrowsingCookieTester : public RemoveCookieTester {
DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester);
};
-class RemoveChannelIDTester : public net::SSLConfigService::Observer {
- public:
- explicit RemoveChannelIDTester(TestingProfile* profile) {
- channel_id_service_ = profile->GetRequestContext()->
- GetURLRequestContext()->channel_id_service();
- ssl_config_service_ = profile->GetSSLConfigService();
- ssl_config_service_->AddObserver(this);
- }
-
- ~RemoveChannelIDTester() override {
- ssl_config_service_->RemoveObserver(this);
- }
-
- int ChannelIDCount() { return channel_id_service_->channel_id_count(); }
-
- // Add a server bound cert for |server| with specific creation and expiry
- // times. The cert and key data will be filled with dummy values.
- void AddChannelIDWithTimes(const std::string& server_identifier,
- base::Time creation_time) {
- GetChannelIDStore()->SetChannelID(
- base::MakeUnique<net::ChannelIDStore::ChannelID>(
- server_identifier, creation_time, crypto::ECPrivateKey::Create()));
- }
-
- // Add a server bound cert for |server|, with the current time as the
- // creation time. The cert and key data will be filled with dummy values.
- void AddChannelID(const std::string& server_identifier) {
- base::Time now = base::Time::Now();
- AddChannelIDWithTimes(server_identifier, now);
- }
-
- void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) {
- GetChannelIDStore()->GetAllChannelIDs(
- base::Bind(&RemoveChannelIDTester::GetAllChannelIDsCallback,
- channel_ids));
- }
-
- net::ChannelIDStore* GetChannelIDStore() {
- return channel_id_service_->GetChannelIDStore();
- }
-
- int ssl_config_changed_count() const {
- return ssl_config_changed_count_;
- }
-
- // net::SSLConfigService::Observer implementation:
- void OnSSLConfigChanged() override { ssl_config_changed_count_++; }
-
- private:
- static void GetAllChannelIDsCallback(
- net::ChannelIDStore::ChannelIDList* dest,
- const net::ChannelIDStore::ChannelIDList& result) {
- *dest = result;
- }
-
- net::ChannelIDService* channel_id_service_;
- scoped_refptr<net::SSLConfigService> ssl_config_service_;
- int ssl_config_changed_count_ = 0;
-
- DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester);
-};
-
class RemoveHistoryTester {
public:
RemoveHistoryTester() {}
@@ -708,218 +385,60 @@ class RemoveFaviconTester {
DISALLOW_COPY_AND_ASSIGN(RemoveFaviconTester);
};
-class RemoveAutofillTester : public autofill::PersonalDataManagerObserver {
+class MockDomainReliabilityService : public DomainReliabilityService {
public:
- explicit RemoveAutofillTester(TestingProfile* profile)
- : personal_data_manager_(
- autofill::PersonalDataManagerFactory::GetForProfile(profile)) {
- autofill::test::DisableSystemServices(profile->GetPrefs());
- personal_data_manager_->AddObserver(this);
- }
+ MockDomainReliabilityService() {}
- ~RemoveAutofillTester() override {
- personal_data_manager_->RemoveObserver(this);
- autofill::test::ReenableSystemServices();
- }
+ ~MockDomainReliabilityService() override {}
- // Returns true if there are autofill profiles.
- bool HasProfile() {
- return !personal_data_manager_->GetProfiles().empty() &&
- !personal_data_manager_->GetCreditCards().empty();
+ std::unique_ptr<DomainReliabilityMonitor> CreateMonitor(
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
+ override {
+ NOTREACHED();
+ return std::unique_ptr<DomainReliabilityMonitor>();
}
- bool HasOrigin(const std::string& origin) {
- const std::vector<autofill::AutofillProfile*>& profiles =
- personal_data_manager_->GetProfiles();
- for (const autofill::AutofillProfile* profile : profiles) {
- if (profile->origin() == origin)
- return true;
- }
-
- const std::vector<autofill::CreditCard*>& credit_cards =
- personal_data_manager_->GetCreditCards();
- for (const autofill::CreditCard* credit_card : credit_cards) {
- if (credit_card->origin() == origin)
- return true;
- }
-
- return false;
+ void ClearBrowsingData(
+ DomainReliabilityClearMode clear_mode,
+ const base::Callback<bool(const GURL&)>& origin_filter,
+ const base::Closure& callback) override {
+ clear_count_++;
+ last_clear_mode_ = clear_mode;
+ last_filter_ = origin_filter;
+ callback.Run();
}
- // Add two profiles and two credit cards to the database. In each pair, one
- // entry has a web origin and the other has a Chrome origin.
- void AddProfilesAndCards() {
- std::vector<autofill::AutofillProfile> profiles;
- autofill::AutofillProfile profile;
- profile.set_guid(base::GenerateGUID());
- profile.set_origin(kWebOrigin);
- profile.SetRawInfo(autofill::NAME_FIRST, base::ASCIIToUTF16("Bob"));
- profile.SetRawInfo(autofill::NAME_LAST, base::ASCIIToUTF16("Smith"));
- profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, base::ASCIIToUTF16("94043"));
- profile.SetRawInfo(autofill::EMAIL_ADDRESS,
- base::ASCIIToUTF16("sue@example.com"));
- profile.SetRawInfo(autofill::COMPANY_NAME, base::ASCIIToUTF16("Company X"));
- profiles.push_back(profile);
+ void GetWebUIData(const base::Callback<void(std::unique_ptr<base::Value>)>&
+ callback) const override {
+ NOTREACHED();
+ }
- profile.set_guid(base::GenerateGUID());
- profile.set_origin(autofill::kSettingsOrigin);
- profiles.push_back(profile);
+ void SetDiscardUploadsForTesting(bool discard_uploads) override {
+ NOTREACHED();
+ }
- personal_data_manager_->SetProfiles(&profiles);
- base::RunLoop().Run();
+ void AddContextForTesting(
+ std::unique_ptr<const domain_reliability::DomainReliabilityConfig> config)
+ override {
+ NOTREACHED();
+ }
- std::vector<autofill::CreditCard> cards;
- autofill::CreditCard card;
- card.set_guid(base::GenerateGUID());
- card.set_origin(kWebOrigin);
- card.SetRawInfo(autofill::CREDIT_CARD_NUMBER,
- base::ASCIIToUTF16("1234-5678-9012-3456"));
- cards.push_back(card);
+ void ForceUploadsForTesting() override { NOTREACHED(); }
- card.set_guid(base::GenerateGUID());
- card.set_origin(autofill::kSettingsOrigin);
- cards.push_back(card);
+ int clear_count() const { return clear_count_; }
- personal_data_manager_->SetCreditCards(&cards);
- base::RunLoop().Run();
+ DomainReliabilityClearMode last_clear_mode() const {
+ return last_clear_mode_;
}
- private:
- void OnPersonalDataChanged() override {
- base::MessageLoop::current()->QuitWhenIdle();
+ const base::Callback<bool(const GURL&)>& last_filter() const {
+ return last_filter_;
}
- autofill::PersonalDataManager* personal_data_manager_;
- DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
-};
-
-class RemoveLocalStorageTester {
- public:
- explicit RemoveLocalStorageTester(TestingProfile* profile)
- : profile_(profile) {
- dom_storage_context_ =
- content::BrowserContext::GetDefaultStoragePartition(profile)->
- GetDOMStorageContext();
- }
-
- // Returns true, if the given origin URL exists.
- bool DOMStorageExistsForOrigin(const GURL& origin) {
- scoped_refptr<content::MessageLoopRunner> message_loop_runner =
- new content::MessageLoopRunner;
- quit_closure_ = message_loop_runner->QuitClosure();
- GetLocalStorageUsage();
- message_loop_runner->Run();
- for (size_t i = 0; i < infos_.size(); ++i) {
- if (origin == infos_[i].origin)
- return true;
- }
- return false;
- }
-
- void AddDOMStorageTestData() {
- // Note: This test depends on details of how the dom_storage library
- // stores data in the host file system.
- base::FilePath storage_path =
- profile_->GetPath().AppendASCII("Local Storage");
- base::CreateDirectory(storage_path);
-
- // Write some files.
- base::WriteFile(storage_path.Append(kDomStorageOrigin1), nullptr, 0);
- base::WriteFile(storage_path.Append(kDomStorageOrigin2), nullptr, 0);
- base::WriteFile(storage_path.Append(kDomStorageOrigin3), nullptr, 0);
- base::WriteFile(storage_path.Append(kDomStorageExt), nullptr, 0);
-
- // Tweak their dates.
- base::Time now = base::Time::Now();
- base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now);
-
- base::Time one_day_ago = now - base::TimeDelta::FromDays(1);
- base::TouchFile(storage_path.Append(kDomStorageOrigin2),
- one_day_ago, one_day_ago);
-
- base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60);
- base::TouchFile(storage_path.Append(kDomStorageOrigin3),
- sixty_days_ago, sixty_days_ago);
-
- base::TouchFile(storage_path.Append(kDomStorageExt), now, now);
- }
-
- private:
- void GetLocalStorageUsage() {
- dom_storage_context_->GetLocalStorageUsage(
- base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage,
- base::Unretained(this)));
- }
- void OnGotLocalStorageUsage(
- const std::vector<content::LocalStorageUsageInfo>& infos) {
- infos_ = infos;
- quit_closure_.Run();
- }
-
- // We don't own these pointers.
- TestingProfile* profile_;
- content::DOMStorageContext* dom_storage_context_ = nullptr;
-
- std::vector<content::LocalStorageUsageInfo> infos_;
- base::Closure quit_closure_;
-
- DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
-};
-
-class MockDomainReliabilityService : public DomainReliabilityService {
- public:
- MockDomainReliabilityService() {}
-
- ~MockDomainReliabilityService() override {}
-
- std::unique_ptr<DomainReliabilityMonitor> CreateMonitor(
- scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
- override {
- NOTREACHED();
- return std::unique_ptr<DomainReliabilityMonitor>();
- }
-
- void ClearBrowsingData(
- DomainReliabilityClearMode clear_mode,
- const base::Callback<bool(const GURL&)>& origin_filter,
- const base::Closure& callback) override {
- clear_count_++;
- last_clear_mode_ = clear_mode;
- last_filter_ = origin_filter;
- callback.Run();
- }
-
- void GetWebUIData(const base::Callback<void(std::unique_ptr<base::Value>)>&
- callback) const override {
- NOTREACHED();
- }
-
- void SetDiscardUploadsForTesting(bool discard_uploads) override {
- NOTREACHED();
- }
-
- void AddContextForTesting(
- std::unique_ptr<const domain_reliability::DomainReliabilityConfig> config)
- override {
- NOTREACHED();
- }
-
- void ForceUploadsForTesting() override { NOTREACHED(); }
-
- int clear_count() const { return clear_count_; }
-
- DomainReliabilityClearMode last_clear_mode() const {
- return last_clear_mode_;
- }
-
- const base::Callback<bool(const GURL&)>& last_filter() const {
- return last_filter_;
- }
-
- private:
- unsigned clear_count_ = 0;
- DomainReliabilityClearMode last_clear_mode_;
- base::Callback<bool(const GURL&)> last_filter_;
+ private:
+ unsigned clear_count_ = 0;
+ DomainReliabilityClearMode last_clear_mode_;
+ base::Callback<bool(const GURL&)> last_filter_;
};
struct TestingDomainReliabilityServiceFactoryUserData
@@ -1002,32 +521,6 @@ class ClearDomainReliabilityTester {
MockDomainReliabilityService* mock_service_;
};
-class RemoveDownloadsTester {
- public:
- explicit RemoveDownloadsTester(TestingProfile* testing_profile)
- : download_manager_(new content::MockDownloadManager()),
- chrome_download_manager_delegate_(testing_profile) {
- content::BrowserContext::SetDownloadManagerForTesting(testing_profile,
- download_manager_);
- EXPECT_EQ(download_manager_,
- content::BrowserContext::GetDownloadManager(testing_profile));
-
- EXPECT_CALL(*download_manager_, GetDelegate())
- .WillOnce(Return(&chrome_download_manager_delegate_));
- EXPECT_CALL(*download_manager_, Shutdown());
- }
-
- ~RemoveDownloadsTester() { chrome_download_manager_delegate_.Shutdown(); }
-
- content::MockDownloadManager* download_manager() { return download_manager_; }
-
- private:
- content::MockDownloadManager* download_manager_;
- ChromeDownloadManagerDelegate chrome_download_manager_delegate_;
-
- DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester);
-};
-
class RemovePasswordsTester {
public:
explicit RemovePasswordsTester(TestingProfile* testing_profile) {
@@ -1141,15 +634,194 @@ class RemovePluginDataTester {
};
#endif
-// Test Class ----------------------------------------------------------------
+// Custom matcher to test the equivalence of two URL filters. Since those are
+// blackbox predicates, we can only approximate the equivalence by testing
+// whether the filter give the same answer for several URLs. This is currently
+// good enough for our testing purposes, to distinguish whitelists
+// and blacklists, empty and non-empty filters and such.
+// TODO(msramek): BrowsingDataRemover and some of its backends support URL
+// filters, but its constructor currently only takes a single URL and constructs
+// its own url filter. If an url filter was directly passed to
+// BrowsingDataRemover (what should eventually be the case), we can use the same
+// instance in the test as well, and thus simply test base::Callback::Equals()
+// in this matcher.
+class ProbablySameFilterMatcher
+ : public MatcherInterface<const base::Callback<bool(const GURL&)>&> {
+ public:
+ explicit ProbablySameFilterMatcher(
+ const base::Callback<bool(const GURL&)>& filter)
+ : to_match_(filter) {
+ }
+
+ virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter,
+ MatchResultListener* listener) const {
+ if (filter.is_null() && to_match_.is_null())
+ return true;
+ if (filter.is_null() != to_match_.is_null())
+ return false;
+
+ const GURL urls_to_test_[] =
+ {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")};
+ for (GURL url : urls_to_test_) {
+ if (filter.Run(url) != to_match_.Run(url)) {
+ if (listener)
+ *listener << "The filters differ on the URL " << url;
+ return false;
+ }
+ }
+ return true;
+ }
+
+ virtual void DescribeTo(::std::ostream* os) const {
+ *os << "is probably the same url filter as " << &to_match_;
+ }
+
+ virtual void DescribeNegationTo(::std::ostream* os) const {
+ *os << "is definitely NOT the same url filter as " << &to_match_;
+ }
+
+ private:
+ const base::Callback<bool(const GURL&)>& to_match_;
+};
+
+inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter(
+ const base::Callback<bool(const GURL&)>& filter) {
+ return MakeMatcher(new ProbablySameFilterMatcher(filter));
+}
+
+bool ProbablySameFilters(
+ const base::Callback<bool(const GURL&)>& filter1,
+ const base::Callback<bool(const GURL&)>& filter2) {
+ return ProbablySameFilter(filter1).MatchAndExplain(filter2, nullptr);
+}
+
+base::Time AnHourAgo() {
+ return base::Time::Now() - base::TimeDelta::FromHours(1);
+}
+
+class RemoveDownloadsTester {
+ public:
+ explicit RemoveDownloadsTester(TestingProfile* testing_profile)
+ : download_manager_(new content::MockDownloadManager()),
+ chrome_download_manager_delegate_(testing_profile) {
+ content::BrowserContext::SetDownloadManagerForTesting(testing_profile,
+ download_manager_);
+ EXPECT_EQ(download_manager_,
+ content::BrowserContext::GetDownloadManager(testing_profile));
+
+ EXPECT_CALL(*download_manager_, GetDelegate())
+ .WillOnce(Return(&chrome_download_manager_delegate_));
+ EXPECT_CALL(*download_manager_, Shutdown());
+ }
+
+ ~RemoveDownloadsTester() { chrome_download_manager_delegate_.Shutdown(); }
+
+ content::MockDownloadManager* download_manager() { return download_manager_; }
-class BrowsingDataRemoverTest : public testing::Test {
+ private:
+ content::MockDownloadManager* download_manager_;
+ ChromeDownloadManagerDelegate chrome_download_manager_delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester);
+};
+
+} // namespace
+
+// RemoveAutofillTester is not a part of the anonymous namespace above, as
+// PersonalDataManager declares it a friend in an empty namespace.
+class RemoveAutofillTester : public autofill::PersonalDataManagerObserver {
public:
- BrowsingDataRemoverTest()
+ explicit RemoveAutofillTester(TestingProfile* profile)
+ : personal_data_manager_(
+ autofill::PersonalDataManagerFactory::GetForProfile(profile)) {
+ autofill::test::DisableSystemServices(profile->GetPrefs());
+ personal_data_manager_->AddObserver(this);
+ }
+
+ ~RemoveAutofillTester() override {
+ personal_data_manager_->RemoveObserver(this);
+ autofill::test::ReenableSystemServices();
+ }
+
+ // Returns true if there are autofill profiles.
+ bool HasProfile() {
+ return !personal_data_manager_->GetProfiles().empty() &&
+ !personal_data_manager_->GetCreditCards().empty();
+ }
+
+ bool HasOrigin(const std::string& origin) {
+ const std::vector<autofill::AutofillProfile*>& profiles =
+ personal_data_manager_->GetProfiles();
+ for (const autofill::AutofillProfile* profile : profiles) {
+ if (profile->origin() == origin)
+ return true;
+ }
+
+ const std::vector<autofill::CreditCard*>& credit_cards =
+ personal_data_manager_->GetCreditCards();
+ for (const autofill::CreditCard* credit_card : credit_cards) {
+ if (credit_card->origin() == origin)
+ return true;
+ }
+
+ return false;
+ }
+
+ // Add two profiles and two credit cards to the database. In each pair, one
+ // entry has a web origin and the other has a Chrome origin.
+ void AddProfilesAndCards() {
+ std::vector<autofill::AutofillProfile> profiles;
+ autofill::AutofillProfile profile;
+ profile.set_guid(base::GenerateGUID());
+ profile.set_origin(kWebOrigin);
+ profile.SetRawInfo(autofill::NAME_FIRST, base::ASCIIToUTF16("Bob"));
+ profile.SetRawInfo(autofill::NAME_LAST, base::ASCIIToUTF16("Smith"));
+ profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, base::ASCIIToUTF16("94043"));
+ profile.SetRawInfo(autofill::EMAIL_ADDRESS,
+ base::ASCIIToUTF16("sue@example.com"));
+ profile.SetRawInfo(autofill::COMPANY_NAME, base::ASCIIToUTF16("Company X"));
+ profiles.push_back(profile);
+
+ profile.set_guid(base::GenerateGUID());
+ profile.set_origin(autofill::kSettingsOrigin);
+ profiles.push_back(profile);
+
+ personal_data_manager_->SetProfiles(&profiles);
+ base::RunLoop().Run();
+
+ std::vector<autofill::CreditCard> cards;
+ autofill::CreditCard card;
+ card.set_guid(base::GenerateGUID());
+ card.set_origin(kWebOrigin);
+ card.SetRawInfo(autofill::CREDIT_CARD_NUMBER,
+ base::ASCIIToUTF16("1234-5678-9012-3456"));
+ cards.push_back(card);
+
+ card.set_guid(base::GenerateGUID());
+ card.set_origin(autofill::kSettingsOrigin);
+ cards.push_back(card);
+
+ personal_data_manager_->SetCreditCards(&cards);
+ base::RunLoop().Run();
+ }
+
+ private:
+ void OnPersonalDataChanged() override {
+ base::MessageLoop::current()->QuitWhenIdle();
+ }
+
+ autofill::PersonalDataManager* personal_data_manager_;
+ DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
+};
+
+// Test Class -----------------------------------------------------------------
+
+class ChromeBrowsingDataRemoverDelegateTest : public testing::Test {
+ public:
+ ChromeBrowsingDataRemoverDelegateTest()
: profile_(new TestingProfile()),
- clear_domain_reliability_tester_(GetProfile()) {
- remover_ = static_cast<BrowsingDataRemoverImpl*>(
- BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()));
+ clear_domain_reliability_tester_(profile_.get()) {
+ remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get());
#if defined(OS_ANDROID)
static_cast<ChromeBrowsingDataRemoverDelegate*>(
@@ -1158,13 +830,7 @@ class BrowsingDataRemoverTest : public testing::Test {
#endif
}
- ~BrowsingDataRemoverTest() override {}
-
void TearDown() override {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- mock_policy_ = nullptr;
-#endif
-
// TestingProfile contains a DOMStorageContext. BrowserContext's destructor
// posts a message to the WEBKIT thread to delete some of its member
// variables. We need to ensure that the profile is destroyed, and that
@@ -1176,13 +842,12 @@ class BrowsingDataRemoverTest : public testing::Test {
TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
}
+ ~ChromeBrowsingDataRemoverDelegateTest() override {}
+
void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin,
const base::Time& delete_end,
int remove_mask,
bool include_protected_origins) {
- TestStoragePartition storage_partition;
- remover_->OverrideStoragePartitionForTesting(&storage_partition);
-
int origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB;
if (include_protected_origins)
origin_type_mask |= BrowsingDataHelper::PROTECTED_WEB;
@@ -1192,10 +857,6 @@ class BrowsingDataRemoverTest : public testing::Test {
delete_begin, delete_end, remove_mask, origin_type_mask,
&completion_observer);
completion_observer.BlockUntilCompletion();
-
- // Save so we can verify later.
- storage_partition_removal_data_ =
- storage_partition.GetStoragePartitionRemovalData();
}
void BlockUntilOriginDataRemoved(
@@ -1203,26 +864,18 @@ class BrowsingDataRemoverTest : public testing::Test {
const base::Time& delete_end,
int remove_mask,
const BrowsingDataFilterBuilder& filter_builder) {
- TestStoragePartition storage_partition;
- remover_->OverrideStoragePartitionForTesting(&storage_partition);
-
BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
- remover_->RemoveImpl(delete_begin, delete_end, remove_mask, filter_builder,
- BrowsingDataHelper::UNPROTECTED_WEB);
+
+ // TODO(crbug.com/668114): ChromeBrowsingDataRemoverTest should not know
+ // about BrowsingDataRemoverImpl. We will be able to remove this cast once
+ // BrowsingDataFilterBuilder is copyable and comparable.
+ static_cast<BrowsingDataRemoverImpl*>(remover_)
+ ->RemoveImpl(delete_begin, delete_end, remove_mask, filter_builder,
+ BrowsingDataHelper::UNPROTECTED_WEB);
completion_inhibitor.BlockUntilNearCompletion();
completion_inhibitor.ContinueToCompletion();
-
- // Save so we can verify later.
- storage_partition_removal_data_ =
- storage_partition.GetStoragePartitionRemovalData();
- }
-
- TestingProfile* GetProfile() {
- return profile_.get();
}
- void DestroyProfile() { profile_.reset(); }
-
const base::Time& GetBeginTime() {
return remover_->GetLastUsedBeginTime();
}
@@ -1235,36 +888,8 @@ class BrowsingDataRemoverTest : public testing::Test {
return remover_->GetLastUsedOriginTypeMask();
}
- StoragePartitionRemovalData GetStoragePartitionRemovalData() {
- return storage_partition_removal_data_;
- }
-
- MockExtensionSpecialStoragePolicy* CreateMockPolicy() {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- mock_policy_ = new MockExtensionSpecialStoragePolicy;
- return mock_policy_.get();
-#else
- NOTREACHED();
- return nullptr;
-#endif
- }
-
- storage::SpecialStoragePolicy* mock_policy() {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- return mock_policy_.get();
-#else
- return nullptr;
-#endif
- }
-
- // If |kOrigin1| is protected when extensions are enabled, the expected
- // result for tests where the OriginMatcherFunction result is variable.
- bool ShouldRemoveForProtectedOriginOne() const {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- return false;
-#else
- return true;
-#endif
+ TestingProfile* GetProfile() {
+ return profile_.get();
}
const ClearDomainReliabilityTester& clear_domain_reliability_tester() {
@@ -1273,94 +898,18 @@ class BrowsingDataRemoverTest : public testing::Test {
private:
// Cached pointer to BrowsingDataRemoverImpl for access to testing methods.
- BrowsingDataRemoverImpl* remover_;
+ BrowsingDataRemover* remover_;
content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<TestingProfile> profile_;
- StoragePartitionRemovalData storage_partition_removal_data_;
-
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_;
-#endif
-
// Needed to mock out DomainReliabilityService, even for unrelated tests.
ClearDomainReliabilityTester clear_domain_reliability_tester_;
- DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest);
+ DISALLOW_COPY_AND_ASSIGN(ChromeBrowsingDataRemoverDelegateTest);
};
-// Tests ---------------------------------------------------------------------
-
-TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) {
- BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_COOKIES, false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify that storage partition was instructed to remove the cookies.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_COOKIES);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
- EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveCookieLastHour) {
- BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_COOKIES, false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify that storage partition was instructed to remove the cookies.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_COOKIES);
- // Removing with time period other than all time should not clear
- // persistent storage data.
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
- EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveCookiesDomainBlacklist) {
- RegistrableDomainFilterBuilder filter(
- RegistrableDomainFilterBuilder::BLACKLIST);
- filter.AddRegisterableDomain(kTestRegisterableDomain1);
- filter.AddRegisterableDomain(kTestRegisterableDomain3);
- BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_COOKIES, filter);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify that storage partition was instructed to remove the cookies.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_COOKIES);
- // Removing with time period other than all time should not clear
- // persistent storage data.
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
- EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
- // Even though it's a different origin, it's the same domain.
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin4, mock_policy()));
-
- EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin1)));
- EXPECT_TRUE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin2)));
- EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin3)));
- // This is false, because this is the same domain as 3, just with a different
- // scheme.
- EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin4)));
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveSafeBrowsingCookieForever) {
RemoveSafeBrowsingCookieTester tester;
tester.AddCookie();
@@ -1374,7 +923,8 @@ TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) {
EXPECT_FALSE(tester.ContainsCookie());
}
-TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ RemoveSafeBrowsingCookieLastHour) {
RemoveSafeBrowsingCookieTester tester;
tester.AddCookie();
@@ -1390,7 +940,8 @@ TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) {
EXPECT_TRUE(tester.ContainsCookie());
}
-TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForeverWithPredicate) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ RemoveSafeBrowsingCookieForeverWithPredicate) {
RemoveSafeBrowsingCookieTester tester;
tester.AddCookie();
@@ -1413,156 +964,7 @@ TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForeverWithPredicate) {
EXPECT_FALSE(tester.ContainsCookie());
}
-TEST_F(BrowsingDataRemoverTest, RemoveChannelIDForever) {
- RemoveChannelIDTester tester(GetProfile());
-
- tester.AddChannelID(kTestOrigin1);
- EXPECT_EQ(0, tester.ssl_config_changed_count());
- EXPECT_EQ(1, tester.ChannelIDCount());
-
- BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
- EXPECT_EQ(1, tester.ssl_config_changed_count());
- EXPECT_EQ(0, tester.ChannelIDCount());
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveChannelIDLastHour) {
- RemoveChannelIDTester tester(GetProfile());
-
- base::Time now = base::Time::Now();
- tester.AddChannelID(kTestOrigin1);
- tester.AddChannelIDWithTimes(kTestOrigin2,
- now - base::TimeDelta::FromHours(2));
- EXPECT_EQ(0, tester.ssl_config_changed_count());
- EXPECT_EQ(2, tester.ChannelIDCount());
-
- BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
- EXPECT_EQ(1, tester.ssl_config_changed_count());
- ASSERT_EQ(1, tester.ChannelIDCount());
- net::ChannelIDStore::ChannelIDList channel_ids;
- tester.GetChannelIDList(&channel_ids);
- ASSERT_EQ(1U, channel_ids.size());
- EXPECT_EQ(kTestOrigin2, channel_ids.front().server_identifier());
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveChannelIDsForServerIdentifiers) {
- RemoveChannelIDTester tester(GetProfile());
-
- tester.AddChannelID(kTestRegisterableDomain1);
- tester.AddChannelID(kTestRegisterableDomain3);
- EXPECT_EQ(2, tester.ChannelIDCount());
-
- RegistrableDomainFilterBuilder filter_builder(
- RegistrableDomainFilterBuilder::WHITELIST);
- filter_builder.AddRegisterableDomain(kTestRegisterableDomain1);
-
- BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_CHANNEL_IDS,
- filter_builder);
-
- EXPECT_EQ(1, tester.ChannelIDCount());
- net::ChannelIDStore::ChannelIDList channel_ids;
- tester.GetChannelIDList(&channel_ids);
- EXPECT_EQ(kTestRegisterableDomain3, channel_ids.front().server_identifier());
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
- // Protect kOrigin1.
- policy->AddProtected(kOrigin1.GetOrigin());
-#endif
-
- BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
- false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify that storage partition was instructed to remove the data correctly.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
- EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
-
- // Check origin matcher.
- EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
- removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveProtectedLocalStorageForever) {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- // Protect kOrigin1.
- MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
- policy->AddProtected(kOrigin1.GetOrigin());
-#endif
-
- BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
- true);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB |
- BrowsingDataHelper::PROTECTED_WEB, GetOriginTypeMask());
-
- // Verify that storage partition was instructed to remove the data correctly.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
- EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
-
- // Check origin matcher all http origin will match since we specified
- // both protected and unprotected.
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveLocalStorageForLastWeek) {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- CreateMockPolicy();
-#endif
-
- BlockUntilBrowsingDataRemoved(
- base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(),
- BrowsingDataRemover::REMOVE_LOCAL_STORAGE, false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify that storage partition was instructed to remove the data correctly.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
- // Persistent storage won't be deleted.
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
- EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
-
- // Check origin matcher.
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveHistoryForever) {
RemoveHistoryTester tester;
ASSERT_TRUE(tester.Init(GetProfile()));
@@ -1577,7 +979,7 @@ TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
}
-TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveHistoryForLastHour) {
RemoveHistoryTester tester;
ASSERT_TRUE(tester.Init(GetProfile()));
@@ -1600,7 +1002,7 @@ TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) {
// This should crash (DCHECK) in Debug, but death tests don't work properly
// here.
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
-TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveHistoryProhibited) {
RemoveHistoryTester tester;
ASSERT_TRUE(tester.Init(GetProfile()));
PrefService* prefs = GetProfile()->GetPrefs();
@@ -1613,47 +1015,18 @@ TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) {
ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
- BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_HISTORY, false);
- EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Nothing should have been deleted.
- EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
- EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
-}
-#endif
-
-TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) {
- // Add some history.
- RemoveHistoryTester history_tester;
- ASSERT_TRUE(history_tester.Init(GetProfile()));
- history_tester.AddHistory(kOrigin1, base::Time::Now());
- ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
-
- int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
- BrowsingDataRemover::REMOVE_COOKIES;
-
- BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
- removal_mask, false);
-
- EXPECT_EQ(removal_mask, GetRemovalMask());
+ BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
+ BrowsingDataRemover::REMOVE_HISTORY, false);
+ EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
- EXPECT_FALSE(history_tester.HistoryContainsURL(kOrigin1));
- // The cookie would be deleted throught the StorageParition, check if the
- // partition was requested to remove cookie.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_COOKIES);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
+ // Nothing should have been deleted.
+ EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
+ EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
}
-// This should crash (DCHECK) in Debug, but death tests don't work properly
-// here.
-#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
-TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ RemoveMultipleTypesHistoryProhibited) {
PrefService* prefs = GetProfile()->GetPrefs();
prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
@@ -1686,7 +1059,7 @@ TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) {
#endif
// Test that clearing history deletes favicons not associated with bookmarks.
-TEST_F(BrowsingDataRemoverTest, RemoveFaviconsForever) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveFaviconsForever) {
GURL page_url("http://a");
RemoveFaviconTester favicon_tester;
@@ -1705,7 +1078,7 @@ TEST_F(BrowsingDataRemoverTest, RemoveFaviconsForever) {
// when the user next visits the bookmarked page. Expiring the bookmark's
// favicon is useful when the bookmark's favicon becomes incorrect (See
// crbug.com/474421 for a sample bug which causes this).
-TEST_F(BrowsingDataRemoverTest, ExpireBookmarkFavicons) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, ExpireBookmarkFavicons) {
GURL bookmarked_page("http://a");
TestingProfile* profile = GetProfile();
@@ -1727,482 +1100,7 @@ TEST_F(BrowsingDataRemoverTest, ExpireBookmarkFavicons) {
EXPECT_TRUE(favicon_tester.HasExpiredFaviconForPageURL(bookmarked_page));
}
-TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
- BlockUntilBrowsingDataRemoved(
- base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify storage partition related stuffs.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
- StoragePartition::REMOVE_DATA_MASK_WEBSQL |
- StoragePartition::REMOVE_DATA_MASK_APPCACHE |
- StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
- StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
- StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- CreateMockPolicy();
-#endif
-
- BlockUntilBrowsingDataRemoved(
- base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify storage partition related stuffs.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
-
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
- StoragePartition::REMOVE_DATA_MASK_WEBSQL |
- StoragePartition::REMOVE_DATA_MASK_APPCACHE |
- StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
- StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
- StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
-
- // Check that all related origin data would be removed, that is, origin
- // matcher would match these origin.
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- CreateMockPolicy();
-#endif
-
- BlockUntilBrowsingDataRemoved(
- base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify storage partition related stuffs.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
-
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
- StoragePartition::REMOVE_DATA_MASK_WEBSQL |
- StoragePartition::REMOVE_DATA_MASK_APPCACHE |
- StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
- StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
- StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
-
- // Check that all related origin data would be removed, that is, origin
- // matcher would match these origin.
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- CreateMockPolicy();
-#endif
-
- BlockUntilBrowsingDataRemoved(
- base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify storage partition related stuffs.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
-
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
- StoragePartition::REMOVE_DATA_MASK_WEBSQL |
- StoragePartition::REMOVE_DATA_MASK_APPCACHE |
- StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
- StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
- StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
-
- // Check that all related origin data would be removed, that is, origin
- // matcher would match these origin.
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
- RegistrableDomainFilterBuilder builder(
- RegistrableDomainFilterBuilder::WHITELIST);
- builder.AddRegisterableDomain(kTestRegisterableDomain1);
- // Remove Origin 1.
- BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_INDEXEDDB |
- BrowsingDataRemover::REMOVE_WEBSQL,
- builder);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_INDEXEDDB |
- BrowsingDataRemover::REMOVE_WEBSQL,
- GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify storage partition related stuffs.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
-
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
- StoragePartition::REMOVE_DATA_MASK_WEBSQL |
- StoragePartition::REMOVE_DATA_MASK_APPCACHE |
- StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
- StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
- StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin4, mock_policy()));
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
- BlockUntilBrowsingDataRemoved(
- AnHourAgo(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify storage partition related stuffs.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
-
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
- StoragePartition::REMOVE_DATA_MASK_WEBSQL |
- StoragePartition::REMOVE_DATA_MASK_APPCACHE |
- StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
- StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
- StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
-
- // Persistent data would be left out since we are not removing from
- // beginning of time.
- uint32_t expected_quota_mask =
- ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
- EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
- // Check removal begin time.
- EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) {
- BlockUntilBrowsingDataRemoved(
- base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(),
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify storage partition related stuffs.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
-
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
- StoragePartition::REMOVE_DATA_MASK_WEBSQL |
- StoragePartition::REMOVE_DATA_MASK_APPCACHE |
- StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
- StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
- StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
-
- // Persistent data would be left out since we are not removing from
- // beginning of time.
- uint32_t expected_quota_mask =
- ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
- EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
- // Check removal begin time.
- EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
- // Protect kOrigin1.
- policy->AddProtected(kOrigin1.GetOrigin());
-#endif
-
- BlockUntilBrowsingDataRemoved(
- base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_WEBSQL |
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_INDEXEDDB,
- GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify storage partition related stuffs.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
-
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
- StoragePartition::REMOVE_DATA_MASK_WEBSQL |
- StoragePartition::REMOVE_DATA_MASK_APPCACHE |
- StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
- StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
- StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
-
- // Check OriginMatcherFunction.
- EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
- removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedSpecificOrigin) {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
- // Protect kOrigin1.
- policy->AddProtected(kOrigin1.GetOrigin());
-#endif
-
- RegistrableDomainFilterBuilder builder(
- RegistrableDomainFilterBuilder::WHITELIST);
- builder.AddRegisterableDomain(kTestRegisterableDomain1);
-
- // Try to remove kOrigin1. Expect failure.
- BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_INDEXEDDB |
- BrowsingDataRemover::REMOVE_WEBSQL,
- builder);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_INDEXEDDB |
- BrowsingDataRemover::REMOVE_WEBSQL,
- GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify storage partition related stuffs.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
-
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
- StoragePartition::REMOVE_DATA_MASK_WEBSQL |
- StoragePartition::REMOVE_DATA_MASK_APPCACHE |
- StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
- StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
- StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
-
- // Check OriginMatcherFunction.
- EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
- removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
- // Since we use the matcher function to validate origins now, this should
- // return false for the origins we're not trying to clear.
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedOrigins) {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
- // Protect kOrigin1.
- policy->AddProtected(kOrigin1.GetOrigin());
-#endif
-
- // Try to remove kOrigin1. Expect success.
- BlockUntilBrowsingDataRemoved(
- base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_INDEXEDDB |
- BrowsingDataRemover::REMOVE_WEBSQL,
- true);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_INDEXEDDB |
- BrowsingDataRemover::REMOVE_WEBSQL,
- GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::PROTECTED_WEB |
- BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify storage partition related stuffs.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
-
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
- StoragePartition::REMOVE_DATA_MASK_WEBSQL |
- StoragePartition::REMOVE_DATA_MASK_APPCACHE |
- StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
- StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
- StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
-
- // Check OriginMatcherFunction, |kOrigin1| would match mask since we
- // would have 'protected' specified in origin_type_mask.
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
- EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
-}
-
-TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedIgnoreExtensionsAndDevTools) {
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- CreateMockPolicy();
-#endif
-
- BlockUntilBrowsingDataRemoved(
- base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_INDEXEDDB |
- BrowsingDataRemover::REMOVE_WEBSQL,
- false);
-
- EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
- BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
- BrowsingDataRemover::REMOVE_CACHE_STORAGE |
- BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
- BrowsingDataRemover::REMOVE_INDEXEDDB |
- BrowsingDataRemover::REMOVE_WEBSQL,
- GetRemovalMask());
- EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
-
- // Verify storage partition related stuffs.
- StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
-
- EXPECT_EQ(removal_data.remove_mask,
- StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
- StoragePartition::REMOVE_DATA_MASK_WEBSQL |
- StoragePartition::REMOVE_DATA_MASK_APPCACHE |
- StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
- StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
- StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
- EXPECT_EQ(removal_data.quota_storage_remove_mask,
- StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
-
- // Check that extension and devtools data wouldn't be removed, that is,
- // origin matcher would not match these origin.
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
- EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy()));
-}
-
-TEST_F(BrowsingDataRemoverTest, TimeBasedHistoryRemoval) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, TimeBasedHistoryRemoval) {
RemoveHistoryTester tester;
ASSERT_TRUE(tester.Init(GetProfile()));
@@ -2225,7 +1123,7 @@ TEST_F(BrowsingDataRemoverTest, TimeBasedHistoryRemoval) {
}
// Verify that clearing autofill form data works.
-TEST_F(BrowsingDataRemoverTest, AutofillRemovalLastHour) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, AutofillRemovalLastHour) {
GetProfile()->CreateWebDataService();
RemoveAutofillTester tester(GetProfile());
@@ -2241,7 +1139,7 @@ TEST_F(BrowsingDataRemoverTest, AutofillRemovalLastHour) {
ASSERT_FALSE(tester.HasProfile());
}
-TEST_F(BrowsingDataRemoverTest, AutofillRemovalEverything) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, AutofillRemovalEverything) {
GetProfile()->CreateWebDataService();
RemoveAutofillTester tester(GetProfile());
@@ -2258,7 +1156,8 @@ TEST_F(BrowsingDataRemoverTest, AutofillRemovalEverything) {
}
// Verify that clearing autofill form data works.
-TEST_F(BrowsingDataRemoverTest, AutofillOriginsRemovedWithHistory) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ AutofillOriginsRemovedWithHistory) {
GetProfile()->CreateWebDataService();
RemoveAutofillTester tester(GetProfile());
@@ -2277,86 +1176,7 @@ TEST_F(BrowsingDataRemoverTest, AutofillOriginsRemovedWithHistory) {
EXPECT_TRUE(tester.HasOrigin(autofill::kSettingsOrigin));
}
-class InspectableCompletionObserver
- : public BrowsingDataRemoverCompletionObserver {
- public:
- explicit InspectableCompletionObserver(BrowsingDataRemover* remover)
- : BrowsingDataRemoverCompletionObserver(remover) {}
- ~InspectableCompletionObserver() override {}
-
- bool called() { return called_; }
-
- protected:
- void OnBrowsingDataRemoverDone() override {
- BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone();
- called_ = true;
- }
-
- private:
- bool called_ = false;
-};
-
-TEST_F(BrowsingDataRemoverTest, CompletionInhibition) {
- // The |completion_inhibitor| on the stack should prevent removal sessions
- // from completing until after ContinueToCompletion() is called.
- BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
-
- BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
- BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()));
- InspectableCompletionObserver completion_observer(remover);
- remover->RemoveAndReply(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_HISTORY,
- BrowsingDataHelper::UNPROTECTED_WEB,
- &completion_observer);
-
- // Process messages until the inhibitor is notified, and then some, to make
- // sure we do not complete asynchronously before ContinueToCompletion() is
- // called.
- completion_inhibitor.BlockUntilNearCompletion();
- base::RunLoop().RunUntilIdle();
-
- // Verify that the removal has not yet been completed and the observer has
- // not been called.
- EXPECT_TRUE(remover->is_removing());
- EXPECT_FALSE(completion_observer.called());
-
- // Now run the removal process until completion, and verify that observers are
- // now notified, and the notifications is sent out.
- completion_inhibitor.ContinueToCompletion();
- completion_observer.BlockUntilCompletion();
-
- EXPECT_FALSE(remover->is_removing());
- EXPECT_TRUE(completion_observer.called());
-}
-
-TEST_F(BrowsingDataRemoverTest, EarlyShutdown) {
- BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
- BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()));
- InspectableCompletionObserver completion_observer(remover);
- BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
- remover->RemoveAndReply(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_HISTORY,
- BrowsingDataHelper::UNPROTECTED_WEB,
- &completion_observer);
-
- completion_inhibitor.BlockUntilNearCompletion();
-
- // Verify that the deletion has not yet been completed and the observer has
- // not been called.
- EXPECT_TRUE(remover->is_removing());
- EXPECT_FALSE(completion_observer.called());
-
- // Destroying the profile should trigger the notification.
- DestroyProfile();
-
- EXPECT_TRUE(completion_observer.called());
-
- // Finishing after shutdown shouldn't break anything.
- completion_inhibitor.ContinueToCompletion();
- completion_observer.BlockUntilCompletion();
-}
-
-TEST_F(BrowsingDataRemoverTest, ZeroSuggestCacheClear) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, ZeroSuggestCacheClear) {
PrefService* prefs = GetProfile()->GetPrefs();
prefs->SetString(omnibox::kZeroSuggestCachedResults,
"[\"\", [\"foo\", \"bar\"]]");
@@ -2370,7 +1190,8 @@ TEST_F(BrowsingDataRemoverTest, ZeroSuggestCacheClear) {
}
#if defined(OS_CHROMEOS)
-TEST_F(BrowsingDataRemoverTest, ContentProtectionPlatformKeysRemoval) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ ContentProtectionPlatformKeysRemoval) {
chromeos::ScopedTestDeviceSettingsService test_device_settings_service;
chromeos::ScopedTestCrosSettings test_cros_settings;
chromeos::MockUserManager* mock_user_manager =
@@ -2399,14 +1220,14 @@ TEST_F(BrowsingDataRemoverTest, ContentProtectionPlatformKeysRemoval) {
}
#endif
-TEST_F(BrowsingDataRemoverTest, DomainReliability_Null) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Null) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
EXPECT_EQ(0u, tester.clear_count());
}
-TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Beacons) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
@@ -2418,7 +1239,8 @@ TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) {
BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter()));
}
-TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons_WithFilter) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ DomainReliability_Beacons_WithFilter) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
@@ -2434,7 +1256,7 @@ TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons_WithFilter) {
builder.BuildGeneralFilter(), tester.last_filter()));
}
-TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Contexts) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
@@ -2446,7 +1268,8 @@ TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) {
BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter()));
}
-TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts_WithFilter) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ DomainReliability_Contexts_WithFilter) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
@@ -2462,7 +1285,7 @@ TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts_WithFilter) {
builder.BuildGeneralFilter(), tester.last_filter()));
}
-TEST_F(BrowsingDataRemoverTest, DomainReliability_ContextsWin) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_ContextsWin) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
@@ -2474,7 +1297,8 @@ TEST_F(BrowsingDataRemoverTest, DomainReliability_ContextsWin) {
EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
}
-TEST_F(BrowsingDataRemoverTest, DomainReliability_ProtectedOrigins) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ DomainReliability_ProtectedOrigins) {
const ClearDomainReliabilityTester& tester =
clear_domain_reliability_tester();
@@ -2488,42 +1312,27 @@ TEST_F(BrowsingDataRemoverTest, DomainReliability_ProtectedOrigins) {
// BrowsingDataRemoverTest now creates one unconditionally, since it's needed
// for some unrelated test cases. This should be fixed so it tests the no-
// monitor case again.
-TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ DISABLED_DomainReliability_NoMonitor) {
BlockUntilBrowsingDataRemoved(
base::Time(), base::Time::Max(),
BrowsingDataRemover::REMOVE_HISTORY | BrowsingDataRemover::REMOVE_COOKIES,
false);
}
-TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByTimeOnly) {
+// Tests that the deletion of downloads completes successfully and that
+// ChromeDownloadManagerDelegate is correctly created and shut down.
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveDownloads) {
RemoveDownloadsTester tester(GetProfile());
- base::Callback<bool(const GURL&)> filter =
- BrowsingDataFilterBuilder::BuildNoopFilter();
EXPECT_CALL(
- *tester.download_manager(),
- RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _));
+ *tester.download_manager(), RemoveDownloadsByURLAndTime(_, _, _));
BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
BrowsingDataRemover::REMOVE_DOWNLOADS, false);
}
-TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByOrigin) {
- RemoveDownloadsTester tester(GetProfile());
- RegistrableDomainFilterBuilder builder(
- RegistrableDomainFilterBuilder::WHITELIST);
- builder.AddRegisterableDomain(kTestRegisterableDomain1);
- base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter();
-
- EXPECT_CALL(
- *tester.download_manager(),
- RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _));
-
- BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_DOWNLOADS, builder);
-}
-
-TEST_F(BrowsingDataRemoverTest, RemovePasswordStatistics) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordStatistics) {
RemovePasswordsTester tester(GetProfile());
base::Callback<bool(const GURL&)> empty_filter;
@@ -2534,7 +1343,8 @@ TEST_F(BrowsingDataRemoverTest, RemovePasswordStatistics) {
BrowsingDataRemover::REMOVE_HISTORY, false);
}
-TEST_F(BrowsingDataRemoverTest, RemovePasswordStatisticsByOrigin) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ RemovePasswordStatisticsByOrigin) {
RemovePasswordsTester tester(GetProfile());
RegistrableDomainFilterBuilder builder(
@@ -2549,7 +1359,7 @@ TEST_F(BrowsingDataRemoverTest, RemovePasswordStatisticsByOrigin) {
BrowsingDataRemover::REMOVE_HISTORY, builder);
}
-TEST_F(BrowsingDataRemoverTest, RemovePasswordsByTimeOnly) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordsByTimeOnly) {
RemovePasswordsTester tester(GetProfile());
base::Callback<bool(const GURL&)> filter =
BrowsingDataFilterBuilder::BuildNoopFilter();
@@ -2561,7 +1371,7 @@ TEST_F(BrowsingDataRemoverTest, RemovePasswordsByTimeOnly) {
BrowsingDataRemover::REMOVE_PASSWORDS, false);
}
-TEST_F(BrowsingDataRemoverTest, RemovePasswordsByOrigin) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordsByOrigin) {
RemovePasswordsTester tester(GetProfile());
RegistrableDomainFilterBuilder builder(
RegistrableDomainFilterBuilder::WHITELIST);
@@ -2575,7 +1385,7 @@ TEST_F(BrowsingDataRemoverTest, RemovePasswordsByOrigin) {
BrowsingDataRemover::REMOVE_PASSWORDS, builder);
}
-TEST_F(BrowsingDataRemoverTest, DisableAutoSignIn) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, DisableAutoSignIn) {
RemovePasswordsTester tester(GetProfile());
base::Callback<bool(const GURL&)> empty_filter =
BrowsingDataFilterBuilder::BuildNoopFilter();
@@ -2589,7 +1399,8 @@ TEST_F(BrowsingDataRemoverTest, DisableAutoSignIn) {
BrowsingDataRemover::REMOVE_COOKIES, false);
}
-TEST_F(BrowsingDataRemoverTest, DisableAutoSignInAfterRemovingPasswords) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ DisableAutoSignInAfterRemovingPasswords) {
RemovePasswordsTester tester(GetProfile());
base::Callback<bool(const GURL&)> empty_filter =
BrowsingDataFilterBuilder::BuildNoopFilter();
@@ -2607,7 +1418,8 @@ TEST_F(BrowsingDataRemoverTest, DisableAutoSignInAfterRemovingPasswords) {
false);
}
-TEST_F(BrowsingDataRemoverTest, RemoveContentSettingsWithBlacklist) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ RemoveContentSettingsWithBlacklist) {
// Add our settings.
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(GetProfile());
@@ -2652,7 +1464,7 @@ TEST_F(BrowsingDataRemoverTest, RemoveContentSettingsWithBlacklist) {
<< host_settings[2].primary_pattern.ToString();
}
-TEST_F(BrowsingDataRemoverTest, RemoveDurablePermission) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveDurablePermission) {
// Add our settings.
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(GetProfile());
@@ -2694,33 +1506,9 @@ TEST_F(BrowsingDataRemoverTest, RemoveDurablePermission) {
EXPECT_EQ(CONTENT_SETTING_ASK, host_settings[1].setting);
}
-// Test that removing cookies clears HTTP auth data.
-TEST_F(BrowsingDataRemoverTest, ClearHttpAuthCache_RemoveCookies) {
- net::HttpNetworkSession* http_session = GetProfile()
- ->GetRequestContext()
- ->GetURLRequestContext()
- ->http_transaction_factory()
- ->GetSession();
- DCHECK(http_session);
-
- net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache();
- http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC,
- "test challenge",
- net::AuthCredentials(base::ASCIIToUTF16("foo"),
- base::ASCIIToUTF16("bar")),
- "/");
- CHECK(http_auth_cache->Lookup(kOrigin1, kTestRealm,
- net::HttpAuth::AUTH_SCHEME_BASIC));
-
- BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_COOKIES, false);
-
- EXPECT_EQ(nullptr, http_auth_cache->Lookup(kOrigin1, kTestRealm,
- net::HttpAuth::AUTH_SCHEME_BASIC));
-}
-
// Test that removing passwords clears HTTP auth data.
-TEST_F(BrowsingDataRemoverTest, ClearHttpAuthCache_RemovePasswords) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ ClearHttpAuthCache_RemovePasswords) {
net::HttpNetworkSession* http_session = GetProfile()
->GetRequestContext()
->GetURLRequestContext()
@@ -2744,7 +1532,7 @@ TEST_F(BrowsingDataRemoverTest, ClearHttpAuthCache_RemovePasswords) {
net::HttpAuth::AUTH_SCHEME_BASIC));
}
-TEST_F(BrowsingDataRemoverTest, ClearPermissionPromptCounts) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, ClearPermissionPromptCounts) {
RemovePermissionPromptCountsTest tester(GetProfile());
RegistrableDomainFilterBuilder filter_builder_1(
@@ -2851,7 +1639,7 @@ TEST_F(BrowsingDataRemoverTest, ClearPermissionPromptCounts) {
}
#if BUILDFLAG(ENABLE_PLUGINS)
-TEST_F(BrowsingDataRemoverTest, RemovePluginData) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePluginData) {
RemovePluginDataTester tester(GetProfile());
tester.AddDomain(kOrigin1.host());
@@ -2879,203 +1667,10 @@ TEST_F(BrowsingDataRemoverTest, RemovePluginData) {
}
#endif
-class MultipleTasksObserver {
- public:
- // A simple implementation of BrowsingDataRemover::Observer.
- // MultipleTasksObserver will use several instances of Target to test
- // that completion callbacks are returned to the correct one.
- class Target : public BrowsingDataRemover::Observer {
- public:
- Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover)
- : parent_(parent),
- observer_(this) {
- observer_.Add(remover);
- }
- ~Target() override {}
-
- void OnBrowsingDataRemoverDone() override {
- parent_->SetLastCalledTarget(this);
- }
-
- private:
- MultipleTasksObserver* parent_;
- ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer>
- observer_;
- };
-
- explicit MultipleTasksObserver(BrowsingDataRemover* remover)
- : target_a_(this, remover),
- target_b_(this, remover),
- last_called_target_(nullptr) {}
- ~MultipleTasksObserver() {}
-
- void ClearLastCalledTarget() {
- last_called_target_ = nullptr;
- }
-
- Target* GetLastCalledTarget() {
- return last_called_target_;
- }
-
- Target* target_a() { return &target_a_; }
- Target* target_b() { return &target_b_; }
-
- private:
- void SetLastCalledTarget(Target* target) {
- DCHECK(!last_called_target_)
- << "Call ClearLastCalledTarget() before every removal task.";
- last_called_target_ = target;
- }
-
- Target target_a_;
- Target target_b_;
- Target* last_called_target_;
-};
-
-TEST_F(BrowsingDataRemoverTest, MultipleTasks) {
- BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
- BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()));
- EXPECT_FALSE(remover->is_removing());
-
- std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_1(
- new RegistrableDomainFilterBuilder(
- RegistrableDomainFilterBuilder::WHITELIST));
- std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_2(
- new RegistrableDomainFilterBuilder(
- RegistrableDomainFilterBuilder::BLACKLIST));
- filter_builder_2->AddRegisterableDomain("example.com");
-
- MultipleTasksObserver observer(remover);
- BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
-
- // Test several tasks with various configuration of masks, filters, and target
- // observers.
- std::list<BrowsingDataRemoverImpl::RemovalTask> tasks;
- tasks.emplace_back(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_HISTORY,
- BrowsingDataHelper::UNPROTECTED_WEB,
- base::MakeUnique<RegistrableDomainFilterBuilder>(
- RegistrableDomainFilterBuilder::BLACKLIST),
- observer.target_a());
- tasks.emplace_back(base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_COOKIES,
- BrowsingDataHelper::PROTECTED_WEB,
- base::MakeUnique<RegistrableDomainFilterBuilder>(
- RegistrableDomainFilterBuilder::BLACKLIST),
- nullptr);
- tasks.emplace_back(
- base::Time::Now(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_PASSWORDS, BrowsingDataHelper::ALL,
- base::MakeUnique<RegistrableDomainFilterBuilder>(
- RegistrableDomainFilterBuilder::BLACKLIST),
- observer.target_b());
- tasks.emplace_back(
- base::Time(), base::Time::UnixEpoch(),
- BrowsingDataRemover::REMOVE_WEBSQL,
- BrowsingDataHelper::UNPROTECTED_WEB,
- std::move(filter_builder_1),
- observer.target_b());
- tasks.emplace_back(
- base::Time::UnixEpoch(), base::Time::Now(),
- BrowsingDataRemover::REMOVE_CHANNEL_IDS,
- BrowsingDataHelper::ALL,
- std::move(filter_builder_2),
- nullptr);
-
- for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) {
- // All tasks can be directly translated to a RemoveInternal() call. Since
- // that is a private method, we must call the four public versions of
- // Remove.* instead. This also serves as a test that those methods are all
- // correctly reduced to RemoveInternal().
- if (!task.observer && task.filter_builder->IsEmptyBlacklist()) {
- remover->Remove(task.delete_begin, task.delete_end,
- task.remove_mask, task.origin_type_mask);
- } else if (task.filter_builder->IsEmptyBlacklist()) {
- remover->RemoveAndReply(task.delete_begin, task.delete_end,
- task.remove_mask, task.origin_type_mask,
- task.observer);
- } else if (!task.observer) {
- remover->RemoveWithFilter(task.delete_begin, task.delete_end,
- task.remove_mask, task.origin_type_mask,
- std::move(task.filter_builder));
- } else {
- remover->RemoveWithFilterAndReply(task.delete_begin, task.delete_end,
- task.remove_mask, task.origin_type_mask,
- std::move(task.filter_builder),
- task.observer);
- }
- }
-
- // Use the inhibitor to stop after every task and check the results.
- for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) {
- EXPECT_TRUE(remover->is_removing());
- observer.ClearLastCalledTarget();
-
- // Finish the task execution synchronously.
- completion_inhibitor.BlockUntilNearCompletion();
- completion_inhibitor.ContinueToCompletion();
-
- // Observers, if any, should have been called by now (since we call
- // observers on the same thread).
- EXPECT_EQ(task.observer, observer.GetLastCalledTarget());
-
- // TODO(msramek): If BrowsingDataRemover took ownership of the last used
- // filter builder and exposed it, we could also test it here. Make it so.
- EXPECT_EQ(task.remove_mask, GetRemovalMask());
- EXPECT_EQ(task.origin_type_mask, GetOriginTypeMask());
- EXPECT_EQ(task.delete_begin, GetBeginTime());
- }
-
- EXPECT_FALSE(remover->is_removing());
-}
-
-// The previous test, BrowsingDataRemoverTest.MultipleTasks, tests that the
-// tasks are not mixed up and they are executed in a correct order. However,
-// the completion inhibitor kept synchronizing the execution in order to verify
-// the parameters. This test demonstrates that even running the tasks without
-// inhibition is executed correctly and doesn't crash.
-TEST_F(BrowsingDataRemoverTest, MultipleTasksInQuickSuccession) {
- BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
- BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()));
- EXPECT_FALSE(remover->is_removing());
-
- int test_removal_masks[] = {
- BrowsingDataRemover::REMOVE_COOKIES,
- BrowsingDataRemover::REMOVE_PASSWORDS,
- BrowsingDataRemover::REMOVE_COOKIES,
- BrowsingDataRemover::REMOVE_COOKIES,
- BrowsingDataRemover::REMOVE_COOKIES,
- BrowsingDataRemover::REMOVE_HISTORY,
- BrowsingDataRemover::REMOVE_HISTORY,
- BrowsingDataRemover::REMOVE_HISTORY,
- BrowsingDataRemover::REMOVE_COOKIES | BrowsingDataRemover::REMOVE_HISTORY,
- BrowsingDataRemover::REMOVE_COOKIES | BrowsingDataRemover::REMOVE_HISTORY,
- BrowsingDataRemover::REMOVE_COOKIES |
- BrowsingDataRemover::REMOVE_HISTORY |
- BrowsingDataRemover::REMOVE_PASSWORDS,
- BrowsingDataRemover::REMOVE_PASSWORDS,
- BrowsingDataRemover::REMOVE_PASSWORDS,
- };
-
- for (int removal_mask : test_removal_masks) {
- remover->Remove(base::Time(), base::Time::Max(), removal_mask,
- BrowsingDataHelper::UNPROTECTED_WEB);
- }
-
- EXPECT_TRUE(remover->is_removing());
-
- // Add one more deletion and wait for it.
- BlockUntilBrowsingDataRemoved(
- base::Time(), base::Time::Max(),
- BrowsingDataRemover::REMOVE_COOKIES,
- BrowsingDataHelper::UNPROTECTED_WEB);
-
- EXPECT_FALSE(remover->is_removing());
-}
-
// Test that the remover clears bookmark meta data (normally added in a tab
// helper).
-TEST_F(BrowsingDataRemoverTest, BookmarkLastVisitDatesGetCleared) {
+TEST_F(ChromeBrowsingDataRemoverDelegateTest,
+ BookmarkLastVisitDatesGetCleared) {
TestingProfile profile;
profile.CreateBookmarkModel(true);
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover_unittest.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698