| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stddef.h> | |
| 6 #include <stdint.h> | |
| 7 | |
| 8 #include <list> | |
| 9 #include <memory> | |
| 10 #include <set> | |
| 11 #include <string> | |
| 12 #include <utility> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/bind.h" | |
| 16 #include "base/bind_helpers.h" | |
| 17 #include "base/files/file_path.h" | |
| 18 #include "base/files/file_util.h" | |
| 19 #include "base/location.h" | |
| 20 #include "base/logging.h" | |
| 21 #include "base/macros.h" | |
| 22 #include "base/memory/ptr_util.h" | |
| 23 #include "base/message_loop/message_loop.h" | |
| 24 #include "base/run_loop.h" | |
| 25 #include "base/single_thread_task_runner.h" | |
| 26 #include "base/strings/utf_string_conversions.h" | |
| 27 #include "base/task/cancelable_task_tracker.h" | |
| 28 #include "base/threading/thread_task_runner_handle.h" | |
| 29 #include "build/build_config.h" | |
| 30 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h" | |
| 31 #include "chrome/browser/browsing_data/browsing_data_helper.h" | |
| 32 #include "chrome/browser/browsing_data/browsing_data_remover.h" | |
| 33 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | |
| 34 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" | |
| 35 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | |
| 36 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h" | |
| 37 #include "chrome/test/base/testing_profile.h" | |
| 38 #include "content/public/browser/browser_context.h" | |
| 39 #include "content/public/browser/cookie_store_factory.h" | |
| 40 #include "content/public/browser/dom_storage_context.h" | |
| 41 #include "content/public/browser/local_storage_usage_info.h" | |
| 42 #include "content/public/browser/permission_type.h" | |
| 43 #include "content/public/browser/storage_partition.h" | |
| 44 #include "content/public/test/mock_download_manager.h" | |
| 45 #include "content/public/test/test_browser_thread.h" | |
| 46 #include "content/public/test/test_browser_thread_bundle.h" | |
| 47 #include "content/public/test/test_utils.h" | |
| 48 #include "extensions/features/features.h" | |
| 49 #include "net/cookies/cookie_store.h" | |
| 50 #include "net/http/http_network_session.h" | |
| 51 #include "net/http/http_transaction_factory.h" | |
| 52 #include "net/ssl/channel_id_service.h" | |
| 53 #include "net/ssl/channel_id_store.h" | |
| 54 #include "net/ssl/ssl_client_cert_type.h" | |
| 55 #include "net/url_request/url_request_context.h" | |
| 56 #include "net/url_request/url_request_context_getter.h" | |
| 57 #include "ppapi/features/features.h" | |
| 58 #include "testing/gmock/include/gmock/gmock.h" | |
| 59 #include "testing/gtest/include/gtest/gtest.h" | |
| 60 #include "url/origin.h" | |
| 61 | |
| 62 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 63 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" | |
| 64 #endif | |
| 65 | |
| 66 class MockExtensionSpecialStoragePolicy; | |
| 67 | |
| 68 using content::BrowserThread; | |
| 69 using content::BrowserContext; | |
| 70 using content::StoragePartition; | |
| 71 using testing::_; | |
| 72 using testing::ByRef; | |
| 73 using testing::Eq; | |
| 74 using testing::Invoke; | |
| 75 using testing::IsEmpty; | |
| 76 using testing::Matcher; | |
| 77 using testing::MakeMatcher; | |
| 78 using testing::MatcherInterface; | |
| 79 using testing::MatchResultListener; | |
| 80 using testing::Not; | |
| 81 using testing::Return; | |
| 82 using testing::SizeIs; | |
| 83 using testing::WithArgs; | |
| 84 | |
| 85 namespace { | |
| 86 | |
| 87 const char kTestOrigin1[] = "http://host1.com:1/"; | |
| 88 const char kTestRegisterableDomain1[] = "host1.com"; | |
| 89 const char kTestOrigin2[] = "http://host2.com:1/"; | |
| 90 const char kTestOrigin3[] = "http://host3.com:1/"; | |
| 91 const char kTestRegisterableDomain3[] = "host3.com"; | |
| 92 const char kTestOrigin4[] = "https://host3.com:1/"; | |
| 93 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; | |
| 94 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; | |
| 95 | |
| 96 // For HTTP auth. | |
| 97 const char kTestRealm[] = "TestRealm"; | |
| 98 | |
| 99 const GURL kOrigin1(kTestOrigin1); | |
| 100 const GURL kOrigin2(kTestOrigin2); | |
| 101 const GURL kOrigin3(kTestOrigin3); | |
| 102 const GURL kOrigin4(kTestOrigin4); | |
| 103 const GURL kOriginExt(kTestOriginExt); | |
| 104 const GURL kOriginDevTools(kTestOriginDevTools); | |
| 105 | |
| 106 const base::FilePath::CharType kDomStorageOrigin1[] = | |
| 107 FILE_PATH_LITERAL("http_host1_1.localstorage"); | |
| 108 | |
| 109 const base::FilePath::CharType kDomStorageOrigin2[] = | |
| 110 FILE_PATH_LITERAL("http_host2_1.localstorage"); | |
| 111 | |
| 112 const base::FilePath::CharType kDomStorageOrigin3[] = | |
| 113 FILE_PATH_LITERAL("http_host3_1.localstorage"); | |
| 114 | |
| 115 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL( | |
| 116 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage"); | |
| 117 | |
| 118 struct StoragePartitionRemovalData { | |
| 119 uint32_t remove_mask = 0; | |
| 120 uint32_t quota_storage_remove_mask = 0; | |
| 121 base::Time remove_begin; | |
| 122 base::Time remove_end; | |
| 123 StoragePartition::OriginMatcherFunction origin_matcher; | |
| 124 StoragePartition::CookieMatcherFunction cookie_matcher; | |
| 125 | |
| 126 StoragePartitionRemovalData() {} | |
| 127 }; | |
| 128 | |
| 129 net::CanonicalCookie CreateCookieWithHost(const GURL& source) { | |
| 130 std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create( | |
| 131 source, "A", "1", std::string(), "/", base::Time::Now(), | |
| 132 base::Time::Now(), false, false, net::CookieSameSite::DEFAULT_MODE, false, | |
| 133 net::COOKIE_PRIORITY_MEDIUM)); | |
| 134 EXPECT_TRUE(cookie); | |
| 135 return *cookie; | |
| 136 } | |
| 137 | |
| 138 class TestStoragePartition : public StoragePartition { | |
| 139 public: | |
| 140 TestStoragePartition() {} | |
| 141 ~TestStoragePartition() override {} | |
| 142 | |
| 143 // content::StoragePartition implementation. | |
| 144 base::FilePath GetPath() override { return base::FilePath(); } | |
| 145 net::URLRequestContextGetter* GetURLRequestContext() override { | |
| 146 return nullptr; | |
| 147 } | |
| 148 net::URLRequestContextGetter* GetMediaURLRequestContext() override { | |
| 149 return nullptr; | |
| 150 } | |
| 151 storage::QuotaManager* GetQuotaManager() override { return nullptr; } | |
| 152 content::AppCacheService* GetAppCacheService() override { return nullptr; } | |
| 153 storage::FileSystemContext* GetFileSystemContext() override { | |
| 154 return nullptr; | |
| 155 } | |
| 156 storage::DatabaseTracker* GetDatabaseTracker() override { return nullptr; } | |
| 157 content::DOMStorageContext* GetDOMStorageContext() override { | |
| 158 return nullptr; | |
| 159 } | |
| 160 content::IndexedDBContext* GetIndexedDBContext() override { return nullptr; } | |
| 161 content::ServiceWorkerContext* GetServiceWorkerContext() override { | |
| 162 return nullptr; | |
| 163 } | |
| 164 content::CacheStorageContext* GetCacheStorageContext() override { | |
| 165 return nullptr; | |
| 166 } | |
| 167 content::PlatformNotificationContext* GetPlatformNotificationContext() | |
| 168 override { | |
| 169 return nullptr; | |
| 170 } | |
| 171 content::HostZoomMap* GetHostZoomMap() override { return nullptr; } | |
| 172 content::HostZoomLevelContext* GetHostZoomLevelContext() override { | |
| 173 return nullptr; | |
| 174 } | |
| 175 content::ZoomLevelDelegate* GetZoomLevelDelegate() override { | |
| 176 return nullptr; | |
| 177 } | |
| 178 | |
| 179 void ClearDataForOrigin(uint32_t remove_mask, | |
| 180 uint32_t quota_storage_remove_mask, | |
| 181 const GURL& storage_origin, | |
| 182 net::URLRequestContextGetter* rq_context, | |
| 183 const base::Closure& callback) override { | |
| 184 BrowserThread::PostTask(BrowserThread::UI, | |
| 185 FROM_HERE, | |
| 186 base::Bind(&TestStoragePartition::AsyncRunCallback, | |
| 187 base::Unretained(this), | |
| 188 callback)); | |
| 189 } | |
| 190 | |
| 191 void ClearData(uint32_t remove_mask, | |
| 192 uint32_t quota_storage_remove_mask, | |
| 193 const GURL& storage_origin, | |
| 194 const OriginMatcherFunction& origin_matcher, | |
| 195 const base::Time begin, | |
| 196 const base::Time end, | |
| 197 const base::Closure& callback) override { | |
| 198 // Store stuff to verify parameters' correctness later. | |
| 199 storage_partition_removal_data_.remove_mask = remove_mask; | |
| 200 storage_partition_removal_data_.quota_storage_remove_mask = | |
| 201 quota_storage_remove_mask; | |
| 202 storage_partition_removal_data_.remove_begin = begin; | |
| 203 storage_partition_removal_data_.remove_end = end; | |
| 204 storage_partition_removal_data_.origin_matcher = origin_matcher; | |
| 205 | |
| 206 BrowserThread::PostTask( | |
| 207 BrowserThread::UI, | |
| 208 FROM_HERE, | |
| 209 base::Bind(&TestStoragePartition::AsyncRunCallback, | |
| 210 base::Unretained(this), callback)); | |
| 211 } | |
| 212 | |
| 213 void ClearData(uint32_t remove_mask, | |
| 214 uint32_t quota_storage_remove_mask, | |
| 215 const OriginMatcherFunction& origin_matcher, | |
| 216 const CookieMatcherFunction& cookie_matcher, | |
| 217 const base::Time begin, | |
| 218 const base::Time end, | |
| 219 const base::Closure& callback) override { | |
| 220 // Store stuff to verify parameters' correctness later. | |
| 221 storage_partition_removal_data_.remove_mask = remove_mask; | |
| 222 storage_partition_removal_data_.quota_storage_remove_mask = | |
| 223 quota_storage_remove_mask; | |
| 224 storage_partition_removal_data_.remove_begin = begin; | |
| 225 storage_partition_removal_data_.remove_end = end; | |
| 226 storage_partition_removal_data_.origin_matcher = origin_matcher; | |
| 227 storage_partition_removal_data_.cookie_matcher = cookie_matcher; | |
| 228 | |
| 229 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 230 base::Bind(&TestStoragePartition::AsyncRunCallback, | |
| 231 base::Unretained(this), callback)); | |
| 232 } | |
| 233 | |
| 234 void Flush() override {} | |
| 235 | |
| 236 StoragePartitionRemovalData GetStoragePartitionRemovalData() { | |
| 237 return storage_partition_removal_data_; | |
| 238 } | |
| 239 | |
| 240 private: | |
| 241 void AsyncRunCallback(const base::Closure& callback) { | |
| 242 callback.Run(); | |
| 243 } | |
| 244 | |
| 245 StoragePartitionRemovalData storage_partition_removal_data_; | |
| 246 | |
| 247 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); | |
| 248 }; | |
| 249 | |
| 250 // Custom matcher to test the equivalence of two URL filters. Since those are | |
| 251 // blackbox predicates, we can only approximate the equivalence by testing | |
| 252 // whether the filter give the same answer for several URLs. This is currently | |
| 253 // good enough for our testing purposes, to distinguish whitelists | |
| 254 // and blacklists, empty and non-empty filters and such. | |
| 255 // TODO(msramek): BrowsingDataRemover and some of its backends support URL | |
| 256 // filters, but its constructor currently only takes a single URL and constructs | |
| 257 // its own url filter. If an url filter was directly passed to | |
| 258 // BrowsingDataRemover (what should eventually be the case), we can use the same | |
| 259 // instance in the test as well, and thus simply test base::Callback::Equals() | |
| 260 // in this matcher. | |
| 261 class ProbablySameFilterMatcher | |
| 262 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> { | |
| 263 public: | |
| 264 explicit ProbablySameFilterMatcher( | |
| 265 const base::Callback<bool(const GURL&)>& filter) | |
| 266 : to_match_(filter) { | |
| 267 } | |
| 268 | |
| 269 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, | |
| 270 MatchResultListener* listener) const { | |
| 271 if (filter.is_null() && to_match_.is_null()) | |
| 272 return true; | |
| 273 if (filter.is_null() != to_match_.is_null()) | |
| 274 return false; | |
| 275 | |
| 276 const GURL urls_to_test_[] = | |
| 277 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")}; | |
| 278 for (GURL url : urls_to_test_) { | |
| 279 if (filter.Run(url) != to_match_.Run(url)) { | |
| 280 if (listener) | |
| 281 *listener << "The filters differ on the URL " << url; | |
| 282 return false; | |
| 283 } | |
| 284 } | |
| 285 return true; | |
| 286 } | |
| 287 | |
| 288 virtual void DescribeTo(::std::ostream* os) const { | |
| 289 *os << "is probably the same url filter as " << &to_match_; | |
| 290 } | |
| 291 | |
| 292 virtual void DescribeNegationTo(::std::ostream* os) const { | |
| 293 *os << "is definitely NOT the same url filter as " << &to_match_; | |
| 294 } | |
| 295 | |
| 296 private: | |
| 297 const base::Callback<bool(const GURL&)>& to_match_; | |
| 298 }; | |
| 299 | |
| 300 inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter( | |
| 301 const base::Callback<bool(const GURL&)>& filter) { | |
| 302 return MakeMatcher(new ProbablySameFilterMatcher(filter)); | |
| 303 } | |
| 304 | |
| 305 base::Time AnHourAgo() { | |
| 306 return base::Time::Now() - base::TimeDelta::FromHours(1); | |
| 307 } | |
| 308 | |
| 309 } // namespace | |
| 310 | |
| 311 // Testers ------------------------------------------------------------------- | |
| 312 | |
| 313 class RemoveCookieTester { | |
| 314 public: | |
| 315 RemoveCookieTester() {} | |
| 316 | |
| 317 // Returns true, if the given cookie exists in the cookie store. | |
| 318 bool ContainsCookie() { | |
| 319 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | |
| 320 new content::MessageLoopRunner; | |
| 321 quit_closure_ = message_loop_runner->QuitClosure(); | |
| 322 get_cookie_success_ = false; | |
| 323 cookie_store_->GetCookiesWithOptionsAsync( | |
| 324 kOrigin1, net::CookieOptions(), | |
| 325 base::Bind(&RemoveCookieTester::GetCookieCallback, | |
| 326 base::Unretained(this))); | |
| 327 message_loop_runner->Run(); | |
| 328 return get_cookie_success_; | |
| 329 } | |
| 330 | |
| 331 void AddCookie() { | |
| 332 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | |
| 333 new content::MessageLoopRunner; | |
| 334 quit_closure_ = message_loop_runner->QuitClosure(); | |
| 335 cookie_store_->SetCookieWithOptionsAsync( | |
| 336 kOrigin1, "A=1", net::CookieOptions(), | |
| 337 base::Bind(&RemoveCookieTester::SetCookieCallback, | |
| 338 base::Unretained(this))); | |
| 339 message_loop_runner->Run(); | |
| 340 } | |
| 341 | |
| 342 protected: | |
| 343 void SetCookieStore(net::CookieStore* cookie_store) { | |
| 344 cookie_store_ = cookie_store; | |
| 345 } | |
| 346 | |
| 347 private: | |
| 348 void GetCookieCallback(const std::string& cookies) { | |
| 349 if (cookies == "A=1") { | |
| 350 get_cookie_success_ = true; | |
| 351 } else { | |
| 352 EXPECT_EQ("", cookies); | |
| 353 get_cookie_success_ = false; | |
| 354 } | |
| 355 quit_closure_.Run(); | |
| 356 } | |
| 357 | |
| 358 void SetCookieCallback(bool result) { | |
| 359 ASSERT_TRUE(result); | |
| 360 quit_closure_.Run(); | |
| 361 } | |
| 362 | |
| 363 bool get_cookie_success_ = false; | |
| 364 base::Closure quit_closure_; | |
| 365 | |
| 366 // CookieStore must out live |this|. | |
| 367 net::CookieStore* cookie_store_ = nullptr; | |
| 368 | |
| 369 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); | |
| 370 }; | |
| 371 | |
| 372 class RemoveChannelIDTester : public net::SSLConfigService::Observer { | |
| 373 public: | |
| 374 explicit RemoveChannelIDTester(BrowserContext* browser_context) { | |
| 375 net::URLRequestContext* url_request_context = | |
| 376 content::BrowserContext::GetDefaultStoragePartition(browser_context) | |
| 377 ->GetURLRequestContext()->GetURLRequestContext(); | |
| 378 channel_id_service_ = url_request_context-> channel_id_service(); | |
| 379 ssl_config_service_ = url_request_context->ssl_config_service(); | |
| 380 ssl_config_service_->AddObserver(this); | |
| 381 } | |
| 382 | |
| 383 ~RemoveChannelIDTester() override { | |
| 384 ssl_config_service_->RemoveObserver(this); | |
| 385 } | |
| 386 | |
| 387 int ChannelIDCount() { return channel_id_service_->channel_id_count(); } | |
| 388 | |
| 389 // Add a server bound cert for |server| with specific creation and expiry | |
| 390 // times. The cert and key data will be filled with dummy values. | |
| 391 void AddChannelIDWithTimes(const std::string& server_identifier, | |
| 392 base::Time creation_time) { | |
| 393 GetChannelIDStore()->SetChannelID( | |
| 394 base::MakeUnique<net::ChannelIDStore::ChannelID>( | |
| 395 server_identifier, creation_time, crypto::ECPrivateKey::Create())); | |
| 396 } | |
| 397 | |
| 398 // Add a server bound cert for |server|, with the current time as the | |
| 399 // creation time. The cert and key data will be filled with dummy values. | |
| 400 void AddChannelID(const std::string& server_identifier) { | |
| 401 base::Time now = base::Time::Now(); | |
| 402 AddChannelIDWithTimes(server_identifier, now); | |
| 403 } | |
| 404 | |
| 405 void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) { | |
| 406 GetChannelIDStore()->GetAllChannelIDs( | |
| 407 base::Bind(&RemoveChannelIDTester::GetAllChannelIDsCallback, | |
| 408 channel_ids)); | |
| 409 } | |
| 410 | |
| 411 net::ChannelIDStore* GetChannelIDStore() { | |
| 412 return channel_id_service_->GetChannelIDStore(); | |
| 413 } | |
| 414 | |
| 415 int ssl_config_changed_count() const { | |
| 416 return ssl_config_changed_count_; | |
| 417 } | |
| 418 | |
| 419 // net::SSLConfigService::Observer implementation: | |
| 420 void OnSSLConfigChanged() override { ssl_config_changed_count_++; } | |
| 421 | |
| 422 private: | |
| 423 static void GetAllChannelIDsCallback( | |
| 424 net::ChannelIDStore::ChannelIDList* dest, | |
| 425 const net::ChannelIDStore::ChannelIDList& result) { | |
| 426 *dest = result; | |
| 427 } | |
| 428 | |
| 429 net::ChannelIDService* channel_id_service_; | |
| 430 scoped_refptr<net::SSLConfigService> ssl_config_service_; | |
| 431 int ssl_config_changed_count_ = 0; | |
| 432 | |
| 433 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester); | |
| 434 }; | |
| 435 | |
| 436 class RemoveLocalStorageTester { | |
| 437 public: | |
| 438 explicit RemoveLocalStorageTester(BrowserContext* browser_context) | |
| 439 : browser_context_(browser_context) { | |
| 440 dom_storage_context_ = | |
| 441 content::BrowserContext::GetDefaultStoragePartition(browser_context_)-> | |
| 442 GetDOMStorageContext(); | |
| 443 } | |
| 444 | |
| 445 // Returns true, if the given origin URL exists. | |
| 446 bool DOMStorageExistsForOrigin(const GURL& origin) { | |
| 447 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | |
| 448 new content::MessageLoopRunner; | |
| 449 quit_closure_ = message_loop_runner->QuitClosure(); | |
| 450 GetLocalStorageUsage(); | |
| 451 message_loop_runner->Run(); | |
| 452 for (size_t i = 0; i < infos_.size(); ++i) { | |
| 453 if (origin == infos_[i].origin) | |
| 454 return true; | |
| 455 } | |
| 456 return false; | |
| 457 } | |
| 458 | |
| 459 void AddDOMStorageTestData() { | |
| 460 // Note: This test depends on details of how the dom_storage library | |
| 461 // stores data in the host file system. | |
| 462 base::FilePath storage_path = | |
| 463 browser_context_->GetPath().AppendASCII("Local Storage"); | |
| 464 base::CreateDirectory(storage_path); | |
| 465 | |
| 466 // Write some files. | |
| 467 base::WriteFile(storage_path.Append(kDomStorageOrigin1), nullptr, 0); | |
| 468 base::WriteFile(storage_path.Append(kDomStorageOrigin2), nullptr, 0); | |
| 469 base::WriteFile(storage_path.Append(kDomStorageOrigin3), nullptr, 0); | |
| 470 base::WriteFile(storage_path.Append(kDomStorageExt), nullptr, 0); | |
| 471 | |
| 472 // Tweak their dates. | |
| 473 base::Time now = base::Time::Now(); | |
| 474 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now); | |
| 475 | |
| 476 base::Time one_day_ago = now - base::TimeDelta::FromDays(1); | |
| 477 base::TouchFile(storage_path.Append(kDomStorageOrigin2), | |
| 478 one_day_ago, one_day_ago); | |
| 479 | |
| 480 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60); | |
| 481 base::TouchFile(storage_path.Append(kDomStorageOrigin3), | |
| 482 sixty_days_ago, sixty_days_ago); | |
| 483 | |
| 484 base::TouchFile(storage_path.Append(kDomStorageExt), now, now); | |
| 485 } | |
| 486 | |
| 487 private: | |
| 488 void GetLocalStorageUsage() { | |
| 489 dom_storage_context_->GetLocalStorageUsage( | |
| 490 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage, | |
| 491 base::Unretained(this))); | |
| 492 } | |
| 493 void OnGotLocalStorageUsage( | |
| 494 const std::vector<content::LocalStorageUsageInfo>& infos) { | |
| 495 infos_ = infos; | |
| 496 quit_closure_.Run(); | |
| 497 } | |
| 498 | |
| 499 // We don't own these pointers. | |
| 500 BrowserContext* browser_context_; | |
| 501 content::DOMStorageContext* dom_storage_context_ = nullptr; | |
| 502 | |
| 503 std::vector<content::LocalStorageUsageInfo> infos_; | |
| 504 base::Closure quit_closure_; | |
| 505 | |
| 506 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); | |
| 507 }; | |
| 508 | |
| 509 class RemoveDownloadsTester { | |
| 510 public: | |
| 511 explicit RemoveDownloadsTester(BrowserContext* browser_context) | |
| 512 : download_manager_(new content::MockDownloadManager()) { | |
| 513 content::BrowserContext::SetDownloadManagerForTesting(browser_context, | |
| 514 download_manager_); | |
| 515 EXPECT_EQ(download_manager_, | |
| 516 content::BrowserContext::GetDownloadManager(browser_context)); | |
| 517 EXPECT_CALL(*download_manager_, Shutdown()); | |
| 518 } | |
| 519 | |
| 520 ~RemoveDownloadsTester() {} | |
| 521 | |
| 522 content::MockDownloadManager* download_manager() { return download_manager_; } | |
| 523 | |
| 524 private: | |
| 525 content::MockDownloadManager* download_manager_; | |
| 526 | |
| 527 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester); | |
| 528 }; | |
| 529 | |
| 530 // Test Class ---------------------------------------------------------------- | |
| 531 | |
| 532 class BrowsingDataRemoverImplTest : public testing::Test { | |
| 533 public: | |
| 534 BrowsingDataRemoverImplTest() | |
| 535 : browser_context_(new TestingProfile()) { | |
| 536 // TODO(crbug.com/668114): To create a BrowsingDataRemoverImpl, we currently | |
| 537 // need a BrowsingDataRemoverFactory which only exists for a Profile. | |
| 538 // Therefore, this test must use a TestingProfile for now. Switch it to | |
| 539 // a BrowserContext or TestBrowserContext when BrowsingDataRemoverImpl | |
| 540 // moves to content/. Furthermore, when in content/, BrowsingDataRemoverImpl | |
| 541 // will have no delegate. For now, explicitly set it to nullptr. | |
| 542 remover_ = static_cast<BrowsingDataRemoverImpl*>( | |
| 543 BrowsingDataRemoverFactory::GetForBrowserContext( | |
| 544 browser_context_.get())); | |
| 545 remover_->SetEmbedderDelegate(nullptr); | |
| 546 } | |
| 547 | |
| 548 ~BrowsingDataRemoverImplTest() override {} | |
| 549 | |
| 550 void TearDown() override { | |
| 551 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 552 mock_policy_ = nullptr; | |
| 553 #endif | |
| 554 | |
| 555 // BrowserContext contains a DOMStorageContext. BrowserContext's | |
| 556 // destructor posts a message to the WEBKIT thread to delete some of its | |
| 557 // member variables. We need to ensure that the browser context is | |
| 558 // destroyed, and that the message loop is cleared out, before destroying | |
| 559 // the threads and loop. Otherwise we leak memory. | |
| 560 browser_context_.reset(); | |
| 561 base::RunLoop().RunUntilIdle(); | |
| 562 } | |
| 563 | |
| 564 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin, | |
| 565 const base::Time& delete_end, | |
| 566 int remove_mask, | |
| 567 bool include_protected_origins) { | |
| 568 TestStoragePartition storage_partition; | |
| 569 remover_->OverrideStoragePartitionForTesting(&storage_partition); | |
| 570 | |
| 571 int origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB; | |
| 572 if (include_protected_origins) | |
| 573 origin_type_mask |= BrowsingDataHelper::PROTECTED_WEB; | |
| 574 | |
| 575 BrowsingDataRemoverCompletionObserver completion_observer(remover_); | |
| 576 remover_->RemoveAndReply( | |
| 577 delete_begin, delete_end, remove_mask, origin_type_mask, | |
| 578 &completion_observer); | |
| 579 completion_observer.BlockUntilCompletion(); | |
| 580 | |
| 581 // Save so we can verify later. | |
| 582 storage_partition_removal_data_ = | |
| 583 storage_partition.GetStoragePartitionRemovalData(); | |
| 584 } | |
| 585 | |
| 586 void BlockUntilOriginDataRemoved( | |
| 587 const base::Time& delete_begin, | |
| 588 const base::Time& delete_end, | |
| 589 int remove_mask, | |
| 590 const BrowsingDataFilterBuilder& filter_builder) { | |
| 591 TestStoragePartition storage_partition; | |
| 592 remover_->OverrideStoragePartitionForTesting(&storage_partition); | |
| 593 | |
| 594 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; | |
| 595 remover_->RemoveImpl(delete_begin, delete_end, remove_mask, filter_builder, | |
| 596 BrowsingDataHelper::UNPROTECTED_WEB); | |
| 597 completion_inhibitor.BlockUntilNearCompletion(); | |
| 598 completion_inhibitor.ContinueToCompletion(); | |
| 599 | |
| 600 // Save so we can verify later. | |
| 601 storage_partition_removal_data_ = | |
| 602 storage_partition.GetStoragePartitionRemovalData(); | |
| 603 } | |
| 604 | |
| 605 BrowserContext* GetBrowserContext() { | |
| 606 return browser_context_.get(); | |
| 607 } | |
| 608 | |
| 609 void DestroyBrowserContext() { browser_context_.reset(); } | |
| 610 | |
| 611 const base::Time& GetBeginTime() { | |
| 612 return remover_->GetLastUsedBeginTime(); | |
| 613 } | |
| 614 | |
| 615 int GetRemovalMask() { | |
| 616 return remover_->GetLastUsedRemovalMask(); | |
| 617 } | |
| 618 | |
| 619 int GetOriginTypeMask() { | |
| 620 return remover_->GetLastUsedOriginTypeMask(); | |
| 621 } | |
| 622 | |
| 623 StoragePartitionRemovalData GetStoragePartitionRemovalData() { | |
| 624 return storage_partition_removal_data_; | |
| 625 } | |
| 626 | |
| 627 MockExtensionSpecialStoragePolicy* CreateMockPolicy() { | |
| 628 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 629 mock_policy_ = new MockExtensionSpecialStoragePolicy; | |
| 630 return mock_policy_.get(); | |
| 631 #else | |
| 632 NOTREACHED(); | |
| 633 return nullptr; | |
| 634 #endif | |
| 635 } | |
| 636 | |
| 637 storage::SpecialStoragePolicy* mock_policy() { | |
| 638 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 639 return mock_policy_.get(); | |
| 640 #else | |
| 641 return nullptr; | |
| 642 #endif | |
| 643 } | |
| 644 | |
| 645 // If |kOrigin1| is protected when extensions are enabled, the expected | |
| 646 // result for tests where the OriginMatcherFunction result is variable. | |
| 647 bool ShouldRemoveForProtectedOriginOne() const { | |
| 648 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 649 return false; | |
| 650 #else | |
| 651 return true; | |
| 652 #endif | |
| 653 } | |
| 654 | |
| 655 private: | |
| 656 // Cached pointer to BrowsingDataRemoverImpl for access to testing methods. | |
| 657 BrowsingDataRemoverImpl* remover_; | |
| 658 | |
| 659 content::TestBrowserThreadBundle thread_bundle_; | |
| 660 std::unique_ptr<BrowserContext> browser_context_; | |
| 661 | |
| 662 StoragePartitionRemovalData storage_partition_removal_data_; | |
| 663 | |
| 664 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 665 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_; | |
| 666 #endif | |
| 667 | |
| 668 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImplTest); | |
| 669 }; | |
| 670 | |
| 671 // Tests --------------------------------------------------------------------- | |
| 672 | |
| 673 TEST_F(BrowsingDataRemoverImplTest, RemoveCookieForever) { | |
| 674 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 675 BrowsingDataRemover::REMOVE_COOKIES, false); | |
| 676 | |
| 677 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); | |
| 678 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 679 | |
| 680 // Verify that storage partition was instructed to remove the cookies. | |
| 681 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 682 EXPECT_EQ(removal_data.remove_mask, | |
| 683 StoragePartition::REMOVE_DATA_MASK_COOKIES); | |
| 684 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 685 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 686 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
| 687 } | |
| 688 | |
| 689 TEST_F(BrowsingDataRemoverImplTest, RemoveCookieLastHour) { | |
| 690 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 691 BrowsingDataRemover::REMOVE_COOKIES, false); | |
| 692 | |
| 693 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); | |
| 694 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 695 | |
| 696 // Verify that storage partition was instructed to remove the cookies. | |
| 697 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 698 EXPECT_EQ(removal_data.remove_mask, | |
| 699 StoragePartition::REMOVE_DATA_MASK_COOKIES); | |
| 700 // Removing with time period other than all time should not clear | |
| 701 // persistent storage data. | |
| 702 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 703 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT); | |
| 704 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
| 705 } | |
| 706 | |
| 707 TEST_F(BrowsingDataRemoverImplTest, RemoveCookiesDomainBlacklist) { | |
| 708 RegistrableDomainFilterBuilder filter( | |
| 709 RegistrableDomainFilterBuilder::BLACKLIST); | |
| 710 filter.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 711 filter.AddRegisterableDomain(kTestRegisterableDomain3); | |
| 712 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 713 BrowsingDataRemover::REMOVE_COOKIES, filter); | |
| 714 | |
| 715 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); | |
| 716 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 717 | |
| 718 // Verify that storage partition was instructed to remove the cookies. | |
| 719 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 720 EXPECT_EQ(removal_data.remove_mask, | |
| 721 StoragePartition::REMOVE_DATA_MASK_COOKIES); | |
| 722 // Removing with time period other than all time should not clear | |
| 723 // persistent storage data. | |
| 724 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 725 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT); | |
| 726 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
| 727 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
| 728 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
| 729 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
| 730 // Even though it's a different origin, it's the same domain. | |
| 731 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin4, mock_policy())); | |
| 732 | |
| 733 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin1))); | |
| 734 EXPECT_TRUE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin2))); | |
| 735 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin3))); | |
| 736 // This is false, because this is the same domain as 3, just with a different | |
| 737 // scheme. | |
| 738 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin4))); | |
| 739 } | |
| 740 | |
| 741 // Test that removing cookies clears HTTP auth data. | |
| 742 TEST_F(BrowsingDataRemoverImplTest, ClearHttpAuthCache_RemoveCookies) { | |
| 743 net::HttpNetworkSession* http_session = | |
| 744 content::BrowserContext::GetDefaultStoragePartition(GetBrowserContext()) | |
| 745 ->GetURLRequestContext() | |
| 746 ->GetURLRequestContext() | |
| 747 ->http_transaction_factory() | |
| 748 ->GetSession(); | |
| 749 DCHECK(http_session); | |
| 750 | |
| 751 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache(); | |
| 752 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC, | |
| 753 "test challenge", | |
| 754 net::AuthCredentials(base::ASCIIToUTF16("foo"), | |
| 755 base::ASCIIToUTF16("bar")), | |
| 756 "/"); | |
| 757 CHECK(http_auth_cache->Lookup(kOrigin1, kTestRealm, | |
| 758 net::HttpAuth::AUTH_SCHEME_BASIC)); | |
| 759 | |
| 760 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 761 BrowsingDataRemover::REMOVE_COOKIES, false); | |
| 762 | |
| 763 EXPECT_EQ(nullptr, http_auth_cache->Lookup(kOrigin1, kTestRealm, | |
| 764 net::HttpAuth::AUTH_SCHEME_BASIC)); | |
| 765 } | |
| 766 | |
| 767 TEST_F(BrowsingDataRemoverImplTest, RemoveChannelIDForever) { | |
| 768 RemoveChannelIDTester tester(GetBrowserContext()); | |
| 769 | |
| 770 tester.AddChannelID(kTestOrigin1); | |
| 771 EXPECT_EQ(0, tester.ssl_config_changed_count()); | |
| 772 EXPECT_EQ(1, tester.ChannelIDCount()); | |
| 773 | |
| 774 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 775 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false); | |
| 776 | |
| 777 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask()); | |
| 778 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 779 EXPECT_EQ(1, tester.ssl_config_changed_count()); | |
| 780 EXPECT_EQ(0, tester.ChannelIDCount()); | |
| 781 } | |
| 782 | |
| 783 TEST_F(BrowsingDataRemoverImplTest, RemoveChannelIDLastHour) { | |
| 784 RemoveChannelIDTester tester(GetBrowserContext()); | |
| 785 | |
| 786 base::Time now = base::Time::Now(); | |
| 787 tester.AddChannelID(kTestOrigin1); | |
| 788 tester.AddChannelIDWithTimes(kTestOrigin2, | |
| 789 now - base::TimeDelta::FromHours(2)); | |
| 790 EXPECT_EQ(0, tester.ssl_config_changed_count()); | |
| 791 EXPECT_EQ(2, tester.ChannelIDCount()); | |
| 792 | |
| 793 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 794 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false); | |
| 795 | |
| 796 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask()); | |
| 797 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 798 EXPECT_EQ(1, tester.ssl_config_changed_count()); | |
| 799 ASSERT_EQ(1, tester.ChannelIDCount()); | |
| 800 net::ChannelIDStore::ChannelIDList channel_ids; | |
| 801 tester.GetChannelIDList(&channel_ids); | |
| 802 ASSERT_EQ(1U, channel_ids.size()); | |
| 803 EXPECT_EQ(kTestOrigin2, channel_ids.front().server_identifier()); | |
| 804 } | |
| 805 | |
| 806 TEST_F(BrowsingDataRemoverImplTest, RemoveChannelIDsForServerIdentifiers) { | |
| 807 RemoveChannelIDTester tester(GetBrowserContext()); | |
| 808 | |
| 809 tester.AddChannelID(kTestRegisterableDomain1); | |
| 810 tester.AddChannelID(kTestRegisterableDomain3); | |
| 811 EXPECT_EQ(2, tester.ChannelIDCount()); | |
| 812 | |
| 813 RegistrableDomainFilterBuilder filter_builder( | |
| 814 RegistrableDomainFilterBuilder::WHITELIST); | |
| 815 filter_builder.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 816 | |
| 817 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
| 818 BrowsingDataRemover::REMOVE_CHANNEL_IDS, | |
| 819 filter_builder); | |
| 820 | |
| 821 EXPECT_EQ(1, tester.ChannelIDCount()); | |
| 822 net::ChannelIDStore::ChannelIDList channel_ids; | |
| 823 tester.GetChannelIDList(&channel_ids); | |
| 824 EXPECT_EQ(kTestRegisterableDomain3, channel_ids.front().server_identifier()); | |
| 825 } | |
| 826 | |
| 827 TEST_F(BrowsingDataRemoverImplTest, RemoveUnprotectedLocalStorageForever) { | |
| 828 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 829 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy(); | |
| 830 // Protect kOrigin1. | |
| 831 policy->AddProtected(kOrigin1.GetOrigin()); | |
| 832 #endif | |
| 833 | |
| 834 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 835 BrowsingDataRemover::REMOVE_LOCAL_STORAGE, | |
| 836 false); | |
| 837 | |
| 838 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask()); | |
| 839 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 840 | |
| 841 // Verify that storage partition was instructed to remove the data correctly. | |
| 842 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 843 EXPECT_EQ(removal_data.remove_mask, | |
| 844 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); | |
| 845 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 846 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 847 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
| 848 | |
| 849 // Check origin matcher. | |
| 850 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(), | |
| 851 removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
| 852 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
| 853 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
| 854 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); | |
| 855 } | |
| 856 | |
| 857 TEST_F(BrowsingDataRemoverImplTest, RemoveProtectedLocalStorageForever) { | |
| 858 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 859 // Protect kOrigin1. | |
| 860 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy(); | |
| 861 policy->AddProtected(kOrigin1.GetOrigin()); | |
| 862 #endif | |
| 863 | |
| 864 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 865 BrowsingDataRemover::REMOVE_LOCAL_STORAGE, | |
| 866 true); | |
| 867 | |
| 868 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask()); | |
| 869 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB | | |
| 870 BrowsingDataHelper::PROTECTED_WEB, GetOriginTypeMask()); | |
| 871 | |
| 872 // Verify that storage partition was instructed to remove the data correctly. | |
| 873 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 874 EXPECT_EQ(removal_data.remove_mask, | |
| 875 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); | |
| 876 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 877 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 878 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
| 879 | |
| 880 // Check origin matcher all http origin will match since we specified | |
| 881 // both protected and unprotected. | |
| 882 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
| 883 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
| 884 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
| 885 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); | |
| 886 } | |
| 887 | |
| 888 TEST_F(BrowsingDataRemoverImplTest, RemoveLocalStorageForLastWeek) { | |
| 889 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 890 CreateMockPolicy(); | |
| 891 #endif | |
| 892 | |
| 893 BlockUntilBrowsingDataRemoved( | |
| 894 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(), | |
| 895 BrowsingDataRemover::REMOVE_LOCAL_STORAGE, false); | |
| 896 | |
| 897 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask()); | |
| 898 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 899 | |
| 900 // Verify that storage partition was instructed to remove the data correctly. | |
| 901 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 902 EXPECT_EQ(removal_data.remove_mask, | |
| 903 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); | |
| 904 // Persistent storage won't be deleted. | |
| 905 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 906 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT); | |
| 907 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
| 908 | |
| 909 // Check origin matcher. | |
| 910 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
| 911 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
| 912 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
| 913 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); | |
| 914 } | |
| 915 | |
| 916 TEST_F(BrowsingDataRemoverImplTest, RemoveMultipleTypes) { | |
| 917 // Downloads should be deleted through the DownloadManager, assure it would | |
| 918 // be called. | |
| 919 RemoveDownloadsTester downloads_tester(GetBrowserContext()); | |
| 920 EXPECT_CALL(*downloads_tester.download_manager(), | |
| 921 RemoveDownloadsByURLAndTime(_, _, _)); | |
| 922 | |
| 923 int removal_mask = BrowsingDataRemover::REMOVE_DOWNLOADS | | |
| 924 BrowsingDataRemover::REMOVE_COOKIES; | |
| 925 | |
| 926 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 927 removal_mask, false); | |
| 928 | |
| 929 EXPECT_EQ(removal_mask, GetRemovalMask()); | |
| 930 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 931 | |
| 932 // The cookie would be deleted throught the StorageParition, check if the | |
| 933 // partition was requested to remove cookie. | |
| 934 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 935 EXPECT_EQ(removal_data.remove_mask, | |
| 936 StoragePartition::REMOVE_DATA_MASK_COOKIES); | |
| 937 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 938 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 939 } | |
| 940 | |
| 941 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForeverBoth) { | |
| 942 BlockUntilBrowsingDataRemoved( | |
| 943 base::Time(), base::Time::Max(), | |
| 944 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 945 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 946 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 947 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 948 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 949 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 950 false); | |
| 951 | |
| 952 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 953 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 954 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 955 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 956 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 957 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 958 GetRemovalMask()); | |
| 959 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 960 | |
| 961 // Verify storage partition related stuffs. | |
| 962 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 963 EXPECT_EQ(removal_data.remove_mask, | |
| 964 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
| 965 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
| 966 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
| 967 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
| 968 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
| 969 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
| 970 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 971 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 972 } | |
| 973 | |
| 974 TEST_F(BrowsingDataRemoverImplTest, | |
| 975 RemoveQuotaManagedDataForeverOnlyTemporary) { | |
| 976 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 977 CreateMockPolicy(); | |
| 978 #endif | |
| 979 | |
| 980 BlockUntilBrowsingDataRemoved( | |
| 981 base::Time(), base::Time::Max(), | |
| 982 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 983 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 984 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 985 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 986 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 987 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 988 false); | |
| 989 | |
| 990 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 991 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 992 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 993 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 994 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 995 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 996 GetRemovalMask()); | |
| 997 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 998 | |
| 999 // Verify storage partition related stuffs. | |
| 1000 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 1001 | |
| 1002 EXPECT_EQ(removal_data.remove_mask, | |
| 1003 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
| 1004 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
| 1005 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
| 1006 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
| 1007 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
| 1008 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
| 1009 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 1010 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 1011 | |
| 1012 // Check that all related origin data would be removed, that is, origin | |
| 1013 // matcher would match these origin. | |
| 1014 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
| 1015 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
| 1016 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
| 1017 } | |
| 1018 | |
| 1019 TEST_F(BrowsingDataRemoverImplTest, | |
| 1020 RemoveQuotaManagedDataForeverOnlyPersistent) { | |
| 1021 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 1022 CreateMockPolicy(); | |
| 1023 #endif | |
| 1024 | |
| 1025 BlockUntilBrowsingDataRemoved( | |
| 1026 base::Time(), base::Time::Max(), | |
| 1027 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1028 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 1029 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1030 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1031 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1032 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 1033 false); | |
| 1034 | |
| 1035 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1036 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 1037 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1038 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1039 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1040 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 1041 GetRemovalMask()); | |
| 1042 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1043 | |
| 1044 // Verify storage partition related stuffs. | |
| 1045 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 1046 | |
| 1047 EXPECT_EQ(removal_data.remove_mask, | |
| 1048 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
| 1049 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
| 1050 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
| 1051 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
| 1052 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
| 1053 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
| 1054 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 1055 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 1056 | |
| 1057 // Check that all related origin data would be removed, that is, origin | |
| 1058 // matcher would match these origin. | |
| 1059 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
| 1060 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
| 1061 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
| 1062 } | |
| 1063 | |
| 1064 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForeverNeither) { | |
| 1065 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 1066 CreateMockPolicy(); | |
| 1067 #endif | |
| 1068 | |
| 1069 BlockUntilBrowsingDataRemoved( | |
| 1070 base::Time(), base::Time::Max(), | |
| 1071 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1072 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 1073 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1074 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1075 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1076 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 1077 false); | |
| 1078 | |
| 1079 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1080 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 1081 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1082 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1083 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1084 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 1085 GetRemovalMask()); | |
| 1086 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1087 | |
| 1088 // Verify storage partition related stuffs. | |
| 1089 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 1090 | |
| 1091 EXPECT_EQ(removal_data.remove_mask, | |
| 1092 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
| 1093 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
| 1094 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
| 1095 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
| 1096 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
| 1097 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
| 1098 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 1099 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 1100 | |
| 1101 // Check that all related origin data would be removed, that is, origin | |
| 1102 // matcher would match these origin. | |
| 1103 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
| 1104 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
| 1105 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
| 1106 } | |
| 1107 | |
| 1108 TEST_F(BrowsingDataRemoverImplTest, | |
| 1109 RemoveQuotaManagedDataForeverSpecificOrigin) { | |
| 1110 RegistrableDomainFilterBuilder builder( | |
| 1111 RegistrableDomainFilterBuilder::WHITELIST); | |
| 1112 builder.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 1113 // Remove Origin 1. | |
| 1114 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
| 1115 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1116 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1117 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1118 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1119 BrowsingDataRemover::REMOVE_INDEXEDDB | | |
| 1120 BrowsingDataRemover::REMOVE_WEBSQL, | |
| 1121 builder); | |
| 1122 | |
| 1123 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1124 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1125 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1126 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1127 BrowsingDataRemover::REMOVE_INDEXEDDB | | |
| 1128 BrowsingDataRemover::REMOVE_WEBSQL, | |
| 1129 GetRemovalMask()); | |
| 1130 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1131 | |
| 1132 // Verify storage partition related stuffs. | |
| 1133 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 1134 | |
| 1135 EXPECT_EQ(removal_data.remove_mask, | |
| 1136 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
| 1137 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
| 1138 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
| 1139 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
| 1140 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
| 1141 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
| 1142 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 1143 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 1144 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
| 1145 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
| 1146 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
| 1147 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin4, mock_policy())); | |
| 1148 } | |
| 1149 | |
| 1150 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForLastHour) { | |
| 1151 BlockUntilBrowsingDataRemoved( | |
| 1152 AnHourAgo(), base::Time::Max(), | |
| 1153 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1154 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 1155 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1156 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1157 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1158 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 1159 false); | |
| 1160 | |
| 1161 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1162 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 1163 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1164 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1165 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1166 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 1167 GetRemovalMask()); | |
| 1168 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1169 | |
| 1170 // Verify storage partition related stuffs. | |
| 1171 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 1172 | |
| 1173 EXPECT_EQ(removal_data.remove_mask, | |
| 1174 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
| 1175 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
| 1176 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
| 1177 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
| 1178 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
| 1179 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
| 1180 | |
| 1181 // Persistent data would be left out since we are not removing from | |
| 1182 // beginning of time. | |
| 1183 uint32_t expected_quota_mask = | |
| 1184 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; | |
| 1185 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask); | |
| 1186 // Check removal begin time. | |
| 1187 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
| 1188 } | |
| 1189 | |
| 1190 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForLastWeek) { | |
| 1191 BlockUntilBrowsingDataRemoved( | |
| 1192 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(), | |
| 1193 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1194 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 1195 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1196 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1197 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1198 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 1199 false); | |
| 1200 | |
| 1201 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1202 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 1203 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1204 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1205 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1206 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 1207 GetRemovalMask()); | |
| 1208 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1209 | |
| 1210 // Verify storage partition related stuffs. | |
| 1211 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 1212 | |
| 1213 EXPECT_EQ(removal_data.remove_mask, | |
| 1214 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
| 1215 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
| 1216 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
| 1217 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
| 1218 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
| 1219 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
| 1220 | |
| 1221 // Persistent data would be left out since we are not removing from | |
| 1222 // beginning of time. | |
| 1223 uint32_t expected_quota_mask = | |
| 1224 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; | |
| 1225 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask); | |
| 1226 // Check removal begin time. | |
| 1227 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
| 1228 } | |
| 1229 | |
| 1230 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedUnprotectedOrigins) { | |
| 1231 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 1232 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy(); | |
| 1233 // Protect kOrigin1. | |
| 1234 policy->AddProtected(kOrigin1.GetOrigin()); | |
| 1235 #endif | |
| 1236 | |
| 1237 BlockUntilBrowsingDataRemoved( | |
| 1238 base::Time(), base::Time::Max(), | |
| 1239 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1240 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 1241 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1242 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1243 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1244 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 1245 false); | |
| 1246 | |
| 1247 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1248 BrowsingDataRemover::REMOVE_WEBSQL | | |
| 1249 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1250 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1251 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1252 BrowsingDataRemover::REMOVE_INDEXEDDB, | |
| 1253 GetRemovalMask()); | |
| 1254 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1255 | |
| 1256 // Verify storage partition related stuffs. | |
| 1257 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 1258 | |
| 1259 EXPECT_EQ(removal_data.remove_mask, | |
| 1260 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
| 1261 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
| 1262 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
| 1263 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
| 1264 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
| 1265 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
| 1266 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 1267 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 1268 | |
| 1269 // Check OriginMatcherFunction. | |
| 1270 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(), | |
| 1271 removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
| 1272 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
| 1273 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
| 1274 } | |
| 1275 | |
| 1276 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedSpecificOrigin) { | |
| 1277 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 1278 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy(); | |
| 1279 // Protect kOrigin1. | |
| 1280 policy->AddProtected(kOrigin1.GetOrigin()); | |
| 1281 #endif | |
| 1282 | |
| 1283 RegistrableDomainFilterBuilder builder( | |
| 1284 RegistrableDomainFilterBuilder::WHITELIST); | |
| 1285 builder.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 1286 | |
| 1287 // Try to remove kOrigin1. Expect failure. | |
| 1288 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
| 1289 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1290 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1291 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1292 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1293 BrowsingDataRemover::REMOVE_INDEXEDDB | | |
| 1294 BrowsingDataRemover::REMOVE_WEBSQL, | |
| 1295 builder); | |
| 1296 | |
| 1297 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1298 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1299 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1300 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1301 BrowsingDataRemover::REMOVE_INDEXEDDB | | |
| 1302 BrowsingDataRemover::REMOVE_WEBSQL, | |
| 1303 GetRemovalMask()); | |
| 1304 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1305 | |
| 1306 // Verify storage partition related stuffs. | |
| 1307 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 1308 | |
| 1309 EXPECT_EQ(removal_data.remove_mask, | |
| 1310 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
| 1311 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
| 1312 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
| 1313 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
| 1314 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
| 1315 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
| 1316 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 1317 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 1318 | |
| 1319 // Check OriginMatcherFunction. | |
| 1320 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(), | |
| 1321 removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
| 1322 // Since we use the matcher function to validate origins now, this should | |
| 1323 // return false for the origins we're not trying to clear. | |
| 1324 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
| 1325 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
| 1326 } | |
| 1327 | |
| 1328 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedOrigins) { | |
| 1329 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 1330 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy(); | |
| 1331 // Protect kOrigin1. | |
| 1332 policy->AddProtected(kOrigin1.GetOrigin()); | |
| 1333 #endif | |
| 1334 | |
| 1335 // Try to remove kOrigin1. Expect success. | |
| 1336 BlockUntilBrowsingDataRemoved( | |
| 1337 base::Time(), base::Time::Max(), | |
| 1338 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1339 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1340 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1341 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1342 BrowsingDataRemover::REMOVE_INDEXEDDB | | |
| 1343 BrowsingDataRemover::REMOVE_WEBSQL, | |
| 1344 true); | |
| 1345 | |
| 1346 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1347 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1348 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1349 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1350 BrowsingDataRemover::REMOVE_INDEXEDDB | | |
| 1351 BrowsingDataRemover::REMOVE_WEBSQL, | |
| 1352 GetRemovalMask()); | |
| 1353 EXPECT_EQ(BrowsingDataHelper::PROTECTED_WEB | | |
| 1354 BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1355 | |
| 1356 // Verify storage partition related stuffs. | |
| 1357 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 1358 | |
| 1359 EXPECT_EQ(removal_data.remove_mask, | |
| 1360 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
| 1361 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
| 1362 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
| 1363 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
| 1364 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
| 1365 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
| 1366 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 1367 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 1368 | |
| 1369 // Check OriginMatcherFunction, |kOrigin1| would match mask since we | |
| 1370 // would have 'protected' specified in origin_type_mask. | |
| 1371 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
| 1372 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
| 1373 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
| 1374 } | |
| 1375 | |
| 1376 TEST_F(BrowsingDataRemoverImplTest, | |
| 1377 RemoveQuotaManagedIgnoreExtensionsAndDevTools) { | |
| 1378 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 1379 CreateMockPolicy(); | |
| 1380 #endif | |
| 1381 | |
| 1382 BlockUntilBrowsingDataRemoved( | |
| 1383 base::Time(), base::Time::Max(), | |
| 1384 BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1385 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1386 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1387 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1388 BrowsingDataRemover::REMOVE_INDEXEDDB | | |
| 1389 BrowsingDataRemover::REMOVE_WEBSQL, | |
| 1390 false); | |
| 1391 | |
| 1392 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE | | |
| 1393 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | |
| 1394 BrowsingDataRemover::REMOVE_CACHE_STORAGE | | |
| 1395 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | |
| 1396 BrowsingDataRemover::REMOVE_INDEXEDDB | | |
| 1397 BrowsingDataRemover::REMOVE_WEBSQL, | |
| 1398 GetRemovalMask()); | |
| 1399 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1400 | |
| 1401 // Verify storage partition related stuffs. | |
| 1402 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 1403 | |
| 1404 EXPECT_EQ(removal_data.remove_mask, | |
| 1405 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
| 1406 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
| 1407 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
| 1408 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
| 1409 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
| 1410 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
| 1411 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 1412 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
| 1413 | |
| 1414 // Check that extension and devtools data wouldn't be removed, that is, | |
| 1415 // origin matcher would not match these origin. | |
| 1416 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); | |
| 1417 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy())); | |
| 1418 } | |
| 1419 | |
| 1420 class InspectableCompletionObserver | |
| 1421 : public BrowsingDataRemoverCompletionObserver { | |
| 1422 public: | |
| 1423 explicit InspectableCompletionObserver(BrowsingDataRemover* remover) | |
| 1424 : BrowsingDataRemoverCompletionObserver(remover) {} | |
| 1425 ~InspectableCompletionObserver() override {} | |
| 1426 | |
| 1427 bool called() { return called_; } | |
| 1428 | |
| 1429 protected: | |
| 1430 void OnBrowsingDataRemoverDone() override { | |
| 1431 BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone(); | |
| 1432 called_ = true; | |
| 1433 } | |
| 1434 | |
| 1435 private: | |
| 1436 bool called_ = false; | |
| 1437 }; | |
| 1438 | |
| 1439 TEST_F(BrowsingDataRemoverImplTest, CompletionInhibition) { | |
| 1440 // The |completion_inhibitor| on the stack should prevent removal sessions | |
| 1441 // from completing until after ContinueToCompletion() is called. | |
| 1442 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; | |
| 1443 | |
| 1444 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | |
| 1445 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | |
| 1446 InspectableCompletionObserver completion_observer(remover); | |
| 1447 remover->RemoveAndReply(base::Time(), base::Time::Max(), | |
| 1448 BrowsingDataRemover::REMOVE_HISTORY, | |
| 1449 BrowsingDataHelper::UNPROTECTED_WEB, | |
| 1450 &completion_observer); | |
| 1451 | |
| 1452 // Process messages until the inhibitor is notified, and then some, to make | |
| 1453 // sure we do not complete asynchronously before ContinueToCompletion() is | |
| 1454 // called. | |
| 1455 completion_inhibitor.BlockUntilNearCompletion(); | |
| 1456 base::RunLoop().RunUntilIdle(); | |
| 1457 | |
| 1458 // Verify that the removal has not yet been completed and the observer has | |
| 1459 // not been called. | |
| 1460 EXPECT_TRUE(remover->is_removing()); | |
| 1461 EXPECT_FALSE(completion_observer.called()); | |
| 1462 | |
| 1463 // Now run the removal process until completion, and verify that observers are | |
| 1464 // now notified, and the notifications is sent out. | |
| 1465 completion_inhibitor.ContinueToCompletion(); | |
| 1466 completion_observer.BlockUntilCompletion(); | |
| 1467 | |
| 1468 EXPECT_FALSE(remover->is_removing()); | |
| 1469 EXPECT_TRUE(completion_observer.called()); | |
| 1470 } | |
| 1471 | |
| 1472 TEST_F(BrowsingDataRemoverImplTest, EarlyShutdown) { | |
| 1473 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | |
| 1474 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | |
| 1475 InspectableCompletionObserver completion_observer(remover); | |
| 1476 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; | |
| 1477 remover->RemoveAndReply(base::Time(), base::Time::Max(), | |
| 1478 BrowsingDataRemover::REMOVE_HISTORY, | |
| 1479 BrowsingDataHelper::UNPROTECTED_WEB, | |
| 1480 &completion_observer); | |
| 1481 | |
| 1482 completion_inhibitor.BlockUntilNearCompletion(); | |
| 1483 | |
| 1484 // Verify that the deletion has not yet been completed and the observer has | |
| 1485 // not been called. | |
| 1486 EXPECT_TRUE(remover->is_removing()); | |
| 1487 EXPECT_FALSE(completion_observer.called()); | |
| 1488 | |
| 1489 // Destroying the profile should trigger the notification. | |
| 1490 DestroyBrowserContext(); | |
| 1491 | |
| 1492 EXPECT_TRUE(completion_observer.called()); | |
| 1493 | |
| 1494 // Finishing after shutdown shouldn't break anything. | |
| 1495 completion_inhibitor.ContinueToCompletion(); | |
| 1496 completion_observer.BlockUntilCompletion(); | |
| 1497 } | |
| 1498 | |
| 1499 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByTimeOnly) { | |
| 1500 RemoveDownloadsTester tester(GetBrowserContext()); | |
| 1501 base::Callback<bool(const GURL&)> filter = | |
| 1502 BrowsingDataFilterBuilder::BuildNoopFilter(); | |
| 1503 | |
| 1504 EXPECT_CALL( | |
| 1505 *tester.download_manager(), | |
| 1506 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); | |
| 1507 | |
| 1508 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1509 BrowsingDataRemover::REMOVE_DOWNLOADS, false); | |
| 1510 } | |
| 1511 | |
| 1512 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByOrigin) { | |
| 1513 RemoveDownloadsTester tester(GetBrowserContext()); | |
| 1514 RegistrableDomainFilterBuilder builder( | |
| 1515 RegistrableDomainFilterBuilder::WHITELIST); | |
| 1516 builder.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 1517 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter(); | |
| 1518 | |
| 1519 EXPECT_CALL( | |
| 1520 *tester.download_manager(), | |
| 1521 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); | |
| 1522 | |
| 1523 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
| 1524 BrowsingDataRemover::REMOVE_DOWNLOADS, builder); | |
| 1525 } | |
| 1526 | |
| 1527 class MultipleTasksObserver { | |
| 1528 public: | |
| 1529 // A simple implementation of BrowsingDataRemover::Observer. | |
| 1530 // MultipleTasksObserver will use several instances of Target to test | |
| 1531 // that completion callbacks are returned to the correct one. | |
| 1532 class Target : public BrowsingDataRemover::Observer { | |
| 1533 public: | |
| 1534 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover) | |
| 1535 : parent_(parent), | |
| 1536 observer_(this) { | |
| 1537 observer_.Add(remover); | |
| 1538 } | |
| 1539 ~Target() override {} | |
| 1540 | |
| 1541 void OnBrowsingDataRemoverDone() override { | |
| 1542 parent_->SetLastCalledTarget(this); | |
| 1543 } | |
| 1544 | |
| 1545 private: | |
| 1546 MultipleTasksObserver* parent_; | |
| 1547 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> | |
| 1548 observer_; | |
| 1549 }; | |
| 1550 | |
| 1551 explicit MultipleTasksObserver(BrowsingDataRemover* remover) | |
| 1552 : target_a_(this, remover), | |
| 1553 target_b_(this, remover), | |
| 1554 last_called_target_(nullptr) {} | |
| 1555 ~MultipleTasksObserver() {} | |
| 1556 | |
| 1557 void ClearLastCalledTarget() { | |
| 1558 last_called_target_ = nullptr; | |
| 1559 } | |
| 1560 | |
| 1561 Target* GetLastCalledTarget() { | |
| 1562 return last_called_target_; | |
| 1563 } | |
| 1564 | |
| 1565 Target* target_a() { return &target_a_; } | |
| 1566 Target* target_b() { return &target_b_; } | |
| 1567 | |
| 1568 private: | |
| 1569 void SetLastCalledTarget(Target* target) { | |
| 1570 DCHECK(!last_called_target_) | |
| 1571 << "Call ClearLastCalledTarget() before every removal task."; | |
| 1572 last_called_target_ = target; | |
| 1573 } | |
| 1574 | |
| 1575 Target target_a_; | |
| 1576 Target target_b_; | |
| 1577 Target* last_called_target_; | |
| 1578 }; | |
| 1579 | |
| 1580 TEST_F(BrowsingDataRemoverImplTest, MultipleTasks) { | |
| 1581 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | |
| 1582 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | |
| 1583 EXPECT_FALSE(remover->is_removing()); | |
| 1584 | |
| 1585 std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_1( | |
| 1586 new RegistrableDomainFilterBuilder( | |
| 1587 RegistrableDomainFilterBuilder::WHITELIST)); | |
| 1588 std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_2( | |
| 1589 new RegistrableDomainFilterBuilder( | |
| 1590 RegistrableDomainFilterBuilder::BLACKLIST)); | |
| 1591 filter_builder_2->AddRegisterableDomain("example.com"); | |
| 1592 | |
| 1593 MultipleTasksObserver observer(remover); | |
| 1594 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; | |
| 1595 | |
| 1596 // Test several tasks with various configuration of masks, filters, and target | |
| 1597 // observers. | |
| 1598 std::list<BrowsingDataRemoverImpl::RemovalTask> tasks; | |
| 1599 tasks.emplace_back(base::Time(), base::Time::Max(), | |
| 1600 BrowsingDataRemover::REMOVE_HISTORY, | |
| 1601 BrowsingDataHelper::UNPROTECTED_WEB, | |
| 1602 base::MakeUnique<RegistrableDomainFilterBuilder>( | |
| 1603 RegistrableDomainFilterBuilder::BLACKLIST), | |
| 1604 observer.target_a()); | |
| 1605 tasks.emplace_back(base::Time(), base::Time::Max(), | |
| 1606 BrowsingDataRemover::REMOVE_COOKIES, | |
| 1607 BrowsingDataHelper::PROTECTED_WEB, | |
| 1608 base::MakeUnique<RegistrableDomainFilterBuilder>( | |
| 1609 RegistrableDomainFilterBuilder::BLACKLIST), | |
| 1610 nullptr); | |
| 1611 tasks.emplace_back( | |
| 1612 base::Time::Now(), base::Time::Max(), | |
| 1613 BrowsingDataRemover::REMOVE_PASSWORDS, BrowsingDataHelper::ALL, | |
| 1614 base::MakeUnique<RegistrableDomainFilterBuilder>( | |
| 1615 RegistrableDomainFilterBuilder::BLACKLIST), | |
| 1616 observer.target_b()); | |
| 1617 tasks.emplace_back( | |
| 1618 base::Time(), base::Time::UnixEpoch(), | |
| 1619 BrowsingDataRemover::REMOVE_WEBSQL, | |
| 1620 BrowsingDataHelper::UNPROTECTED_WEB, | |
| 1621 std::move(filter_builder_1), | |
| 1622 observer.target_b()); | |
| 1623 tasks.emplace_back( | |
| 1624 base::Time::UnixEpoch(), base::Time::Now(), | |
| 1625 BrowsingDataRemover::REMOVE_CHANNEL_IDS, | |
| 1626 BrowsingDataHelper::ALL, | |
| 1627 std::move(filter_builder_2), | |
| 1628 nullptr); | |
| 1629 | |
| 1630 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) { | |
| 1631 // All tasks can be directly translated to a RemoveInternal() call. Since | |
| 1632 // that is a private method, we must call the four public versions of | |
| 1633 // Remove.* instead. This also serves as a test that those methods are all | |
| 1634 // correctly reduced to RemoveInternal(). | |
| 1635 if (!task.observer && task.filter_builder->IsEmptyBlacklist()) { | |
| 1636 remover->Remove(task.delete_begin, task.delete_end, | |
| 1637 task.remove_mask, task.origin_type_mask); | |
| 1638 } else if (task.filter_builder->IsEmptyBlacklist()) { | |
| 1639 remover->RemoveAndReply(task.delete_begin, task.delete_end, | |
| 1640 task.remove_mask, task.origin_type_mask, | |
| 1641 task.observer); | |
| 1642 } else if (!task.observer) { | |
| 1643 remover->RemoveWithFilter(task.delete_begin, task.delete_end, | |
| 1644 task.remove_mask, task.origin_type_mask, | |
| 1645 std::move(task.filter_builder)); | |
| 1646 } else { | |
| 1647 remover->RemoveWithFilterAndReply(task.delete_begin, task.delete_end, | |
| 1648 task.remove_mask, task.origin_type_mask, | |
| 1649 std::move(task.filter_builder), | |
| 1650 task.observer); | |
| 1651 } | |
| 1652 } | |
| 1653 | |
| 1654 // Use the inhibitor to stop after every task and check the results. | |
| 1655 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) { | |
| 1656 EXPECT_TRUE(remover->is_removing()); | |
| 1657 observer.ClearLastCalledTarget(); | |
| 1658 | |
| 1659 // Finish the task execution synchronously. | |
| 1660 completion_inhibitor.BlockUntilNearCompletion(); | |
| 1661 completion_inhibitor.ContinueToCompletion(); | |
| 1662 | |
| 1663 // Observers, if any, should have been called by now (since we call | |
| 1664 // observers on the same thread). | |
| 1665 EXPECT_EQ(task.observer, observer.GetLastCalledTarget()); | |
| 1666 | |
| 1667 // TODO(msramek): If BrowsingDataRemover took ownership of the last used | |
| 1668 // filter builder and exposed it, we could also test it here. Make it so. | |
| 1669 EXPECT_EQ(task.remove_mask, GetRemovalMask()); | |
| 1670 EXPECT_EQ(task.origin_type_mask, GetOriginTypeMask()); | |
| 1671 EXPECT_EQ(task.delete_begin, GetBeginTime()); | |
| 1672 } | |
| 1673 | |
| 1674 EXPECT_FALSE(remover->is_removing()); | |
| 1675 } | |
| 1676 | |
| 1677 // The previous test, BrowsingDataRemoverTest.MultipleTasks, tests that the | |
| 1678 // tasks are not mixed up and they are executed in a correct order. However, | |
| 1679 // the completion inhibitor kept synchronizing the execution in order to verify | |
| 1680 // the parameters. This test demonstrates that even running the tasks without | |
| 1681 // inhibition is executed correctly and doesn't crash. | |
| 1682 TEST_F(BrowsingDataRemoverImplTest, MultipleTasksInQuickSuccession) { | |
| 1683 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | |
| 1684 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | |
| 1685 EXPECT_FALSE(remover->is_removing()); | |
| 1686 | |
| 1687 int test_removal_masks[] = { | |
| 1688 BrowsingDataRemover::REMOVE_COOKIES, | |
| 1689 BrowsingDataRemover::REMOVE_PASSWORDS, | |
| 1690 BrowsingDataRemover::REMOVE_COOKIES, | |
| 1691 BrowsingDataRemover::REMOVE_COOKIES, | |
| 1692 BrowsingDataRemover::REMOVE_COOKIES, | |
| 1693 BrowsingDataRemover::REMOVE_HISTORY, | |
| 1694 BrowsingDataRemover::REMOVE_HISTORY, | |
| 1695 BrowsingDataRemover::REMOVE_HISTORY, | |
| 1696 BrowsingDataRemover::REMOVE_COOKIES | BrowsingDataRemover::REMOVE_HISTORY, | |
| 1697 BrowsingDataRemover::REMOVE_COOKIES | BrowsingDataRemover::REMOVE_HISTORY, | |
| 1698 BrowsingDataRemover::REMOVE_COOKIES | | |
| 1699 BrowsingDataRemover::REMOVE_HISTORY | | |
| 1700 BrowsingDataRemover::REMOVE_PASSWORDS, | |
| 1701 BrowsingDataRemover::REMOVE_PASSWORDS, | |
| 1702 BrowsingDataRemover::REMOVE_PASSWORDS, | |
| 1703 }; | |
| 1704 | |
| 1705 for (int removal_mask : test_removal_masks) { | |
| 1706 remover->Remove(base::Time(), base::Time::Max(), removal_mask, | |
| 1707 BrowsingDataHelper::UNPROTECTED_WEB); | |
| 1708 } | |
| 1709 | |
| 1710 EXPECT_TRUE(remover->is_removing()); | |
| 1711 | |
| 1712 // Add one more deletion and wait for it. | |
| 1713 BlockUntilBrowsingDataRemoved( | |
| 1714 base::Time(), base::Time::Max(), | |
| 1715 BrowsingDataRemover::REMOVE_COOKIES, | |
| 1716 BrowsingDataHelper::UNPROTECTED_WEB); | |
| 1717 | |
| 1718 EXPECT_FALSE(remover->is_removing()); | |
| 1719 } | |
| OLD | NEW |