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 "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
| 6 |
| 7 #include "base/guid.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 13 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 14 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 15 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 16 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" |
| 17 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
| 18 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
| 19 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h" |
| 20 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 21 #include "chrome/browser/domain_reliability/service_factory.h" |
| 22 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 23 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 24 #include "chrome/browser/history/history_service_factory.h" |
| 25 #include "chrome/browser/password_manager/password_store_factory.h" |
| 26 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
| 27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 28 #include "chrome/browser/storage/durable_storage_permission_context.h" |
| 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/test/base/testing_browser_process.h" |
| 31 #include "chrome/test/base/testing_profile.h" |
| 32 #include "components/autofill/core/browser/autofill_profile.h" |
| 33 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 34 #include "components/autofill/core/browser/credit_card.h" |
| 35 #include "components/autofill/core/browser/personal_data_manager.h" |
| 36 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 37 #include "components/autofill/core/common/autofill_constants.h" |
| 38 #include "components/bookmarks/browser/bookmark_model.h" |
| 39 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 40 #include "components/browsing_data/core/browsing_data_utils.h" |
| 41 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 42 #include "components/content_settings/core/common/content_settings.h" |
| 43 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 44 #include "components/domain_reliability/clear_mode.h" |
| 45 #include "components/domain_reliability/monitor.h" |
| 46 #include "components/domain_reliability/service.h" |
| 47 #include "components/favicon/core/favicon_service.h" |
| 48 #include "components/history/core/browser/history_service.h" |
| 49 #include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h" |
| 50 #include "components/omnibox/browser/omnibox_pref_names.h" |
| 51 #include "components/os_crypt/os_crypt_mocker.h" |
| 52 #include "components/password_manager/core/browser/mock_password_store.h" |
| 53 #include "components/password_manager/core/browser/password_manager_test_utils.h
" |
| 54 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 55 #include "components/prefs/testing_pref_service.h" |
| 56 #include "content/public/test/mock_download_manager.h" |
| 57 #include "content/public/test/test_browser_thread_bundle.h" |
| 58 #include "content/public/test/test_utils.h" |
| 59 #include "net/cookies/cookie_store.h" |
| 60 #include "net/http/http_transaction_factory.h" |
| 61 #include "net/url_request/url_request_context.h" |
| 62 #include "net/url_request/url_request_context_getter.h" |
| 63 #include "third_party/skia/include/core/SkBitmap.h" |
| 64 #include "ui/gfx/favicon_size.h" |
| 65 |
| 66 #if defined(OS_ANDROID) |
| 67 #include "chrome/browser/android/webapps/webapp_registry.h" |
| 68 #endif |
| 69 |
| 70 #if defined(OS_CHROMEOS) |
| 71 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 72 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 73 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 74 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 75 #include "chromeos/dbus/dbus_thread_manager.h" |
| 76 #include "chromeos/dbus/mock_cryptohome_client.h" |
| 77 #include "components/signin/core/account_id/account_id.h" |
| 78 #endif |
| 79 |
| 80 #if BUILDFLAG(ENABLE_PLUGINS) |
| 81 #include "chrome/browser/browsing_data/mock_browsing_data_flash_lso_helper.h" |
| 82 #endif |
| 83 |
| 84 using domain_reliability::CLEAR_BEACONS; |
| 85 using domain_reliability::CLEAR_CONTEXTS; |
| 86 using domain_reliability::DomainReliabilityClearMode; |
| 87 using domain_reliability::DomainReliabilityMonitor; |
| 88 using domain_reliability::DomainReliabilityService; |
| 89 using domain_reliability::DomainReliabilityServiceFactory; |
| 90 using testing::_; |
| 91 using testing::ByRef; |
| 92 using testing::Eq; |
| 93 using testing::Invoke; |
| 94 using testing::IsEmpty; |
| 95 using testing::Matcher; |
| 96 using testing::MakeMatcher; |
| 97 using testing::MatcherInterface; |
| 98 using testing::MatchResultListener; |
| 99 using testing::Not; |
| 100 using testing::Return; |
| 101 using testing::SizeIs; |
| 102 using testing::WithArgs; |
| 103 |
| 104 namespace { |
| 105 |
| 106 const char kTestOrigin1[] = "http://host1.com:1/"; |
| 107 const char kTestRegisterableDomain1[] = "host1.com"; |
| 108 const char kTestOrigin2[] = "http://host2.com:1/"; |
| 109 const char kTestOrigin3[] = "http://host3.com:1/"; |
| 110 const char kTestRegisterableDomain3[] = "host3.com"; |
| 111 const char kTestOrigin4[] = "https://host3.com:1/"; |
| 112 |
| 113 // For HTTP auth. |
| 114 const char kTestRealm[] = "TestRealm"; |
| 115 |
| 116 // For Autofill. |
| 117 const char kWebOrigin[] = "https://www.example.com/"; |
| 118 |
| 119 const GURL kOrigin1(kTestOrigin1); |
| 120 const GURL kOrigin2(kTestOrigin2); |
| 121 const GURL kOrigin3(kTestOrigin3); |
| 122 const GURL kOrigin4(kTestOrigin4); |
| 123 |
| 124 // Testers -------------------------------------------------------------------- |
| 125 |
| 126 #if defined(OS_ANDROID) |
| 127 class TestWebappRegistry : public WebappRegistry { |
| 128 public: |
| 129 TestWebappRegistry() : WebappRegistry() { } |
| 130 |
| 131 void UnregisterWebappsForUrls( |
| 132 const base::Callback<bool(const GURL&)>& url_filter) override { |
| 133 // Mocks out a JNI call. |
| 134 } |
| 135 |
| 136 void ClearWebappHistoryForUrls( |
| 137 const base::Callback<bool(const GURL&)>& url_filter) override { |
| 138 // Mocks out a JNI call. |
| 139 } |
| 140 }; |
| 141 #endif |
| 142 |
| 143 #if defined(OS_CHROMEOS) |
| 144 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) { |
| 145 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 146 FROM_HERE, |
| 147 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true)); |
| 148 } |
| 149 #endif |
| 150 |
| 151 class RemoveCookieTester { |
| 152 public: |
| 153 RemoveCookieTester() {} |
| 154 |
| 155 // Returns true, if the given cookie exists in the cookie store. |
| 156 bool ContainsCookie() { |
| 157 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 158 new content::MessageLoopRunner; |
| 159 quit_closure_ = message_loop_runner->QuitClosure(); |
| 160 get_cookie_success_ = false; |
| 161 cookie_store_->GetCookiesWithOptionsAsync( |
| 162 kOrigin1, net::CookieOptions(), |
| 163 base::Bind(&RemoveCookieTester::GetCookieCallback, |
| 164 base::Unretained(this))); |
| 165 message_loop_runner->Run(); |
| 166 return get_cookie_success_; |
| 167 } |
| 168 |
| 169 void AddCookie() { |
| 170 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 171 new content::MessageLoopRunner; |
| 172 quit_closure_ = message_loop_runner->QuitClosure(); |
| 173 cookie_store_->SetCookieWithOptionsAsync( |
| 174 kOrigin1, "A=1", net::CookieOptions(), |
| 175 base::Bind(&RemoveCookieTester::SetCookieCallback, |
| 176 base::Unretained(this))); |
| 177 message_loop_runner->Run(); |
| 178 } |
| 179 |
| 180 protected: |
| 181 void SetCookieStore(net::CookieStore* cookie_store) { |
| 182 cookie_store_ = cookie_store; |
| 183 } |
| 184 |
| 185 private: |
| 186 void GetCookieCallback(const std::string& cookies) { |
| 187 if (cookies == "A=1") { |
| 188 get_cookie_success_ = true; |
| 189 } else { |
| 190 EXPECT_EQ("", cookies); |
| 191 get_cookie_success_ = false; |
| 192 } |
| 193 quit_closure_.Run(); |
| 194 } |
| 195 |
| 196 void SetCookieCallback(bool result) { |
| 197 ASSERT_TRUE(result); |
| 198 quit_closure_.Run(); |
| 199 } |
| 200 |
| 201 bool get_cookie_success_ = false; |
| 202 base::Closure quit_closure_; |
| 203 |
| 204 // CookieStore must out live |this|. |
| 205 net::CookieStore* cookie_store_ = nullptr; |
| 206 |
| 207 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); |
| 208 }; |
| 209 |
| 210 void RunClosureAfterCookiesCleared(const base::Closure& task, |
| 211 int cookies_deleted) { |
| 212 task.Run(); |
| 213 } |
| 214 |
| 215 class RemoveSafeBrowsingCookieTester : public RemoveCookieTester { |
| 216 public: |
| 217 RemoveSafeBrowsingCookieTester() |
| 218 : browser_process_(TestingBrowserProcess::GetGlobal()) { |
| 219 scoped_refptr<safe_browsing::SafeBrowsingService> sb_service = |
| 220 safe_browsing::SafeBrowsingService::CreateSafeBrowsingService(); |
| 221 browser_process_->SetSafeBrowsingService(sb_service.get()); |
| 222 sb_service->Initialize(); |
| 223 base::RunLoop().RunUntilIdle(); |
| 224 |
| 225 // Make sure the safe browsing cookie store has no cookies. |
| 226 // TODO(mmenke): Is this really needed? |
| 227 base::RunLoop run_loop; |
| 228 net::URLRequestContext* request_context = |
| 229 sb_service->url_request_context()->GetURLRequestContext(); |
| 230 request_context->cookie_store()->DeleteAllAsync( |
| 231 base::Bind(&RunClosureAfterCookiesCleared, run_loop.QuitClosure())); |
| 232 run_loop.Run(); |
| 233 |
| 234 SetCookieStore(request_context->cookie_store()); |
| 235 } |
| 236 |
| 237 virtual ~RemoveSafeBrowsingCookieTester() { |
| 238 browser_process_->safe_browsing_service()->ShutDown(); |
| 239 base::RunLoop().RunUntilIdle(); |
| 240 browser_process_->SetSafeBrowsingService(nullptr); |
| 241 } |
| 242 |
| 243 private: |
| 244 TestingBrowserProcess* browser_process_; |
| 245 |
| 246 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester); |
| 247 }; |
| 248 |
| 249 class RemoveHistoryTester { |
| 250 public: |
| 251 RemoveHistoryTester() {} |
| 252 |
| 253 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT { |
| 254 if (!profile->CreateHistoryService(true, false)) |
| 255 return false; |
| 256 history_service_ = HistoryServiceFactory::GetForProfile( |
| 257 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 258 return true; |
| 259 } |
| 260 |
| 261 // Returns true, if the given URL exists in the history service. |
| 262 bool HistoryContainsURL(const GURL& url) { |
| 263 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 264 new content::MessageLoopRunner; |
| 265 quit_closure_ = message_loop_runner->QuitClosure(); |
| 266 history_service_->QueryURL( |
| 267 url, |
| 268 true, |
| 269 base::Bind(&RemoveHistoryTester::SaveResultAndQuit, |
| 270 base::Unretained(this)), |
| 271 &tracker_); |
| 272 message_loop_runner->Run(); |
| 273 return query_url_success_; |
| 274 } |
| 275 |
| 276 void AddHistory(const GURL& url, base::Time time) { |
| 277 history_service_->AddPage(url, time, nullptr, 0, GURL(), |
| 278 history::RedirectList(), ui::PAGE_TRANSITION_LINK, |
| 279 history::SOURCE_BROWSED, false); |
| 280 } |
| 281 |
| 282 private: |
| 283 // Callback for HistoryService::QueryURL. |
| 284 void SaveResultAndQuit(bool success, |
| 285 const history::URLRow&, |
| 286 const history::VisitVector&) { |
| 287 query_url_success_ = success; |
| 288 quit_closure_.Run(); |
| 289 } |
| 290 |
| 291 // For History requests. |
| 292 base::CancelableTaskTracker tracker_; |
| 293 bool query_url_success_ = false; |
| 294 base::Closure quit_closure_; |
| 295 |
| 296 // TestingProfile owns the history service; we shouldn't delete it. |
| 297 history::HistoryService* history_service_ = nullptr; |
| 298 |
| 299 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester); |
| 300 }; |
| 301 |
| 302 class RemoveFaviconTester { |
| 303 public: |
| 304 RemoveFaviconTester() {} |
| 305 |
| 306 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT { |
| 307 // Create the history service if it has not been created yet. |
| 308 history_service_ = HistoryServiceFactory::GetForProfile( |
| 309 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 310 if (!history_service_) { |
| 311 if (!profile->CreateHistoryService(true, false)) |
| 312 return false; |
| 313 history_service_ = HistoryServiceFactory::GetForProfile( |
| 314 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 315 } |
| 316 |
| 317 profile->CreateFaviconService(); |
| 318 favicon_service_ = FaviconServiceFactory::GetForProfile( |
| 319 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 320 return true; |
| 321 } |
| 322 |
| 323 // Returns true if there is a favicon stored for |page_url| in the favicon |
| 324 // database. |
| 325 bool HasFaviconForPageURL(const GURL& page_url) { |
| 326 RequestFaviconSyncForPageURL(page_url); |
| 327 return got_favicon_; |
| 328 } |
| 329 |
| 330 // Returns true if: |
| 331 // - There is a favicon stored for |page_url| in the favicon database. |
| 332 // - The stored favicon is expired. |
| 333 bool HasExpiredFaviconForPageURL(const GURL& page_url) { |
| 334 RequestFaviconSyncForPageURL(page_url); |
| 335 return got_expired_favicon_; |
| 336 } |
| 337 |
| 338 // Adds a visit to history and stores an arbitrary favicon bitmap for |
| 339 // |page_url|. |
| 340 void VisitAndAddFavicon(const GURL& page_url) { |
| 341 history_service_->AddPage(page_url, base::Time::Now(), nullptr, 0, GURL(), |
| 342 history::RedirectList(), ui::PAGE_TRANSITION_LINK, |
| 343 history::SOURCE_BROWSED, false); |
| 344 |
| 345 SkBitmap bitmap; |
| 346 bitmap.allocN32Pixels(gfx::kFaviconSize, gfx::kFaviconSize); |
| 347 bitmap.eraseColor(SK_ColorBLUE); |
| 348 favicon_service_->SetFavicons(page_url, page_url, favicon_base::FAVICON, |
| 349 gfx::Image::CreateFrom1xBitmap(bitmap)); |
| 350 } |
| 351 |
| 352 private: |
| 353 // Synchronously requests the favicon for |page_url| from the favicon |
| 354 // database. |
| 355 void RequestFaviconSyncForPageURL(const GURL& page_url) { |
| 356 base::RunLoop run_loop; |
| 357 quit_closure_ = run_loop.QuitClosure(); |
| 358 favicon_service_->GetRawFaviconForPageURL( |
| 359 page_url, |
| 360 favicon_base::FAVICON, |
| 361 gfx::kFaviconSize, |
| 362 base::Bind(&RemoveFaviconTester::SaveResultAndQuit, |
| 363 base::Unretained(this)), |
| 364 &tracker_); |
| 365 run_loop.Run(); |
| 366 } |
| 367 |
| 368 // Callback for HistoryService::QueryURL. |
| 369 void SaveResultAndQuit(const favicon_base::FaviconRawBitmapResult& result) { |
| 370 got_favicon_ = result.is_valid(); |
| 371 got_expired_favicon_ = result.is_valid() && result.expired; |
| 372 quit_closure_.Run(); |
| 373 } |
| 374 |
| 375 // For favicon requests. |
| 376 base::CancelableTaskTracker tracker_; |
| 377 bool got_favicon_ = false; |
| 378 bool got_expired_favicon_ = false; |
| 379 base::Closure quit_closure_; |
| 380 |
| 381 // Owned by TestingProfile. |
| 382 history::HistoryService* history_service_ = nullptr; |
| 383 favicon::FaviconService* favicon_service_ = nullptr; |
| 384 |
| 385 DISALLOW_COPY_AND_ASSIGN(RemoveFaviconTester); |
| 386 }; |
| 387 |
| 388 class MockDomainReliabilityService : public DomainReliabilityService { |
| 389 public: |
| 390 MockDomainReliabilityService() {} |
| 391 |
| 392 ~MockDomainReliabilityService() override {} |
| 393 |
| 394 std::unique_ptr<DomainReliabilityMonitor> CreateMonitor( |
| 395 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) |
| 396 override { |
| 397 NOTREACHED(); |
| 398 return std::unique_ptr<DomainReliabilityMonitor>(); |
| 399 } |
| 400 |
| 401 void ClearBrowsingData( |
| 402 DomainReliabilityClearMode clear_mode, |
| 403 const base::Callback<bool(const GURL&)>& origin_filter, |
| 404 const base::Closure& callback) override { |
| 405 clear_count_++; |
| 406 last_clear_mode_ = clear_mode; |
| 407 last_filter_ = origin_filter; |
| 408 callback.Run(); |
| 409 } |
| 410 |
| 411 void GetWebUIData(const base::Callback<void(std::unique_ptr<base::Value>)>& |
| 412 callback) const override { |
| 413 NOTREACHED(); |
| 414 } |
| 415 |
| 416 void SetDiscardUploadsForTesting(bool discard_uploads) override { |
| 417 NOTREACHED(); |
| 418 } |
| 419 |
| 420 void AddContextForTesting( |
| 421 std::unique_ptr<const domain_reliability::DomainReliabilityConfig> config) |
| 422 override { |
| 423 NOTREACHED(); |
| 424 } |
| 425 |
| 426 void ForceUploadsForTesting() override { NOTREACHED(); } |
| 427 |
| 428 int clear_count() const { return clear_count_; } |
| 429 |
| 430 DomainReliabilityClearMode last_clear_mode() const { |
| 431 return last_clear_mode_; |
| 432 } |
| 433 |
| 434 const base::Callback<bool(const GURL&)>& last_filter() const { |
| 435 return last_filter_; |
| 436 } |
| 437 |
| 438 private: |
| 439 unsigned clear_count_ = 0; |
| 440 DomainReliabilityClearMode last_clear_mode_; |
| 441 base::Callback<bool(const GURL&)> last_filter_; |
| 442 }; |
| 443 |
| 444 struct TestingDomainReliabilityServiceFactoryUserData |
| 445 : public base::SupportsUserData::Data { |
| 446 TestingDomainReliabilityServiceFactoryUserData( |
| 447 content::BrowserContext* context, |
| 448 MockDomainReliabilityService* service) |
| 449 : context(context), |
| 450 service(service), |
| 451 attached(false) {} |
| 452 ~TestingDomainReliabilityServiceFactoryUserData() override {} |
| 453 |
| 454 content::BrowserContext* const context; |
| 455 MockDomainReliabilityService* const service; |
| 456 bool attached; |
| 457 |
| 458 static const void* kKey; |
| 459 }; |
| 460 |
| 461 // static |
| 462 const void* TestingDomainReliabilityServiceFactoryUserData::kKey = |
| 463 &TestingDomainReliabilityServiceFactoryUserData::kKey; |
| 464 |
| 465 std::unique_ptr<KeyedService> TestingDomainReliabilityServiceFactoryFunction( |
| 466 content::BrowserContext* context) { |
| 467 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey; |
| 468 |
| 469 TestingDomainReliabilityServiceFactoryUserData* data = |
| 470 static_cast<TestingDomainReliabilityServiceFactoryUserData*>( |
| 471 context->GetUserData(kKey)); |
| 472 EXPECT_TRUE(data); |
| 473 EXPECT_EQ(data->context, context); |
| 474 EXPECT_FALSE(data->attached); |
| 475 |
| 476 data->attached = true; |
| 477 return base::WrapUnique(data->service); |
| 478 } |
| 479 |
| 480 class ClearDomainReliabilityTester { |
| 481 public: |
| 482 explicit ClearDomainReliabilityTester(TestingProfile* profile) : |
| 483 profile_(profile), |
| 484 mock_service_(new MockDomainReliabilityService()) { |
| 485 AttachService(); |
| 486 } |
| 487 |
| 488 unsigned clear_count() const { return mock_service_->clear_count(); } |
| 489 |
| 490 DomainReliabilityClearMode last_clear_mode() const { |
| 491 return mock_service_->last_clear_mode(); |
| 492 } |
| 493 |
| 494 const base::Callback<bool(const GURL&)>& last_filter() const { |
| 495 return mock_service_->last_filter(); |
| 496 } |
| 497 |
| 498 private: |
| 499 void AttachService() { |
| 500 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey; |
| 501 |
| 502 // Attach kludgey UserData struct to profile. |
| 503 TestingDomainReliabilityServiceFactoryUserData* data = |
| 504 new TestingDomainReliabilityServiceFactoryUserData(profile_, |
| 505 mock_service_); |
| 506 EXPECT_FALSE(profile_->GetUserData(kKey)); |
| 507 profile_->SetUserData(kKey, data); |
| 508 |
| 509 // Set and use factory that will attach service stuffed in kludgey struct. |
| 510 DomainReliabilityServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 511 profile_, |
| 512 &TestingDomainReliabilityServiceFactoryFunction); |
| 513 |
| 514 // Verify and detach kludgey struct. |
| 515 EXPECT_EQ(data, profile_->GetUserData(kKey)); |
| 516 EXPECT_TRUE(data->attached); |
| 517 profile_->RemoveUserData(kKey); |
| 518 } |
| 519 |
| 520 TestingProfile* profile_; |
| 521 MockDomainReliabilityService* mock_service_; |
| 522 }; |
| 523 |
| 524 class RemovePasswordsTester { |
| 525 public: |
| 526 explicit RemovePasswordsTester(TestingProfile* testing_profile) { |
| 527 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( |
| 528 testing_profile, |
| 529 password_manager::BuildPasswordStore< |
| 530 content::BrowserContext, |
| 531 testing::NiceMock<password_manager::MockPasswordStore>>); |
| 532 |
| 533 store_ = static_cast<password_manager::MockPasswordStore*>( |
| 534 PasswordStoreFactory::GetInstance() |
| 535 ->GetForProfile(testing_profile, ServiceAccessType::EXPLICIT_ACCESS) |
| 536 .get()); |
| 537 |
| 538 OSCryptMocker::SetUpWithSingleton(); |
| 539 } |
| 540 |
| 541 ~RemovePasswordsTester() { OSCryptMocker::TearDown(); } |
| 542 |
| 543 password_manager::MockPasswordStore* store() { return store_; } |
| 544 |
| 545 private: |
| 546 password_manager::MockPasswordStore* store_; |
| 547 |
| 548 DISALLOW_COPY_AND_ASSIGN(RemovePasswordsTester); |
| 549 }; |
| 550 |
| 551 class RemovePermissionPromptCountsTest { |
| 552 public: |
| 553 explicit RemovePermissionPromptCountsTest(TestingProfile* profile) |
| 554 : profile_(profile) {} |
| 555 |
| 556 int GetDismissCount(const GURL& url, content::PermissionType permission) { |
| 557 return PermissionDecisionAutoBlocker::GetDismissCount( |
| 558 url, permission, profile_); |
| 559 } |
| 560 |
| 561 int GetIgnoreCount(const GURL& url, content::PermissionType permission) { |
| 562 return PermissionDecisionAutoBlocker::GetIgnoreCount( |
| 563 url, permission, profile_); |
| 564 } |
| 565 |
| 566 int RecordIgnore(const GURL& url, content::PermissionType permission) { |
| 567 return PermissionDecisionAutoBlocker::RecordIgnore(url, permission, |
| 568 profile_); |
| 569 } |
| 570 |
| 571 bool ShouldChangeDismissalToBlock(const GURL& url, |
| 572 content::PermissionType permission) { |
| 573 return PermissionDecisionAutoBlocker::ShouldChangeDismissalToBlock( |
| 574 url, permission, profile_); |
| 575 } |
| 576 |
| 577 private: |
| 578 TestingProfile* profile_; |
| 579 |
| 580 DISALLOW_COPY_AND_ASSIGN(RemovePermissionPromptCountsTest); |
| 581 }; |
| 582 |
| 583 #if BUILDFLAG(ENABLE_PLUGINS) |
| 584 // A small modification to MockBrowsingDataFlashLSOHelper so that it responds |
| 585 // immediately and does not wait for the Notify() call. Otherwise it would |
| 586 // deadlock BrowsingDataRemoverImpl::RemoveImpl. |
| 587 class TestBrowsingDataFlashLSOHelper : public MockBrowsingDataFlashLSOHelper { |
| 588 public: |
| 589 explicit TestBrowsingDataFlashLSOHelper(TestingProfile* profile) |
| 590 : MockBrowsingDataFlashLSOHelper(profile) {} |
| 591 |
| 592 void StartFetching(const GetSitesWithFlashDataCallback& callback) override { |
| 593 MockBrowsingDataFlashLSOHelper::StartFetching(callback); |
| 594 Notify(); |
| 595 } |
| 596 |
| 597 private: |
| 598 ~TestBrowsingDataFlashLSOHelper() override {} |
| 599 |
| 600 DISALLOW_COPY_AND_ASSIGN(TestBrowsingDataFlashLSOHelper); |
| 601 }; |
| 602 |
| 603 class RemovePluginDataTester { |
| 604 public: |
| 605 explicit RemovePluginDataTester(TestingProfile* profile) |
| 606 : helper_(new TestBrowsingDataFlashLSOHelper(profile)) { |
| 607 static_cast<ChromeBrowsingDataRemoverDelegate*>( |
| 608 BrowsingDataRemoverFactory::GetForBrowserContext(profile) |
| 609 ->GetEmbedderDelegate())->OverrideFlashLSOHelperForTesting(helper_); |
| 610 } |
| 611 |
| 612 void AddDomain(const std::string& domain) { |
| 613 helper_->AddFlashLSODomain(domain); |
| 614 } |
| 615 |
| 616 const std::vector<std::string>& GetDomains() { |
| 617 // TestBrowsingDataFlashLSOHelper is synchronous, so we can immediately |
| 618 // return the fetched domains. |
| 619 helper_->StartFetching( |
| 620 base::Bind(&RemovePluginDataTester::OnSitesWithFlashDataFetched, |
| 621 base::Unretained(this))); |
| 622 return domains_; |
| 623 } |
| 624 |
| 625 private: |
| 626 void OnSitesWithFlashDataFetched(const std::vector<std::string>& sites) { |
| 627 domains_ = sites; |
| 628 } |
| 629 |
| 630 std::vector<std::string> domains_; |
| 631 scoped_refptr<TestBrowsingDataFlashLSOHelper> helper_; |
| 632 |
| 633 DISALLOW_COPY_AND_ASSIGN(RemovePluginDataTester); |
| 634 }; |
| 635 #endif |
| 636 |
| 637 // Custom matcher to test the equivalence of two URL filters. Since those are |
| 638 // blackbox predicates, we can only approximate the equivalence by testing |
| 639 // whether the filter give the same answer for several URLs. This is currently |
| 640 // good enough for our testing purposes, to distinguish whitelists |
| 641 // and blacklists, empty and non-empty filters and such. |
| 642 // TODO(msramek): BrowsingDataRemover and some of its backends support URL |
| 643 // filters, but its constructor currently only takes a single URL and constructs |
| 644 // its own url filter. If an url filter was directly passed to |
| 645 // BrowsingDataRemover (what should eventually be the case), we can use the same |
| 646 // instance in the test as well, and thus simply test base::Callback::Equals() |
| 647 // in this matcher. |
| 648 class ProbablySameFilterMatcher |
| 649 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> { |
| 650 public: |
| 651 explicit ProbablySameFilterMatcher( |
| 652 const base::Callback<bool(const GURL&)>& filter) |
| 653 : to_match_(filter) { |
| 654 } |
| 655 |
| 656 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, |
| 657 MatchResultListener* listener) const { |
| 658 if (filter.is_null() && to_match_.is_null()) |
| 659 return true; |
| 660 if (filter.is_null() != to_match_.is_null()) |
| 661 return false; |
| 662 |
| 663 const GURL urls_to_test_[] = |
| 664 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")}; |
| 665 for (GURL url : urls_to_test_) { |
| 666 if (filter.Run(url) != to_match_.Run(url)) { |
| 667 if (listener) |
| 668 *listener << "The filters differ on the URL " << url; |
| 669 return false; |
| 670 } |
| 671 } |
| 672 return true; |
| 673 } |
| 674 |
| 675 virtual void DescribeTo(::std::ostream* os) const { |
| 676 *os << "is probably the same url filter as " << &to_match_; |
| 677 } |
| 678 |
| 679 virtual void DescribeNegationTo(::std::ostream* os) const { |
| 680 *os << "is definitely NOT the same url filter as " << &to_match_; |
| 681 } |
| 682 |
| 683 private: |
| 684 const base::Callback<bool(const GURL&)>& to_match_; |
| 685 }; |
| 686 |
| 687 inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter( |
| 688 const base::Callback<bool(const GURL&)>& filter) { |
| 689 return MakeMatcher(new ProbablySameFilterMatcher(filter)); |
| 690 } |
| 691 |
| 692 bool ProbablySameFilters( |
| 693 const base::Callback<bool(const GURL&)>& filter1, |
| 694 const base::Callback<bool(const GURL&)>& filter2) { |
| 695 return ProbablySameFilter(filter1).MatchAndExplain(filter2, nullptr); |
| 696 } |
| 697 |
| 698 base::Time AnHourAgo() { |
| 699 return base::Time::Now() - base::TimeDelta::FromHours(1); |
| 700 } |
| 701 |
| 702 class RemoveDownloadsTester { |
| 703 public: |
| 704 explicit RemoveDownloadsTester(TestingProfile* testing_profile) |
| 705 : download_manager_(new content::MockDownloadManager()), |
| 706 chrome_download_manager_delegate_(testing_profile) { |
| 707 content::BrowserContext::SetDownloadManagerForTesting(testing_profile, |
| 708 download_manager_); |
| 709 EXPECT_EQ(download_manager_, |
| 710 content::BrowserContext::GetDownloadManager(testing_profile)); |
| 711 |
| 712 EXPECT_CALL(*download_manager_, GetDelegate()) |
| 713 .WillOnce(Return(&chrome_download_manager_delegate_)); |
| 714 EXPECT_CALL(*download_manager_, Shutdown()); |
| 715 } |
| 716 |
| 717 ~RemoveDownloadsTester() { chrome_download_manager_delegate_.Shutdown(); } |
| 718 |
| 719 content::MockDownloadManager* download_manager() { return download_manager_; } |
| 720 |
| 721 private: |
| 722 content::MockDownloadManager* download_manager_; |
| 723 ChromeDownloadManagerDelegate chrome_download_manager_delegate_; |
| 724 |
| 725 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester); |
| 726 }; |
| 727 |
| 728 } // namespace |
| 729 |
| 730 // RemoveAutofillTester is not a part of the anonymous namespace above, as |
| 731 // PersonalDataManager declares it a friend in an empty namespace. |
| 732 class RemoveAutofillTester : public autofill::PersonalDataManagerObserver { |
| 733 public: |
| 734 explicit RemoveAutofillTester(TestingProfile* profile) |
| 735 : personal_data_manager_( |
| 736 autofill::PersonalDataManagerFactory::GetForProfile(profile)) { |
| 737 autofill::test::DisableSystemServices(profile->GetPrefs()); |
| 738 personal_data_manager_->AddObserver(this); |
| 739 } |
| 740 |
| 741 ~RemoveAutofillTester() override { |
| 742 personal_data_manager_->RemoveObserver(this); |
| 743 autofill::test::ReenableSystemServices(); |
| 744 } |
| 745 |
| 746 // Returns true if there are autofill profiles. |
| 747 bool HasProfile() { |
| 748 return !personal_data_manager_->GetProfiles().empty() && |
| 749 !personal_data_manager_->GetCreditCards().empty(); |
| 750 } |
| 751 |
| 752 bool HasOrigin(const std::string& origin) { |
| 753 const std::vector<autofill::AutofillProfile*>& profiles = |
| 754 personal_data_manager_->GetProfiles(); |
| 755 for (const autofill::AutofillProfile* profile : profiles) { |
| 756 if (profile->origin() == origin) |
| 757 return true; |
| 758 } |
| 759 |
| 760 const std::vector<autofill::CreditCard*>& credit_cards = |
| 761 personal_data_manager_->GetCreditCards(); |
| 762 for (const autofill::CreditCard* credit_card : credit_cards) { |
| 763 if (credit_card->origin() == origin) |
| 764 return true; |
| 765 } |
| 766 |
| 767 return false; |
| 768 } |
| 769 |
| 770 // Add two profiles and two credit cards to the database. In each pair, one |
| 771 // entry has a web origin and the other has a Chrome origin. |
| 772 void AddProfilesAndCards() { |
| 773 std::vector<autofill::AutofillProfile> profiles; |
| 774 autofill::AutofillProfile profile; |
| 775 profile.set_guid(base::GenerateGUID()); |
| 776 profile.set_origin(kWebOrigin); |
| 777 profile.SetRawInfo(autofill::NAME_FIRST, base::ASCIIToUTF16("Bob")); |
| 778 profile.SetRawInfo(autofill::NAME_LAST, base::ASCIIToUTF16("Smith")); |
| 779 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, base::ASCIIToUTF16("94043")); |
| 780 profile.SetRawInfo(autofill::EMAIL_ADDRESS, |
| 781 base::ASCIIToUTF16("sue@example.com")); |
| 782 profile.SetRawInfo(autofill::COMPANY_NAME, base::ASCIIToUTF16("Company X")); |
| 783 profiles.push_back(profile); |
| 784 |
| 785 profile.set_guid(base::GenerateGUID()); |
| 786 profile.set_origin(autofill::kSettingsOrigin); |
| 787 profiles.push_back(profile); |
| 788 |
| 789 personal_data_manager_->SetProfiles(&profiles); |
| 790 base::RunLoop().Run(); |
| 791 |
| 792 std::vector<autofill::CreditCard> cards; |
| 793 autofill::CreditCard card; |
| 794 card.set_guid(base::GenerateGUID()); |
| 795 card.set_origin(kWebOrigin); |
| 796 card.SetRawInfo(autofill::CREDIT_CARD_NUMBER, |
| 797 base::ASCIIToUTF16("1234-5678-9012-3456")); |
| 798 cards.push_back(card); |
| 799 |
| 800 card.set_guid(base::GenerateGUID()); |
| 801 card.set_origin(autofill::kSettingsOrigin); |
| 802 cards.push_back(card); |
| 803 |
| 804 personal_data_manager_->SetCreditCards(&cards); |
| 805 base::RunLoop().Run(); |
| 806 } |
| 807 |
| 808 private: |
| 809 void OnPersonalDataChanged() override { |
| 810 base::MessageLoop::current()->QuitWhenIdle(); |
| 811 } |
| 812 |
| 813 autofill::PersonalDataManager* personal_data_manager_; |
| 814 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester); |
| 815 }; |
| 816 |
| 817 // Test Class ----------------------------------------------------------------- |
| 818 |
| 819 class ChromeBrowsingDataRemoverDelegateTest : public testing::Test { |
| 820 public: |
| 821 ChromeBrowsingDataRemoverDelegateTest() |
| 822 : profile_(new TestingProfile()), |
| 823 clear_domain_reliability_tester_(profile_.get()) { |
| 824 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()); |
| 825 |
| 826 #if defined(OS_ANDROID) |
| 827 static_cast<ChromeBrowsingDataRemoverDelegate*>( |
| 828 remover_->GetEmbedderDelegate())->OverrideWebappRegistryForTesting( |
| 829 base::WrapUnique<WebappRegistry>(new TestWebappRegistry())); |
| 830 #endif |
| 831 } |
| 832 |
| 833 void TearDown() override { |
| 834 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor |
| 835 // posts a message to the WEBKIT thread to delete some of its member |
| 836 // variables. We need to ensure that the profile is destroyed, and that |
| 837 // the message loop is cleared out, before destroying the threads and loop. |
| 838 // Otherwise we leak memory. |
| 839 profile_.reset(); |
| 840 base::RunLoop().RunUntilIdle(); |
| 841 |
| 842 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); |
| 843 } |
| 844 |
| 845 ~ChromeBrowsingDataRemoverDelegateTest() override {} |
| 846 |
| 847 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin, |
| 848 const base::Time& delete_end, |
| 849 int remove_mask, |
| 850 bool include_protected_origins) { |
| 851 int origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB; |
| 852 if (include_protected_origins) |
| 853 origin_type_mask |= BrowsingDataHelper::PROTECTED_WEB; |
| 854 |
| 855 BrowsingDataRemoverCompletionObserver completion_observer(remover_); |
| 856 remover_->RemoveAndReply( |
| 857 delete_begin, delete_end, remove_mask, origin_type_mask, |
| 858 &completion_observer); |
| 859 completion_observer.BlockUntilCompletion(); |
| 860 } |
| 861 |
| 862 void BlockUntilOriginDataRemoved( |
| 863 const base::Time& delete_begin, |
| 864 const base::Time& delete_end, |
| 865 int remove_mask, |
| 866 const BrowsingDataFilterBuilder& filter_builder) { |
| 867 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; |
| 868 |
| 869 // TODO(crbug.com/668114): ChromeBrowsingDataRemoverTest should not know |
| 870 // about BrowsingDataRemoverImpl. We will be able to remove this cast once |
| 871 // BrowsingDataFilterBuilder is copyable and comparable. |
| 872 static_cast<BrowsingDataRemoverImpl*>(remover_) |
| 873 ->RemoveImpl(delete_begin, delete_end, remove_mask, filter_builder, |
| 874 BrowsingDataHelper::UNPROTECTED_WEB); |
| 875 completion_inhibitor.BlockUntilNearCompletion(); |
| 876 completion_inhibitor.ContinueToCompletion(); |
| 877 } |
| 878 |
| 879 const base::Time& GetBeginTime() { |
| 880 return remover_->GetLastUsedBeginTime(); |
| 881 } |
| 882 |
| 883 int GetRemovalMask() { |
| 884 return remover_->GetLastUsedRemovalMask(); |
| 885 } |
| 886 |
| 887 int GetOriginTypeMask() { |
| 888 return remover_->GetLastUsedOriginTypeMask(); |
| 889 } |
| 890 |
| 891 TestingProfile* GetProfile() { |
| 892 return profile_.get(); |
| 893 } |
| 894 |
| 895 const ClearDomainReliabilityTester& clear_domain_reliability_tester() { |
| 896 return clear_domain_reliability_tester_; |
| 897 } |
| 898 |
| 899 private: |
| 900 // Cached pointer to BrowsingDataRemoverImpl for access to testing methods. |
| 901 BrowsingDataRemover* remover_; |
| 902 |
| 903 content::TestBrowserThreadBundle thread_bundle_; |
| 904 std::unique_ptr<TestingProfile> profile_; |
| 905 |
| 906 // Needed to mock out DomainReliabilityService, even for unrelated tests. |
| 907 ClearDomainReliabilityTester clear_domain_reliability_tester_; |
| 908 |
| 909 DISALLOW_COPY_AND_ASSIGN(ChromeBrowsingDataRemoverDelegateTest); |
| 910 }; |
| 911 |
| 912 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveSafeBrowsingCookieForever) { |
| 913 RemoveSafeBrowsingCookieTester tester; |
| 914 |
| 915 tester.AddCookie(); |
| 916 ASSERT_TRUE(tester.ContainsCookie()); |
| 917 |
| 918 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 919 BrowsingDataRemover::REMOVE_COOKIES, false); |
| 920 |
| 921 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); |
| 922 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 923 EXPECT_FALSE(tester.ContainsCookie()); |
| 924 } |
| 925 |
| 926 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 927 RemoveSafeBrowsingCookieLastHour) { |
| 928 RemoveSafeBrowsingCookieTester tester; |
| 929 |
| 930 tester.AddCookie(); |
| 931 ASSERT_TRUE(tester.ContainsCookie()); |
| 932 |
| 933 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), |
| 934 BrowsingDataRemover::REMOVE_COOKIES, false); |
| 935 |
| 936 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); |
| 937 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 938 // Removing with time period other than all time should not clear safe |
| 939 // browsing cookies. |
| 940 EXPECT_TRUE(tester.ContainsCookie()); |
| 941 } |
| 942 |
| 943 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 944 RemoveSafeBrowsingCookieForeverWithPredicate) { |
| 945 RemoveSafeBrowsingCookieTester tester; |
| 946 |
| 947 tester.AddCookie(); |
| 948 ASSERT_TRUE(tester.ContainsCookie()); |
| 949 RegistrableDomainFilterBuilder filter( |
| 950 RegistrableDomainFilterBuilder::BLACKLIST); |
| 951 filter.AddRegisterableDomain(kTestRegisterableDomain1); |
| 952 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), |
| 953 BrowsingDataRemover::REMOVE_COOKIES, filter); |
| 954 |
| 955 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); |
| 956 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 957 EXPECT_TRUE(tester.ContainsCookie()); |
| 958 |
| 959 RegistrableDomainFilterBuilder filter2( |
| 960 RegistrableDomainFilterBuilder::WHITELIST); |
| 961 filter2.AddRegisterableDomain(kTestRegisterableDomain1); |
| 962 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), |
| 963 BrowsingDataRemover::REMOVE_COOKIES, filter2); |
| 964 EXPECT_FALSE(tester.ContainsCookie()); |
| 965 } |
| 966 |
| 967 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveHistoryForever) { |
| 968 RemoveHistoryTester tester; |
| 969 ASSERT_TRUE(tester.Init(GetProfile())); |
| 970 |
| 971 tester.AddHistory(kOrigin1, base::Time::Now()); |
| 972 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
| 973 |
| 974 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 975 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 976 |
| 977 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 978 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 979 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1)); |
| 980 } |
| 981 |
| 982 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveHistoryForLastHour) { |
| 983 RemoveHistoryTester tester; |
| 984 ASSERT_TRUE(tester.Init(GetProfile())); |
| 985 |
| 986 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); |
| 987 |
| 988 tester.AddHistory(kOrigin1, base::Time::Now()); |
| 989 tester.AddHistory(kOrigin2, two_hours_ago); |
| 990 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
| 991 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); |
| 992 |
| 993 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), |
| 994 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 995 |
| 996 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 997 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 998 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1)); |
| 999 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); |
| 1000 } |
| 1001 |
| 1002 // This should crash (DCHECK) in Debug, but death tests don't work properly |
| 1003 // here. |
| 1004 // TODO(msramek): To make this testable, the refusal to delete history should |
| 1005 // be made a part of interface (e.g. a success value) as opposed to a DCHECK. |
| 1006 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
| 1007 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveHistoryProhibited) { |
| 1008 RemoveHistoryTester tester; |
| 1009 ASSERT_TRUE(tester.Init(GetProfile())); |
| 1010 PrefService* prefs = GetProfile()->GetPrefs(); |
| 1011 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); |
| 1012 |
| 1013 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); |
| 1014 |
| 1015 tester.AddHistory(kOrigin1, base::Time::Now()); |
| 1016 tester.AddHistory(kOrigin2, two_hours_ago); |
| 1017 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
| 1018 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); |
| 1019 |
| 1020 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), |
| 1021 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 1022 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 1023 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 1024 |
| 1025 // Nothing should have been deleted. |
| 1026 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
| 1027 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); |
| 1028 } |
| 1029 |
| 1030 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1031 RemoveMultipleTypesHistoryProhibited) { |
| 1032 PrefService* prefs = GetProfile()->GetPrefs(); |
| 1033 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); |
| 1034 |
| 1035 // Add some history. |
| 1036 RemoveHistoryTester history_tester; |
| 1037 ASSERT_TRUE(history_tester.Init(GetProfile())); |
| 1038 history_tester.AddHistory(kOrigin1, base::Time::Now()); |
| 1039 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1)); |
| 1040 |
| 1041 // Expect that passwords will be deleted, as they do not depend |
| 1042 // on |prefs::kAllowDeletingBrowserHistory|. |
| 1043 RemovePasswordsTester tester(GetProfile()); |
| 1044 EXPECT_CALL(*tester.store(), RemoveLoginsByURLAndTimeImpl(_, _, _)); |
| 1045 |
| 1046 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY | |
| 1047 BrowsingDataRemover::REMOVE_PASSWORDS; |
| 1048 |
| 1049 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), |
| 1050 removal_mask, false); |
| 1051 EXPECT_EQ(removal_mask, GetRemovalMask()); |
| 1052 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 1053 |
| 1054 // Verify that history was not deleted. |
| 1055 EXPECT_TRUE(history_tester.HistoryContainsURL(kOrigin1)); |
| 1056 } |
| 1057 #endif |
| 1058 |
| 1059 // Test that clearing history deletes favicons not associated with bookmarks. |
| 1060 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveFaviconsForever) { |
| 1061 GURL page_url("http://a"); |
| 1062 |
| 1063 RemoveFaviconTester favicon_tester; |
| 1064 ASSERT_TRUE(favicon_tester.Init(GetProfile())); |
| 1065 favicon_tester.VisitAndAddFavicon(page_url); |
| 1066 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(page_url)); |
| 1067 |
| 1068 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1069 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 1070 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 1071 EXPECT_FALSE(favicon_tester.HasFaviconForPageURL(page_url)); |
| 1072 } |
| 1073 |
| 1074 // Test that a bookmark's favicon is expired and not deleted when clearing |
| 1075 // history. Expiring the favicon causes the bookmark's favicon to be updated |
| 1076 // when the user next visits the bookmarked page. Expiring the bookmark's |
| 1077 // favicon is useful when the bookmark's favicon becomes incorrect (See |
| 1078 // crbug.com/474421 for a sample bug which causes this). |
| 1079 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ExpireBookmarkFavicons) { |
| 1080 GURL bookmarked_page("http://a"); |
| 1081 |
| 1082 TestingProfile* profile = GetProfile(); |
| 1083 profile->CreateBookmarkModel(true); |
| 1084 bookmarks::BookmarkModel* bookmark_model = |
| 1085 BookmarkModelFactory::GetForBrowserContext(profile); |
| 1086 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); |
| 1087 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0, |
| 1088 base::ASCIIToUTF16("a"), bookmarked_page); |
| 1089 |
| 1090 RemoveFaviconTester favicon_tester; |
| 1091 ASSERT_TRUE(favicon_tester.Init(GetProfile())); |
| 1092 favicon_tester.VisitAndAddFavicon(bookmarked_page); |
| 1093 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(bookmarked_page)); |
| 1094 |
| 1095 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1096 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 1097 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 1098 EXPECT_TRUE(favicon_tester.HasExpiredFaviconForPageURL(bookmarked_page)); |
| 1099 } |
| 1100 |
| 1101 TEST_F(ChromeBrowsingDataRemoverDelegateTest, TimeBasedHistoryRemoval) { |
| 1102 RemoveHistoryTester tester; |
| 1103 ASSERT_TRUE(tester.Init(GetProfile())); |
| 1104 |
| 1105 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); |
| 1106 |
| 1107 tester.AddHistory(kOrigin1, base::Time::Now()); |
| 1108 tester.AddHistory(kOrigin2, two_hours_ago); |
| 1109 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); |
| 1110 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); |
| 1111 |
| 1112 RegistrableDomainFilterBuilder builder( |
| 1113 RegistrableDomainFilterBuilder::BLACKLIST); |
| 1114 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), |
| 1115 BrowsingDataRemover::REMOVE_HISTORY, builder); |
| 1116 |
| 1117 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 1118 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 1119 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1)); |
| 1120 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); |
| 1121 } |
| 1122 |
| 1123 // Verify that clearing autofill form data works. |
| 1124 TEST_F(ChromeBrowsingDataRemoverDelegateTest, AutofillRemovalLastHour) { |
| 1125 GetProfile()->CreateWebDataService(); |
| 1126 RemoveAutofillTester tester(GetProfile()); |
| 1127 |
| 1128 ASSERT_FALSE(tester.HasProfile()); |
| 1129 tester.AddProfilesAndCards(); |
| 1130 ASSERT_TRUE(tester.HasProfile()); |
| 1131 |
| 1132 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), |
| 1133 BrowsingDataRemover::REMOVE_FORM_DATA, false); |
| 1134 |
| 1135 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask()); |
| 1136 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 1137 ASSERT_FALSE(tester.HasProfile()); |
| 1138 } |
| 1139 |
| 1140 TEST_F(ChromeBrowsingDataRemoverDelegateTest, AutofillRemovalEverything) { |
| 1141 GetProfile()->CreateWebDataService(); |
| 1142 RemoveAutofillTester tester(GetProfile()); |
| 1143 |
| 1144 ASSERT_FALSE(tester.HasProfile()); |
| 1145 tester.AddProfilesAndCards(); |
| 1146 ASSERT_TRUE(tester.HasProfile()); |
| 1147 |
| 1148 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1149 BrowsingDataRemover::REMOVE_FORM_DATA, false); |
| 1150 |
| 1151 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask()); |
| 1152 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 1153 ASSERT_FALSE(tester.HasProfile()); |
| 1154 } |
| 1155 |
| 1156 // Verify that clearing autofill form data works. |
| 1157 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1158 AutofillOriginsRemovedWithHistory) { |
| 1159 GetProfile()->CreateWebDataService(); |
| 1160 RemoveAutofillTester tester(GetProfile()); |
| 1161 |
| 1162 tester.AddProfilesAndCards(); |
| 1163 EXPECT_FALSE(tester.HasOrigin(std::string())); |
| 1164 EXPECT_TRUE(tester.HasOrigin(kWebOrigin)); |
| 1165 EXPECT_TRUE(tester.HasOrigin(autofill::kSettingsOrigin)); |
| 1166 |
| 1167 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), |
| 1168 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 1169 |
| 1170 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 1171 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 1172 EXPECT_TRUE(tester.HasOrigin(std::string())); |
| 1173 EXPECT_FALSE(tester.HasOrigin(kWebOrigin)); |
| 1174 EXPECT_TRUE(tester.HasOrigin(autofill::kSettingsOrigin)); |
| 1175 } |
| 1176 |
| 1177 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ZeroSuggestCacheClear) { |
| 1178 PrefService* prefs = GetProfile()->GetPrefs(); |
| 1179 prefs->SetString(omnibox::kZeroSuggestCachedResults, |
| 1180 "[\"\", [\"foo\", \"bar\"]]"); |
| 1181 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1182 BrowsingDataRemover::REMOVE_COOKIES, false); |
| 1183 |
| 1184 // Expect the prefs to be cleared when cookies are removed. |
| 1185 EXPECT_TRUE(prefs->GetString(omnibox::kZeroSuggestCachedResults).empty()); |
| 1186 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); |
| 1187 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 1188 } |
| 1189 |
| 1190 #if defined(OS_CHROMEOS) |
| 1191 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1192 ContentProtectionPlatformKeysRemoval) { |
| 1193 chromeos::ScopedTestDeviceSettingsService test_device_settings_service; |
| 1194 chromeos::ScopedTestCrosSettings test_cros_settings; |
| 1195 chromeos::MockUserManager* mock_user_manager = |
| 1196 new testing::NiceMock<chromeos::MockUserManager>(); |
| 1197 mock_user_manager->SetActiveUser( |
| 1198 AccountId::FromUserEmail("test@example.com")); |
| 1199 chromeos::ScopedUserManagerEnabler user_manager_enabler(mock_user_manager); |
| 1200 |
| 1201 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter = |
| 1202 chromeos::DBusThreadManager::GetSetterForTesting(); |
| 1203 chromeos::MockCryptohomeClient* cryptohome_client = |
| 1204 new chromeos::MockCryptohomeClient; |
| 1205 dbus_setter->SetCryptohomeClient( |
| 1206 std::unique_ptr<chromeos::CryptohomeClient>(cryptohome_client)); |
| 1207 |
| 1208 // Expect exactly one call. No calls means no attempt to delete keys and more |
| 1209 // than one call means a significant performance problem. |
| 1210 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _)) |
| 1211 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall))); |
| 1212 |
| 1213 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1214 BrowsingDataRemover::REMOVE_MEDIA_LICENSES, |
| 1215 false); |
| 1216 |
| 1217 chromeos::DBusThreadManager::Shutdown(); |
| 1218 } |
| 1219 #endif |
| 1220 |
| 1221 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Null) { |
| 1222 const ClearDomainReliabilityTester& tester = |
| 1223 clear_domain_reliability_tester(); |
| 1224 |
| 1225 EXPECT_EQ(0u, tester.clear_count()); |
| 1226 } |
| 1227 |
| 1228 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Beacons) { |
| 1229 const ClearDomainReliabilityTester& tester = |
| 1230 clear_domain_reliability_tester(); |
| 1231 |
| 1232 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1233 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 1234 EXPECT_EQ(1u, tester.clear_count()); |
| 1235 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode()); |
| 1236 EXPECT_TRUE(ProbablySameFilters( |
| 1237 BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter())); |
| 1238 } |
| 1239 |
| 1240 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1241 DomainReliability_Beacons_WithFilter) { |
| 1242 const ClearDomainReliabilityTester& tester = |
| 1243 clear_domain_reliability_tester(); |
| 1244 |
| 1245 RegistrableDomainFilterBuilder builder( |
| 1246 RegistrableDomainFilterBuilder::WHITELIST); |
| 1247 builder.AddRegisterableDomain(kTestRegisterableDomain1); |
| 1248 |
| 1249 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), |
| 1250 BrowsingDataRemover::REMOVE_HISTORY, builder); |
| 1251 EXPECT_EQ(1u, tester.clear_count()); |
| 1252 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode()); |
| 1253 EXPECT_TRUE(ProbablySameFilters( |
| 1254 builder.BuildGeneralFilter(), tester.last_filter())); |
| 1255 } |
| 1256 |
| 1257 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Contexts) { |
| 1258 const ClearDomainReliabilityTester& tester = |
| 1259 clear_domain_reliability_tester(); |
| 1260 |
| 1261 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1262 BrowsingDataRemover::REMOVE_COOKIES, false); |
| 1263 EXPECT_EQ(1u, tester.clear_count()); |
| 1264 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); |
| 1265 EXPECT_TRUE(ProbablySameFilters( |
| 1266 BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter())); |
| 1267 } |
| 1268 |
| 1269 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1270 DomainReliability_Contexts_WithFilter) { |
| 1271 const ClearDomainReliabilityTester& tester = |
| 1272 clear_domain_reliability_tester(); |
| 1273 |
| 1274 RegistrableDomainFilterBuilder builder( |
| 1275 RegistrableDomainFilterBuilder::WHITELIST); |
| 1276 builder.AddRegisterableDomain(kTestRegisterableDomain1); |
| 1277 |
| 1278 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), |
| 1279 BrowsingDataRemover::REMOVE_COOKIES, builder); |
| 1280 EXPECT_EQ(1u, tester.clear_count()); |
| 1281 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); |
| 1282 EXPECT_TRUE(ProbablySameFilters( |
| 1283 builder.BuildGeneralFilter(), tester.last_filter())); |
| 1284 } |
| 1285 |
| 1286 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_ContextsWin) { |
| 1287 const ClearDomainReliabilityTester& tester = |
| 1288 clear_domain_reliability_tester(); |
| 1289 |
| 1290 BlockUntilBrowsingDataRemoved( |
| 1291 base::Time(), base::Time::Max(), |
| 1292 BrowsingDataRemover::REMOVE_HISTORY | BrowsingDataRemover::REMOVE_COOKIES, |
| 1293 false); |
| 1294 EXPECT_EQ(1u, tester.clear_count()); |
| 1295 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); |
| 1296 } |
| 1297 |
| 1298 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1299 DomainReliability_ProtectedOrigins) { |
| 1300 const ClearDomainReliabilityTester& tester = |
| 1301 clear_domain_reliability_tester(); |
| 1302 |
| 1303 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1304 BrowsingDataRemover::REMOVE_COOKIES, true); |
| 1305 EXPECT_EQ(1u, tester.clear_count()); |
| 1306 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); |
| 1307 } |
| 1308 |
| 1309 // TODO(juliatuttle): This isn't actually testing the no-monitor case, since |
| 1310 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed |
| 1311 // for some unrelated test cases. This should be fixed so it tests the no- |
| 1312 // monitor case again. |
| 1313 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1314 DISABLED_DomainReliability_NoMonitor) { |
| 1315 BlockUntilBrowsingDataRemoved( |
| 1316 base::Time(), base::Time::Max(), |
| 1317 BrowsingDataRemover::REMOVE_HISTORY | BrowsingDataRemover::REMOVE_COOKIES, |
| 1318 false); |
| 1319 } |
| 1320 |
| 1321 // Tests that the deletion of downloads completes successfully and that |
| 1322 // ChromeDownloadManagerDelegate is correctly created and shut down. |
| 1323 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveDownloads) { |
| 1324 RemoveDownloadsTester tester(GetProfile()); |
| 1325 |
| 1326 EXPECT_CALL( |
| 1327 *tester.download_manager(), RemoveDownloadsByURLAndTime(_, _, _)); |
| 1328 |
| 1329 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1330 BrowsingDataRemover::REMOVE_DOWNLOADS, false); |
| 1331 } |
| 1332 |
| 1333 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordStatistics) { |
| 1334 RemovePasswordsTester tester(GetProfile()); |
| 1335 base::Callback<bool(const GURL&)> empty_filter; |
| 1336 |
| 1337 EXPECT_CALL(*tester.store(), RemoveStatisticsByOriginAndTimeImpl( |
| 1338 ProbablySameFilter(empty_filter), |
| 1339 base::Time(), base::Time::Max())); |
| 1340 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1341 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 1342 } |
| 1343 |
| 1344 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1345 RemovePasswordStatisticsByOrigin) { |
| 1346 RemovePasswordsTester tester(GetProfile()); |
| 1347 |
| 1348 RegistrableDomainFilterBuilder builder( |
| 1349 RegistrableDomainFilterBuilder::WHITELIST); |
| 1350 builder.AddRegisterableDomain(kTestRegisterableDomain1); |
| 1351 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter(); |
| 1352 |
| 1353 EXPECT_CALL(*tester.store(), |
| 1354 RemoveStatisticsByOriginAndTimeImpl( |
| 1355 ProbablySameFilter(filter), base::Time(), base::Time::Max())); |
| 1356 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), |
| 1357 BrowsingDataRemover::REMOVE_HISTORY, builder); |
| 1358 } |
| 1359 |
| 1360 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordsByTimeOnly) { |
| 1361 RemovePasswordsTester tester(GetProfile()); |
| 1362 base::Callback<bool(const GURL&)> filter = |
| 1363 BrowsingDataFilterBuilder::BuildNoopFilter(); |
| 1364 |
| 1365 EXPECT_CALL(*tester.store(), |
| 1366 RemoveLoginsByURLAndTimeImpl(ProbablySameFilter(filter), _, _)) |
| 1367 .WillOnce(Return(password_manager::PasswordStoreChangeList())); |
| 1368 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1369 BrowsingDataRemover::REMOVE_PASSWORDS, false); |
| 1370 } |
| 1371 |
| 1372 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordsByOrigin) { |
| 1373 RemovePasswordsTester tester(GetProfile()); |
| 1374 RegistrableDomainFilterBuilder builder( |
| 1375 RegistrableDomainFilterBuilder::WHITELIST); |
| 1376 builder.AddRegisterableDomain(kTestRegisterableDomain1); |
| 1377 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter(); |
| 1378 |
| 1379 EXPECT_CALL(*tester.store(), |
| 1380 RemoveLoginsByURLAndTimeImpl(ProbablySameFilter(filter), _, _)) |
| 1381 .WillOnce(Return(password_manager::PasswordStoreChangeList())); |
| 1382 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), |
| 1383 BrowsingDataRemover::REMOVE_PASSWORDS, builder); |
| 1384 } |
| 1385 |
| 1386 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DisableAutoSignIn) { |
| 1387 RemovePasswordsTester tester(GetProfile()); |
| 1388 base::Callback<bool(const GURL&)> empty_filter = |
| 1389 BrowsingDataFilterBuilder::BuildNoopFilter(); |
| 1390 |
| 1391 EXPECT_CALL( |
| 1392 *tester.store(), |
| 1393 DisableAutoSignInForOriginsImpl(ProbablySameFilter(empty_filter))) |
| 1394 .WillOnce(Return(password_manager::PasswordStoreChangeList())); |
| 1395 |
| 1396 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1397 BrowsingDataRemover::REMOVE_COOKIES, false); |
| 1398 } |
| 1399 |
| 1400 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1401 DisableAutoSignInAfterRemovingPasswords) { |
| 1402 RemovePasswordsTester tester(GetProfile()); |
| 1403 base::Callback<bool(const GURL&)> empty_filter = |
| 1404 BrowsingDataFilterBuilder::BuildNoopFilter(); |
| 1405 |
| 1406 EXPECT_CALL(*tester.store(), RemoveLoginsByURLAndTimeImpl(_, _, _)) |
| 1407 .WillOnce(Return(password_manager::PasswordStoreChangeList())); |
| 1408 EXPECT_CALL( |
| 1409 *tester.store(), |
| 1410 DisableAutoSignInForOriginsImpl(ProbablySameFilter(empty_filter))) |
| 1411 .WillOnce(Return(password_manager::PasswordStoreChangeList())); |
| 1412 |
| 1413 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1414 BrowsingDataRemover::REMOVE_COOKIES | |
| 1415 BrowsingDataRemover::REMOVE_PASSWORDS, |
| 1416 false); |
| 1417 } |
| 1418 |
| 1419 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1420 RemoveContentSettingsWithBlacklist) { |
| 1421 // Add our settings. |
| 1422 HostContentSettingsMap* host_content_settings_map = |
| 1423 HostContentSettingsMapFactory::GetForProfile(GetProfile()); |
| 1424 host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 1425 kOrigin1, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| 1426 base::MakeUnique<base::DictionaryValue>()); |
| 1427 host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 1428 kOrigin2, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| 1429 base::MakeUnique<base::DictionaryValue>()); |
| 1430 host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 1431 kOrigin3, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| 1432 base::MakeUnique<base::DictionaryValue>()); |
| 1433 host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 1434 kOrigin4, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| 1435 base::MakeUnique<base::DictionaryValue>()); |
| 1436 |
| 1437 // Clear all except for origin1 and origin3. |
| 1438 RegistrableDomainFilterBuilder filter( |
| 1439 RegistrableDomainFilterBuilder::BLACKLIST); |
| 1440 filter.AddRegisterableDomain(kTestRegisterableDomain1); |
| 1441 filter.AddRegisterableDomain(kTestRegisterableDomain3); |
| 1442 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), |
| 1443 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, |
| 1444 filter); |
| 1445 |
| 1446 EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, GetRemovalMask()); |
| 1447 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 1448 |
| 1449 // Verify we only have true, and they're origin1, origin3, and origin4. |
| 1450 ContentSettingsForOneType host_settings; |
| 1451 host_content_settings_map->GetSettingsForOneType( |
| 1452 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
| 1453 EXPECT_EQ(3u, host_settings.size()); |
| 1454 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin1), |
| 1455 host_settings[0].primary_pattern) |
| 1456 << host_settings[0].primary_pattern.ToString(); |
| 1457 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin4), |
| 1458 host_settings[1].primary_pattern) |
| 1459 << host_settings[1].primary_pattern.ToString(); |
| 1460 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin3), |
| 1461 host_settings[2].primary_pattern) |
| 1462 << host_settings[2].primary_pattern.ToString(); |
| 1463 } |
| 1464 |
| 1465 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveDurablePermission) { |
| 1466 // Add our settings. |
| 1467 HostContentSettingsMap* host_content_settings_map = |
| 1468 HostContentSettingsMapFactory::GetForProfile(GetProfile()); |
| 1469 |
| 1470 DurableStoragePermissionContext durable_permission(GetProfile()); |
| 1471 durable_permission.UpdateContentSetting(kOrigin1, GURL(), |
| 1472 CONTENT_SETTING_ALLOW); |
| 1473 durable_permission.UpdateContentSetting(kOrigin2, GURL(), |
| 1474 CONTENT_SETTING_ALLOW); |
| 1475 |
| 1476 // Clear all except for origin1 and origin3. |
| 1477 RegistrableDomainFilterBuilder filter( |
| 1478 RegistrableDomainFilterBuilder::BLACKLIST); |
| 1479 filter.AddRegisterableDomain(kTestRegisterableDomain1); |
| 1480 filter.AddRegisterableDomain(kTestRegisterableDomain3); |
| 1481 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), |
| 1482 BrowsingDataRemover::REMOVE_DURABLE_PERMISSION, |
| 1483 filter); |
| 1484 |
| 1485 EXPECT_EQ(BrowsingDataRemover::REMOVE_DURABLE_PERMISSION, GetRemovalMask()); |
| 1486 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); |
| 1487 |
| 1488 // Verify we only have allow for the first origin. |
| 1489 ContentSettingsForOneType host_settings; |
| 1490 host_content_settings_map->GetSettingsForOneType( |
| 1491 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, std::string(), &host_settings); |
| 1492 |
| 1493 ASSERT_EQ(2u, host_settings.size()); |
| 1494 // Only the first should should have a setting. |
| 1495 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin1), |
| 1496 host_settings[0].primary_pattern) |
| 1497 << host_settings[0].primary_pattern.ToString(); |
| 1498 EXPECT_EQ(CONTENT_SETTING_ALLOW, host_settings[0].setting); |
| 1499 |
| 1500 // And our wildcard. |
| 1501 EXPECT_EQ(ContentSettingsPattern::Wildcard(), |
| 1502 host_settings[1].primary_pattern) |
| 1503 << host_settings[1].primary_pattern.ToString(); |
| 1504 EXPECT_EQ(CONTENT_SETTING_ASK, host_settings[1].setting); |
| 1505 } |
| 1506 |
| 1507 // Test that removing passwords clears HTTP auth data. |
| 1508 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1509 ClearHttpAuthCache_RemovePasswords) { |
| 1510 net::HttpNetworkSession* http_session = GetProfile() |
| 1511 ->GetRequestContext() |
| 1512 ->GetURLRequestContext() |
| 1513 ->http_transaction_factory() |
| 1514 ->GetSession(); |
| 1515 DCHECK(http_session); |
| 1516 |
| 1517 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache(); |
| 1518 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC, |
| 1519 "test challenge", |
| 1520 net::AuthCredentials(base::ASCIIToUTF16("foo"), |
| 1521 base::ASCIIToUTF16("bar")), |
| 1522 "/"); |
| 1523 CHECK(http_auth_cache->Lookup(kOrigin1, kTestRealm, |
| 1524 net::HttpAuth::AUTH_SCHEME_BASIC)); |
| 1525 |
| 1526 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1527 BrowsingDataRemover::REMOVE_PASSWORDS, false); |
| 1528 |
| 1529 EXPECT_EQ(nullptr, http_auth_cache->Lookup(kOrigin1, kTestRealm, |
| 1530 net::HttpAuth::AUTH_SCHEME_BASIC)); |
| 1531 } |
| 1532 |
| 1533 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ClearPermissionPromptCounts) { |
| 1534 RemovePermissionPromptCountsTest tester(GetProfile()); |
| 1535 |
| 1536 RegistrableDomainFilterBuilder filter_builder_1( |
| 1537 RegistrableDomainFilterBuilder::WHITELIST); |
| 1538 filter_builder_1.AddRegisterableDomain(kTestRegisterableDomain1); |
| 1539 |
| 1540 RegistrableDomainFilterBuilder filter_builder_2( |
| 1541 RegistrableDomainFilterBuilder::BLACKLIST); |
| 1542 filter_builder_2.AddRegisterableDomain(kTestRegisterableDomain1); |
| 1543 |
| 1544 { |
| 1545 // Test REMOVE_HISTORY. |
| 1546 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, |
| 1547 content::PermissionType::GEOLOCATION)); |
| 1548 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1, |
| 1549 content::PermissionType::GEOLOCATION)); |
| 1550 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, |
| 1551 content::PermissionType::NOTIFICATIONS)); |
| 1552 tester.ShouldChangeDismissalToBlock(kOrigin1, |
| 1553 content::PermissionType::MIDI_SYSEX); |
| 1554 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2, |
| 1555 content::PermissionType::DURABLE_STORAGE)); |
| 1556 tester.ShouldChangeDismissalToBlock(kOrigin2, |
| 1557 content::PermissionType::NOTIFICATIONS); |
| 1558 |
| 1559 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), |
| 1560 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, |
| 1561 filter_builder_1); |
| 1562 |
| 1563 // kOrigin1 should be gone, but kOrigin2 remains. |
| 1564 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, |
| 1565 content::PermissionType::GEOLOCATION)); |
| 1566 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, |
| 1567 content::PermissionType::NOTIFICATIONS)); |
| 1568 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1, |
| 1569 content::PermissionType::MIDI_SYSEX)); |
| 1570 EXPECT_EQ(1, tester.GetIgnoreCount( |
| 1571 kOrigin2, content::PermissionType::DURABLE_STORAGE)); |
| 1572 EXPECT_EQ(1, tester.GetDismissCount( |
| 1573 kOrigin2, content::PermissionType::NOTIFICATIONS)); |
| 1574 |
| 1575 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), |
| 1576 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 1577 |
| 1578 // Everything should be gone. |
| 1579 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, |
| 1580 content::PermissionType::GEOLOCATION)); |
| 1581 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, |
| 1582 content::PermissionType::NOTIFICATIONS)); |
| 1583 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1, |
| 1584 content::PermissionType::MIDI_SYSEX)); |
| 1585 EXPECT_EQ(0, tester.GetIgnoreCount( |
| 1586 kOrigin2, content::PermissionType::DURABLE_STORAGE)); |
| 1587 EXPECT_EQ(0, tester.GetDismissCount( |
| 1588 kOrigin2, content::PermissionType::NOTIFICATIONS)); |
| 1589 } |
| 1590 { |
| 1591 // Test REMOVE_SITE_DATA. |
| 1592 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, |
| 1593 content::PermissionType::GEOLOCATION)); |
| 1594 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1, |
| 1595 content::PermissionType::GEOLOCATION)); |
| 1596 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, |
| 1597 content::PermissionType::NOTIFICATIONS)); |
| 1598 tester.ShouldChangeDismissalToBlock(kOrigin1, |
| 1599 content::PermissionType::MIDI_SYSEX); |
| 1600 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2, |
| 1601 content::PermissionType::DURABLE_STORAGE)); |
| 1602 tester.ShouldChangeDismissalToBlock(kOrigin2, |
| 1603 content::PermissionType::NOTIFICATIONS); |
| 1604 |
| 1605 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), |
| 1606 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, |
| 1607 filter_builder_2); |
| 1608 |
| 1609 // kOrigin2 should be gone, but kOrigin1 remains. |
| 1610 EXPECT_EQ(2, tester.GetIgnoreCount(kOrigin1, |
| 1611 content::PermissionType::GEOLOCATION)); |
| 1612 EXPECT_EQ(1, tester.GetIgnoreCount(kOrigin1, |
| 1613 content::PermissionType::NOTIFICATIONS)); |
| 1614 EXPECT_EQ(1, tester.GetDismissCount(kOrigin1, |
| 1615 content::PermissionType::MIDI_SYSEX)); |
| 1616 EXPECT_EQ(0, tester.GetIgnoreCount( |
| 1617 kOrigin2, content::PermissionType::DURABLE_STORAGE)); |
| 1618 EXPECT_EQ(0, tester.GetDismissCount( |
| 1619 kOrigin2, content::PermissionType::NOTIFICATIONS)); |
| 1620 |
| 1621 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), |
| 1622 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, |
| 1623 false); |
| 1624 |
| 1625 // Everything should be gone. |
| 1626 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, |
| 1627 content::PermissionType::GEOLOCATION)); |
| 1628 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, |
| 1629 content::PermissionType::NOTIFICATIONS)); |
| 1630 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1, |
| 1631 content::PermissionType::MIDI_SYSEX)); |
| 1632 EXPECT_EQ(0, tester.GetIgnoreCount( |
| 1633 kOrigin2, content::PermissionType::DURABLE_STORAGE)); |
| 1634 EXPECT_EQ(0, tester.GetDismissCount( |
| 1635 kOrigin2, content::PermissionType::NOTIFICATIONS)); |
| 1636 } |
| 1637 } |
| 1638 |
| 1639 #if BUILDFLAG(ENABLE_PLUGINS) |
| 1640 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePluginData) { |
| 1641 RemovePluginDataTester tester(GetProfile()); |
| 1642 |
| 1643 tester.AddDomain(kOrigin1.host()); |
| 1644 tester.AddDomain(kOrigin2.host()); |
| 1645 tester.AddDomain(kOrigin3.host()); |
| 1646 |
| 1647 std::vector<std::string> expected = { |
| 1648 kOrigin1.host(), kOrigin2.host(), kOrigin3.host() }; |
| 1649 EXPECT_EQ(expected, tester.GetDomains()); |
| 1650 |
| 1651 // Delete data with a filter for the registrable domain of |kOrigin3|. |
| 1652 RegistrableDomainFilterBuilder filter_builder( |
| 1653 RegistrableDomainFilterBuilder::WHITELIST); |
| 1654 filter_builder.AddRegisterableDomain(kTestRegisterableDomain3); |
| 1655 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), |
| 1656 BrowsingDataRemover::REMOVE_PLUGIN_DATA, |
| 1657 filter_builder); |
| 1658 |
| 1659 // Plugin data for |kOrigin3.host()| should have been removed. |
| 1660 expected.pop_back(); |
| 1661 EXPECT_EQ(expected, tester.GetDomains()); |
| 1662 |
| 1663 // TODO(msramek): Mock PluginDataRemover and test the complete deletion |
| 1664 // of plugin data as well. |
| 1665 } |
| 1666 #endif |
| 1667 |
| 1668 // Test that the remover clears bookmark meta data (normally added in a tab |
| 1669 // helper). |
| 1670 TEST_F(ChromeBrowsingDataRemoverDelegateTest, |
| 1671 BookmarkLastVisitDatesGetCleared) { |
| 1672 TestingProfile profile; |
| 1673 profile.CreateBookmarkModel(true); |
| 1674 |
| 1675 bookmarks::BookmarkModel* bookmark_model = |
| 1676 BookmarkModelFactory::GetForBrowserContext(&profile); |
| 1677 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); |
| 1678 |
| 1679 const base::Time delete_begin = |
| 1680 base::Time::Now() - base::TimeDelta::FromDays(1); |
| 1681 |
| 1682 // Create a couple of bookmarks. |
| 1683 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0, |
| 1684 base::string16(), |
| 1685 GURL("http://foo.org/desktop")); |
| 1686 bookmark_model->AddURL(bookmark_model->mobile_node(), 0, |
| 1687 base::string16(), |
| 1688 GURL("http://foo.org/mobile")); |
| 1689 |
| 1690 // Simulate their visits (this is using Time::Now() as timestamps). |
| 1691 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( |
| 1692 bookmark_model, GURL("http://foo.org/desktop"), |
| 1693 /*is_mobile_platform=*/false); |
| 1694 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( |
| 1695 bookmark_model, GURL("http://foo.org/mobile"), |
| 1696 /*is_mobile_platform=*/true); |
| 1697 |
| 1698 // Add a bookmark with a visited timestamp before the deletion interval. |
| 1699 bookmarks::BookmarkNode::MetaInfoMap meta_info = { |
| 1700 {"last_visited", |
| 1701 base::Int64ToString((delete_begin - base::TimeDelta::FromSeconds(1)) |
| 1702 .ToInternalValue())}}; |
| 1703 bookmark_model->AddURLWithCreationTimeAndMetaInfo( |
| 1704 bookmark_model->mobile_node(), 0, base::ASCIIToUTF16("my title"), |
| 1705 GURL("http://foo-2.org/"), delete_begin - base::TimeDelta::FromDays(1), |
| 1706 &meta_info); |
| 1707 |
| 1708 // There should be some recently visited bookmarks. |
| 1709 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks( |
| 1710 bookmark_model, 2, base::Time::UnixEpoch(), |
| 1711 /*consider_visits_from_desktop=*/false), |
| 1712 Not(IsEmpty())); |
| 1713 |
| 1714 // Inject the bookmark model into the remover. |
| 1715 BrowsingDataRemover* remover = |
| 1716 BrowsingDataRemoverFactory::GetForBrowserContext(&profile); |
| 1717 |
| 1718 BrowsingDataRemoverCompletionObserver completion_observer(remover); |
| 1719 remover->RemoveAndReply(delete_begin, base::Time::Max(), |
| 1720 BrowsingDataRemover::REMOVE_HISTORY, |
| 1721 BrowsingDataHelper::ALL, &completion_observer); |
| 1722 completion_observer.BlockUntilCompletion(); |
| 1723 |
| 1724 // There should be only 1 recently visited bookmarks. |
| 1725 std::vector<const bookmarks::BookmarkNode*> remaining_nodes = |
| 1726 ntp_snippets::GetRecentlyVisitedBookmarks( |
| 1727 bookmark_model, 3, base::Time::UnixEpoch(), |
| 1728 /*consider_visits_from_desktop=*/true); |
| 1729 EXPECT_THAT(remaining_nodes, SizeIs(1)); |
| 1730 EXPECT_THAT(remaining_nodes[0]->url().spec(), Eq("http://foo-2.org/")); |
| 1731 } |
OLD | NEW |