| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data_remover.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 // Test Class ---------------------------------------------------------------- | 285 // Test Class ---------------------------------------------------------------- |
| 286 | 286 |
| 287 class BrowsingDataRemoverTest : public testing::Test, | 287 class BrowsingDataRemoverTest : public testing::Test, |
| 288 public content::NotificationObserver { | 288 public content::NotificationObserver { |
| 289 public: | 289 public: |
| 290 BrowsingDataRemoverTest() | 290 BrowsingDataRemoverTest() |
| 291 : ui_thread_(BrowserThread::UI, &message_loop_), | 291 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 292 db_thread_(BrowserThread::DB, &message_loop_), | 292 db_thread_(BrowserThread::DB, &message_loop_), |
| 293 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), | 293 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), |
| 294 file_thread_(BrowserThread::FILE, &message_loop_), | 294 file_thread_(BrowserThread::FILE, &message_loop_), |
| 295 file_user_blocking_thread_( |
| 296 BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
| 295 io_thread_(BrowserThread::IO, &message_loop_), | 297 io_thread_(BrowserThread::IO, &message_loop_), |
| 296 profile_(new TestingProfile()) { | 298 profile_(new TestingProfile()) { |
| 297 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, | 299 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, |
| 298 content::Source<Profile>(profile_.get())); | 300 content::Source<Profile>(profile_.get())); |
| 299 } | 301 } |
| 300 | 302 |
| 301 virtual ~BrowsingDataRemoverTest() { | 303 virtual ~BrowsingDataRemoverTest() { |
| 302 } | 304 } |
| 303 | 305 |
| 304 void TearDown() { | 306 void TearDown() { |
| 305 // TestingProfile contains a WebKitContext. WebKitContext's destructor | 307 // TestingProfile contains a WebKitContext. WebKitContext's destructor |
| 306 // posts a message to the WEBKIT thread to delete some of its member | 308 // posts a message to the WEBKIT thread to delete some of its member |
| 307 // variables. We need to ensure that the profile is destroyed, and that | 309 // variables. We need to ensure that the profile is destroyed, and that |
| 308 // the message loop is cleared out, before destroying the threads and loop. | 310 // the message loop is cleared out, before destroying the threads and loop. |
| 309 // Otherwise we leak memory. | 311 // Otherwise we leak memory. |
| 310 profile_.reset(); | 312 profile_.reset(); |
| 311 message_loop_.RunAllPending(); | 313 message_loop_.RunAllPending(); |
| 312 } | 314 } |
| 313 | 315 |
| 314 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, | 316 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, |
| 315 int remove_mask, | 317 int remove_mask, |
| 316 BrowsingDataRemoverTester* tester) { | 318 BrowsingDataRemoverTester* tester) { |
| 317 BrowsingDataRemover* remover = new BrowsingDataRemover( | 319 BrowsingDataRemover* remover = new BrowsingDataRemover( |
| 318 profile_.get(), period, | 320 profile_.get(), period, |
| 319 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); | 321 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); |
| 322 remover->OverrideQuotaManagerForTesting(GetMockManager()); |
| 320 remover->AddObserver(tester); | 323 remover->AddObserver(tester); |
| 321 | 324 |
| 322 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); | 325 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); |
| 323 | 326 |
| 324 // BrowsingDataRemover deletes itself when it completes. | 327 // BrowsingDataRemover deletes itself when it completes. |
| 325 remover->Remove(remove_mask); | 328 remover->Remove(remove_mask); |
| 326 tester->BlockUntilNotified(); | 329 tester->BlockUntilNotified(); |
| 327 } | 330 } |
| 328 | 331 |
| 329 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period, | 332 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period, |
| 330 int remove_mask, | 333 int remove_mask, |
| 331 const GURL& remove_origin, | 334 const GURL& remove_origin, |
| 332 BrowsingDataRemoverTester* tester) { | 335 BrowsingDataRemoverTester* tester) { |
| 333 BrowsingDataRemover* remover = new BrowsingDataRemover( | 336 BrowsingDataRemover* remover = new BrowsingDataRemover( |
| 334 profile_.get(), period, | 337 profile_.get(), period, |
| 335 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); | 338 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); |
| 339 remover->OverrideQuotaManagerForTesting(GetMockManager()); |
| 336 remover->AddObserver(tester); | 340 remover->AddObserver(tester); |
| 337 | 341 |
| 338 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); | 342 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); |
| 339 | 343 |
| 340 // BrowsingDataRemover deletes itself when it completes. | 344 // BrowsingDataRemover deletes itself when it completes. |
| 341 remover->RemoveImpl(remove_mask, remove_origin, false); | 345 remover->RemoveImpl(remove_mask, remove_origin, false); |
| 342 tester->BlockUntilNotified(); | 346 tester->BlockUntilNotified(); |
| 343 } | 347 } |
| 344 | 348 |
| 345 TestingProfile* GetProfile() { | 349 TestingProfile* GetProfile() { |
| 346 return profile_.get(); | 350 return profile_.get(); |
| 347 } | 351 } |
| 348 | 352 |
| 349 base::Time GetBeginTime() { | 353 base::Time GetBeginTime() { |
| 350 return called_with_details_->removal_begin; | 354 return called_with_details_->removal_begin; |
| 351 } | 355 } |
| 352 | 356 |
| 353 int GetRemovalMask() { | 357 int GetRemovalMask() { |
| 354 return called_with_details_->removal_mask; | 358 return called_with_details_->removal_mask; |
| 355 } | 359 } |
| 356 | 360 |
| 357 quota::MockQuotaManager* GetMockManager() { | 361 quota::MockQuotaManager* GetMockManager() { |
| 358 if (profile_->GetQuotaManager() == NULL) { | 362 if (!quota_manager_) { |
| 359 profile_->SetQuotaManager(new quota::MockQuotaManager( | 363 quota_manager_ = new quota::MockQuotaManager( |
| 360 profile_->IsOffTheRecord(), | 364 profile_->IsOffTheRecord(), |
| 361 profile_->GetPath(), | 365 profile_->GetPath(), |
| 362 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 366 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 363 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 367 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
| 364 profile_->GetExtensionSpecialStoragePolicy())); | 368 profile_->GetExtensionSpecialStoragePolicy()); |
| 365 } | 369 } |
| 366 return (quota::MockQuotaManager*) profile_->GetQuotaManager(); | 370 return quota_manager_; |
| 367 } | 371 } |
| 368 | 372 |
| 369 // content::NotificationObserver implementation. | 373 // content::NotificationObserver implementation. |
| 370 virtual void Observe(int type, | 374 virtual void Observe(int type, |
| 371 const content::NotificationSource& source, | 375 const content::NotificationSource& source, |
| 372 const content::NotificationDetails& details) OVERRIDE { | 376 const content::NotificationDetails& details) OVERRIDE { |
| 373 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED); | 377 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED); |
| 374 | 378 |
| 375 // We're not taking ownership of the details object, but storing a copy of | 379 // We're not taking ownership of the details object, but storing a copy of |
| 376 // it locally. | 380 // it locally. |
| 377 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( | 381 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( |
| 378 *content::Details<BrowsingDataRemover::NotificationDetails>( | 382 *content::Details<BrowsingDataRemover::NotificationDetails>( |
| 379 details).ptr())); | 383 details).ptr())); |
| 380 | 384 |
| 381 registrar_.RemoveAll(); | 385 registrar_.RemoveAll(); |
| 382 } | 386 } |
| 383 | 387 |
| 384 private: | 388 private: |
| 385 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; | 389 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; |
| 386 content::NotificationRegistrar registrar_; | 390 content::NotificationRegistrar registrar_; |
| 387 | 391 |
| 388 // message_loop_, as well as all the threads associated with it must be | 392 // message_loop_, as well as all the threads associated with it must be |
| 389 // defined before profile_ to prevent explosions. Oh how I love C++. | 393 // defined before profile_ to prevent explosions. Oh how I love C++. |
| 390 MessageLoopForUI message_loop_; | 394 MessageLoopForUI message_loop_; |
| 391 content::TestBrowserThread ui_thread_; | 395 content::TestBrowserThread ui_thread_; |
| 392 content::TestBrowserThread db_thread_; | 396 content::TestBrowserThread db_thread_; |
| 393 content::TestBrowserThread webkit_thread_; | 397 content::TestBrowserThread webkit_thread_; |
| 394 content::TestBrowserThread file_thread_; | 398 content::TestBrowserThread file_thread_; |
| 399 content::TestBrowserThread file_user_blocking_thread_; |
| 395 content::TestBrowserThread io_thread_; | 400 content::TestBrowserThread io_thread_; |
| 396 scoped_ptr<TestingProfile> profile_; | 401 scoped_ptr<TestingProfile> profile_; |
| 402 scoped_refptr<quota::MockQuotaManager> quota_manager_; |
| 397 | 403 |
| 398 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); | 404 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); |
| 399 }; | 405 }; |
| 400 | 406 |
| 401 // Tests --------------------------------------------------------------------- | 407 // Tests --------------------------------------------------------------------- |
| 402 | 408 |
| 403 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { | 409 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { |
| 404 scoped_ptr<RemoveCookieTester> tester( | 410 scoped_ptr<RemoveCookieTester> tester( |
| 405 new RemoveCookieTester(GetProfile())); | 411 new RemoveCookieTester(GetProfile())); |
| 406 | 412 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); | 789 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
| 784 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); | 790 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
| 785 | 791 |
| 786 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, | 792 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, |
| 787 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get()); | 793 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get()); |
| 788 | 794 |
| 789 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); | 795 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 790 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1)); | 796 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
| 791 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); | 797 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
| 792 } | 798 } |
| OLD | NEW |