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