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

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

Issue 238863005: Domain Reliability: Remove browsing data when requested. (Closed) Base URL: http://git.chromium.org/chromium/src.git@domrel_bakedin
Patch Set: Add unittest Created 6 years, 7 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
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/browsing_data_remover.h" 5 #include "chrome/browser/browsing_data/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 25 matching lines...) Expand all
36 #if defined(OS_CHROMEOS) 36 #if defined(OS_CHROMEOS)
37 #include "chromeos/dbus/dbus_thread_manager.h" 37 #include "chromeos/dbus/dbus_thread_manager.h"
38 #include "chromeos/dbus/fake_dbus_thread_manager.h" 38 #include "chromeos/dbus/fake_dbus_thread_manager.h"
39 #include "chromeos/dbus/mock_cryptohome_client.h" 39 #include "chromeos/dbus/mock_cryptohome_client.h"
40 #endif 40 #endif
41 #include "components/autofill/core/browser/autofill_profile.h" 41 #include "components/autofill/core/browser/autofill_profile.h"
42 #include "components/autofill/core/browser/autofill_test_utils.h" 42 #include "components/autofill/core/browser/autofill_test_utils.h"
43 #include "components/autofill/core/browser/credit_card.h" 43 #include "components/autofill/core/browser/credit_card.h"
44 #include "components/autofill/core/browser/personal_data_manager.h" 44 #include "components/autofill/core/browser/personal_data_manager.h"
45 #include "components/autofill/core/browser/personal_data_manager_observer.h" 45 #include "components/autofill/core/browser/personal_data_manager_observer.h"
46 #include "components/domain_reliability/clear_mode.h"
47 #include "components/domain_reliability/monitor.h"
46 #include "content/public/browser/cookie_store_factory.h" 48 #include "content/public/browser/cookie_store_factory.h"
47 #include "content/public/browser/dom_storage_context.h" 49 #include "content/public/browser/dom_storage_context.h"
48 #include "content/public/browser/local_storage_usage_info.h" 50 #include "content/public/browser/local_storage_usage_info.h"
49 #include "content/public/browser/notification_service.h" 51 #include "content/public/browser/notification_service.h"
50 #include "content/public/browser/storage_partition.h" 52 #include "content/public/browser/storage_partition.h"
51 #include "content/public/test/test_browser_thread.h" 53 #include "content/public/test/test_browser_thread.h"
52 #include "content/public/test/test_browser_thread_bundle.h" 54 #include "content/public/test/test_browser_thread_bundle.h"
53 #include "content/public/test/test_utils.h" 55 #include "content/public/test/test_utils.h"
54 #include "net/cookies/cookie_store.h" 56 #include "net/cookies/cookie_store.h"
55 #include "net/ssl/server_bound_cert_service.h" 57 #include "net/ssl/server_bound_cert_service.h"
56 #include "net/ssl/server_bound_cert_store.h" 58 #include "net/ssl/server_bound_cert_store.h"
57 #include "net/ssl/ssl_client_cert_type.h" 59 #include "net/ssl/ssl_client_cert_type.h"
58 #include "net/url_request/url_request_context.h" 60 #include "net/url_request/url_request_context.h"
59 #include "net/url_request/url_request_context_getter.h" 61 #include "net/url_request/url_request_context_getter.h"
60 #include "testing/gmock/include/gmock/gmock.h" 62 #include "testing/gmock/include/gmock/gmock.h"
61 #include "testing/gtest/include/gtest/gtest.h" 63 #include "testing/gtest/include/gtest/gtest.h"
62 64
63 using content::BrowserThread; 65 using content::BrowserThread;
64 using content::StoragePartition; 66 using content::StoragePartition;
67 using domain_reliability::CLEAR_BEACONS;
68 using domain_reliability::CLEAR_CONTEXTS;
69 using domain_reliability::DomainReliabilityClearMode;
70 using domain_reliability::DomainReliabilityMonitor;
65 using testing::_; 71 using testing::_;
66 using testing::Invoke; 72 using testing::Invoke;
67 using testing::WithArgs; 73 using testing::WithArgs;
68 74
69 namespace { 75 namespace {
70 76
71 const char kTestOrigin1[] = "http://host1:1/"; 77 const char kTestOrigin1[] = "http://host1:1/";
72 const char kTestOrigin2[] = "http://host2:1/"; 78 const char kTestOrigin2[] = "http://host2:1/";
73 const char kTestOrigin3[] = "http://host3:1/"; 79 const char kTestOrigin3[] = "http://host3:1/";
74 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; 80 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // We don't own these pointers. 573 // We don't own these pointers.
568 TestingProfile* profile_; 574 TestingProfile* profile_;
569 content::DOMStorageContext* dom_storage_context_; 575 content::DOMStorageContext* dom_storage_context_;
570 576
571 std::vector<content::LocalStorageUsageInfo> infos_; 577 std::vector<content::LocalStorageUsageInfo> infos_;
572 base::Closure quit_closure_; 578 base::Closure quit_closure_;
573 579
574 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); 580 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
575 }; 581 };
576 582
583 class TestingProfileWithDomainReliabilityMonitor : public TestingProfile {
584 public:
585 TestingProfileWithDomainReliabilityMonitor() :
586 TestingProfile(),
587 monitor_(GetRequestContext()->GetURLRequestContext()) {}
588
589 virtual void ClearDomainReliabilityMonitor(
590 DomainReliabilityClearMode mode,
591 const base::Closure& completion) OVERRIDE {
592 monitor_.ClearBrowsingData(mode);
593 completion.Run();
594 }
595
596 DomainReliabilityMonitor* monitor() { return &monitor_; }
597
598 private:
599 DomainReliabilityMonitor monitor_;
600 };
601
577 // Test Class ---------------------------------------------------------------- 602 // Test Class ----------------------------------------------------------------
578 603
579 class BrowsingDataRemoverTest : public testing::Test, 604 class BrowsingDataRemoverTest : public testing::Test,
580 public content::NotificationObserver { 605 public content::NotificationObserver {
581 public: 606 public:
582 BrowsingDataRemoverTest() 607 BrowsingDataRemoverTest()
583 : profile_(new TestingProfile()) { 608 : profile_(new TestingProfile()) {
584 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, 609 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
585 content::Source<Profile>(profile_.get())); 610 content::Source<Profile>(profile_.get()));
586 } 611 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 697
673 // We're not taking ownership of the details object, but storing a copy of 698 // We're not taking ownership of the details object, but storing a copy of
674 // it locally. 699 // it locally.
675 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( 700 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails(
676 *content::Details<BrowsingDataRemover::NotificationDetails>( 701 *content::Details<BrowsingDataRemover::NotificationDetails>(
677 details).ptr())); 702 details).ptr()));
678 703
679 registrar_.RemoveAll(); 704 registrar_.RemoveAll();
680 } 705 }
681 706
707 DomainReliabilityMonitor *UseProfileWithDomainReliabilityMonitor() {
708 TestingProfileWithDomainReliabilityMonitor* new_profile =
709 new TestingProfileWithDomainReliabilityMonitor();
710 DomainReliabilityMonitor* monitor = new_profile->monitor();
711 profile_.reset(new_profile);
712 return monitor;
713 }
714
682 protected: 715 protected:
683 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; 716 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
684 717
685 private: 718 private:
686 content::NotificationRegistrar registrar_; 719 content::NotificationRegistrar registrar_;
687 720
688 content::TestBrowserThreadBundle thread_bundle_; 721 content::TestBrowserThreadBundle thread_bundle_;
689 scoped_ptr<TestingProfile> profile_; 722 scoped_ptr<TestingProfile> profile_;
690 723
691 StoragePartitionRemovalData storage_partition_removal_data_; 724 StoragePartitionRemovalData storage_partition_removal_data_;
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _)) 1630 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _))
1598 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall))); 1631 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall)));
1599 1632
1600 BlockUntilBrowsingDataRemoved( 1633 BlockUntilBrowsingDataRemoved(
1601 BrowsingDataRemover::EVERYTHING, 1634 BrowsingDataRemover::EVERYTHING,
1602 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false); 1635 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false);
1603 1636
1604 chromeos::DBusThreadManager::Shutdown(); 1637 chromeos::DBusThreadManager::Shutdown();
1605 } 1638 }
1606 #endif 1639 #endif
1640
1641 TEST_F(BrowsingDataRemoverTest, ClearDomainReliabilityMonitor_Null) {
1642 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1643 EXPECT_FALSE(monitor->was_cleared_for_testing());
1644 }
1645
1646 TEST_F(BrowsingDataRemoverTest, ClearDomainReliabilityMonitor_Beacons) {
1647 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1648 BlockUntilBrowsingDataRemoved(
1649 BrowsingDataRemover::EVERYTHING,
1650 BrowsingDataRemover::REMOVE_HISTORY, false);
1651 EXPECT_TRUE(monitor->was_cleared_for_testing());
1652 EXPECT_EQ(CLEAR_BEACONS, monitor->cleared_mode_for_testing());
1653 }
1654
1655 TEST_F(BrowsingDataRemoverTest, ClearDomainReliabilityMonitor_Contexts) {
1656 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1657 BlockUntilBrowsingDataRemoved(
1658 BrowsingDataRemover::EVERYTHING,
1659 BrowsingDataRemover::REMOVE_COOKIES, false);
Mike West 2014/05/08 11:00:40 Could you add a test with the protected origins fl
Deprecated (see juliatuttle) 2014/05/08 15:47:39 Done.
1660 EXPECT_TRUE(monitor->was_cleared_for_testing());
1661 EXPECT_EQ(CLEAR_CONTEXTS, monitor->cleared_mode_for_testing());
1662 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698