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

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

Issue 2613833004: Split BrowsingDataRemover into an abstract interface and implementation. (Closed)
Patch Set: Removed unnecessary instantiations. Created 3 years, 11 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"
6
7 #include <stddef.h> 5 #include <stddef.h>
8 #include <stdint.h> 6 #include <stdint.h>
9 7
10 #include <list> 8 #include <list>
11 #include <memory> 9 #include <memory>
12 #include <set> 10 #include <set>
13 #include <string> 11 #include <string>
14 #include <utility> 12 #include <utility>
15 #include <vector> 13 #include <vector>
16 14
(...skipping 11 matching lines...) Expand all
28 #include "base/single_thread_task_runner.h" 26 #include "base/single_thread_task_runner.h"
29 #include "base/strings/string_number_conversions.h" 27 #include "base/strings/string_number_conversions.h"
30 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
31 #include "base/task/cancelable_task_tracker.h" 29 #include "base/task/cancelable_task_tracker.h"
32 #include "base/threading/thread_task_runner_handle.h" 30 #include "base/threading/thread_task_runner_handle.h"
33 #include "build/build_config.h" 31 #include "build/build_config.h"
34 #include "chrome/browser/autofill/personal_data_manager_factory.h" 32 #include "chrome/browser/autofill/personal_data_manager_factory.h"
35 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 33 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
36 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h" 34 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h"
37 #include "chrome/browser/browsing_data/browsing_data_helper.h" 35 #include "chrome/browser/browsing_data/browsing_data_helper.h"
36 #include "chrome/browser/browsing_data/browsing_data_remover.h"
38 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 37 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
38 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h"
39 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" 39 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
40 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" 40 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
41 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h" 41 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h"
42 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 42 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
43 #include "chrome/browser/domain_reliability/service_factory.h" 43 #include "chrome/browser/domain_reliability/service_factory.h"
44 #include "chrome/browser/download/chrome_download_manager_delegate.h" 44 #include "chrome/browser/download/chrome_download_manager_delegate.h"
45 #include "chrome/browser/favicon/favicon_service_factory.h" 45 #include "chrome/browser/favicon/favicon_service_factory.h"
46 #include "chrome/browser/history/history_service_factory.h" 46 #include "chrome/browser/history/history_service_factory.h"
47 #include "chrome/browser/password_manager/password_store_factory.h" 47 #include "chrome/browser/password_manager/password_store_factory.h"
48 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" 48 #include "chrome/browser/permissions/permission_decision_auto_blocker.h"
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 1083
1084 private: 1084 private:
1085 TestingProfile* profile_; 1085 TestingProfile* profile_;
1086 1086
1087 DISALLOW_COPY_AND_ASSIGN(RemovePermissionPromptCountsTest); 1087 DISALLOW_COPY_AND_ASSIGN(RemovePermissionPromptCountsTest);
1088 }; 1088 };
1089 1089
1090 #if BUILDFLAG(ENABLE_PLUGINS) 1090 #if BUILDFLAG(ENABLE_PLUGINS)
1091 // A small modification to MockBrowsingDataFlashLSOHelper so that it responds 1091 // A small modification to MockBrowsingDataFlashLSOHelper so that it responds
1092 // immediately and does not wait for the Notify() call. Otherwise it would 1092 // immediately and does not wait for the Notify() call. Otherwise it would
1093 // deadlock BrowsingDataRemover::RemoveImpl. 1093 // deadlock BrowsingDataRemoverImpl::RemoveImpl.
1094 class TestBrowsingDataFlashLSOHelper : public MockBrowsingDataFlashLSOHelper { 1094 class TestBrowsingDataFlashLSOHelper : public MockBrowsingDataFlashLSOHelper {
1095 public: 1095 public:
1096 explicit TestBrowsingDataFlashLSOHelper(TestingProfile* profile) 1096 explicit TestBrowsingDataFlashLSOHelper(TestingProfile* profile)
1097 : MockBrowsingDataFlashLSOHelper(profile) {} 1097 : MockBrowsingDataFlashLSOHelper(profile) {}
1098 1098
1099 void StartFetching(const GetSitesWithFlashDataCallback& callback) override { 1099 void StartFetching(const GetSitesWithFlashDataCallback& callback) override {
1100 MockBrowsingDataFlashLSOHelper::StartFetching(callback); 1100 MockBrowsingDataFlashLSOHelper::StartFetching(callback);
1101 Notify(); 1101 Notify();
1102 } 1102 }
1103 1103
1104 private: 1104 private:
1105 ~TestBrowsingDataFlashLSOHelper() override {} 1105 ~TestBrowsingDataFlashLSOHelper() override {}
1106 1106
1107 DISALLOW_COPY_AND_ASSIGN(TestBrowsingDataFlashLSOHelper); 1107 DISALLOW_COPY_AND_ASSIGN(TestBrowsingDataFlashLSOHelper);
1108 }; 1108 };
1109 1109
1110 class RemovePluginDataTester { 1110 class RemovePluginDataTester {
1111 public: 1111 public:
1112 explicit RemovePluginDataTester(TestingProfile* profile) 1112 explicit RemovePluginDataTester(TestingProfile* profile)
1113 : helper_(new TestBrowsingDataFlashLSOHelper(profile)) { 1113 : helper_(new TestBrowsingDataFlashLSOHelper(profile)) {
1114 BrowsingDataRemoverFactory::GetForBrowserContext(profile) 1114 static_cast<BrowsingDataRemoverImpl*>(
1115 ->OverrideFlashLSOHelperForTesting(helper_); 1115 BrowsingDataRemoverFactory::GetForBrowserContext(profile))
1116 ->OverrideFlashLSOHelperForTesting(helper_);
1116 } 1117 }
1117 1118
1118 void AddDomain(const std::string& domain) { 1119 void AddDomain(const std::string& domain) {
1119 helper_->AddFlashLSODomain(domain); 1120 helper_->AddFlashLSODomain(domain);
1120 } 1121 }
1121 1122
1122 const std::vector<std::string>& GetDomains() { 1123 const std::vector<std::string>& GetDomains() {
1123 // TestBrowsingDataFlashLSOHelper is synchronous, so we can immediately 1124 // TestBrowsingDataFlashLSOHelper is synchronous, so we can immediately
1124 // return the fetched domains. 1125 // return the fetched domains.
1125 helper_->StartFetching( 1126 helper_->StartFetching(
(...skipping 14 matching lines...) Expand all
1140 }; 1141 };
1141 #endif 1142 #endif
1142 1143
1143 // Test Class ---------------------------------------------------------------- 1144 // Test Class ----------------------------------------------------------------
1144 1145
1145 class BrowsingDataRemoverTest : public testing::Test { 1146 class BrowsingDataRemoverTest : public testing::Test {
1146 public: 1147 public:
1147 BrowsingDataRemoverTest() 1148 BrowsingDataRemoverTest()
1148 : profile_(new TestingProfile()), 1149 : profile_(new TestingProfile()),
1149 clear_domain_reliability_tester_(GetProfile()) { 1150 clear_domain_reliability_tester_(GetProfile()) {
1150 remover_ = 1151 remover_ = static_cast<BrowsingDataRemoverImpl*>(
1151 BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()); 1152 BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()));
1152 1153
1153 #if BUILDFLAG(ANDROID_JAVA_UI) 1154 #if BUILDFLAG(ANDROID_JAVA_UI)
1154 static_cast<ChromeBrowsingDataRemoverDelegate*>( 1155 static_cast<ChromeBrowsingDataRemoverDelegate*>(
1155 remover_->get_embedder_delegate())->OverrideWebappRegistryForTesting( 1156 remover_->GetEmbedderDelegate())->OverrideWebappRegistryForTesting(
1156 base::WrapUnique<WebappRegistry>(new TestWebappRegistry())); 1157 base::WrapUnique<WebappRegistry>(new TestWebappRegistry()));
1157 #endif 1158 #endif
1158 } 1159 }
1159 1160
1160 ~BrowsingDataRemoverTest() override {} 1161 ~BrowsingDataRemoverTest() override {}
1161 1162
1162 void TearDown() override { 1163 void TearDown() override {
1163 #if BUILDFLAG(ENABLE_EXTENSIONS) 1164 #if BUILDFLAG(ENABLE_EXTENSIONS)
1164 mock_policy_ = nullptr; 1165 mock_policy_ = nullptr;
1165 #endif 1166 #endif
1166 1167
1167 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor 1168 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor
1168 // posts a message to the WEBKIT thread to delete some of its member 1169 // posts a message to the WEBKIT thread to delete some of its member
1169 // variables. We need to ensure that the profile is destroyed, and that 1170 // variables. We need to ensure that the profile is destroyed, and that
1170 // the message loop is cleared out, before destroying the threads and loop. 1171 // the message loop is cleared out, before destroying the threads and loop.
1171 // Otherwise we leak memory. 1172 // Otherwise we leak memory.
1172 profile_.reset(); 1173 profile_.reset();
1173 base::RunLoop().RunUntilIdle(); 1174 base::RunLoop().RunUntilIdle();
1174 1175
1175 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); 1176 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
1176 } 1177 }
1177 1178
1178 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin, 1179 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin,
1179 const base::Time& delete_end, 1180 const base::Time& delete_end,
1180 int remove_mask, 1181 int remove_mask,
1181 bool include_protected_origins) { 1182 bool include_protected_origins) {
1182 BrowsingDataRemover* remover =
1183 BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get());
1184
1185 TestStoragePartition storage_partition; 1183 TestStoragePartition storage_partition;
1186 remover->OverrideStoragePartitionForTesting(&storage_partition); 1184 remover_->OverrideStoragePartitionForTesting(&storage_partition);
1187 1185
1188 int origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB; 1186 int origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB;
1189 if (include_protected_origins) 1187 if (include_protected_origins)
1190 origin_type_mask |= BrowsingDataHelper::PROTECTED_WEB; 1188 origin_type_mask |= BrowsingDataHelper::PROTECTED_WEB;
1191 1189
1192 BrowsingDataRemoverCompletionObserver completion_observer(remover); 1190 BrowsingDataRemoverCompletionObserver completion_observer(remover_);
1193 remover->RemoveAndReply( 1191 remover_->RemoveAndReply(
1194 delete_begin, delete_end, remove_mask, origin_type_mask, 1192 delete_begin, delete_end, remove_mask, origin_type_mask,
1195 &completion_observer); 1193 &completion_observer);
1196 completion_observer.BlockUntilCompletion(); 1194 completion_observer.BlockUntilCompletion();
1197 1195
1198 // Save so we can verify later. 1196 // Save so we can verify later.
1199 storage_partition_removal_data_ = 1197 storage_partition_removal_data_ =
1200 storage_partition.GetStoragePartitionRemovalData(); 1198 storage_partition.GetStoragePartitionRemovalData();
1201 } 1199 }
1202 1200
1203 void BlockUntilOriginDataRemoved( 1201 void BlockUntilOriginDataRemoved(
1204 const base::Time& delete_begin, 1202 const base::Time& delete_begin,
1205 const base::Time& delete_end, 1203 const base::Time& delete_end,
1206 int remove_mask, 1204 int remove_mask,
1207 const BrowsingDataFilterBuilder& filter_builder) { 1205 const BrowsingDataFilterBuilder& filter_builder) {
1208 BrowsingDataRemover* remover =
1209 BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get());
1210 TestStoragePartition storage_partition; 1206 TestStoragePartition storage_partition;
1211 remover->OverrideStoragePartitionForTesting(&storage_partition); 1207 remover_->OverrideStoragePartitionForTesting(&storage_partition);
1212 1208
1213 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; 1209 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
1214 remover->RemoveImpl(delete_begin, delete_end, remove_mask, filter_builder, 1210 remover_->RemoveImpl(delete_begin, delete_end, remove_mask, filter_builder,
1215 BrowsingDataHelper::UNPROTECTED_WEB); 1211 BrowsingDataHelper::UNPROTECTED_WEB);
1216 completion_inhibitor.BlockUntilNearCompletion(); 1212 completion_inhibitor.BlockUntilNearCompletion();
1217 completion_inhibitor.ContinueToCompletion(); 1213 completion_inhibitor.ContinueToCompletion();
1218 1214
1219 // Save so we can verify later. 1215 // Save so we can verify later.
1220 storage_partition_removal_data_ = 1216 storage_partition_removal_data_ =
1221 storage_partition.GetStoragePartitionRemovalData(); 1217 storage_partition.GetStoragePartitionRemovalData();
1222 } 1218 }
1223 1219
1224 TestingProfile* GetProfile() { 1220 TestingProfile* GetProfile() {
1225 return profile_.get(); 1221 return profile_.get();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 #else 1265 #else
1270 return true; 1266 return true;
1271 #endif 1267 #endif
1272 } 1268 }
1273 1269
1274 const ClearDomainReliabilityTester& clear_domain_reliability_tester() { 1270 const ClearDomainReliabilityTester& clear_domain_reliability_tester() {
1275 return clear_domain_reliability_tester_; 1271 return clear_domain_reliability_tester_;
1276 } 1272 }
1277 1273
1278 private: 1274 private:
1279 // Cached pointer to BrowsingDataRemover for access to testing methods. 1275 // Cached pointer to BrowsingDataRemoverImpl for access to testing methods.
1280 BrowsingDataRemover* remover_; 1276 BrowsingDataRemoverImpl* remover_;
1281 1277
1282 content::TestBrowserThreadBundle thread_bundle_; 1278 content::TestBrowserThreadBundle thread_bundle_;
1283 std::unique_ptr<TestingProfile> profile_; 1279 std::unique_ptr<TestingProfile> profile_;
1284 1280
1285 StoragePartitionRemovalData storage_partition_removal_data_; 1281 StoragePartitionRemovalData storage_partition_removal_data_;
1286 1282
1287 #if BUILDFLAG(ENABLE_EXTENSIONS) 1283 #if BUILDFLAG(ENABLE_EXTENSIONS)
1288 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_; 1284 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_;
1289 #endif 1285 #endif
1290 1286
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
2298 2294
2299 private: 2295 private:
2300 bool called_ = false; 2296 bool called_ = false;
2301 }; 2297 };
2302 2298
2303 TEST_F(BrowsingDataRemoverTest, CompletionInhibition) { 2299 TEST_F(BrowsingDataRemoverTest, CompletionInhibition) {
2304 // The |completion_inhibitor| on the stack should prevent removal sessions 2300 // The |completion_inhibitor| on the stack should prevent removal sessions
2305 // from completing until after ContinueToCompletion() is called. 2301 // from completing until after ContinueToCompletion() is called.
2306 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; 2302 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
2307 2303
2308 BrowsingDataRemover* remover = 2304 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
2309 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()); 2305 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()));
2310 InspectableCompletionObserver completion_observer(remover); 2306 InspectableCompletionObserver completion_observer(remover);
2311 remover->RemoveAndReply(base::Time(), base::Time::Max(), 2307 remover->RemoveAndReply(base::Time(), base::Time::Max(),
2312 BrowsingDataRemover::REMOVE_HISTORY, 2308 BrowsingDataRemover::REMOVE_HISTORY,
2313 BrowsingDataHelper::UNPROTECTED_WEB, 2309 BrowsingDataHelper::UNPROTECTED_WEB,
2314 &completion_observer); 2310 &completion_observer);
2315 2311
2316 // Process messages until the inhibitor is notified, and then some, to make 2312 // Process messages until the inhibitor is notified, and then some, to make
2317 // sure we do not complete asynchronously before ContinueToCompletion() is 2313 // sure we do not complete asynchronously before ContinueToCompletion() is
2318 // called. 2314 // called.
2319 completion_inhibitor.BlockUntilNearCompletion(); 2315 completion_inhibitor.BlockUntilNearCompletion();
2320 base::RunLoop().RunUntilIdle(); 2316 base::RunLoop().RunUntilIdle();
2321 2317
2322 // Verify that the removal has not yet been completed and the observer has 2318 // Verify that the removal has not yet been completed and the observer has
2323 // not been called. 2319 // not been called.
2324 EXPECT_TRUE(remover->is_removing()); 2320 EXPECT_TRUE(remover->is_removing());
2325 EXPECT_FALSE(completion_observer.called()); 2321 EXPECT_FALSE(completion_observer.called());
2326 2322
2327 // Now run the removal process until completion, and verify that observers are 2323 // Now run the removal process until completion, and verify that observers are
2328 // now notified, and the notifications is sent out. 2324 // now notified, and the notifications is sent out.
2329 completion_inhibitor.ContinueToCompletion(); 2325 completion_inhibitor.ContinueToCompletion();
2330 completion_observer.BlockUntilCompletion(); 2326 completion_observer.BlockUntilCompletion();
2331 2327
2332 EXPECT_FALSE(remover->is_removing()); 2328 EXPECT_FALSE(remover->is_removing());
2333 EXPECT_TRUE(completion_observer.called()); 2329 EXPECT_TRUE(completion_observer.called());
2334 } 2330 }
2335 2331
2336 TEST_F(BrowsingDataRemoverTest, EarlyShutdown) { 2332 TEST_F(BrowsingDataRemoverTest, EarlyShutdown) {
2337 BrowsingDataRemover* remover = 2333 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
2338 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()); 2334 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()));
2339 InspectableCompletionObserver completion_observer(remover); 2335 InspectableCompletionObserver completion_observer(remover);
2340 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; 2336 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
2341 remover->RemoveAndReply(base::Time(), base::Time::Max(), 2337 remover->RemoveAndReply(base::Time(), base::Time::Max(),
2342 BrowsingDataRemover::REMOVE_HISTORY, 2338 BrowsingDataRemover::REMOVE_HISTORY,
2343 BrowsingDataHelper::UNPROTECTED_WEB, 2339 BrowsingDataHelper::UNPROTECTED_WEB,
2344 &completion_observer); 2340 &completion_observer);
2345 2341
2346 completion_inhibitor.BlockUntilNearCompletion(); 2342 completion_inhibitor.BlockUntilNearCompletion();
2347 2343
2348 // Verify that the deletion has not yet been completed and the observer has 2344 // Verify that the deletion has not yet been completed and the observer has
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
2930 << "Call ClearLastCalledTarget() before every removal task."; 2926 << "Call ClearLastCalledTarget() before every removal task.";
2931 last_called_target_ = target; 2927 last_called_target_ = target;
2932 } 2928 }
2933 2929
2934 Target target_a_; 2930 Target target_a_;
2935 Target target_b_; 2931 Target target_b_;
2936 Target* last_called_target_; 2932 Target* last_called_target_;
2937 }; 2933 };
2938 2934
2939 TEST_F(BrowsingDataRemoverTest, MultipleTasks) { 2935 TEST_F(BrowsingDataRemoverTest, MultipleTasks) {
2940 BrowsingDataRemover* remover = 2936 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
2941 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()); 2937 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()));
2942 EXPECT_FALSE(remover->is_removing()); 2938 EXPECT_FALSE(remover->is_removing());
2943 2939
2944 std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_1( 2940 std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_1(
2945 new RegistrableDomainFilterBuilder( 2941 new RegistrableDomainFilterBuilder(
2946 RegistrableDomainFilterBuilder::WHITELIST)); 2942 RegistrableDomainFilterBuilder::WHITELIST));
2947 std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_2( 2943 std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_2(
2948 new RegistrableDomainFilterBuilder( 2944 new RegistrableDomainFilterBuilder(
2949 RegistrableDomainFilterBuilder::BLACKLIST)); 2945 RegistrableDomainFilterBuilder::BLACKLIST));
2950 filter_builder_2->AddRegisterableDomain("example.com"); 2946 filter_builder_2->AddRegisterableDomain("example.com");
2951 2947
2952 MultipleTasksObserver observer(remover); 2948 MultipleTasksObserver observer(remover);
2953 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; 2949 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
2954 2950
2955 // Test several tasks with various configuration of masks, filters, and target 2951 // Test several tasks with various configuration of masks, filters, and target
2956 // observers. 2952 // observers.
2957 std::list<BrowsingDataRemover::RemovalTask> tasks; 2953 std::list<BrowsingDataRemoverImpl::RemovalTask> tasks;
2958 tasks.emplace_back(base::Time(), base::Time::Max(), 2954 tasks.emplace_back(base::Time(), base::Time::Max(),
2959 BrowsingDataRemover::REMOVE_HISTORY, 2955 BrowsingDataRemover::REMOVE_HISTORY,
2960 BrowsingDataHelper::UNPROTECTED_WEB, 2956 BrowsingDataHelper::UNPROTECTED_WEB,
2961 base::MakeUnique<RegistrableDomainFilterBuilder>( 2957 base::MakeUnique<RegistrableDomainFilterBuilder>(
2962 RegistrableDomainFilterBuilder::BLACKLIST), 2958 RegistrableDomainFilterBuilder::BLACKLIST),
2963 observer.target_a()); 2959 observer.target_a());
2964 tasks.emplace_back(base::Time(), base::Time::Max(), 2960 tasks.emplace_back(base::Time(), base::Time::Max(),
2965 BrowsingDataRemover::REMOVE_COOKIES, 2961 BrowsingDataRemover::REMOVE_COOKIES,
2966 BrowsingDataHelper::PROTECTED_WEB, 2962 BrowsingDataHelper::PROTECTED_WEB,
2967 base::MakeUnique<RegistrableDomainFilterBuilder>( 2963 base::MakeUnique<RegistrableDomainFilterBuilder>(
(...skipping 11 matching lines...) Expand all
2979 BrowsingDataHelper::UNPROTECTED_WEB, 2975 BrowsingDataHelper::UNPROTECTED_WEB,
2980 std::move(filter_builder_1), 2976 std::move(filter_builder_1),
2981 observer.target_b()); 2977 observer.target_b());
2982 tasks.emplace_back( 2978 tasks.emplace_back(
2983 base::Time::UnixEpoch(), base::Time::Now(), 2979 base::Time::UnixEpoch(), base::Time::Now(),
2984 BrowsingDataRemover::REMOVE_CHANNEL_IDS, 2980 BrowsingDataRemover::REMOVE_CHANNEL_IDS,
2985 BrowsingDataHelper::ALL, 2981 BrowsingDataHelper::ALL,
2986 std::move(filter_builder_2), 2982 std::move(filter_builder_2),
2987 nullptr); 2983 nullptr);
2988 2984
2989 for (BrowsingDataRemover::RemovalTask& task : tasks) { 2985 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) {
2990 // All tasks can be directly translated to a RemoveInternal() call. Since 2986 // All tasks can be directly translated to a RemoveInternal() call. Since
2991 // that is a private method, we must call the four public versions of 2987 // that is a private method, we must call the four public versions of
2992 // Remove.* instead. This also serves as a test that those methods are all 2988 // Remove.* instead. This also serves as a test that those methods are all
2993 // correctly reduced to RemoveInternal(). 2989 // correctly reduced to RemoveInternal().
2994 if (!task.observer && task.filter_builder->IsEmptyBlacklist()) { 2990 if (!task.observer && task.filter_builder->IsEmptyBlacklist()) {
2995 remover->Remove(task.delete_begin, task.delete_end, 2991 remover->Remove(task.delete_begin, task.delete_end,
2996 task.remove_mask, task.origin_type_mask); 2992 task.remove_mask, task.origin_type_mask);
2997 } else if (task.filter_builder->IsEmptyBlacklist()) { 2993 } else if (task.filter_builder->IsEmptyBlacklist()) {
2998 remover->RemoveAndReply(task.delete_begin, task.delete_end, 2994 remover->RemoveAndReply(task.delete_begin, task.delete_end,
2999 task.remove_mask, task.origin_type_mask, 2995 task.remove_mask, task.origin_type_mask,
3000 task.observer); 2996 task.observer);
3001 } else if (!task.observer) { 2997 } else if (!task.observer) {
3002 remover->RemoveWithFilter(task.delete_begin, task.delete_end, 2998 remover->RemoveWithFilter(task.delete_begin, task.delete_end,
3003 task.remove_mask, task.origin_type_mask, 2999 task.remove_mask, task.origin_type_mask,
3004 std::move(task.filter_builder)); 3000 std::move(task.filter_builder));
3005 } else { 3001 } else {
3006 remover->RemoveWithFilterAndReply(task.delete_begin, task.delete_end, 3002 remover->RemoveWithFilterAndReply(task.delete_begin, task.delete_end,
3007 task.remove_mask, task.origin_type_mask, 3003 task.remove_mask, task.origin_type_mask,
3008 std::move(task.filter_builder), 3004 std::move(task.filter_builder),
3009 task.observer); 3005 task.observer);
3010 } 3006 }
3011 } 3007 }
3012 3008
3013 // Use the inhibitor to stop after every task and check the results. 3009 // Use the inhibitor to stop after every task and check the results.
3014 for (BrowsingDataRemover::RemovalTask& task : tasks) { 3010 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) {
3015 EXPECT_TRUE(remover->is_removing()); 3011 EXPECT_TRUE(remover->is_removing());
3016 observer.ClearLastCalledTarget(); 3012 observer.ClearLastCalledTarget();
3017 3013
3018 // Finish the task execution synchronously. 3014 // Finish the task execution synchronously.
3019 completion_inhibitor.BlockUntilNearCompletion(); 3015 completion_inhibitor.BlockUntilNearCompletion();
3020 completion_inhibitor.ContinueToCompletion(); 3016 completion_inhibitor.ContinueToCompletion();
3021 3017
3022 // Observers, if any, should have been called by now (since we call 3018 // Observers, if any, should have been called by now (since we call
3023 // observers on the same thread). 3019 // observers on the same thread).
3024 EXPECT_EQ(task.observer, observer.GetLastCalledTarget()); 3020 EXPECT_EQ(task.observer, observer.GetLastCalledTarget());
3025 3021
3026 // TODO(msramek): If BrowsingDataRemover took ownership of the last used 3022 // TODO(msramek): If BrowsingDataRemover took ownership of the last used
3027 // filter builder and exposed it, we could also test it here. Make it so. 3023 // filter builder and exposed it, we could also test it here. Make it so.
3028 EXPECT_EQ(task.remove_mask, GetRemovalMask()); 3024 EXPECT_EQ(task.remove_mask, GetRemovalMask());
3029 EXPECT_EQ(task.origin_type_mask, GetOriginTypeMask()); 3025 EXPECT_EQ(task.origin_type_mask, GetOriginTypeMask());
3030 EXPECT_EQ(task.delete_begin, GetBeginTime()); 3026 EXPECT_EQ(task.delete_begin, GetBeginTime());
3031 } 3027 }
3032 3028
3033 EXPECT_FALSE(remover->is_removing()); 3029 EXPECT_FALSE(remover->is_removing());
3034 } 3030 }
3035 3031
3036 // The previous test, BrowsingDataRemoverTest.MultipleTasks, tests that the 3032 // The previous test, BrowsingDataRemoverTest.MultipleTasks, tests that the
3037 // tasks are not mixed up and they are executed in a correct order. However, 3033 // tasks are not mixed up and they are executed in a correct order. However,
3038 // the completion inhibitor kept synchronizing the execution in order to verify 3034 // the completion inhibitor kept synchronizing the execution in order to verify
3039 // the parameters. This test demonstrates that even running the tasks without 3035 // the parameters. This test demonstrates that even running the tasks without
3040 // inhibition is executed correctly and doesn't crash. 3036 // inhibition is executed correctly and doesn't crash.
3041 TEST_F(BrowsingDataRemoverTest, MultipleTasksInQuickSuccession) { 3037 TEST_F(BrowsingDataRemoverTest, MultipleTasksInQuickSuccession) {
3042 BrowsingDataRemover* remover = 3038 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
3043 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()); 3039 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile()));
3044 EXPECT_FALSE(remover->is_removing()); 3040 EXPECT_FALSE(remover->is_removing());
3045 3041
3046 int test_removal_masks[] = { 3042 int test_removal_masks[] = {
3047 BrowsingDataRemover::REMOVE_COOKIES, 3043 BrowsingDataRemover::REMOVE_COOKIES,
3048 BrowsingDataRemover::REMOVE_PASSWORDS, 3044 BrowsingDataRemover::REMOVE_PASSWORDS,
3049 BrowsingDataRemover::REMOVE_COOKIES, 3045 BrowsingDataRemover::REMOVE_COOKIES,
3050 BrowsingDataRemover::REMOVE_COOKIES, 3046 BrowsingDataRemover::REMOVE_COOKIES,
3051 BrowsingDataRemover::REMOVE_COOKIES, 3047 BrowsingDataRemover::REMOVE_COOKIES,
3052 BrowsingDataRemover::REMOVE_HISTORY, 3048 BrowsingDataRemover::REMOVE_HISTORY,
3053 BrowsingDataRemover::REMOVE_HISTORY, 3049 BrowsingDataRemover::REMOVE_HISTORY,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3133 completion_observer.BlockUntilCompletion(); 3129 completion_observer.BlockUntilCompletion();
3134 3130
3135 // There should be only 1 recently visited bookmarks. 3131 // There should be only 1 recently visited bookmarks.
3136 std::vector<const bookmarks::BookmarkNode*> remaining_nodes = 3132 std::vector<const bookmarks::BookmarkNode*> remaining_nodes =
3137 ntp_snippets::GetRecentlyVisitedBookmarks( 3133 ntp_snippets::GetRecentlyVisitedBookmarks(
3138 bookmark_model, 3, base::Time::UnixEpoch(), 3134 bookmark_model, 3, base::Time::UnixEpoch(),
3139 /*consider_visits_from_desktop=*/true); 3135 /*consider_visits_from_desktop=*/true);
3140 EXPECT_THAT(remaining_nodes, SizeIs(1)); 3136 EXPECT_THAT(remaining_nodes, SizeIs(1));
3141 EXPECT_THAT(remaining_nodes[0]->url().spec(), Eq("http://foo-2.org/")); 3137 EXPECT_THAT(remaining_nodes[0]->url().spec(), Eq("http://foo-2.org/"));
3142 } 3138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698