| 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 // Test Class ---------------------------------------------------------------- | 283 // Test Class ---------------------------------------------------------------- |
| 284 | 284 |
| 285 class BrowsingDataRemoverTest : public testing::Test, | 285 class BrowsingDataRemoverTest : public testing::Test, |
| 286 public content::NotificationObserver { | 286 public content::NotificationObserver { |
| 287 public: | 287 public: |
| 288 BrowsingDataRemoverTest() | 288 BrowsingDataRemoverTest() |
| 289 : ui_thread_(BrowserThread::UI, &message_loop_), | 289 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 290 db_thread_(BrowserThread::DB, &message_loop_), | 290 db_thread_(BrowserThread::DB, &message_loop_), |
| 291 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), | 291 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), |
| 292 file_thread_(BrowserThread::FILE, &message_loop_), | 292 file_thread_(BrowserThread::FILE, &message_loop_), |
| 293 file_user_blocking_thread_( |
| 294 BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
| 293 io_thread_(BrowserThread::IO, &message_loop_), | 295 io_thread_(BrowserThread::IO, &message_loop_), |
| 294 profile_(new TestingProfile()) { | 296 profile_(new TestingProfile()) { |
| 295 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, | 297 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, |
| 296 content::Source<Profile>(profile_.get())); | 298 content::Source<Profile>(profile_.get())); |
| 297 } | 299 } |
| 298 | 300 |
| 299 virtual ~BrowsingDataRemoverTest() { | 301 virtual ~BrowsingDataRemoverTest() { |
| 300 } | 302 } |
| 301 | 303 |
| 302 void TearDown() { | 304 void TearDown() { |
| 303 // TestingProfile contains a WebKitContext. WebKitContext's destructor | 305 // TestingProfile contains a WebKitContext. WebKitContext's destructor |
| 304 // posts a message to the WEBKIT thread to delete some of its member | 306 // posts a message to the WEBKIT thread to delete some of its member |
| 305 // variables. We need to ensure that the profile is destroyed, and that | 307 // variables. We need to ensure that the profile is destroyed, and that |
| 306 // the message loop is cleared out, before destroying the threads and loop. | 308 // the message loop is cleared out, before destroying the threads and loop. |
| 307 // Otherwise we leak memory. | 309 // Otherwise we leak memory. |
| 308 profile_.reset(); | 310 profile_.reset(); |
| 309 message_loop_.RunAllPending(); | 311 message_loop_.RunAllPending(); |
| 310 } | 312 } |
| 311 | 313 |
| 312 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, | 314 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, |
| 313 int remove_mask, | 315 int remove_mask, |
| 314 BrowsingDataRemoverTester* tester) { | 316 BrowsingDataRemoverTester* tester) { |
| 315 BrowsingDataRemover* remover = new BrowsingDataRemover( | 317 BrowsingDataRemover* remover = new BrowsingDataRemover( |
| 316 profile_.get(), period, | 318 profile_.get(), period, |
| 317 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); | 319 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); |
| 320 remover->OverrideQuotaManagerForTesting(GetMockManager()); |
| 318 remover->AddObserver(tester); | 321 remover->AddObserver(tester); |
| 319 | 322 |
| 320 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); | 323 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); |
| 321 | 324 |
| 322 // BrowsingDataRemover deletes itself when it completes. | 325 // BrowsingDataRemover deletes itself when it completes. |
| 323 remover->Remove(remove_mask); | 326 remover->Remove(remove_mask); |
| 324 tester->BlockUntilNotified(); | 327 tester->BlockUntilNotified(); |
| 325 } | 328 } |
| 326 | 329 |
| 327 TestingProfile* GetProfile() { | 330 TestingProfile* GetProfile() { |
| 328 return profile_.get(); | 331 return profile_.get(); |
| 329 } | 332 } |
| 330 | 333 |
| 331 base::Time GetBeginTime() { | 334 base::Time GetBeginTime() { |
| 332 return called_with_details_->removal_begin; | 335 return called_with_details_->removal_begin; |
| 333 } | 336 } |
| 334 | 337 |
| 335 int GetRemovalMask() { | 338 int GetRemovalMask() { |
| 336 return called_with_details_->removal_mask; | 339 return called_with_details_->removal_mask; |
| 337 } | 340 } |
| 338 | 341 |
| 339 quota::MockQuotaManager* GetMockManager() { | 342 quota::MockQuotaManager* GetMockManager() { |
| 340 if (profile_->GetQuotaManager() == NULL) { | 343 if (!quota_manager_) { |
| 341 profile_->SetQuotaManager(new quota::MockQuotaManager( | 344 quota_manager_ = new quota::MockQuotaManager( |
| 342 profile_->IsOffTheRecord(), | 345 profile_->IsOffTheRecord(), |
| 343 profile_->GetPath(), | 346 profile_->GetPath(), |
| 344 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 347 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 345 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 348 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
| 346 profile_->GetExtensionSpecialStoragePolicy())); | 349 profile_->GetExtensionSpecialStoragePolicy()); |
| 347 } | 350 } |
| 348 return (quota::MockQuotaManager*) profile_->GetQuotaManager(); | 351 return quota_manager_; |
| 349 } | 352 } |
| 350 | 353 |
| 351 // content::NotificationObserver implementation. | 354 // content::NotificationObserver implementation. |
| 352 virtual void Observe(int type, | 355 virtual void Observe(int type, |
| 353 const content::NotificationSource& source, | 356 const content::NotificationSource& source, |
| 354 const content::NotificationDetails& details) OVERRIDE { | 357 const content::NotificationDetails& details) OVERRIDE { |
| 355 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED); | 358 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED); |
| 356 | 359 |
| 357 // We're not taking ownership of the details object, but storing a copy of | 360 // We're not taking ownership of the details object, but storing a copy of |
| 358 // it locally. | 361 // it locally. |
| 359 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( | 362 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( |
| 360 *content::Details<BrowsingDataRemover::NotificationDetails>( | 363 *content::Details<BrowsingDataRemover::NotificationDetails>( |
| 361 details).ptr())); | 364 details).ptr())); |
| 362 | 365 |
| 363 registrar_.RemoveAll(); | 366 registrar_.RemoveAll(); |
| 364 } | 367 } |
| 365 | 368 |
| 366 private: | 369 private: |
| 367 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; | 370 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; |
| 368 content::NotificationRegistrar registrar_; | 371 content::NotificationRegistrar registrar_; |
| 369 | 372 |
| 370 // message_loop_, as well as all the threads associated with it must be | 373 // message_loop_, as well as all the threads associated with it must be |
| 371 // defined before profile_ to prevent explosions. Oh how I love C++. | 374 // defined before profile_ to prevent explosions. Oh how I love C++. |
| 372 MessageLoopForUI message_loop_; | 375 MessageLoopForUI message_loop_; |
| 373 content::TestBrowserThread ui_thread_; | 376 content::TestBrowserThread ui_thread_; |
| 374 content::TestBrowserThread db_thread_; | 377 content::TestBrowserThread db_thread_; |
| 375 content::TestBrowserThread webkit_thread_; | 378 content::TestBrowserThread webkit_thread_; |
| 376 content::TestBrowserThread file_thread_; | 379 content::TestBrowserThread file_thread_; |
| 380 content::TestBrowserThread file_user_blocking_thread_; |
| 377 content::TestBrowserThread io_thread_; | 381 content::TestBrowserThread io_thread_; |
| 378 scoped_ptr<TestingProfile> profile_; | 382 scoped_ptr<TestingProfile> profile_; |
| 383 scoped_refptr<quota::MockQuotaManager> quota_manager_; |
| 379 | 384 |
| 380 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); | 385 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); |
| 381 }; | 386 }; |
| 382 | 387 |
| 383 // Tests --------------------------------------------------------------------- | 388 // Tests --------------------------------------------------------------------- |
| 384 | 389 |
| 385 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { | 390 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { |
| 386 scoped_ptr<RemoveCookieTester> tester( | 391 scoped_ptr<RemoveCookieTester> tester( |
| 387 new RemoveCookieTester(GetProfile())); | 392 new RemoveCookieTester(GetProfile())); |
| 388 | 393 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 kClientFile)); | 668 kClientFile)); |
| 664 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, | 669 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 665 kClientFile)); | 670 kClientFile)); |
| 666 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, | 671 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 667 kClientFile)); | 672 kClientFile)); |
| 668 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, | 673 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 669 kClientFile)); | 674 kClientFile)); |
| 670 } | 675 } |
| 671 | 676 |
| 672 } // namespace | 677 } // namespace |
| OLD | NEW |