Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(737)

Side by Side Diff: chrome/browser/browsing_data_remover_unittest.cc

Issue 9379008: Add origin-based deletion to BrowsingDataRemover (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased + Denitted. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 const GURL kOrigin1(kTestkOrigin1); 45 const GURL kOrigin1(kTestkOrigin1);
46 const GURL kOrigin2(kTestkOrigin2); 46 const GURL kOrigin2(kTestkOrigin2);
47 const GURL kOrigin3(kTestkOrigin3); 47 const GURL kOrigin3(kTestkOrigin3);
48 48
49 const quota::StorageType kTemporary = quota::kStorageTypeTemporary; 49 const quota::StorageType kTemporary = quota::kStorageTypeTemporary;
50 const quota::StorageType kPersistent = quota::kStorageTypePersistent; 50 const quota::StorageType kPersistent = quota::kStorageTypePersistent;
51 51
52 const quota::QuotaClient::ID kClientFile = quota::QuotaClient::kFileSystem; 52 const quota::QuotaClient::ID kClientFile = quota::QuotaClient::kFileSystem;
53 const quota::QuotaClient::ID kClientDB = quota::QuotaClient::kIndexedDatabase; 53 const quota::QuotaClient::ID kClientDB = quota::QuotaClient::kIndexedDatabase;
54 54
55 } // namespace
56
55 class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer { 57 class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer {
56 public: 58 public:
57 BrowsingDataRemoverTester() 59 BrowsingDataRemoverTester()
58 : start_(false), 60 : start_(false),
59 already_quit_(false) {} 61 already_quit_(false) {}
60 virtual ~BrowsingDataRemoverTester() {} 62 virtual ~BrowsingDataRemoverTester() {}
61 63
62 void BlockUntilNotified() { 64 void BlockUntilNotified() {
63 if (!already_quit_) { 65 if (!already_quit_) {
64 DCHECK(!start_); 66 DCHECK(!start_);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); 319 base::Time::Now() + base::TimeDelta::FromMilliseconds(10));
318 remover->AddObserver(tester); 320 remover->AddObserver(tester);
319 321
320 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); 322 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
321 323
322 // BrowsingDataRemover deletes itself when it completes. 324 // BrowsingDataRemover deletes itself when it completes.
323 remover->Remove(remove_mask); 325 remover->Remove(remove_mask);
324 tester->BlockUntilNotified(); 326 tester->BlockUntilNotified();
325 } 327 }
326 328
329 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period,
330 int remove_mask,
331 const GURL& remove_origin,
332 BrowsingDataRemoverTester* tester) {
333 BrowsingDataRemover* remover = new BrowsingDataRemover(
334 profile_.get(), period,
335 base::Time::Now() + base::TimeDelta::FromMilliseconds(10));
336 remover->AddObserver(tester);
337
338 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
339
340 // BrowsingDataRemover deletes itself when it completes.
341 remover->RemoveImpl(remove_mask, remove_origin, false);
342 tester->BlockUntilNotified();
343 }
344
327 TestingProfile* GetProfile() { 345 TestingProfile* GetProfile() {
328 return profile_.get(); 346 return profile_.get();
329 } 347 }
330 348
331 base::Time GetBeginTime() { 349 base::Time GetBeginTime() {
332 return called_with_details_->removal_begin; 350 return called_with_details_->removal_begin;
333 } 351 }
334 352
335 int GetRemovalMask() { 353 int GetRemovalMask() {
336 return called_with_details_->removal_mask; 354 return called_with_details_->removal_mask;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, 680 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
663 kClientFile)); 681 kClientFile));
664 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, 682 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
665 kClientFile)); 683 kClientFile));
666 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, 684 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
667 kClientFile)); 685 kClientFile));
668 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, 686 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
669 kClientFile)); 687 kClientFile));
670 } 688 }
671 689
672 } // namespace 690 TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) {
691 scoped_ptr<RemoveHistoryTester> tester(
692 new RemoveHistoryTester(GetProfile()));
693
694 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
695
696 tester->AddHistory(kOrigin1, base::Time::Now());
697 tester->AddHistory(kOrigin2, two_hours_ago);
698 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1));
699 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2));
700
701 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
702 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get());
703
704 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
705 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1));
706 EXPECT_FALSE(tester->HistoryContainsURL(kOrigin2));
707 }
708
709 TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) {
710 scoped_ptr<RemoveHistoryTester> tester(
711 new RemoveHistoryTester(GetProfile()));
712
713 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
714
715 tester->AddHistory(kOrigin1, base::Time::Now());
716 tester->AddHistory(kOrigin2, two_hours_ago);
717 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1));
718 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2));
719
720 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
721 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get());
722
723 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
724 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1));
725 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2));
726 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698