| 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 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | |
| 1005 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveHistoryProhibited) { | |
| 1006 RemoveHistoryTester tester; | |
| 1007 ASSERT_TRUE(tester.Init(GetProfile())); | |
| 1008 PrefService* prefs = GetProfile()->GetPrefs(); | |
| 1009 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); | |
| 1010 | |
| 1011 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); | |
| 1012 | |
| 1013 tester.AddHistory(kOrigin1, base::Time::Now()); | |
| 1014 tester.AddHistory(kOrigin2, two_hours_ago); | |
| 1015 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); | |
| 1016 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); | |
| 1017 | |
| 1018 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 1019 BrowsingDataRemover::REMOVE_HISTORY, false); | |
| 1020 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); | |
| 1021 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1022 | |
| 1023 // Nothing should have been deleted. | |
| 1024 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); | |
| 1025 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); | |
| 1026 } | |
| 1027 | |
| 1028 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1029 RemoveMultipleTypesHistoryProhibited) { | |
| 1030 PrefService* prefs = GetProfile()->GetPrefs(); | |
| 1031 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); | |
| 1032 | |
| 1033 // Add some history. | |
| 1034 RemoveHistoryTester history_tester; | |
| 1035 ASSERT_TRUE(history_tester.Init(GetProfile())); | |
| 1036 history_tester.AddHistory(kOrigin1, base::Time::Now()); | |
| 1037 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1)); | |
| 1038 | |
| 1039 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY | | |
| 1040 BrowsingDataRemover::REMOVE_COOKIES; | |
| 1041 | |
| 1042 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 1043 removal_mask, false); | |
| 1044 EXPECT_EQ(removal_mask, GetRemovalMask()); | |
| 1045 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1046 | |
| 1047 // 1/2. History should remain. | |
| 1048 EXPECT_TRUE(history_tester.HistoryContainsURL(kOrigin1)); | |
| 1049 | |
| 1050 // 2/2. The cookie(s) would be deleted throught the StorageParition, check if | |
| 1051 // the partition was requested to remove cookie. | |
| 1052 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
| 1053 EXPECT_EQ(removal_data.remove_mask, | |
| 1054 StoragePartition::REMOVE_DATA_MASK_COOKIES); | |
| 1055 // Persistent storage won't be deleted, since the time period is not all time. | |
| 1056 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
| 1057 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT); | |
| 1058 } | |
| 1059 #endif | |
| 1060 | |
| 1061 // Test that clearing history deletes favicons not associated with bookmarks. | |
| 1062 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveFaviconsForever) { | |
| 1063 GURL page_url("http://a"); | |
| 1064 | |
| 1065 RemoveFaviconTester favicon_tester; | |
| 1066 ASSERT_TRUE(favicon_tester.Init(GetProfile())); | |
| 1067 favicon_tester.VisitAndAddFavicon(page_url); | |
| 1068 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(page_url)); | |
| 1069 | |
| 1070 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1071 BrowsingDataRemover::REMOVE_HISTORY, false); | |
| 1072 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); | |
| 1073 EXPECT_FALSE(favicon_tester.HasFaviconForPageURL(page_url)); | |
| 1074 } | |
| 1075 | |
| 1076 // Test that a bookmark's favicon is expired and not deleted when clearing | |
| 1077 // history. Expiring the favicon causes the bookmark's favicon to be updated | |
| 1078 // when the user next visits the bookmarked page. Expiring the bookmark's | |
| 1079 // favicon is useful when the bookmark's favicon becomes incorrect (See | |
| 1080 // crbug.com/474421 for a sample bug which causes this). | |
| 1081 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ExpireBookmarkFavicons) { | |
| 1082 GURL bookmarked_page("http://a"); | |
| 1083 | |
| 1084 TestingProfile* profile = GetProfile(); | |
| 1085 profile->CreateBookmarkModel(true); | |
| 1086 bookmarks::BookmarkModel* bookmark_model = | |
| 1087 BookmarkModelFactory::GetForBrowserContext(profile); | |
| 1088 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); | |
| 1089 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0, | |
| 1090 base::ASCIIToUTF16("a"), bookmarked_page); | |
| 1091 | |
| 1092 RemoveFaviconTester favicon_tester; | |
| 1093 ASSERT_TRUE(favicon_tester.Init(GetProfile())); | |
| 1094 favicon_tester.VisitAndAddFavicon(bookmarked_page); | |
| 1095 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(bookmarked_page)); | |
| 1096 | |
| 1097 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1098 BrowsingDataRemover::REMOVE_HISTORY, false); | |
| 1099 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); | |
| 1100 EXPECT_TRUE(favicon_tester.HasExpiredFaviconForPageURL(bookmarked_page)); | |
| 1101 } | |
| 1102 | |
| 1103 TEST_F(ChromeBrowsingDataRemoverDelegateTest, TimeBasedHistoryRemoval) { | |
| 1104 RemoveHistoryTester tester; | |
| 1105 ASSERT_TRUE(tester.Init(GetProfile())); | |
| 1106 | |
| 1107 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); | |
| 1108 | |
| 1109 tester.AddHistory(kOrigin1, base::Time::Now()); | |
| 1110 tester.AddHistory(kOrigin2, two_hours_ago); | |
| 1111 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); | |
| 1112 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); | |
| 1113 | |
| 1114 RegistrableDomainFilterBuilder builder( | |
| 1115 RegistrableDomainFilterBuilder::BLACKLIST); | |
| 1116 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 1117 BrowsingDataRemover::REMOVE_HISTORY, builder); | |
| 1118 | |
| 1119 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); | |
| 1120 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1121 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1)); | |
| 1122 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); | |
| 1123 } | |
| 1124 | |
| 1125 // Verify that clearing autofill form data works. | |
| 1126 TEST_F(ChromeBrowsingDataRemoverDelegateTest, AutofillRemovalLastHour) { | |
| 1127 GetProfile()->CreateWebDataService(); | |
| 1128 RemoveAutofillTester tester(GetProfile()); | |
| 1129 | |
| 1130 ASSERT_FALSE(tester.HasProfile()); | |
| 1131 tester.AddProfilesAndCards(); | |
| 1132 ASSERT_TRUE(tester.HasProfile()); | |
| 1133 | |
| 1134 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 1135 BrowsingDataRemover::REMOVE_FORM_DATA, false); | |
| 1136 | |
| 1137 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask()); | |
| 1138 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1139 ASSERT_FALSE(tester.HasProfile()); | |
| 1140 } | |
| 1141 | |
| 1142 TEST_F(ChromeBrowsingDataRemoverDelegateTest, AutofillRemovalEverything) { | |
| 1143 GetProfile()->CreateWebDataService(); | |
| 1144 RemoveAutofillTester tester(GetProfile()); | |
| 1145 | |
| 1146 ASSERT_FALSE(tester.HasProfile()); | |
| 1147 tester.AddProfilesAndCards(); | |
| 1148 ASSERT_TRUE(tester.HasProfile()); | |
| 1149 | |
| 1150 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1151 BrowsingDataRemover::REMOVE_FORM_DATA, false); | |
| 1152 | |
| 1153 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask()); | |
| 1154 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1155 ASSERT_FALSE(tester.HasProfile()); | |
| 1156 } | |
| 1157 | |
| 1158 // Verify that clearing autofill form data works. | |
| 1159 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1160 AutofillOriginsRemovedWithHistory) { | |
| 1161 GetProfile()->CreateWebDataService(); | |
| 1162 RemoveAutofillTester tester(GetProfile()); | |
| 1163 | |
| 1164 tester.AddProfilesAndCards(); | |
| 1165 EXPECT_FALSE(tester.HasOrigin(std::string())); | |
| 1166 EXPECT_TRUE(tester.HasOrigin(kWebOrigin)); | |
| 1167 EXPECT_TRUE(tester.HasOrigin(autofill::kSettingsOrigin)); | |
| 1168 | |
| 1169 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 1170 BrowsingDataRemover::REMOVE_HISTORY, false); | |
| 1171 | |
| 1172 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); | |
| 1173 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1174 EXPECT_TRUE(tester.HasOrigin(std::string())); | |
| 1175 EXPECT_FALSE(tester.HasOrigin(kWebOrigin)); | |
| 1176 EXPECT_TRUE(tester.HasOrigin(autofill::kSettingsOrigin)); | |
| 1177 } | |
| 1178 | |
| 1179 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ZeroSuggestCacheClear) { | |
| 1180 PrefService* prefs = GetProfile()->GetPrefs(); | |
| 1181 prefs->SetString(omnibox::kZeroSuggestCachedResults, | |
| 1182 "[\"\", [\"foo\", \"bar\"]]"); | |
| 1183 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1184 BrowsingDataRemover::REMOVE_COOKIES, false); | |
| 1185 | |
| 1186 // Expect the prefs to be cleared when cookies are removed. | |
| 1187 EXPECT_TRUE(prefs->GetString(omnibox::kZeroSuggestCachedResults).empty()); | |
| 1188 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); | |
| 1189 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1190 } | |
| 1191 | |
| 1192 #if defined(OS_CHROMEOS) | |
| 1193 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1194 ContentProtectionPlatformKeysRemoval) { | |
| 1195 chromeos::ScopedTestDeviceSettingsService test_device_settings_service; | |
| 1196 chromeos::ScopedTestCrosSettings test_cros_settings; | |
| 1197 chromeos::MockUserManager* mock_user_manager = | |
| 1198 new testing::NiceMock<chromeos::MockUserManager>(); | |
| 1199 mock_user_manager->SetActiveUser( | |
| 1200 AccountId::FromUserEmail("test@example.com")); | |
| 1201 chromeos::ScopedUserManagerEnabler user_manager_enabler(mock_user_manager); | |
| 1202 | |
| 1203 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter = | |
| 1204 chromeos::DBusThreadManager::GetSetterForTesting(); | |
| 1205 chromeos::MockCryptohomeClient* cryptohome_client = | |
| 1206 new chromeos::MockCryptohomeClient; | |
| 1207 dbus_setter->SetCryptohomeClient( | |
| 1208 std::unique_ptr<chromeos::CryptohomeClient>(cryptohome_client)); | |
| 1209 | |
| 1210 // Expect exactly one call. No calls means no attempt to delete keys and more | |
| 1211 // than one call means a significant performance problem. | |
| 1212 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _)) | |
| 1213 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall))); | |
| 1214 | |
| 1215 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1216 BrowsingDataRemover::REMOVE_MEDIA_LICENSES, | |
| 1217 false); | |
| 1218 | |
| 1219 chromeos::DBusThreadManager::Shutdown(); | |
| 1220 } | |
| 1221 #endif | |
| 1222 | |
| 1223 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Null) { | |
| 1224 const ClearDomainReliabilityTester& tester = | |
| 1225 clear_domain_reliability_tester(); | |
| 1226 | |
| 1227 EXPECT_EQ(0u, tester.clear_count()); | |
| 1228 } | |
| 1229 | |
| 1230 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Beacons) { | |
| 1231 const ClearDomainReliabilityTester& tester = | |
| 1232 clear_domain_reliability_tester(); | |
| 1233 | |
| 1234 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1235 BrowsingDataRemover::REMOVE_HISTORY, false); | |
| 1236 EXPECT_EQ(1u, tester.clear_count()); | |
| 1237 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode()); | |
| 1238 EXPECT_TRUE(ProbablySameFilters( | |
| 1239 BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter())); | |
| 1240 } | |
| 1241 | |
| 1242 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1243 DomainReliability_Beacons_WithFilter) { | |
| 1244 const ClearDomainReliabilityTester& tester = | |
| 1245 clear_domain_reliability_tester(); | |
| 1246 | |
| 1247 RegistrableDomainFilterBuilder builder( | |
| 1248 RegistrableDomainFilterBuilder::WHITELIST); | |
| 1249 builder.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 1250 | |
| 1251 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
| 1252 BrowsingDataRemover::REMOVE_HISTORY, builder); | |
| 1253 EXPECT_EQ(1u, tester.clear_count()); | |
| 1254 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode()); | |
| 1255 EXPECT_TRUE(ProbablySameFilters( | |
| 1256 builder.BuildGeneralFilter(), tester.last_filter())); | |
| 1257 } | |
| 1258 | |
| 1259 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Contexts) { | |
| 1260 const ClearDomainReliabilityTester& tester = | |
| 1261 clear_domain_reliability_tester(); | |
| 1262 | |
| 1263 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1264 BrowsingDataRemover::REMOVE_COOKIES, false); | |
| 1265 EXPECT_EQ(1u, tester.clear_count()); | |
| 1266 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); | |
| 1267 EXPECT_TRUE(ProbablySameFilters( | |
| 1268 BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter())); | |
| 1269 } | |
| 1270 | |
| 1271 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1272 DomainReliability_Contexts_WithFilter) { | |
| 1273 const ClearDomainReliabilityTester& tester = | |
| 1274 clear_domain_reliability_tester(); | |
| 1275 | |
| 1276 RegistrableDomainFilterBuilder builder( | |
| 1277 RegistrableDomainFilterBuilder::WHITELIST); | |
| 1278 builder.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 1279 | |
| 1280 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
| 1281 BrowsingDataRemover::REMOVE_COOKIES, builder); | |
| 1282 EXPECT_EQ(1u, tester.clear_count()); | |
| 1283 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); | |
| 1284 EXPECT_TRUE(ProbablySameFilters( | |
| 1285 builder.BuildGeneralFilter(), tester.last_filter())); | |
| 1286 } | |
| 1287 | |
| 1288 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_ContextsWin) { | |
| 1289 const ClearDomainReliabilityTester& tester = | |
| 1290 clear_domain_reliability_tester(); | |
| 1291 | |
| 1292 BlockUntilBrowsingDataRemoved( | |
| 1293 base::Time(), base::Time::Max(), | |
| 1294 BrowsingDataRemover::REMOVE_HISTORY | BrowsingDataRemover::REMOVE_COOKIES, | |
| 1295 false); | |
| 1296 EXPECT_EQ(1u, tester.clear_count()); | |
| 1297 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); | |
| 1298 } | |
| 1299 | |
| 1300 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1301 DomainReliability_ProtectedOrigins) { | |
| 1302 const ClearDomainReliabilityTester& tester = | |
| 1303 clear_domain_reliability_tester(); | |
| 1304 | |
| 1305 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1306 BrowsingDataRemover::REMOVE_COOKIES, true); | |
| 1307 EXPECT_EQ(1u, tester.clear_count()); | |
| 1308 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); | |
| 1309 } | |
| 1310 | |
| 1311 // TODO(juliatuttle): This isn't actually testing the no-monitor case, since | |
| 1312 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed | |
| 1313 // for some unrelated test cases. This should be fixed so it tests the no- | |
| 1314 // monitor case again. | |
| 1315 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1316 DISABLED_DomainReliability_NoMonitor) { | |
| 1317 BlockUntilBrowsingDataRemoved( | |
| 1318 base::Time(), base::Time::Max(), | |
| 1319 BrowsingDataRemover::REMOVE_HISTORY | BrowsingDataRemover::REMOVE_COOKIES, | |
| 1320 false); | |
| 1321 } | |
| 1322 | |
| 1323 // Tests that the deletion of downloads completes successfully and that | |
| 1324 // ChromeDownloadManagerDelegate is correctly created and shut down. | |
| 1325 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveDownloads) { | |
| 1326 RemoveDownloadsTester tester(GetProfile()); | |
| 1327 | |
| 1328 EXPECT_CALL( | |
| 1329 *tester.download_manager(), RemoveDownloadsByURLAndTime(_, _, _)); | |
| 1330 | |
| 1331 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1332 BrowsingDataRemover::REMOVE_DOWNLOADS, false); | |
| 1333 } | |
| 1334 | |
| 1335 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordStatistics) { | |
| 1336 RemovePasswordsTester tester(GetProfile()); | |
| 1337 base::Callback<bool(const GURL&)> empty_filter; | |
| 1338 | |
| 1339 EXPECT_CALL(*tester.store(), RemoveStatisticsByOriginAndTimeImpl( | |
| 1340 ProbablySameFilter(empty_filter), | |
| 1341 base::Time(), base::Time::Max())); | |
| 1342 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1343 BrowsingDataRemover::REMOVE_HISTORY, false); | |
| 1344 } | |
| 1345 | |
| 1346 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1347 RemovePasswordStatisticsByOrigin) { | |
| 1348 RemovePasswordsTester tester(GetProfile()); | |
| 1349 | |
| 1350 RegistrableDomainFilterBuilder builder( | |
| 1351 RegistrableDomainFilterBuilder::WHITELIST); | |
| 1352 builder.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 1353 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter(); | |
| 1354 | |
| 1355 EXPECT_CALL(*tester.store(), | |
| 1356 RemoveStatisticsByOriginAndTimeImpl( | |
| 1357 ProbablySameFilter(filter), base::Time(), base::Time::Max())); | |
| 1358 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
| 1359 BrowsingDataRemover::REMOVE_HISTORY, builder); | |
| 1360 } | |
| 1361 | |
| 1362 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordsByTimeOnly) { | |
| 1363 RemovePasswordsTester tester(GetProfile()); | |
| 1364 base::Callback<bool(const GURL&)> filter = | |
| 1365 BrowsingDataFilterBuilder::BuildNoopFilter(); | |
| 1366 | |
| 1367 EXPECT_CALL(*tester.store(), | |
| 1368 RemoveLoginsByURLAndTimeImpl(ProbablySameFilter(filter), _, _)) | |
| 1369 .WillOnce(Return(password_manager::PasswordStoreChangeList())); | |
| 1370 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1371 BrowsingDataRemover::REMOVE_PASSWORDS, false); | |
| 1372 } | |
| 1373 | |
| 1374 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordsByOrigin) { | |
| 1375 RemovePasswordsTester tester(GetProfile()); | |
| 1376 RegistrableDomainFilterBuilder builder( | |
| 1377 RegistrableDomainFilterBuilder::WHITELIST); | |
| 1378 builder.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 1379 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter(); | |
| 1380 | |
| 1381 EXPECT_CALL(*tester.store(), | |
| 1382 RemoveLoginsByURLAndTimeImpl(ProbablySameFilter(filter), _, _)) | |
| 1383 .WillOnce(Return(password_manager::PasswordStoreChangeList())); | |
| 1384 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
| 1385 BrowsingDataRemover::REMOVE_PASSWORDS, builder); | |
| 1386 } | |
| 1387 | |
| 1388 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DisableAutoSignIn) { | |
| 1389 RemovePasswordsTester tester(GetProfile()); | |
| 1390 base::Callback<bool(const GURL&)> empty_filter = | |
| 1391 BrowsingDataFilterBuilder::BuildNoopFilter(); | |
| 1392 | |
| 1393 EXPECT_CALL( | |
| 1394 *tester.store(), | |
| 1395 DisableAutoSignInForOriginsImpl(ProbablySameFilter(empty_filter))) | |
| 1396 .WillOnce(Return(password_manager::PasswordStoreChangeList())); | |
| 1397 | |
| 1398 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1399 BrowsingDataRemover::REMOVE_COOKIES, false); | |
| 1400 } | |
| 1401 | |
| 1402 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1403 DisableAutoSignInAfterRemovingPasswords) { | |
| 1404 RemovePasswordsTester tester(GetProfile()); | |
| 1405 base::Callback<bool(const GURL&)> empty_filter = | |
| 1406 BrowsingDataFilterBuilder::BuildNoopFilter(); | |
| 1407 | |
| 1408 EXPECT_CALL(*tester.store(), RemoveLoginsByURLAndTimeImpl(_, _, _)) | |
| 1409 .WillOnce(Return(password_manager::PasswordStoreChangeList())); | |
| 1410 EXPECT_CALL( | |
| 1411 *tester.store(), | |
| 1412 DisableAutoSignInForOriginsImpl(ProbablySameFilter(empty_filter))) | |
| 1413 .WillOnce(Return(password_manager::PasswordStoreChangeList())); | |
| 1414 | |
| 1415 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1416 BrowsingDataRemover::REMOVE_COOKIES | | |
| 1417 BrowsingDataRemover::REMOVE_PASSWORDS, | |
| 1418 false); | |
| 1419 } | |
| 1420 | |
| 1421 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1422 RemoveContentSettingsWithBlacklist) { | |
| 1423 // Add our settings. | |
| 1424 HostContentSettingsMap* host_content_settings_map = | |
| 1425 HostContentSettingsMapFactory::GetForProfile(GetProfile()); | |
| 1426 host_content_settings_map->SetWebsiteSettingDefaultScope( | |
| 1427 kOrigin1, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), | |
| 1428 base::MakeUnique<base::DictionaryValue>()); | |
| 1429 host_content_settings_map->SetWebsiteSettingDefaultScope( | |
| 1430 kOrigin2, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), | |
| 1431 base::MakeUnique<base::DictionaryValue>()); | |
| 1432 host_content_settings_map->SetWebsiteSettingDefaultScope( | |
| 1433 kOrigin3, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), | |
| 1434 base::MakeUnique<base::DictionaryValue>()); | |
| 1435 host_content_settings_map->SetWebsiteSettingDefaultScope( | |
| 1436 kOrigin4, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), | |
| 1437 base::MakeUnique<base::DictionaryValue>()); | |
| 1438 | |
| 1439 // Clear all except for origin1 and origin3. | |
| 1440 RegistrableDomainFilterBuilder filter( | |
| 1441 RegistrableDomainFilterBuilder::BLACKLIST); | |
| 1442 filter.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 1443 filter.AddRegisterableDomain(kTestRegisterableDomain3); | |
| 1444 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 1445 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, | |
| 1446 filter); | |
| 1447 | |
| 1448 EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, GetRemovalMask()); | |
| 1449 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1450 | |
| 1451 // Verify we only have true, and they're origin1, origin3, and origin4. | |
| 1452 ContentSettingsForOneType host_settings; | |
| 1453 host_content_settings_map->GetSettingsForOneType( | |
| 1454 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | |
| 1455 EXPECT_EQ(3u, host_settings.size()); | |
| 1456 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin1), | |
| 1457 host_settings[0].primary_pattern) | |
| 1458 << host_settings[0].primary_pattern.ToString(); | |
| 1459 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin4), | |
| 1460 host_settings[1].primary_pattern) | |
| 1461 << host_settings[1].primary_pattern.ToString(); | |
| 1462 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin3), | |
| 1463 host_settings[2].primary_pattern) | |
| 1464 << host_settings[2].primary_pattern.ToString(); | |
| 1465 } | |
| 1466 | |
| 1467 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveDurablePermission) { | |
| 1468 // Add our settings. | |
| 1469 HostContentSettingsMap* host_content_settings_map = | |
| 1470 HostContentSettingsMapFactory::GetForProfile(GetProfile()); | |
| 1471 | |
| 1472 DurableStoragePermissionContext durable_permission(GetProfile()); | |
| 1473 durable_permission.UpdateContentSetting(kOrigin1, GURL(), | |
| 1474 CONTENT_SETTING_ALLOW); | |
| 1475 durable_permission.UpdateContentSetting(kOrigin2, GURL(), | |
| 1476 CONTENT_SETTING_ALLOW); | |
| 1477 | |
| 1478 // Clear all except for origin1 and origin3. | |
| 1479 RegistrableDomainFilterBuilder filter( | |
| 1480 RegistrableDomainFilterBuilder::BLACKLIST); | |
| 1481 filter.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 1482 filter.AddRegisterableDomain(kTestRegisterableDomain3); | |
| 1483 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 1484 BrowsingDataRemover::REMOVE_DURABLE_PERMISSION, | |
| 1485 filter); | |
| 1486 | |
| 1487 EXPECT_EQ(BrowsingDataRemover::REMOVE_DURABLE_PERMISSION, GetRemovalMask()); | |
| 1488 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); | |
| 1489 | |
| 1490 // Verify we only have allow for the first origin. | |
| 1491 ContentSettingsForOneType host_settings; | |
| 1492 host_content_settings_map->GetSettingsForOneType( | |
| 1493 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, std::string(), &host_settings); | |
| 1494 | |
| 1495 ASSERT_EQ(2u, host_settings.size()); | |
| 1496 // Only the first should should have a setting. | |
| 1497 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin1), | |
| 1498 host_settings[0].primary_pattern) | |
| 1499 << host_settings[0].primary_pattern.ToString(); | |
| 1500 EXPECT_EQ(CONTENT_SETTING_ALLOW, host_settings[0].setting); | |
| 1501 | |
| 1502 // And our wildcard. | |
| 1503 EXPECT_EQ(ContentSettingsPattern::Wildcard(), | |
| 1504 host_settings[1].primary_pattern) | |
| 1505 << host_settings[1].primary_pattern.ToString(); | |
| 1506 EXPECT_EQ(CONTENT_SETTING_ASK, host_settings[1].setting); | |
| 1507 } | |
| 1508 | |
| 1509 // Test that removing passwords clears HTTP auth data. | |
| 1510 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1511 ClearHttpAuthCache_RemovePasswords) { | |
| 1512 net::HttpNetworkSession* http_session = GetProfile() | |
| 1513 ->GetRequestContext() | |
| 1514 ->GetURLRequestContext() | |
| 1515 ->http_transaction_factory() | |
| 1516 ->GetSession(); | |
| 1517 DCHECK(http_session); | |
| 1518 | |
| 1519 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache(); | |
| 1520 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC, | |
| 1521 "test challenge", | |
| 1522 net::AuthCredentials(base::ASCIIToUTF16("foo"), | |
| 1523 base::ASCIIToUTF16("bar")), | |
| 1524 "/"); | |
| 1525 CHECK(http_auth_cache->Lookup(kOrigin1, kTestRealm, | |
| 1526 net::HttpAuth::AUTH_SCHEME_BASIC)); | |
| 1527 | |
| 1528 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
| 1529 BrowsingDataRemover::REMOVE_PASSWORDS, false); | |
| 1530 | |
| 1531 EXPECT_EQ(nullptr, http_auth_cache->Lookup(kOrigin1, kTestRealm, | |
| 1532 net::HttpAuth::AUTH_SCHEME_BASIC)); | |
| 1533 } | |
| 1534 | |
| 1535 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ClearPermissionPromptCounts) { | |
| 1536 RemovePermissionPromptCountsTest tester(GetProfile()); | |
| 1537 | |
| 1538 RegistrableDomainFilterBuilder filter_builder_1( | |
| 1539 RegistrableDomainFilterBuilder::WHITELIST); | |
| 1540 filter_builder_1.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 1541 | |
| 1542 RegistrableDomainFilterBuilder filter_builder_2( | |
| 1543 RegistrableDomainFilterBuilder::BLACKLIST); | |
| 1544 filter_builder_2.AddRegisterableDomain(kTestRegisterableDomain1); | |
| 1545 | |
| 1546 { | |
| 1547 // Test REMOVE_HISTORY. | |
| 1548 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, | |
| 1549 content::PermissionType::GEOLOCATION)); | |
| 1550 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1, | |
| 1551 content::PermissionType::GEOLOCATION)); | |
| 1552 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, | |
| 1553 content::PermissionType::NOTIFICATIONS)); | |
| 1554 tester.ShouldChangeDismissalToBlock(kOrigin1, | |
| 1555 content::PermissionType::MIDI_SYSEX); | |
| 1556 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2, | |
| 1557 content::PermissionType::DURABLE_STORAGE)); | |
| 1558 tester.ShouldChangeDismissalToBlock(kOrigin2, | |
| 1559 content::PermissionType::NOTIFICATIONS); | |
| 1560 | |
| 1561 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 1562 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, | |
| 1563 filter_builder_1); | |
| 1564 | |
| 1565 // kOrigin1 should be gone, but kOrigin2 remains. | |
| 1566 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, | |
| 1567 content::PermissionType::GEOLOCATION)); | |
| 1568 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, | |
| 1569 content::PermissionType::NOTIFICATIONS)); | |
| 1570 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1, | |
| 1571 content::PermissionType::MIDI_SYSEX)); | |
| 1572 EXPECT_EQ(1, tester.GetIgnoreCount( | |
| 1573 kOrigin2, content::PermissionType::DURABLE_STORAGE)); | |
| 1574 EXPECT_EQ(1, tester.GetDismissCount( | |
| 1575 kOrigin2, content::PermissionType::NOTIFICATIONS)); | |
| 1576 | |
| 1577 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 1578 BrowsingDataRemover::REMOVE_HISTORY, false); | |
| 1579 | |
| 1580 // Everything should be gone. | |
| 1581 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, | |
| 1582 content::PermissionType::GEOLOCATION)); | |
| 1583 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, | |
| 1584 content::PermissionType::NOTIFICATIONS)); | |
| 1585 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1, | |
| 1586 content::PermissionType::MIDI_SYSEX)); | |
| 1587 EXPECT_EQ(0, tester.GetIgnoreCount( | |
| 1588 kOrigin2, content::PermissionType::DURABLE_STORAGE)); | |
| 1589 EXPECT_EQ(0, tester.GetDismissCount( | |
| 1590 kOrigin2, content::PermissionType::NOTIFICATIONS)); | |
| 1591 } | |
| 1592 { | |
| 1593 // Test REMOVE_SITE_DATA. | |
| 1594 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, | |
| 1595 content::PermissionType::GEOLOCATION)); | |
| 1596 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1, | |
| 1597 content::PermissionType::GEOLOCATION)); | |
| 1598 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1, | |
| 1599 content::PermissionType::NOTIFICATIONS)); | |
| 1600 tester.ShouldChangeDismissalToBlock(kOrigin1, | |
| 1601 content::PermissionType::MIDI_SYSEX); | |
| 1602 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2, | |
| 1603 content::PermissionType::DURABLE_STORAGE)); | |
| 1604 tester.ShouldChangeDismissalToBlock(kOrigin2, | |
| 1605 content::PermissionType::NOTIFICATIONS); | |
| 1606 | |
| 1607 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 1608 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, | |
| 1609 filter_builder_2); | |
| 1610 | |
| 1611 // kOrigin2 should be gone, but kOrigin1 remains. | |
| 1612 EXPECT_EQ(2, tester.GetIgnoreCount(kOrigin1, | |
| 1613 content::PermissionType::GEOLOCATION)); | |
| 1614 EXPECT_EQ(1, tester.GetIgnoreCount(kOrigin1, | |
| 1615 content::PermissionType::NOTIFICATIONS)); | |
| 1616 EXPECT_EQ(1, tester.GetDismissCount(kOrigin1, | |
| 1617 content::PermissionType::MIDI_SYSEX)); | |
| 1618 EXPECT_EQ(0, tester.GetIgnoreCount( | |
| 1619 kOrigin2, content::PermissionType::DURABLE_STORAGE)); | |
| 1620 EXPECT_EQ(0, tester.GetDismissCount( | |
| 1621 kOrigin2, content::PermissionType::NOTIFICATIONS)); | |
| 1622 | |
| 1623 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), | |
| 1624 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, | |
| 1625 false); | |
| 1626 | |
| 1627 // Everything should be gone. | |
| 1628 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, | |
| 1629 content::PermissionType::GEOLOCATION)); | |
| 1630 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1, | |
| 1631 content::PermissionType::NOTIFICATIONS)); | |
| 1632 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1, | |
| 1633 content::PermissionType::MIDI_SYSEX)); | |
| 1634 EXPECT_EQ(0, tester.GetIgnoreCount( | |
| 1635 kOrigin2, content::PermissionType::DURABLE_STORAGE)); | |
| 1636 EXPECT_EQ(0, tester.GetDismissCount( | |
| 1637 kOrigin2, content::PermissionType::NOTIFICATIONS)); | |
| 1638 } | |
| 1639 } | |
| 1640 | |
| 1641 #if BUILDFLAG(ENABLE_PLUGINS) | |
| 1642 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePluginData) { | |
| 1643 RemovePluginDataTester tester(GetProfile()); | |
| 1644 | |
| 1645 tester.AddDomain(kOrigin1.host()); | |
| 1646 tester.AddDomain(kOrigin2.host()); | |
| 1647 tester.AddDomain(kOrigin3.host()); | |
| 1648 | |
| 1649 std::vector<std::string> expected = { | |
| 1650 kOrigin1.host(), kOrigin2.host(), kOrigin3.host() }; | |
| 1651 EXPECT_EQ(expected, tester.GetDomains()); | |
| 1652 | |
| 1653 // Delete data with a filter for the registrable domain of |kOrigin3|. | |
| 1654 RegistrableDomainFilterBuilder filter_builder( | |
| 1655 RegistrableDomainFilterBuilder::WHITELIST); | |
| 1656 filter_builder.AddRegisterableDomain(kTestRegisterableDomain3); | |
| 1657 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
| 1658 BrowsingDataRemover::REMOVE_PLUGIN_DATA, | |
| 1659 filter_builder); | |
| 1660 | |
| 1661 // Plugin data for |kOrigin3.host()| should have been removed. | |
| 1662 expected.pop_back(); | |
| 1663 EXPECT_EQ(expected, tester.GetDomains()); | |
| 1664 | |
| 1665 // TODO(msramek): Mock PluginDataRemover and test the complete deletion | |
| 1666 // of plugin data as well. | |
| 1667 } | |
| 1668 #endif | |
| 1669 | |
| 1670 // Test that the remover clears bookmark meta data (normally added in a tab | |
| 1671 // helper). | |
| 1672 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
| 1673 BookmarkLastVisitDatesGetCleared) { | |
| 1674 TestingProfile profile; | |
| 1675 profile.CreateBookmarkModel(true); | |
| 1676 | |
| 1677 bookmarks::BookmarkModel* bookmark_model = | |
| 1678 BookmarkModelFactory::GetForBrowserContext(&profile); | |
| 1679 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); | |
| 1680 | |
| 1681 const base::Time delete_begin = | |
| 1682 base::Time::Now() - base::TimeDelta::FromDays(1); | |
| 1683 | |
| 1684 // Create a couple of bookmarks. | |
| 1685 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0, | |
| 1686 base::string16(), | |
| 1687 GURL("http://foo.org/desktop")); | |
| 1688 bookmark_model->AddURL(bookmark_model->mobile_node(), 0, | |
| 1689 base::string16(), | |
| 1690 GURL("http://foo.org/mobile")); | |
| 1691 | |
| 1692 // Simulate their visits (this is using Time::Now() as timestamps). | |
| 1693 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( | |
| 1694 bookmark_model, GURL("http://foo.org/desktop"), | |
| 1695 /*is_mobile_platform=*/false); | |
| 1696 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( | |
| 1697 bookmark_model, GURL("http://foo.org/mobile"), | |
| 1698 /*is_mobile_platform=*/true); | |
| 1699 | |
| 1700 // Add a bookmark with a visited timestamp before the deletion interval. | |
| 1701 bookmarks::BookmarkNode::MetaInfoMap meta_info = { | |
| 1702 {"last_visited", | |
| 1703 base::Int64ToString((delete_begin - base::TimeDelta::FromSeconds(1)) | |
| 1704 .ToInternalValue())}}; | |
| 1705 bookmark_model->AddURLWithCreationTimeAndMetaInfo( | |
| 1706 bookmark_model->mobile_node(), 0, base::ASCIIToUTF16("my title"), | |
| 1707 GURL("http://foo-2.org/"), delete_begin - base::TimeDelta::FromDays(1), | |
| 1708 &meta_info); | |
| 1709 | |
| 1710 // There should be some recently visited bookmarks. | |
| 1711 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks( | |
| 1712 bookmark_model, 2, base::Time::UnixEpoch(), | |
| 1713 /*consider_visits_from_desktop=*/false), | |
| 1714 Not(IsEmpty())); | |
| 1715 | |
| 1716 // Inject the bookmark model into the remover. | |
| 1717 BrowsingDataRemover* remover = | |
| 1718 BrowsingDataRemoverFactory::GetForBrowserContext(&profile); | |
| 1719 | |
| 1720 BrowsingDataRemoverCompletionObserver completion_observer(remover); | |
| 1721 remover->RemoveAndReply(delete_begin, base::Time::Max(), | |
| 1722 BrowsingDataRemover::REMOVE_HISTORY, | |
| 1723 BrowsingDataHelper::ALL, &completion_observer); | |
| 1724 completion_observer.BlockUntilCompletion(); | |
| 1725 | |
| 1726 // There should be only 1 recently visited bookmarks. | |
| 1727 std::vector<const bookmarks::BookmarkNode*> remaining_nodes = | |
| 1728 ntp_snippets::GetRecentlyVisitedBookmarks( | |
| 1729 bookmark_model, 3, base::Time::UnixEpoch(), | |
| 1730 /*consider_visits_from_desktop=*/true); | |
| 1731 EXPECT_THAT(remaining_nodes, SizeIs(1)); | |
| 1732 EXPECT_THAT(remaining_nodes[0]->url().spec(), Eq("http://foo-2.org/")); | |
| 1733 } | |
| OLD | NEW |