Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
| 23 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 24 #include "base/run_loop.h" | 24 #include "base/run_loop.h" |
| 25 #include "base/single_thread_task_runner.h" | 25 #include "base/single_thread_task_runner.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/task/cancelable_task_tracker.h" | 27 #include "base/task/cancelable_task_tracker.h" |
| 28 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 29 #include "base/time/time.h" | 29 #include "base/time/time.h" |
| 30 #include "build/build_config.h" | 30 #include "build/build_config.h" |
| 31 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 31 #include "content/browser/browsing_data/browsing_data_remover_impl.h" |
| 32 #include "chrome/browser/browsing_data/browsing_data_remover.h" | |
| 33 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | |
| 34 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" | |
| 35 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | |
| 36 #include "chrome/test/base/testing_profile.h" | |
| 37 #include "content/public/browser/browser_context.h" | 32 #include "content/public/browser/browser_context.h" |
| 38 #include "content/public/browser/browsing_data_filter_builder.h" | 33 #include "content/public/browser/browsing_data_filter_builder.h" |
| 34 #include "content/public/browser/browsing_data_remover.h" | |
| 39 #include "content/public/browser/cookie_store_factory.h" | 35 #include "content/public/browser/cookie_store_factory.h" |
| 40 #include "content/public/browser/dom_storage_context.h" | 36 #include "content/public/browser/dom_storage_context.h" |
| 41 #include "content/public/browser/local_storage_usage_info.h" | 37 #include "content/public/browser/local_storage_usage_info.h" |
| 42 #include "content/public/browser/storage_partition.h" | 38 #include "content/public/browser/storage_partition.h" |
| 39 #include "content/public/test/browsing_data_remover_test_util.h" | |
| 43 #include "content/public/test/mock_download_manager.h" | 40 #include "content/public/test/mock_download_manager.h" |
| 41 #include "content/public/test/test_browser_context.h" | |
| 44 #include "content/public/test/test_browser_thread.h" | 42 #include "content/public/test/test_browser_thread.h" |
| 45 #include "content/public/test/test_browser_thread_bundle.h" | 43 #include "content/public/test/test_browser_thread_bundle.h" |
| 46 #include "content/public/test/test_utils.h" | 44 #include "content/public/test/test_utils.h" |
| 47 #include "extensions/features/features.h" | |
| 48 #include "net/cookies/cookie_store.h" | 45 #include "net/cookies/cookie_store.h" |
| 49 #include "net/http/http_network_session.h" | 46 #include "net/http/http_network_session.h" |
| 50 #include "net/http/http_transaction_factory.h" | 47 #include "net/http/http_transaction_factory.h" |
| 51 #include "net/ssl/channel_id_service.h" | 48 #include "net/ssl/channel_id_service.h" |
| 52 #include "net/ssl/channel_id_store.h" | 49 #include "net/ssl/channel_id_store.h" |
| 53 #include "net/ssl/ssl_client_cert_type.h" | 50 #include "net/ssl/ssl_client_cert_type.h" |
| 54 #include "net/url_request/url_request_context.h" | 51 #include "net/url_request/url_request_context.h" |
| 55 #include "net/url_request/url_request_context_getter.h" | 52 #include "net/url_request/url_request_context_getter.h" |
| 56 #include "ppapi/features/features.h" | 53 #include "ppapi/features/features.h" |
| 57 #include "storage/browser/test/mock_special_storage_policy.h" | 54 #include "storage/browser/test/mock_special_storage_policy.h" |
| 58 #include "testing/gmock/include/gmock/gmock.h" | 55 #include "testing/gmock/include/gmock/gmock.h" |
| 59 #include "testing/gtest/include/gtest/gtest.h" | 56 #include "testing/gtest/include/gtest/gtest.h" |
| 60 #include "url/origin.h" | 57 #include "url/origin.h" |
| 61 | 58 |
| 62 using content::BrowserThread; | |
| 63 using content::BrowserContext; | |
| 64 using content::BrowsingDataFilterBuilder; | |
| 65 using content::StoragePartition; | |
| 66 using testing::_; | 59 using testing::_; |
| 67 using testing::ByRef; | 60 using testing::ByRef; |
| 68 using testing::Eq; | 61 using testing::Eq; |
| 69 using testing::Invoke; | 62 using testing::Invoke; |
| 70 using testing::IsEmpty; | 63 using testing::IsEmpty; |
| 71 using testing::Matcher; | 64 using testing::Matcher; |
| 72 using testing::MakeMatcher; | 65 using testing::MakeMatcher; |
| 73 using testing::MatcherInterface; | 66 using testing::MatcherInterface; |
| 74 using testing::MatchResultListener; | 67 using testing::MatchResultListener; |
| 75 using testing::Not; | 68 using testing::Not; |
| 76 using testing::Return; | 69 using testing::Return; |
| 77 using testing::SizeIs; | 70 using testing::SizeIs; |
| 78 using testing::WithArgs; | 71 using testing::WithArgs; |
| 79 | 72 |
| 73 namespace content { | |
| 74 | |
| 80 namespace { | 75 namespace { |
| 81 | 76 |
| 82 const char kTestOrigin1[] = "http://host1.com:1/"; | 77 const char kTestOrigin1[] = "http://host1.com:1/"; |
| 83 const char kTestRegisterableDomain1[] = "host1.com"; | 78 const char kTestRegisterableDomain1[] = "host1.com"; |
| 84 const char kTestOrigin2[] = "http://host2.com:1/"; | 79 const char kTestOrigin2[] = "http://host2.com:1/"; |
| 85 const char kTestOrigin3[] = "http://host3.com:1/"; | 80 const char kTestOrigin3[] = "http://host3.com:1/"; |
| 86 const char kTestRegisterableDomain3[] = "host3.com"; | 81 const char kTestRegisterableDomain3[] = "host3.com"; |
| 87 const char kTestOrigin4[] = "https://host3.com:1/"; | 82 const char kTestOrigin4[] = "https://host3.com:1/"; |
| 88 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; | 83 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; |
| 89 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; | 84 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 net::COOKIE_PRIORITY_MEDIUM)); | 123 net::COOKIE_PRIORITY_MEDIUM)); |
| 129 EXPECT_TRUE(cookie); | 124 EXPECT_TRUE(cookie); |
| 130 return *cookie; | 125 return *cookie; |
| 131 } | 126 } |
| 132 | 127 |
| 133 class TestStoragePartition : public StoragePartition { | 128 class TestStoragePartition : public StoragePartition { |
| 134 public: | 129 public: |
| 135 TestStoragePartition() {} | 130 TestStoragePartition() {} |
| 136 ~TestStoragePartition() override {} | 131 ~TestStoragePartition() override {} |
| 137 | 132 |
| 138 // content::StoragePartition implementation. | 133 // StoragePartition implementation. |
| 139 base::FilePath GetPath() override { return base::FilePath(); } | 134 base::FilePath GetPath() override { return base::FilePath(); } |
| 140 net::URLRequestContextGetter* GetURLRequestContext() override { | 135 net::URLRequestContextGetter* GetURLRequestContext() override { |
| 141 return nullptr; | 136 return nullptr; |
| 142 } | 137 } |
| 143 net::URLRequestContextGetter* GetMediaURLRequestContext() override { | 138 net::URLRequestContextGetter* GetMediaURLRequestContext() override { |
| 144 return nullptr; | 139 return nullptr; |
| 145 } | 140 } |
| 146 storage::QuotaManager* GetQuotaManager() override { return nullptr; } | 141 storage::QuotaManager* GetQuotaManager() override { return nullptr; } |
| 147 content::AppCacheService* GetAppCacheService() override { return nullptr; } | 142 AppCacheService* GetAppCacheService() override { return nullptr; } |
| 148 storage::FileSystemContext* GetFileSystemContext() override { | 143 storage::FileSystemContext* GetFileSystemContext() override { |
| 149 return nullptr; | 144 return nullptr; |
| 150 } | 145 } |
| 151 storage::DatabaseTracker* GetDatabaseTracker() override { return nullptr; } | 146 storage::DatabaseTracker* GetDatabaseTracker() override { return nullptr; } |
| 152 content::DOMStorageContext* GetDOMStorageContext() override { | 147 DOMStorageContext* GetDOMStorageContext() override { return nullptr; } |
| 148 IndexedDBContext* GetIndexedDBContext() override { return nullptr; } | |
| 149 ServiceWorkerContext* GetServiceWorkerContext() override { return nullptr; } | |
| 150 CacheStorageContext* GetCacheStorageContext() override { return nullptr; } | |
| 151 PlatformNotificationContext* GetPlatformNotificationContext() override { | |
| 153 return nullptr; | 152 return nullptr; |
| 154 } | 153 } |
| 155 content::IndexedDBContext* GetIndexedDBContext() override { return nullptr; } | 154 HostZoomMap* GetHostZoomMap() override { return nullptr; } |
| 156 content::ServiceWorkerContext* GetServiceWorkerContext() override { | 155 HostZoomLevelContext* GetHostZoomLevelContext() override { return nullptr; } |
| 157 return nullptr; | 156 ZoomLevelDelegate* GetZoomLevelDelegate() override { return nullptr; } |
| 158 } | |
| 159 content::CacheStorageContext* GetCacheStorageContext() override { | |
| 160 return nullptr; | |
| 161 } | |
| 162 content::PlatformNotificationContext* GetPlatformNotificationContext() | |
| 163 override { | |
| 164 return nullptr; | |
| 165 } | |
| 166 content::HostZoomMap* GetHostZoomMap() override { return nullptr; } | |
| 167 content::HostZoomLevelContext* GetHostZoomLevelContext() override { | |
| 168 return nullptr; | |
| 169 } | |
| 170 content::ZoomLevelDelegate* GetZoomLevelDelegate() override { | |
| 171 return nullptr; | |
| 172 } | |
| 173 | 157 |
| 174 void ClearDataForOrigin(uint32_t remove_mask, | 158 void ClearDataForOrigin(uint32_t remove_mask, |
| 175 uint32_t quota_storage_remove_mask, | 159 uint32_t quota_storage_remove_mask, |
| 176 const GURL& storage_origin, | 160 const GURL& storage_origin, |
| 177 net::URLRequestContextGetter* rq_context, | 161 net::URLRequestContextGetter* rq_context, |
| 178 const base::Closure& callback) override { | 162 const base::Closure& callback) override { |
| 179 BrowserThread::PostTask(BrowserThread::UI, | 163 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 180 FROM_HERE, | |
| 181 base::Bind(&TestStoragePartition::AsyncRunCallback, | 164 base::Bind(&TestStoragePartition::AsyncRunCallback, |
| 182 base::Unretained(this), | 165 base::Unretained(this), callback)); |
| 183 callback)); | |
| 184 } | 166 } |
| 185 | 167 |
| 186 void ClearData(uint32_t remove_mask, | 168 void ClearData(uint32_t remove_mask, |
| 187 uint32_t quota_storage_remove_mask, | 169 uint32_t quota_storage_remove_mask, |
| 188 const GURL& storage_origin, | 170 const GURL& storage_origin, |
| 189 const OriginMatcherFunction& origin_matcher, | 171 const OriginMatcherFunction& origin_matcher, |
| 190 const base::Time begin, | 172 const base::Time begin, |
| 191 const base::Time end, | 173 const base::Time end, |
| 192 const base::Closure& callback) override { | 174 const base::Closure& callback) override { |
| 193 // Store stuff to verify parameters' correctness later. | 175 // Store stuff to verify parameters' correctness later. |
| 194 storage_partition_removal_data_.remove_mask = remove_mask; | 176 storage_partition_removal_data_.remove_mask = remove_mask; |
| 195 storage_partition_removal_data_.quota_storage_remove_mask = | 177 storage_partition_removal_data_.quota_storage_remove_mask = |
| 196 quota_storage_remove_mask; | 178 quota_storage_remove_mask; |
| 197 storage_partition_removal_data_.remove_begin = begin; | 179 storage_partition_removal_data_.remove_begin = begin; |
| 198 storage_partition_removal_data_.remove_end = end; | 180 storage_partition_removal_data_.remove_end = end; |
| 199 storage_partition_removal_data_.origin_matcher = origin_matcher; | 181 storage_partition_removal_data_.origin_matcher = origin_matcher; |
| 200 | 182 |
| 201 BrowserThread::PostTask( | 183 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 202 BrowserThread::UI, | 184 base::Bind(&TestStoragePartition::AsyncRunCallback, |
| 203 FROM_HERE, | 185 base::Unretained(this), callback)); |
| 204 base::Bind(&TestStoragePartition::AsyncRunCallback, | |
| 205 base::Unretained(this), callback)); | |
| 206 } | 186 } |
| 207 | 187 |
| 208 void ClearData(uint32_t remove_mask, | 188 void ClearData(uint32_t remove_mask, |
| 209 uint32_t quota_storage_remove_mask, | 189 uint32_t quota_storage_remove_mask, |
| 210 const OriginMatcherFunction& origin_matcher, | 190 const OriginMatcherFunction& origin_matcher, |
| 211 const CookieMatcherFunction& cookie_matcher, | 191 const CookieMatcherFunction& cookie_matcher, |
| 212 const base::Time begin, | 192 const base::Time begin, |
| 213 const base::Time end, | 193 const base::Time end, |
| 214 const base::Closure& callback) override { | 194 const base::Closure& callback) override { |
| 215 // Store stuff to verify parameters' correctness later. | 195 // Store stuff to verify parameters' correctness later. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 236 | 216 |
| 237 void Flush() override {} | 217 void Flush() override {} |
| 238 | 218 |
| 239 void ClearBluetoothAllowedDevicesMapForTesting() override {} | 219 void ClearBluetoothAllowedDevicesMapForTesting() override {} |
| 240 | 220 |
| 241 StoragePartitionRemovalData GetStoragePartitionRemovalData() { | 221 StoragePartitionRemovalData GetStoragePartitionRemovalData() { |
| 242 return storage_partition_removal_data_; | 222 return storage_partition_removal_data_; |
| 243 } | 223 } |
| 244 | 224 |
| 245 private: | 225 private: |
| 246 void AsyncRunCallback(const base::Closure& callback) { | 226 void AsyncRunCallback(const base::Closure& callback) { callback.Run(); } |
| 247 callback.Run(); | |
| 248 } | |
| 249 | 227 |
| 250 StoragePartitionRemovalData storage_partition_removal_data_; | 228 StoragePartitionRemovalData storage_partition_removal_data_; |
| 251 | 229 |
| 252 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); | 230 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); |
| 253 }; | 231 }; |
| 254 | 232 |
| 255 // Custom matcher to test the equivalence of two URL filters. Since those are | 233 // Custom matcher to test the equivalence of two URL filters. Since those are |
| 256 // blackbox predicates, we can only approximate the equivalence by testing | 234 // blackbox predicates, we can only approximate the equivalence by testing |
| 257 // whether the filter give the same answer for several URLs. This is currently | 235 // whether the filter give the same answer for several URLs. This is currently |
| 258 // good enough for our testing purposes, to distinguish whitelists | 236 // good enough for our testing purposes, to distinguish whitelists |
| 259 // and blacklists, empty and non-empty filters and such. | 237 // and blacklists, empty and non-empty filters and such. |
| 260 // TODO(msramek): BrowsingDataRemover and some of its backends support URL | 238 // TODO(msramek): BrowsingDataRemover and some of its backends support URL |
| 261 // filters, but its constructor currently only takes a single URL and constructs | 239 // filters, but its constructor currently only takes a single URL and constructs |
| 262 // its own url filter. If an url filter was directly passed to | 240 // its own url filter. If an url filter was directly passed to |
| 263 // BrowsingDataRemover (what should eventually be the case), we can use the same | 241 // BrowsingDataRemover (what should eventually be the case), we can use the same |
| 264 // instance in the test as well, and thus simply test base::Callback::Equals() | 242 // instance in the test as well, and thus simply test base::Callback::Equals() |
| 265 // in this matcher. | 243 // in this matcher. |
| 266 class ProbablySameFilterMatcher | 244 class ProbablySameFilterMatcher |
| 267 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> { | 245 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> { |
| 268 public: | 246 public: |
| 269 explicit ProbablySameFilterMatcher( | 247 explicit ProbablySameFilterMatcher( |
| 270 const base::Callback<bool(const GURL&)>& filter) | 248 const base::Callback<bool(const GURL&)>& filter) |
| 271 : to_match_(filter) { | 249 : to_match_(filter) {} |
| 272 } | |
| 273 | 250 |
| 274 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, | 251 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, |
| 275 MatchResultListener* listener) const { | 252 MatchResultListener* listener) const { |
| 276 if (filter.is_null() && to_match_.is_null()) | 253 if (filter.is_null() && to_match_.is_null()) |
| 277 return true; | 254 return true; |
| 278 if (filter.is_null() != to_match_.is_null()) | 255 if (filter.is_null() != to_match_.is_null()) |
| 279 return false; | 256 return false; |
| 280 | 257 |
| 281 const GURL urls_to_test_[] = | 258 const GURL urls_to_test_[] = {kOrigin1, kOrigin2, kOrigin3, |
| 282 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")}; | 259 GURL("invalid spec")}; |
| 283 for (GURL url : urls_to_test_) { | 260 for (GURL url : urls_to_test_) { |
| 284 if (filter.Run(url) != to_match_.Run(url)) { | 261 if (filter.Run(url) != to_match_.Run(url)) { |
| 285 if (listener) | 262 if (listener) |
| 286 *listener << "The filters differ on the URL " << url; | 263 *listener << "The filters differ on the URL " << url; |
| 287 return false; | 264 return false; |
| 288 } | 265 } |
| 289 } | 266 } |
| 290 return true; | 267 return true; |
| 291 } | 268 } |
| 292 | 269 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 314 } // namespace | 291 } // namespace |
| 315 | 292 |
| 316 // Testers ------------------------------------------------------------------- | 293 // Testers ------------------------------------------------------------------- |
| 317 | 294 |
| 318 class RemoveCookieTester { | 295 class RemoveCookieTester { |
| 319 public: | 296 public: |
| 320 RemoveCookieTester() {} | 297 RemoveCookieTester() {} |
| 321 | 298 |
| 322 // Returns true, if the given cookie exists in the cookie store. | 299 // Returns true, if the given cookie exists in the cookie store. |
| 323 bool ContainsCookie() { | 300 bool ContainsCookie() { |
| 324 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 301 scoped_refptr<MessageLoopRunner> message_loop_runner = |
| 325 new content::MessageLoopRunner; | 302 new MessageLoopRunner(); |
| 326 quit_closure_ = message_loop_runner->QuitClosure(); | 303 quit_closure_ = message_loop_runner->QuitClosure(); |
| 327 get_cookie_success_ = false; | 304 get_cookie_success_ = false; |
| 328 cookie_store_->GetCookiesWithOptionsAsync( | 305 cookie_store_->GetCookiesWithOptionsAsync( |
| 329 kOrigin1, net::CookieOptions(), | 306 kOrigin1, net::CookieOptions(), |
| 330 base::Bind(&RemoveCookieTester::GetCookieCallback, | 307 base::Bind(&RemoveCookieTester::GetCookieCallback, |
| 331 base::Unretained(this))); | 308 base::Unretained(this))); |
| 332 message_loop_runner->Run(); | 309 message_loop_runner->Run(); |
| 333 return get_cookie_success_; | 310 return get_cookie_success_; |
| 334 } | 311 } |
| 335 | 312 |
| 336 void AddCookie() { | 313 void AddCookie() { |
| 337 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 314 scoped_refptr<MessageLoopRunner> message_loop_runner = |
| 338 new content::MessageLoopRunner; | 315 new MessageLoopRunner(); |
| 339 quit_closure_ = message_loop_runner->QuitClosure(); | 316 quit_closure_ = message_loop_runner->QuitClosure(); |
| 340 cookie_store_->SetCookieWithOptionsAsync( | 317 cookie_store_->SetCookieWithOptionsAsync( |
| 341 kOrigin1, "A=1", net::CookieOptions(), | 318 kOrigin1, "A=1", net::CookieOptions(), |
| 342 base::Bind(&RemoveCookieTester::SetCookieCallback, | 319 base::Bind(&RemoveCookieTester::SetCookieCallback, |
| 343 base::Unretained(this))); | 320 base::Unretained(this))); |
| 344 message_loop_runner->Run(); | 321 message_loop_runner->Run(); |
| 345 } | 322 } |
| 346 | 323 |
| 347 protected: | 324 protected: |
| 348 void SetCookieStore(net::CookieStore* cookie_store) { | 325 void SetCookieStore(net::CookieStore* cookie_store) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 371 // CookieStore must out live |this|. | 348 // CookieStore must out live |this|. |
| 372 net::CookieStore* cookie_store_ = nullptr; | 349 net::CookieStore* cookie_store_ = nullptr; |
| 373 | 350 |
| 374 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); | 351 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); |
| 375 }; | 352 }; |
| 376 | 353 |
| 377 class RemoveChannelIDTester : public net::SSLConfigService::Observer { | 354 class RemoveChannelIDTester : public net::SSLConfigService::Observer { |
| 378 public: | 355 public: |
| 379 explicit RemoveChannelIDTester(BrowserContext* browser_context) { | 356 explicit RemoveChannelIDTester(BrowserContext* browser_context) { |
| 380 net::URLRequestContext* url_request_context = | 357 net::URLRequestContext* url_request_context = |
| 381 content::BrowserContext::GetDefaultStoragePartition(browser_context) | 358 BrowserContext::GetDefaultStoragePartition(browser_context) |
| 382 ->GetURLRequestContext()->GetURLRequestContext(); | 359 ->GetURLRequestContext() |
| 383 channel_id_service_ = url_request_context-> channel_id_service(); | 360 ->GetURLRequestContext(); |
| 361 channel_id_service_ = url_request_context->channel_id_service(); | |
| 384 ssl_config_service_ = url_request_context->ssl_config_service(); | 362 ssl_config_service_ = url_request_context->ssl_config_service(); |
| 385 ssl_config_service_->AddObserver(this); | 363 ssl_config_service_->AddObserver(this); |
| 386 } | 364 } |
| 387 | 365 |
| 388 ~RemoveChannelIDTester() override { | 366 ~RemoveChannelIDTester() override { |
| 389 ssl_config_service_->RemoveObserver(this); | 367 ssl_config_service_->RemoveObserver(this); |
| 390 } | 368 } |
| 391 | 369 |
| 392 int ChannelIDCount() { return channel_id_service_->channel_id_count(); } | 370 int ChannelIDCount() { return channel_id_service_->channel_id_count(); } |
| 393 | 371 |
| 394 // Add a server bound cert for |server| with specific creation and expiry | 372 // Add a server bound cert for |server| with specific creation and expiry |
| 395 // times. The cert and key data will be filled with dummy values. | 373 // times. The cert and key data will be filled with dummy values. |
| 396 void AddChannelIDWithTimes(const std::string& server_identifier, | 374 void AddChannelIDWithTimes(const std::string& server_identifier, |
| 397 base::Time creation_time) { | 375 base::Time creation_time) { |
| 398 GetChannelIDStore()->SetChannelID( | 376 GetChannelIDStore()->SetChannelID( |
| 399 base::MakeUnique<net::ChannelIDStore::ChannelID>( | 377 base::MakeUnique<net::ChannelIDStore::ChannelID>( |
| 400 server_identifier, creation_time, crypto::ECPrivateKey::Create())); | 378 server_identifier, creation_time, crypto::ECPrivateKey::Create())); |
| 401 } | 379 } |
| 402 | 380 |
| 403 // Add a server bound cert for |server|, with the current time as the | 381 // Add a server bound cert for |server|, with the current time as the |
| 404 // creation time. The cert and key data will be filled with dummy values. | 382 // creation time. The cert and key data will be filled with dummy values. |
| 405 void AddChannelID(const std::string& server_identifier) { | 383 void AddChannelID(const std::string& server_identifier) { |
| 406 base::Time now = base::Time::Now(); | 384 base::Time now = base::Time::Now(); |
| 407 AddChannelIDWithTimes(server_identifier, now); | 385 AddChannelIDWithTimes(server_identifier, now); |
| 408 } | 386 } |
| 409 | 387 |
| 410 void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) { | 388 void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) { |
| 411 GetChannelIDStore()->GetAllChannelIDs( | 389 GetChannelIDStore()->GetAllChannelIDs(base::Bind( |
| 412 base::Bind(&RemoveChannelIDTester::GetAllChannelIDsCallback, | 390 &RemoveChannelIDTester::GetAllChannelIDsCallback, channel_ids)); |
| 413 channel_ids)); | |
| 414 } | 391 } |
| 415 | 392 |
| 416 net::ChannelIDStore* GetChannelIDStore() { | 393 net::ChannelIDStore* GetChannelIDStore() { |
| 417 return channel_id_service_->GetChannelIDStore(); | 394 return channel_id_service_->GetChannelIDStore(); |
| 418 } | 395 } |
| 419 | 396 |
| 420 int ssl_config_changed_count() const { | 397 int ssl_config_changed_count() const { return ssl_config_changed_count_; } |
| 421 return ssl_config_changed_count_; | |
| 422 } | |
| 423 | 398 |
| 424 // net::SSLConfigService::Observer implementation: | 399 // net::SSLConfigService::Observer implementation: |
| 425 void OnSSLConfigChanged() override { ssl_config_changed_count_++; } | 400 void OnSSLConfigChanged() override { ssl_config_changed_count_++; } |
| 426 | 401 |
| 427 private: | 402 private: |
| 428 static void GetAllChannelIDsCallback( | 403 static void GetAllChannelIDsCallback( |
| 429 net::ChannelIDStore::ChannelIDList* dest, | 404 net::ChannelIDStore::ChannelIDList* dest, |
| 430 const net::ChannelIDStore::ChannelIDList& result) { | 405 const net::ChannelIDStore::ChannelIDList& result) { |
| 431 *dest = result; | 406 *dest = result; |
| 432 } | 407 } |
| 433 | 408 |
| 434 net::ChannelIDService* channel_id_service_; | 409 net::ChannelIDService* channel_id_service_; |
| 435 scoped_refptr<net::SSLConfigService> ssl_config_service_; | 410 scoped_refptr<net::SSLConfigService> ssl_config_service_; |
| 436 int ssl_config_changed_count_ = 0; | 411 int ssl_config_changed_count_ = 0; |
| 437 | 412 |
| 438 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester); | 413 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester); |
| 439 }; | 414 }; |
| 440 | 415 |
| 441 class RemoveLocalStorageTester { | 416 class RemoveLocalStorageTester { |
| 442 public: | 417 public: |
| 443 explicit RemoveLocalStorageTester(BrowserContext* browser_context) | 418 explicit RemoveLocalStorageTester(BrowserContext* browser_context) |
| 444 : browser_context_(browser_context) { | 419 : browser_context_(browser_context) { |
| 445 dom_storage_context_ = | 420 dom_storage_context_ = |
| 446 content::BrowserContext::GetDefaultStoragePartition(browser_context_)-> | 421 BrowserContext::GetDefaultStoragePartition(browser_context_) |
| 447 GetDOMStorageContext(); | 422 ->GetDOMStorageContext(); |
| 448 } | 423 } |
| 449 | 424 |
| 450 // Returns true, if the given origin URL exists. | 425 // Returns true, if the given origin URL exists. |
| 451 bool DOMStorageExistsForOrigin(const GURL& origin) { | 426 bool DOMStorageExistsForOrigin(const GURL& origin) { |
| 452 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 427 scoped_refptr<MessageLoopRunner> message_loop_runner = |
| 453 new content::MessageLoopRunner; | 428 new MessageLoopRunner(); |
| 454 quit_closure_ = message_loop_runner->QuitClosure(); | 429 quit_closure_ = message_loop_runner->QuitClosure(); |
| 455 GetLocalStorageUsage(); | 430 GetLocalStorageUsage(); |
| 456 message_loop_runner->Run(); | 431 message_loop_runner->Run(); |
| 457 for (size_t i = 0; i < infos_.size(); ++i) { | 432 for (size_t i = 0; i < infos_.size(); ++i) { |
| 458 if (origin == infos_[i].origin) | 433 if (origin == infos_[i].origin) |
| 459 return true; | 434 return true; |
| 460 } | 435 } |
| 461 return false; | 436 return false; |
| 462 } | 437 } |
| 463 | 438 |
| 464 void AddDOMStorageTestData() { | 439 void AddDOMStorageTestData() { |
| 465 // Note: This test depends on details of how the dom_storage library | 440 // Note: This test depends on details of how the dom_storage library |
| 466 // stores data in the host file system. | 441 // stores data in the host file system. |
| 467 base::FilePath storage_path = | 442 base::FilePath storage_path = |
| 468 browser_context_->GetPath().AppendASCII("Local Storage"); | 443 browser_context_->GetPath().AppendASCII("Local Storage"); |
| 469 base::CreateDirectory(storage_path); | 444 base::CreateDirectory(storage_path); |
| 470 | 445 |
| 471 // Write some files. | 446 // Write some files. |
| 472 base::WriteFile(storage_path.Append(kDomStorageOrigin1), nullptr, 0); | 447 base::WriteFile(storage_path.Append(kDomStorageOrigin1), nullptr, 0); |
| 473 base::WriteFile(storage_path.Append(kDomStorageOrigin2), nullptr, 0); | 448 base::WriteFile(storage_path.Append(kDomStorageOrigin2), nullptr, 0); |
| 474 base::WriteFile(storage_path.Append(kDomStorageOrigin3), nullptr, 0); | 449 base::WriteFile(storage_path.Append(kDomStorageOrigin3), nullptr, 0); |
| 475 base::WriteFile(storage_path.Append(kDomStorageExt), nullptr, 0); | 450 base::WriteFile(storage_path.Append(kDomStorageExt), nullptr, 0); |
| 476 | 451 |
| 477 // Tweak their dates. | 452 // Tweak their dates. |
| 478 base::Time now = base::Time::Now(); | 453 base::Time now = base::Time::Now(); |
| 479 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now); | 454 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now); |
| 480 | 455 |
| 481 base::Time one_day_ago = now - base::TimeDelta::FromDays(1); | 456 base::Time one_day_ago = now - base::TimeDelta::FromDays(1); |
| 482 base::TouchFile(storage_path.Append(kDomStorageOrigin2), | 457 base::TouchFile(storage_path.Append(kDomStorageOrigin2), one_day_ago, |
| 483 one_day_ago, one_day_ago); | 458 one_day_ago); |
| 484 | 459 |
| 485 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60); | 460 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60); |
| 486 base::TouchFile(storage_path.Append(kDomStorageOrigin3), | 461 base::TouchFile(storage_path.Append(kDomStorageOrigin3), sixty_days_ago, |
| 487 sixty_days_ago, sixty_days_ago); | 462 sixty_days_ago); |
| 488 | 463 |
| 489 base::TouchFile(storage_path.Append(kDomStorageExt), now, now); | 464 base::TouchFile(storage_path.Append(kDomStorageExt), now, now); |
| 490 } | 465 } |
| 491 | 466 |
| 492 private: | 467 private: |
| 493 void GetLocalStorageUsage() { | 468 void GetLocalStorageUsage() { |
| 494 dom_storage_context_->GetLocalStorageUsage( | 469 dom_storage_context_->GetLocalStorageUsage( |
| 495 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage, | 470 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage, |
| 496 base::Unretained(this))); | 471 base::Unretained(this))); |
| 497 } | 472 } |
| 498 void OnGotLocalStorageUsage( | 473 void OnGotLocalStorageUsage(const std::vector<LocalStorageUsageInfo>& infos) { |
| 499 const std::vector<content::LocalStorageUsageInfo>& infos) { | |
| 500 infos_ = infos; | 474 infos_ = infos; |
| 501 quit_closure_.Run(); | 475 quit_closure_.Run(); |
| 502 } | 476 } |
| 503 | 477 |
| 504 // We don't own these pointers. | 478 // We don't own these pointers. |
| 505 BrowserContext* browser_context_; | 479 BrowserContext* browser_context_; |
| 506 content::DOMStorageContext* dom_storage_context_ = nullptr; | 480 DOMStorageContext* dom_storage_context_ = nullptr; |
| 507 | 481 |
| 508 std::vector<content::LocalStorageUsageInfo> infos_; | 482 std::vector<LocalStorageUsageInfo> infos_; |
| 509 base::Closure quit_closure_; | 483 base::Closure quit_closure_; |
| 510 | 484 |
| 511 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); | 485 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); |
| 512 }; | 486 }; |
| 513 | 487 |
| 514 class RemoveDownloadsTester { | 488 class RemoveDownloadsTester { |
| 515 public: | 489 public: |
| 516 explicit RemoveDownloadsTester(BrowserContext* browser_context) | 490 explicit RemoveDownloadsTester(BrowserContext* browser_context) |
| 517 : download_manager_(new content::MockDownloadManager()) { | 491 : download_manager_(new MockDownloadManager()) { |
| 518 content::BrowserContext::SetDownloadManagerForTesting(browser_context, | 492 BrowserContext::SetDownloadManagerForTesting(browser_context, |
| 519 download_manager_); | 493 download_manager_); |
| 520 EXPECT_EQ(download_manager_, | 494 EXPECT_EQ(download_manager_, |
| 521 content::BrowserContext::GetDownloadManager(browser_context)); | 495 BrowserContext::GetDownloadManager(browser_context)); |
| 522 EXPECT_CALL(*download_manager_, Shutdown()); | 496 EXPECT_CALL(*download_manager_, Shutdown()); |
| 523 } | 497 } |
| 524 | 498 |
| 525 ~RemoveDownloadsTester() {} | 499 ~RemoveDownloadsTester() {} |
| 526 | 500 |
| 527 content::MockDownloadManager* download_manager() { return download_manager_; } | 501 MockDownloadManager* download_manager() { return download_manager_; } |
| 528 | 502 |
| 529 private: | 503 private: |
| 530 content::MockDownloadManager* download_manager_; | 504 MockDownloadManager* download_manager_; |
| 531 | 505 |
| 532 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester); | 506 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester); |
| 533 }; | 507 }; |
| 534 | 508 |
| 535 // Test Class ---------------------------------------------------------------- | 509 // Test Class ---------------------------------------------------------------- |
| 536 | 510 |
| 537 class BrowsingDataRemoverImplTest : public testing::Test { | 511 class BrowsingDataRemoverImplTest : public testing::Test { |
| 538 public: | 512 public: |
| 539 BrowsingDataRemoverImplTest() | 513 BrowsingDataRemoverImplTest() : browser_context_(new TestBrowserContext()) { |
| 540 : browser_context_(new TestingProfile()) { | |
| 541 // TODO(crbug.com/668114): To create a BrowsingDataRemoverImpl, we currently | |
| 542 // need a BrowsingDataRemoverFactory which only exists for a Profile. | |
| 543 // Therefore, this test must use a TestingProfile for now. Switch it to | |
| 544 // a BrowserContext or TestBrowserContext when BrowsingDataRemoverImpl | |
| 545 // moves to content/. Furthermore, when in content/, BrowsingDataRemoverImpl | |
| 546 // will have no delegate. For now, explicitly set it to nullptr. | |
| 547 remover_ = static_cast<BrowsingDataRemoverImpl*>( | 514 remover_ = static_cast<BrowsingDataRemoverImpl*>( |
| 548 BrowsingDataRemoverFactory::GetForBrowserContext( | 515 content::BrowserContext::GetBrowsingDataRemover( |
|
jam
2017/04/21 22:58:31
ditto
msramek
2017/04/25 01:29:10
Done.
| |
| 549 browser_context_.get())); | 516 browser_context_.get())); |
| 550 remover_->SetEmbedderDelegate(nullptr); | |
| 551 } | 517 } |
| 552 | 518 |
| 553 ~BrowsingDataRemoverImplTest() override {} | 519 ~BrowsingDataRemoverImplTest() override {} |
| 554 | 520 |
| 555 void TearDown() override { | 521 void TearDown() override { |
| 556 mock_policy_ = nullptr; | 522 mock_policy_ = nullptr; |
| 557 | 523 |
| 558 // BrowserContext contains a DOMStorageContext. BrowserContext's | 524 // BrowserContext contains a DOMStorageContext. BrowserContext's |
| 559 // destructor posts a message to the WEBKIT thread to delete some of its | 525 // destructor posts a message to the WEBKIT thread to delete some of its |
| 560 // member variables. We need to ensure that the browser context is | 526 // member variables. We need to ensure that the browser context is |
| 561 // destroyed, and that the message loop is cleared out, before destroying | 527 // destroyed, and that the message loop is cleared out, before destroying |
| 562 // the threads and loop. Otherwise we leak memory. | 528 // the threads and loop. Otherwise we leak memory. |
| 563 browser_context_.reset(); | 529 browser_context_.reset(); |
| 564 base::RunLoop().RunUntilIdle(); | 530 base::RunLoop().RunUntilIdle(); |
| 565 } | 531 } |
| 566 | 532 |
| 567 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin, | 533 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin, |
| 568 const base::Time& delete_end, | 534 const base::Time& delete_end, |
| 569 int remove_mask, | 535 int remove_mask, |
| 570 bool include_protected_origins) { | 536 bool include_protected_origins) { |
| 571 TestStoragePartition storage_partition; | 537 TestStoragePartition storage_partition; |
| 572 remover_->OverrideStoragePartitionForTesting(&storage_partition); | 538 remover_->OverrideStoragePartitionForTesting(&storage_partition); |
| 573 | 539 |
| 574 int origin_type_mask = BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB; | 540 int origin_type_mask = BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB; |
| 575 if (include_protected_origins) | 541 if (include_protected_origins) |
| 576 origin_type_mask |= BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB; | 542 origin_type_mask |= BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB; |
| 577 | 543 |
| 578 BrowsingDataRemoverCompletionObserver completion_observer(remover_); | 544 BrowsingDataRemoverCompletionObserver completion_observer(remover_); |
| 579 remover_->RemoveAndReply( | 545 remover_->RemoveAndReply(delete_begin, delete_end, remove_mask, |
| 580 delete_begin, delete_end, remove_mask, origin_type_mask, | 546 origin_type_mask, &completion_observer); |
| 581 &completion_observer); | |
| 582 completion_observer.BlockUntilCompletion(); | 547 completion_observer.BlockUntilCompletion(); |
| 583 | 548 |
| 584 // Save so we can verify later. | 549 // Save so we can verify later. |
| 585 storage_partition_removal_data_ = | 550 storage_partition_removal_data_ = |
| 586 storage_partition.GetStoragePartitionRemovalData(); | 551 storage_partition.GetStoragePartitionRemovalData(); |
| 587 } | 552 } |
| 588 | 553 |
| 589 void BlockUntilOriginDataRemoved( | 554 void BlockUntilOriginDataRemoved( |
| 590 const base::Time& delete_begin, | 555 const base::Time& delete_begin, |
| 591 const base::Time& delete_end, | 556 const base::Time& delete_end, |
| 592 int remove_mask, | 557 int remove_mask, |
| 593 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { | 558 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { |
| 594 TestStoragePartition storage_partition; | 559 TestStoragePartition storage_partition; |
| 595 remover_->OverrideStoragePartitionForTesting(&storage_partition); | 560 remover_->OverrideStoragePartitionForTesting(&storage_partition); |
| 596 | 561 |
| 597 BrowsingDataRemoverCompletionObserver completion_observer(remover_); | 562 BrowsingDataRemoverCompletionObserver completion_observer(remover_); |
| 598 remover_->RemoveWithFilterAndReply( | 563 remover_->RemoveWithFilterAndReply( |
| 599 delete_begin, delete_end, remove_mask, | 564 delete_begin, delete_end, remove_mask, |
| 600 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | 565 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, |
| 601 std::move(filter_builder), &completion_observer); | 566 std::move(filter_builder), &completion_observer); |
| 602 completion_observer.BlockUntilCompletion(); | 567 completion_observer.BlockUntilCompletion(); |
| 603 | 568 |
| 604 // Save so we can verify later. | 569 // Save so we can verify later. |
| 605 storage_partition_removal_data_ = | 570 storage_partition_removal_data_ = |
| 606 storage_partition.GetStoragePartitionRemovalData(); | 571 storage_partition.GetStoragePartitionRemovalData(); |
| 607 } | 572 } |
| 608 | 573 |
| 609 BrowserContext* GetBrowserContext() { | 574 BrowserContext* GetBrowserContext() { return browser_context_.get(); } |
| 610 return browser_context_.get(); | |
| 611 } | |
| 612 | 575 |
| 613 void DestroyBrowserContext() { browser_context_.reset(); } | 576 void DestroyBrowserContext() { browser_context_.reset(); } |
| 614 | 577 |
| 615 const base::Time& GetBeginTime() { | 578 const base::Time& GetBeginTime() { return remover_->GetLastUsedBeginTime(); } |
| 616 return remover_->GetLastUsedBeginTime(); | |
| 617 } | |
| 618 | 579 |
| 619 int GetRemovalMask() { | 580 int GetRemovalMask() { return remover_->GetLastUsedRemovalMask(); } |
| 620 return remover_->GetLastUsedRemovalMask(); | |
| 621 } | |
| 622 | 581 |
| 623 int GetOriginTypeMask() { | 582 int GetOriginTypeMask() { return remover_->GetLastUsedOriginTypeMask(); } |
| 624 return remover_->GetLastUsedOriginTypeMask(); | |
| 625 } | |
| 626 | 583 |
| 627 StoragePartitionRemovalData GetStoragePartitionRemovalData() { | 584 StoragePartitionRemovalData GetStoragePartitionRemovalData() { |
| 628 return storage_partition_removal_data_; | 585 return storage_partition_removal_data_; |
| 629 } | 586 } |
| 630 | 587 |
| 631 content::MockSpecialStoragePolicy* CreateMockPolicy() { | 588 MockSpecialStoragePolicy* CreateMockPolicy() { |
| 632 mock_policy_ = new content::MockSpecialStoragePolicy(); | 589 mock_policy_ = new MockSpecialStoragePolicy(); |
| 633 return mock_policy_.get(); | 590 return mock_policy_.get(); |
| 634 } | 591 } |
| 635 | 592 |
| 636 content::MockSpecialStoragePolicy* mock_policy() { | 593 MockSpecialStoragePolicy* mock_policy() { return mock_policy_.get(); } |
| 637 return mock_policy_.get(); | |
| 638 } | |
| 639 | 594 |
| 640 bool Match(const GURL& origin, | 595 bool Match(const GURL& origin, |
| 641 int mask, | 596 int mask, |
| 642 storage::SpecialStoragePolicy* policy) { | 597 storage::SpecialStoragePolicy* policy) { |
| 643 return remover_->DoesOriginMatchMask(mask, origin, policy); | 598 return remover_->DoesOriginMatchMask(mask, origin, policy); |
| 644 } | 599 } |
| 645 | 600 |
| 646 private: | 601 private: |
| 647 // Cached pointer to BrowsingDataRemoverImpl for access to testing methods. | 602 // Cached pointer to BrowsingDataRemoverImpl for access to testing methods. |
| 648 BrowsingDataRemoverImpl* remover_; | 603 BrowsingDataRemoverImpl* remover_; |
| 649 | 604 |
| 650 content::TestBrowserThreadBundle thread_bundle_; | 605 TestBrowserThreadBundle thread_bundle_; |
| 651 std::unique_ptr<BrowserContext> browser_context_; | 606 std::unique_ptr<BrowserContext> browser_context_; |
| 652 | 607 |
| 653 StoragePartitionRemovalData storage_partition_removal_data_; | 608 StoragePartitionRemovalData storage_partition_removal_data_; |
| 654 | 609 |
| 655 scoped_refptr<content::MockSpecialStoragePolicy> mock_policy_; | 610 scoped_refptr<MockSpecialStoragePolicy> mock_policy_; |
| 656 | 611 |
| 657 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImplTest); | 612 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImplTest); |
| 658 }; | 613 }; |
| 659 | 614 |
| 660 // Tests --------------------------------------------------------------------- | 615 // Tests --------------------------------------------------------------------- |
| 661 | 616 |
| 662 TEST_F(BrowsingDataRemoverImplTest, RemoveCookieForever) { | 617 TEST_F(BrowsingDataRemoverImplTest, RemoveCookieForever) { |
| 663 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | 618 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 664 BrowsingDataRemover::DATA_TYPE_COOKIES, false); | 619 BrowsingDataRemover::DATA_TYPE_COOKIES, false); |
| 665 | 620 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 EXPECT_TRUE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin2))); | 682 EXPECT_TRUE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin2))); |
| 728 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin3))); | 683 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin3))); |
| 729 // This is false, because this is the same domain as 3, just with a different | 684 // This is false, because this is the same domain as 3, just with a different |
| 730 // scheme. | 685 // scheme. |
| 731 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin4))); | 686 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin4))); |
| 732 } | 687 } |
| 733 | 688 |
| 734 // Test that removing cookies clears HTTP auth data. | 689 // Test that removing cookies clears HTTP auth data. |
| 735 TEST_F(BrowsingDataRemoverImplTest, ClearHttpAuthCache_RemoveCookies) { | 690 TEST_F(BrowsingDataRemoverImplTest, ClearHttpAuthCache_RemoveCookies) { |
| 736 net::HttpNetworkSession* http_session = | 691 net::HttpNetworkSession* http_session = |
| 737 content::BrowserContext::GetDefaultStoragePartition(GetBrowserContext()) | 692 BrowserContext::GetDefaultStoragePartition(GetBrowserContext()) |
| 738 ->GetURLRequestContext() | 693 ->GetURLRequestContext() |
| 739 ->GetURLRequestContext() | 694 ->GetURLRequestContext() |
| 740 ->http_transaction_factory() | 695 ->http_transaction_factory() |
| 741 ->GetSession(); | 696 ->GetSession(); |
| 742 DCHECK(http_session); | 697 DCHECK(http_session); |
| 743 | 698 |
| 744 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache(); | 699 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache(); |
| 745 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC, | 700 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC, |
| 746 "test challenge", | 701 "test challenge", |
| 747 net::AuthCredentials(base::ASCIIToUTF16("foo"), | 702 net::AuthCredentials(base::ASCIIToUTF16("foo"), |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS, | 770 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS, |
| 816 std::move(filter_builder)); | 771 std::move(filter_builder)); |
| 817 | 772 |
| 818 EXPECT_EQ(1, tester.ChannelIDCount()); | 773 EXPECT_EQ(1, tester.ChannelIDCount()); |
| 819 net::ChannelIDStore::ChannelIDList channel_ids; | 774 net::ChannelIDStore::ChannelIDList channel_ids; |
| 820 tester.GetChannelIDList(&channel_ids); | 775 tester.GetChannelIDList(&channel_ids); |
| 821 EXPECT_EQ(kTestRegisterableDomain3, channel_ids.front().server_identifier()); | 776 EXPECT_EQ(kTestRegisterableDomain3, channel_ids.front().server_identifier()); |
| 822 } | 777 } |
| 823 | 778 |
| 824 TEST_F(BrowsingDataRemoverImplTest, RemoveUnprotectedLocalStorageForever) { | 779 TEST_F(BrowsingDataRemoverImplTest, RemoveUnprotectedLocalStorageForever) { |
| 825 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); | 780 MockSpecialStoragePolicy* policy = CreateMockPolicy(); |
| 826 // Protect kOrigin1. | 781 // Protect kOrigin1. |
| 827 policy->AddProtected(kOrigin1.GetOrigin()); | 782 policy->AddProtected(kOrigin1.GetOrigin()); |
| 828 | 783 |
| 829 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | 784 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 830 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, | 785 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, |
| 831 false); | 786 false); |
| 832 | 787 |
| 833 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); | 788 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); |
| 834 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | 789 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, |
| 835 GetOriginTypeMask()); | 790 GetOriginTypeMask()); |
| 836 | 791 |
| 837 // Verify that storage partition was instructed to remove the data correctly. | 792 // Verify that storage partition was instructed to remove the data correctly. |
| 838 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | 793 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); |
| 839 EXPECT_EQ(removal_data.remove_mask, | 794 EXPECT_EQ(removal_data.remove_mask, |
| 840 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); | 795 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); |
| 841 EXPECT_EQ(removal_data.quota_storage_remove_mask, | 796 EXPECT_EQ(removal_data.quota_storage_remove_mask, |
| 842 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | 797 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); |
| 843 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | 798 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); |
| 844 | 799 |
| 845 // Check origin matcher. | 800 // Check origin matcher. |
| 846 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | 801 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); |
| 847 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | 802 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); |
| 848 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | 803 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); |
| 849 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); | 804 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); |
| 850 } | 805 } |
| 851 | 806 |
| 852 TEST_F(BrowsingDataRemoverImplTest, RemoveProtectedLocalStorageForever) { | 807 TEST_F(BrowsingDataRemoverImplTest, RemoveProtectedLocalStorageForever) { |
| 853 // Protect kOrigin1. | 808 // Protect kOrigin1. |
| 854 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); | 809 MockSpecialStoragePolicy* policy = CreateMockPolicy(); |
| 855 policy->AddProtected(kOrigin1.GetOrigin()); | 810 policy->AddProtected(kOrigin1.GetOrigin()); |
| 856 | 811 |
| 857 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | 812 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 858 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, | 813 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, |
| 859 true); | 814 true); |
| 860 | 815 |
| 861 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); | 816 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); |
| 862 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | | 817 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | |
| 863 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB, | 818 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB, |
| 864 GetOriginTypeMask()); | 819 GetOriginTypeMask()); |
| 865 | 820 |
| 866 // Verify that storage partition was instructed to remove the data correctly. | 821 // Verify that storage partition was instructed to remove the data correctly. |
| 867 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | 822 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); |
| 868 EXPECT_EQ(removal_data.remove_mask, | 823 EXPECT_EQ(removal_data.remove_mask, |
| 869 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); | 824 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); |
| 870 EXPECT_EQ(removal_data.quota_storage_remove_mask, | 825 EXPECT_EQ(removal_data.quota_storage_remove_mask, |
| 871 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | 826 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); |
| 872 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | 827 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); |
| 873 | 828 |
| 874 // Check origin matcher all http origin will match since we specified | 829 // Check origin matcher all http origin will match since we specified |
| 875 // both protected and unprotected. | 830 // both protected and unprotected. |
| 876 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | 831 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); |
| 877 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | 832 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); |
| 878 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | 833 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); |
| 879 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); | 834 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); |
| 880 } | 835 } |
| 881 | 836 |
| 882 TEST_F(BrowsingDataRemoverImplTest, RemoveLocalStorageForLastWeek) { | 837 TEST_F(BrowsingDataRemoverImplTest, RemoveLocalStorageForLastWeek) { |
| 883 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 884 CreateMockPolicy(); | 838 CreateMockPolicy(); |
| 885 #endif | |
| 886 | 839 |
| 887 BlockUntilBrowsingDataRemoved( | 840 BlockUntilBrowsingDataRemoved( |
| 888 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(), | 841 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(), |
| 889 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, false); | 842 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, false); |
| 890 | 843 |
| 891 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); | 844 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); |
| 892 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | 845 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, |
| 893 GetOriginTypeMask()); | 846 GetOriginTypeMask()); |
| 894 | 847 |
| 895 // Verify that storage partition was instructed to remove the data correctly. | 848 // Verify that storage partition was instructed to remove the data correctly. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 911 TEST_F(BrowsingDataRemoverImplTest, RemoveMultipleTypes) { | 864 TEST_F(BrowsingDataRemoverImplTest, RemoveMultipleTypes) { |
| 912 // Downloads should be deleted through the DownloadManager, assure it would | 865 // Downloads should be deleted through the DownloadManager, assure it would |
| 913 // be called. | 866 // be called. |
| 914 RemoveDownloadsTester downloads_tester(GetBrowserContext()); | 867 RemoveDownloadsTester downloads_tester(GetBrowserContext()); |
| 915 EXPECT_CALL(*downloads_tester.download_manager(), | 868 EXPECT_CALL(*downloads_tester.download_manager(), |
| 916 RemoveDownloadsByURLAndTime(_, _, _)); | 869 RemoveDownloadsByURLAndTime(_, _, _)); |
| 917 | 870 |
| 918 int removal_mask = BrowsingDataRemover::DATA_TYPE_DOWNLOADS | | 871 int removal_mask = BrowsingDataRemover::DATA_TYPE_DOWNLOADS | |
| 919 BrowsingDataRemover::DATA_TYPE_COOKIES; | 872 BrowsingDataRemover::DATA_TYPE_COOKIES; |
| 920 | 873 |
| 921 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | 874 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), removal_mask, |
| 922 removal_mask, false); | 875 false); |
| 923 | 876 |
| 924 EXPECT_EQ(removal_mask, GetRemovalMask()); | 877 EXPECT_EQ(removal_mask, GetRemovalMask()); |
| 925 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | 878 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, |
| 926 GetOriginTypeMask()); | 879 GetOriginTypeMask()); |
| 927 | 880 |
| 928 // The cookie would be deleted throught the StorageParition, check if the | 881 // The cookie would be deleted throught the StorageParition, check if the |
| 929 // partition was requested to remove cookie. | 882 // partition was requested to remove cookie. |
| 930 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | 883 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); |
| 931 EXPECT_EQ(removal_data.remove_mask, | 884 EXPECT_EQ(removal_data.remove_mask, |
| 932 StoragePartition::REMOVE_DATA_MASK_COOKIES); | 885 StoragePartition::REMOVE_DATA_MASK_COOKIES); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 963 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | 916 StoragePartition::REMOVE_DATA_MASK_APPCACHE | |
| 964 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | 917 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | |
| 965 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | 918 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | |
| 966 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | 919 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); |
| 967 EXPECT_EQ(removal_data.quota_storage_remove_mask, | 920 EXPECT_EQ(removal_data.quota_storage_remove_mask, |
| 968 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | 921 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); |
| 969 } | 922 } |
| 970 | 923 |
| 971 TEST_F(BrowsingDataRemoverImplTest, | 924 TEST_F(BrowsingDataRemoverImplTest, |
| 972 RemoveQuotaManagedDataForeverOnlyTemporary) { | 925 RemoveQuotaManagedDataForeverOnlyTemporary) { |
| 973 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 974 CreateMockPolicy(); | 926 CreateMockPolicy(); |
| 975 #endif | |
| 976 | 927 |
| 977 BlockUntilBrowsingDataRemoved( | 928 BlockUntilBrowsingDataRemoved( |
| 978 base::Time(), base::Time::Max(), | 929 base::Time(), base::Time::Max(), |
| 979 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | 930 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | |
| 980 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | 931 BrowsingDataRemover::DATA_TYPE_WEB_SQL | |
| 981 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | 932 BrowsingDataRemover::DATA_TYPE_APP_CACHE | |
| 982 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | 933 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | |
| 983 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | 934 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | |
| 984 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | 935 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, |
| 985 false); | 936 false); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1009 | 960 |
| 1010 // Check that all related origin data would be removed, that is, origin | 961 // Check that all related origin data would be removed, that is, origin |
| 1011 // matcher would match these origin. | 962 // matcher would match these origin. |
| 1012 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | 963 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); |
| 1013 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | 964 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); |
| 1014 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | 965 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); |
| 1015 } | 966 } |
| 1016 | 967 |
| 1017 TEST_F(BrowsingDataRemoverImplTest, | 968 TEST_F(BrowsingDataRemoverImplTest, |
| 1018 RemoveQuotaManagedDataForeverOnlyPersistent) { | 969 RemoveQuotaManagedDataForeverOnlyPersistent) { |
| 1019 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 1020 CreateMockPolicy(); | 970 CreateMockPolicy(); |
| 1021 #endif | |
| 1022 | 971 |
| 1023 BlockUntilBrowsingDataRemoved( | 972 BlockUntilBrowsingDataRemoved( |
| 1024 base::Time(), base::Time::Max(), | 973 base::Time(), base::Time::Max(), |
| 1025 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | 974 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | |
| 1026 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | 975 BrowsingDataRemover::DATA_TYPE_WEB_SQL | |
| 1027 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | 976 BrowsingDataRemover::DATA_TYPE_APP_CACHE | |
| 1028 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | 977 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | |
| 1029 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | 978 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | |
| 1030 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | 979 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, |
| 1031 false); | 980 false); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1054 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | 1003 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); |
| 1055 | 1004 |
| 1056 // Check that all related origin data would be removed, that is, origin | 1005 // Check that all related origin data would be removed, that is, origin |
| 1057 // matcher would match these origin. | 1006 // matcher would match these origin. |
| 1058 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | 1007 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); |
| 1059 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | 1008 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); |
| 1060 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | 1009 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); |
| 1061 } | 1010 } |
| 1062 | 1011 |
| 1063 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForeverNeither) { | 1012 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForeverNeither) { |
| 1064 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 1065 CreateMockPolicy(); | 1013 CreateMockPolicy(); |
| 1066 #endif | |
| 1067 | 1014 |
| 1068 BlockUntilBrowsingDataRemoved( | 1015 BlockUntilBrowsingDataRemoved( |
| 1069 base::Time(), base::Time::Max(), | 1016 base::Time(), base::Time::Max(), |
| 1070 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | 1017 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | |
| 1071 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | 1018 BrowsingDataRemover::DATA_TYPE_WEB_SQL | |
| 1072 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | 1019 BrowsingDataRemover::DATA_TYPE_APP_CACHE | |
| 1073 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | 1020 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | |
| 1074 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | 1021 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | |
| 1075 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | 1022 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, |
| 1076 false); | 1023 false); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1225 // Persistent data would be left out since we are not removing from | 1172 // Persistent data would be left out since we are not removing from |
| 1226 // beginning of time. | 1173 // beginning of time. |
| 1227 uint32_t expected_quota_mask = | 1174 uint32_t expected_quota_mask = |
| 1228 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; | 1175 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; |
| 1229 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask); | 1176 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask); |
| 1230 // Check removal begin time. | 1177 // Check removal begin time. |
| 1231 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | 1178 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); |
| 1232 } | 1179 } |
| 1233 | 1180 |
| 1234 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedUnprotectedOrigins) { | 1181 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedUnprotectedOrigins) { |
| 1235 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); | 1182 MockSpecialStoragePolicy* policy = CreateMockPolicy(); |
| 1236 // Protect kOrigin1. | 1183 // Protect kOrigin1. |
| 1237 policy->AddProtected(kOrigin1.GetOrigin()); | 1184 policy->AddProtected(kOrigin1.GetOrigin()); |
| 1238 | 1185 |
| 1239 BlockUntilBrowsingDataRemoved( | 1186 BlockUntilBrowsingDataRemoved( |
| 1240 base::Time(), base::Time::Max(), | 1187 base::Time(), base::Time::Max(), |
| 1241 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | 1188 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | |
| 1242 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | 1189 BrowsingDataRemover::DATA_TYPE_WEB_SQL | |
| 1243 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | 1190 BrowsingDataRemover::DATA_TYPE_APP_CACHE | |
| 1244 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | 1191 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | |
| 1245 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | 1192 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1269 EXPECT_EQ(removal_data.quota_storage_remove_mask, | 1216 EXPECT_EQ(removal_data.quota_storage_remove_mask, |
| 1270 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | 1217 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); |
| 1271 | 1218 |
| 1272 // Check OriginMatcherFunction. | 1219 // Check OriginMatcherFunction. |
| 1273 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | 1220 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); |
| 1274 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | 1221 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); |
| 1275 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | 1222 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); |
| 1276 } | 1223 } |
| 1277 | 1224 |
| 1278 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedSpecificOrigin) { | 1225 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedSpecificOrigin) { |
| 1279 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); | 1226 MockSpecialStoragePolicy* policy = CreateMockPolicy(); |
| 1280 // Protect kOrigin1. | 1227 // Protect kOrigin1. |
| 1281 policy->AddProtected(kOrigin1.GetOrigin()); | 1228 policy->AddProtected(kOrigin1.GetOrigin()); |
| 1282 | 1229 |
| 1283 std::unique_ptr<BrowsingDataFilterBuilder> builder( | 1230 std::unique_ptr<BrowsingDataFilterBuilder> builder( |
| 1284 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); | 1231 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); |
| 1285 builder->AddRegisterableDomain(kTestRegisterableDomain1); | 1232 builder->AddRegisterableDomain(kTestRegisterableDomain1); |
| 1286 | 1233 |
| 1287 // Try to remove kOrigin1. Expect failure. | 1234 // Try to remove kOrigin1. Expect failure. |
| 1288 BlockUntilOriginDataRemoved( | 1235 BlockUntilOriginDataRemoved( |
| 1289 base::Time(), base::Time::Max(), | 1236 base::Time(), base::Time::Max(), |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1320 | 1267 |
| 1321 // Check OriginMatcherFunction. | 1268 // Check OriginMatcherFunction. |
| 1322 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | 1269 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); |
| 1323 // Since we use the matcher function to validate origins now, this should | 1270 // Since we use the matcher function to validate origins now, this should |
| 1324 // return false for the origins we're not trying to clear. | 1271 // return false for the origins we're not trying to clear. |
| 1325 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | 1272 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); |
| 1326 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | 1273 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); |
| 1327 } | 1274 } |
| 1328 | 1275 |
| 1329 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedOrigins) { | 1276 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedOrigins) { |
| 1330 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); | 1277 MockSpecialStoragePolicy* policy = CreateMockPolicy(); |
| 1331 // Protect kOrigin1. | 1278 // Protect kOrigin1. |
| 1332 policy->AddProtected(kOrigin1.GetOrigin()); | 1279 policy->AddProtected(kOrigin1.GetOrigin()); |
| 1333 | 1280 |
| 1334 // Try to remove kOrigin1. Expect success. | 1281 // Try to remove kOrigin1. Expect success. |
| 1335 BlockUntilBrowsingDataRemoved( | 1282 BlockUntilBrowsingDataRemoved( |
| 1336 base::Time(), base::Time::Max(), | 1283 base::Time(), base::Time::Max(), |
| 1337 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | 1284 BrowsingDataRemover::DATA_TYPE_APP_CACHE | |
| 1338 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | 1285 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | |
| 1339 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | 1286 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | |
| 1340 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | 1287 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1368 | 1315 |
| 1369 // Check OriginMatcherFunction, |kOrigin1| would match mask since we | 1316 // Check OriginMatcherFunction, |kOrigin1| would match mask since we |
| 1370 // would have 'protected' specified in origin_type_mask. | 1317 // would have 'protected' specified in origin_type_mask. |
| 1371 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | 1318 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); |
| 1372 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | 1319 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); |
| 1373 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | 1320 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); |
| 1374 } | 1321 } |
| 1375 | 1322 |
| 1376 TEST_F(BrowsingDataRemoverImplTest, | 1323 TEST_F(BrowsingDataRemoverImplTest, |
| 1377 RemoveQuotaManagedIgnoreExtensionsAndDevTools) { | 1324 RemoveQuotaManagedIgnoreExtensionsAndDevTools) { |
| 1378 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 1379 CreateMockPolicy(); | 1325 CreateMockPolicy(); |
| 1380 #endif | |
| 1381 | 1326 |
| 1382 BlockUntilBrowsingDataRemoved( | 1327 BlockUntilBrowsingDataRemoved( |
| 1383 base::Time(), base::Time::Max(), | 1328 base::Time(), base::Time::Max(), |
| 1384 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | 1329 BrowsingDataRemover::DATA_TYPE_APP_CACHE | |
| 1385 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | 1330 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | |
| 1386 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | 1331 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | |
| 1387 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | 1332 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | |
| 1388 BrowsingDataRemover::DATA_TYPE_INDEXED_DB | | 1333 BrowsingDataRemover::DATA_TYPE_INDEXED_DB | |
| 1389 BrowsingDataRemover::DATA_TYPE_WEB_SQL, | 1334 BrowsingDataRemover::DATA_TYPE_WEB_SQL, |
| 1390 false); | 1335 false); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1432 BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone(); | 1377 BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone(); |
| 1433 called_ = true; | 1378 called_ = true; |
| 1434 } | 1379 } |
| 1435 | 1380 |
| 1436 private: | 1381 private: |
| 1437 bool called_ = false; | 1382 bool called_ = false; |
| 1438 }; | 1383 }; |
| 1439 | 1384 |
| 1440 TEST_F(BrowsingDataRemoverImplTest, CompletionInhibition) { | 1385 TEST_F(BrowsingDataRemoverImplTest, CompletionInhibition) { |
| 1441 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | 1386 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( |
| 1442 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | 1387 BrowserContext::GetBrowsingDataRemover(GetBrowserContext())); |
| 1443 | 1388 |
| 1444 // The |completion_inhibitor| on the stack should prevent removal sessions | 1389 // The |completion_inhibitor| on the stack should prevent removal sessions |
| 1445 // from completing until after ContinueToCompletion() is called. | 1390 // from completing until after ContinueToCompletion() is called. |
| 1446 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); | 1391 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); |
| 1447 InspectableCompletionObserver completion_observer(remover); | 1392 InspectableCompletionObserver completion_observer(remover); |
| 1448 remover->RemoveAndReply( | 1393 remover->RemoveAndReply( |
| 1449 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, | 1394 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, |
| 1450 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer); | 1395 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer); |
| 1451 | 1396 |
| 1452 // Process messages until the inhibitor is notified, and then some, to make | 1397 // Process messages until the inhibitor is notified, and then some, to make |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1464 // now notified, and the notifications is sent out. | 1409 // now notified, and the notifications is sent out. |
| 1465 completion_inhibitor.ContinueToCompletion(); | 1410 completion_inhibitor.ContinueToCompletion(); |
| 1466 completion_observer.BlockUntilCompletion(); | 1411 completion_observer.BlockUntilCompletion(); |
| 1467 | 1412 |
| 1468 EXPECT_FALSE(remover->is_removing()); | 1413 EXPECT_FALSE(remover->is_removing()); |
| 1469 EXPECT_TRUE(completion_observer.called()); | 1414 EXPECT_TRUE(completion_observer.called()); |
| 1470 } | 1415 } |
| 1471 | 1416 |
| 1472 TEST_F(BrowsingDataRemoverImplTest, EarlyShutdown) { | 1417 TEST_F(BrowsingDataRemoverImplTest, EarlyShutdown) { |
| 1473 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | 1418 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( |
| 1474 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | 1419 BrowserContext::GetBrowsingDataRemover(GetBrowserContext())); |
| 1475 InspectableCompletionObserver completion_observer(remover); | 1420 InspectableCompletionObserver completion_observer(remover); |
| 1476 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); | 1421 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); |
| 1477 remover->RemoveAndReply( | 1422 remover->RemoveAndReply( |
| 1478 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, | 1423 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, |
| 1479 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer); | 1424 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer); |
| 1480 | 1425 |
| 1481 completion_inhibitor.BlockUntilNearCompletion(); | 1426 completion_inhibitor.BlockUntilNearCompletion(); |
| 1482 completion_inhibitor.Reset(); | 1427 completion_inhibitor.Reset(); |
| 1483 | 1428 |
| 1484 // Verify that the deletion has not yet been completed and the observer has | 1429 // Verify that the deletion has not yet been completed and the observer has |
| 1485 // not been called. | 1430 // not been called. |
| 1486 EXPECT_TRUE(remover->is_removing()); | 1431 EXPECT_TRUE(remover->is_removing()); |
| 1487 EXPECT_FALSE(completion_observer.called()); | 1432 EXPECT_FALSE(completion_observer.called()); |
| 1488 | 1433 |
| 1489 // Destroying the profile should trigger the notification. | 1434 // Destroying the profile should trigger the notification. |
| 1490 DestroyBrowserContext(); | 1435 DestroyBrowserContext(); |
| 1491 | 1436 |
| 1492 EXPECT_TRUE(completion_observer.called()); | 1437 EXPECT_TRUE(completion_observer.called()); |
| 1493 | 1438 |
| 1494 // Finishing after shutdown shouldn't break anything. | 1439 // Finishing after shutdown shouldn't break anything. |
| 1495 completion_inhibitor.ContinueToCompletion(); | 1440 completion_inhibitor.ContinueToCompletion(); |
| 1496 completion_observer.BlockUntilCompletion(); | 1441 completion_observer.BlockUntilCompletion(); |
| 1497 } | 1442 } |
| 1498 | 1443 |
| 1499 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByTimeOnly) { | 1444 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByTimeOnly) { |
| 1500 RemoveDownloadsTester tester(GetBrowserContext()); | 1445 RemoveDownloadsTester tester(GetBrowserContext()); |
| 1501 base::Callback<bool(const GURL&)> filter = | 1446 base::Callback<bool(const GURL&)> filter = |
| 1502 BrowsingDataFilterBuilder::BuildNoopFilter(); | 1447 BrowsingDataFilterBuilder::BuildNoopFilter(); |
| 1503 | 1448 |
| 1504 EXPECT_CALL( | 1449 EXPECT_CALL(*tester.download_manager(), |
| 1505 *tester.download_manager(), | 1450 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); |
| 1506 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); | |
| 1507 | 1451 |
| 1508 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | 1452 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), |
| 1509 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | 1453 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, |
| 1510 false); | 1454 false); |
| 1511 } | 1455 } |
| 1512 | 1456 |
| 1513 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByOrigin) { | 1457 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByOrigin) { |
| 1514 RemoveDownloadsTester tester(GetBrowserContext()); | 1458 RemoveDownloadsTester tester(GetBrowserContext()); |
| 1515 std::unique_ptr<BrowsingDataFilterBuilder> builder( | 1459 std::unique_ptr<BrowsingDataFilterBuilder> builder( |
| 1516 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); | 1460 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); |
| 1517 builder->AddRegisterableDomain(kTestRegisterableDomain1); | 1461 builder->AddRegisterableDomain(kTestRegisterableDomain1); |
| 1518 base::Callback<bool(const GURL&)> filter = builder->BuildGeneralFilter(); | 1462 base::Callback<bool(const GURL&)> filter = builder->BuildGeneralFilter(); |
| 1519 | 1463 |
| 1520 EXPECT_CALL( | 1464 EXPECT_CALL(*tester.download_manager(), |
| 1521 *tester.download_manager(), | 1465 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); |
| 1522 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); | |
| 1523 | 1466 |
| 1524 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | 1467 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), |
| 1525 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | 1468 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, |
| 1526 std::move(builder)); | 1469 std::move(builder)); |
| 1527 } | 1470 } |
| 1528 | 1471 |
| 1529 class MultipleTasksObserver { | 1472 class MultipleTasksObserver { |
| 1530 public: | 1473 public: |
| 1531 // A simple implementation of BrowsingDataRemover::Observer. | 1474 // A simple implementation of BrowsingDataRemover::Observer. |
| 1532 // MultipleTasksObserver will use several instances of Target to test | 1475 // MultipleTasksObserver will use several instances of Target to test |
| 1533 // that completion callbacks are returned to the correct one. | 1476 // that completion callbacks are returned to the correct one. |
| 1534 class Target : public BrowsingDataRemover::Observer { | 1477 class Target : public BrowsingDataRemover::Observer { |
| 1535 public: | 1478 public: |
| 1536 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover) | 1479 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover) |
| 1537 : parent_(parent), | 1480 : parent_(parent), observer_(this) { |
| 1538 observer_(this) { | |
| 1539 observer_.Add(remover); | 1481 observer_.Add(remover); |
| 1540 } | 1482 } |
| 1541 ~Target() override {} | 1483 ~Target() override {} |
| 1542 | 1484 |
| 1543 void OnBrowsingDataRemoverDone() override { | 1485 void OnBrowsingDataRemoverDone() override { |
| 1544 parent_->SetLastCalledTarget(this); | 1486 parent_->SetLastCalledTarget(this); |
| 1545 } | 1487 } |
| 1546 | 1488 |
| 1547 private: | 1489 private: |
| 1548 MultipleTasksObserver* parent_; | 1490 MultipleTasksObserver* parent_; |
| 1549 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> | 1491 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> |
| 1550 observer_; | 1492 observer_; |
| 1551 }; | 1493 }; |
| 1552 | 1494 |
| 1553 explicit MultipleTasksObserver(BrowsingDataRemover* remover) | 1495 explicit MultipleTasksObserver(BrowsingDataRemover* remover) |
| 1554 : target_a_(this, remover), | 1496 : target_a_(this, remover), |
| 1555 target_b_(this, remover), | 1497 target_b_(this, remover), |
| 1556 last_called_target_(nullptr) {} | 1498 last_called_target_(nullptr) {} |
| 1557 ~MultipleTasksObserver() {} | 1499 ~MultipleTasksObserver() {} |
| 1558 | 1500 |
| 1559 void ClearLastCalledTarget() { | 1501 void ClearLastCalledTarget() { last_called_target_ = nullptr; } |
| 1560 last_called_target_ = nullptr; | |
| 1561 } | |
| 1562 | 1502 |
| 1563 Target* GetLastCalledTarget() { | 1503 Target* GetLastCalledTarget() { return last_called_target_; } |
| 1564 return last_called_target_; | |
| 1565 } | |
| 1566 | 1504 |
| 1567 Target* target_a() { return &target_a_; } | 1505 Target* target_a() { return &target_a_; } |
| 1568 Target* target_b() { return &target_b_; } | 1506 Target* target_b() { return &target_b_; } |
| 1569 | 1507 |
| 1570 private: | 1508 private: |
| 1571 void SetLastCalledTarget(Target* target) { | 1509 void SetLastCalledTarget(Target* target) { |
| 1572 DCHECK(!last_called_target_) | 1510 DCHECK(!last_called_target_) |
| 1573 << "Call ClearLastCalledTarget() before every removal task."; | 1511 << "Call ClearLastCalledTarget() before every removal task."; |
| 1574 last_called_target_ = target; | 1512 last_called_target_ = target; |
| 1575 } | 1513 } |
| 1576 | 1514 |
| 1577 Target target_a_; | 1515 Target target_a_; |
| 1578 Target target_b_; | 1516 Target target_b_; |
| 1579 Target* last_called_target_; | 1517 Target* last_called_target_; |
| 1580 }; | 1518 }; |
| 1581 | 1519 |
| 1582 TEST_F(BrowsingDataRemoverImplTest, MultipleTasks) { | 1520 TEST_F(BrowsingDataRemoverImplTest, MultipleTasks) { |
| 1583 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | 1521 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( |
| 1584 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | 1522 BrowserContext::GetBrowsingDataRemover(GetBrowserContext())); |
| 1585 EXPECT_FALSE(remover->is_removing()); | 1523 EXPECT_FALSE(remover->is_removing()); |
| 1586 | 1524 |
| 1587 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_1( | 1525 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_1( |
| 1588 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); | 1526 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); |
| 1589 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_2( | 1527 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_2( |
| 1590 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST)); | 1528 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST)); |
| 1591 filter_builder_2->AddRegisterableDomain("example.com"); | 1529 filter_builder_2->AddRegisterableDomain("example.com"); |
| 1592 | 1530 |
| 1593 MultipleTasksObserver observer(remover); | 1531 MultipleTasksObserver observer(remover); |
| 1594 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); | 1532 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1622 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | | 1560 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | |
| 1623 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB, | 1561 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB, |
| 1624 std::move(filter_builder_2), nullptr); | 1562 std::move(filter_builder_2), nullptr); |
| 1625 | 1563 |
| 1626 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) { | 1564 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) { |
| 1627 // All tasks can be directly translated to a RemoveInternal() call. Since | 1565 // All tasks can be directly translated to a RemoveInternal() call. Since |
| 1628 // that is a private method, we must call the four public versions of | 1566 // that is a private method, we must call the four public versions of |
| 1629 // Remove.* instead. This also serves as a test that those methods are all | 1567 // Remove.* instead. This also serves as a test that those methods are all |
| 1630 // correctly reduced to RemoveInternal(). | 1568 // correctly reduced to RemoveInternal(). |
| 1631 if (!task.observer && task.filter_builder->IsEmptyBlacklist()) { | 1569 if (!task.observer && task.filter_builder->IsEmptyBlacklist()) { |
| 1632 remover->Remove(task.delete_begin, task.delete_end, | 1570 remover->Remove(task.delete_begin, task.delete_end, task.remove_mask, |
| 1633 task.remove_mask, task.origin_type_mask); | 1571 task.origin_type_mask); |
| 1634 } else if (task.filter_builder->IsEmptyBlacklist()) { | 1572 } else if (task.filter_builder->IsEmptyBlacklist()) { |
| 1635 remover->RemoveAndReply(task.delete_begin, task.delete_end, | 1573 remover->RemoveAndReply(task.delete_begin, task.delete_end, |
| 1636 task.remove_mask, task.origin_type_mask, | 1574 task.remove_mask, task.origin_type_mask, |
| 1637 task.observer); | 1575 task.observer); |
| 1638 } else if (!task.observer) { | 1576 } else if (!task.observer) { |
| 1639 remover->RemoveWithFilter(task.delete_begin, task.delete_end, | 1577 remover->RemoveWithFilter(task.delete_begin, task.delete_end, |
| 1640 task.remove_mask, task.origin_type_mask, | 1578 task.remove_mask, task.origin_type_mask, |
| 1641 std::move(task.filter_builder)); | 1579 std::move(task.filter_builder)); |
| 1642 } else { | 1580 } else { |
| 1643 remover->RemoveWithFilterAndReply(task.delete_begin, task.delete_end, | 1581 remover->RemoveWithFilterAndReply( |
| 1644 task.remove_mask, task.origin_type_mask, | 1582 task.delete_begin, task.delete_end, task.remove_mask, |
| 1645 std::move(task.filter_builder), | 1583 task.origin_type_mask, std::move(task.filter_builder), task.observer); |
| 1646 task.observer); | |
| 1647 } | 1584 } |
| 1648 } | 1585 } |
| 1649 | 1586 |
| 1650 // Use the inhibitor to stop after every task and check the results. | 1587 // Use the inhibitor to stop after every task and check the results. |
| 1651 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) { | 1588 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) { |
| 1652 EXPECT_TRUE(remover->is_removing()); | 1589 EXPECT_TRUE(remover->is_removing()); |
| 1653 observer.ClearLastCalledTarget(); | 1590 observer.ClearLastCalledTarget(); |
| 1654 | 1591 |
| 1655 // Finish the task execution synchronously. | 1592 // Finish the task execution synchronously. |
| 1656 completion_inhibitor.BlockUntilNearCompletion(); | 1593 completion_inhibitor.BlockUntilNearCompletion(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1670 EXPECT_FALSE(remover->is_removing()); | 1607 EXPECT_FALSE(remover->is_removing()); |
| 1671 } | 1608 } |
| 1672 | 1609 |
| 1673 // The previous test, BrowsingDataRemoverTest.MultipleTasks, tests that the | 1610 // The previous test, BrowsingDataRemoverTest.MultipleTasks, tests that the |
| 1674 // tasks are not mixed up and they are executed in a correct order. However, | 1611 // tasks are not mixed up and they are executed in a correct order. However, |
| 1675 // the completion inhibitor kept synchronizing the execution in order to verify | 1612 // the completion inhibitor kept synchronizing the execution in order to verify |
| 1676 // the parameters. This test demonstrates that even running the tasks without | 1613 // the parameters. This test demonstrates that even running the tasks without |
| 1677 // inhibition is executed correctly and doesn't crash. | 1614 // inhibition is executed correctly and doesn't crash. |
| 1678 TEST_F(BrowsingDataRemoverImplTest, MultipleTasksInQuickSuccession) { | 1615 TEST_F(BrowsingDataRemoverImplTest, MultipleTasksInQuickSuccession) { |
| 1679 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | 1616 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( |
| 1680 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | 1617 BrowserContext::GetBrowsingDataRemover(GetBrowserContext())); |
| 1681 EXPECT_FALSE(remover->is_removing()); | 1618 EXPECT_FALSE(remover->is_removing()); |
| 1682 | 1619 |
| 1683 int test_removal_masks[] = { | 1620 int test_removal_masks[] = { |
| 1684 BrowsingDataRemover::DATA_TYPE_COOKIES, | 1621 BrowsingDataRemover::DATA_TYPE_COOKIES, |
| 1685 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, | 1622 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, |
| 1686 BrowsingDataRemover::DATA_TYPE_COOKIES, | 1623 BrowsingDataRemover::DATA_TYPE_COOKIES, |
| 1687 BrowsingDataRemover::DATA_TYPE_COOKIES, | 1624 BrowsingDataRemover::DATA_TYPE_COOKIES, |
| 1688 BrowsingDataRemover::DATA_TYPE_COOKIES, | 1625 BrowsingDataRemover::DATA_TYPE_COOKIES, |
| 1689 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | 1626 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, |
| 1690 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | 1627 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1707 | 1644 |
| 1708 EXPECT_TRUE(remover->is_removing()); | 1645 EXPECT_TRUE(remover->is_removing()); |
| 1709 | 1646 |
| 1710 // Add one more deletion and wait for it. | 1647 // Add one more deletion and wait for it. |
| 1711 BlockUntilBrowsingDataRemoved( | 1648 BlockUntilBrowsingDataRemoved( |
| 1712 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, | 1649 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, |
| 1713 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB); | 1650 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB); |
| 1714 | 1651 |
| 1715 EXPECT_FALSE(remover->is_removing()); | 1652 EXPECT_FALSE(remover->is_removing()); |
| 1716 } | 1653 } |
| 1654 | |
| 1655 } // namespace content | |
| OLD | NEW |