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

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

Issue 2248403002: Implement origin-based deletion of plugin data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 4 years, 4 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 #include "chrome/browser/chromeos/settings/device_settings_service.h" 102 #include "chrome/browser/chromeos/settings/device_settings_service.h"
103 #include "chromeos/dbus/dbus_thread_manager.h" 103 #include "chromeos/dbus/dbus_thread_manager.h"
104 #include "chromeos/dbus/mock_cryptohome_client.h" 104 #include "chromeos/dbus/mock_cryptohome_client.h"
105 #include "components/signin/core/account_id/account_id.h" 105 #include "components/signin/core/account_id/account_id.h"
106 #endif 106 #endif
107 107
108 #if defined(ENABLE_EXTENSIONS) 108 #if defined(ENABLE_EXTENSIONS)
109 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" 109 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
110 #endif 110 #endif
111 111
112 #if defined(ENABLE_PLUGINS)
113 #include "chrome/browser/browsing_data/mock_browsing_data_flash_lso_helper.h"
114 #endif
115
112 class MockExtensionSpecialStoragePolicy; 116 class MockExtensionSpecialStoragePolicy;
113 117
114 using content::BrowserThread; 118 using content::BrowserThread;
115 using content::StoragePartition; 119 using content::StoragePartition;
116 using domain_reliability::CLEAR_BEACONS; 120 using domain_reliability::CLEAR_BEACONS;
117 using domain_reliability::CLEAR_CONTEXTS; 121 using domain_reliability::CLEAR_CONTEXTS;
118 using domain_reliability::DomainReliabilityClearMode; 122 using domain_reliability::DomainReliabilityClearMode;
119 using domain_reliability::DomainReliabilityMonitor; 123 using domain_reliability::DomainReliabilityMonitor;
120 using domain_reliability::DomainReliabilityService; 124 using domain_reliability::DomainReliabilityService;
121 using domain_reliability::DomainReliabilityServiceFactory; 125 using domain_reliability::DomainReliabilityServiceFactory;
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 content::PermissionType permission) { 1050 content::PermissionType permission) {
1047 return blocker_->ShouldChangeDismissalToBlock(url, permission); 1051 return blocker_->ShouldChangeDismissalToBlock(url, permission);
1048 } 1052 }
1049 1053
1050 private: 1054 private:
1051 std::unique_ptr<PermissionDecisionAutoBlocker> blocker_; 1055 std::unique_ptr<PermissionDecisionAutoBlocker> blocker_;
1052 1056
1053 DISALLOW_COPY_AND_ASSIGN(RemovePermissionPromptCountsTest); 1057 DISALLOW_COPY_AND_ASSIGN(RemovePermissionPromptCountsTest);
1054 }; 1058 };
1055 1059
1060 #if defined(ENABLE_PLUGINS)
1061 // A small modification to MockBrowsingDataFlashLSOHelper so that it responds
1062 // immediately and does not wait for the Notify() call. Otherwise it would
1063 // deadlock BrowsingDataRemover::RemoveImpl.
1064 class TestBrowsingDataFlashLSOHelper : public MockBrowsingDataFlashLSOHelper {
1065 public:
1066 explicit TestBrowsingDataFlashLSOHelper(TestingProfile* profile)
1067 : MockBrowsingDataFlashLSOHelper(profile) {}
1068
1069 void StartFetching(const GetSitesWithFlashDataCallback& callback) override {
1070 MockBrowsingDataFlashLSOHelper::StartFetching(callback);
1071 Notify();
1072 }
1073
1074 private:
1075 ~TestBrowsingDataFlashLSOHelper() override {}
1076
1077 DISALLOW_COPY_AND_ASSIGN(TestBrowsingDataFlashLSOHelper);
1078 };
1079
1080 class RemovePluginDataTester {
1081 public:
1082 explicit RemovePluginDataTester(TestingProfile* profile)
1083 : helper_(new TestBrowsingDataFlashLSOHelper(profile)) {
1084 BrowsingDataRemoverFactory::GetForBrowserContext(profile)
1085 ->OverrideFlashLSOHelperForTesting(helper_);
1086 }
1087
1088 void AddDomain(const std::string& domain) {
1089 helper_->AddFlashLSODomain(domain);
1090 }
1091
1092 const std::vector<std::string>& GetDomains() {
1093 // TestBrowsingDataFlashLSOHelper is synchronous, so we can immediately
1094 // return the fetched domains.
1095 helper_->StartFetching(
1096 base::Bind(&RemovePluginDataTester::OnSitesWithFlashDataFetched,
1097 base::Unretained(this)));
1098 return domains_;
1099 }
1100
1101 private:
1102 void OnSitesWithFlashDataFetched(const std::vector<std::string>& sites) {
1103 domains_ = sites;
1104 }
1105
1106 std::vector<std::string> domains_;
1107 scoped_refptr<TestBrowsingDataFlashLSOHelper> helper_;
1108
1109 DISALLOW_COPY_AND_ASSIGN(RemovePluginDataTester);
1110 };
1111 #endif
1112
1056 // Test Class ---------------------------------------------------------------- 1113 // Test Class ----------------------------------------------------------------
1057 1114
1058 class BrowsingDataRemoverTest : public testing::Test { 1115 class BrowsingDataRemoverTest : public testing::Test {
1059 public: 1116 public:
1060 BrowsingDataRemoverTest() 1117 BrowsingDataRemoverTest()
1061 : profile_(new TestingProfile()), 1118 : profile_(new TestingProfile()),
1062 clear_domain_reliability_tester_(GetProfile()) { 1119 clear_domain_reliability_tester_(GetProfile()) {
1063 remover_ = 1120 remover_ =
1064 BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()); 1121 BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get());
1065 1122
(...skipping 1664 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 content::PermissionType::NOTIFICATIONS)); 2787 content::PermissionType::NOTIFICATIONS));
2731 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1, 2788 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1,
2732 content::PermissionType::MIDI_SYSEX)); 2789 content::PermissionType::MIDI_SYSEX));
2733 EXPECT_EQ(0, tester.GetIgnoreCount( 2790 EXPECT_EQ(0, tester.GetIgnoreCount(
2734 kOrigin2, content::PermissionType::DURABLE_STORAGE)); 2791 kOrigin2, content::PermissionType::DURABLE_STORAGE));
2735 EXPECT_EQ(0, tester.GetDismissCount( 2792 EXPECT_EQ(0, tester.GetDismissCount(
2736 kOrigin2, content::PermissionType::NOTIFICATIONS)); 2793 kOrigin2, content::PermissionType::NOTIFICATIONS));
2737 } 2794 }
2738 } 2795 }
2739 2796
2797 #if defined(ENABLE_PLUGINS)
2798 TEST_F(BrowsingDataRemoverTest, RemovePluginData) {
2799 RemovePluginDataTester tester(GetProfile());
2800
2801 tester.AddDomain(kOrigin1.host());
2802 tester.AddDomain(kOrigin2.host());
2803 tester.AddDomain(kOrigin3.host());
2804
2805 std::vector<std::string> expected = {
2806 kOrigin1.host(), kOrigin2.host(), kOrigin3.host() };
2807 EXPECT_EQ(expected, tester.GetDomains());
2808
2809 // Delete data with a filter for the registrable domain of |kOrigin3|.
2810 RegistrableDomainFilterBuilder filter_builder(
2811 RegistrableDomainFilterBuilder::WHITELIST);
2812 filter_builder.AddRegisterableDomain(kTestRegisterableDomain3);
2813 BlockUntilOriginDataRemoved(browsing_data::ALL_TIME,
2814 BrowsingDataRemover::REMOVE_PLUGIN_DATA,
2815 filter_builder);
2816
2817 // Plugin data for |kOrigin3.host()| should have been removed.
2818 expected.pop_back();
2819 EXPECT_EQ(expected, tester.GetDomains());
2820
2821 // TODO(msramek): Mock PluginDataRemover and test the complete deletion
2822 // of plugin data as well.
2823 }
2824 #endif
2825
2740 class MultipleTasksObserver { 2826 class MultipleTasksObserver {
2741 public: 2827 public:
2742 // A simple implementation of BrowsingDataRemover::Observer. 2828 // A simple implementation of BrowsingDataRemover::Observer.
2743 // MultipleTasksObserver will use several instances of Target to test 2829 // MultipleTasksObserver will use several instances of Target to test
2744 // that completion callbacks are returned to the correct one. 2830 // that completion callbacks are returned to the correct one.
2745 class Target : public BrowsingDataRemover::Observer { 2831 class Target : public BrowsingDataRemover::Observer {
2746 public: 2832 public:
2747 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover) 2833 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover)
2748 : parent_(parent), 2834 : parent_(parent),
2749 observer_(this) { 2835 observer_(this) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2925 EXPECT_TRUE(remover->is_removing()); 3011 EXPECT_TRUE(remover->is_removing());
2926 3012
2927 // Add one more deletion and wait for it. 3013 // Add one more deletion and wait for it.
2928 BlockUntilBrowsingDataRemoved( 3014 BlockUntilBrowsingDataRemoved(
2929 browsing_data::ALL_TIME, 3015 browsing_data::ALL_TIME,
2930 BrowsingDataRemover::REMOVE_COOKIES, 3016 BrowsingDataRemover::REMOVE_COOKIES,
2931 BrowsingDataHelper::UNPROTECTED_WEB); 3017 BrowsingDataHelper::UNPROTECTED_WEB);
2932 3018
2933 EXPECT_FALSE(remover->is_removing()); 3019 EXPECT_FALSE(remover->is_removing());
2934 } 3020 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover.cc ('k') | chrome/browser/browsing_data/cookies_tree_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698