OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include <stddef.h> | |
6 #include <stdint.h> | |
7 | |
8 #include <list> | |
9 #include <memory> | |
10 #include <set> | |
11 #include <string> | |
12 #include <utility> | |
13 #include <vector> | |
14 | |
15 #include "base/bind.h" | |
16 #include "base/bind_helpers.h" | |
17 #include "base/files/file_path.h" | |
18 #include "base/files/file_util.h" | |
19 #include "base/location.h" | |
20 #include "base/logging.h" | |
21 #include "base/macros.h" | |
22 #include "base/memory/ptr_util.h" | |
23 #include "base/message_loop/message_loop.h" | |
24 #include "base/run_loop.h" | |
25 #include "base/single_thread_task_runner.h" | |
26 #include "base/strings/utf_string_conversions.h" | |
27 #include "base/task/cancelable_task_tracker.h" | |
28 #include "base/threading/thread_task_runner_handle.h" | |
29 #include "base/time/time.h" | |
30 #include "build/build_config.h" | |
31 #include "chrome/browser/browsing_data/browsing_data_helper.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" | |
38 #include "content/public/browser/browsing_data_filter_builder.h" | |
39 #include "content/public/browser/cookie_store_factory.h" | |
40 #include "content/public/browser/dom_storage_context.h" | |
41 #include "content/public/browser/local_storage_usage_info.h" | |
42 #include "content/public/browser/storage_partition.h" | |
43 #include "content/public/test/mock_download_manager.h" | |
44 #include "content/public/test/test_browser_thread.h" | |
45 #include "content/public/test/test_browser_thread_bundle.h" | |
46 #include "content/public/test/test_utils.h" | |
47 #include "extensions/features/features.h" | |
48 #include "net/cookies/cookie_store.h" | |
49 #include "net/http/http_network_session.h" | |
50 #include "net/http/http_transaction_factory.h" | |
51 #include "net/ssl/channel_id_service.h" | |
52 #include "net/ssl/channel_id_store.h" | |
53 #include "net/ssl/ssl_client_cert_type.h" | |
54 #include "net/url_request/url_request_context.h" | |
55 #include "net/url_request/url_request_context_getter.h" | |
56 #include "ppapi/features/features.h" | |
57 #include "storage/browser/test/mock_special_storage_policy.h" | |
58 #include "testing/gmock/include/gmock/gmock.h" | |
59 #include "testing/gtest/include/gtest/gtest.h" | |
60 #include "url/origin.h" | |
61 | |
62 using content::BrowserThread; | |
63 using content::BrowserContext; | |
64 using content::BrowsingDataFilterBuilder; | |
65 using content::StoragePartition; | |
66 using testing::_; | |
67 using testing::ByRef; | |
68 using testing::Eq; | |
69 using testing::Invoke; | |
70 using testing::IsEmpty; | |
71 using testing::Matcher; | |
72 using testing::MakeMatcher; | |
73 using testing::MatcherInterface; | |
74 using testing::MatchResultListener; | |
75 using testing::Not; | |
76 using testing::Return; | |
77 using testing::SizeIs; | |
78 using testing::WithArgs; | |
79 | |
80 namespace { | |
81 | |
82 const char kTestOrigin1[] = "http://host1.com:1/"; | |
83 const char kTestRegisterableDomain1[] = "host1.com"; | |
84 const char kTestOrigin2[] = "http://host2.com:1/"; | |
85 const char kTestOrigin3[] = "http://host3.com:1/"; | |
86 const char kTestRegisterableDomain3[] = "host3.com"; | |
87 const char kTestOrigin4[] = "https://host3.com:1/"; | |
88 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; | |
89 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; | |
90 | |
91 // For HTTP auth. | |
92 const char kTestRealm[] = "TestRealm"; | |
93 | |
94 const GURL kOrigin1(kTestOrigin1); | |
95 const GURL kOrigin2(kTestOrigin2); | |
96 const GURL kOrigin3(kTestOrigin3); | |
97 const GURL kOrigin4(kTestOrigin4); | |
98 const GURL kOriginExt(kTestOriginExt); | |
99 const GURL kOriginDevTools(kTestOriginDevTools); | |
100 | |
101 const base::FilePath::CharType kDomStorageOrigin1[] = | |
102 FILE_PATH_LITERAL("http_host1_1.localstorage"); | |
103 | |
104 const base::FilePath::CharType kDomStorageOrigin2[] = | |
105 FILE_PATH_LITERAL("http_host2_1.localstorage"); | |
106 | |
107 const base::FilePath::CharType kDomStorageOrigin3[] = | |
108 FILE_PATH_LITERAL("http_host3_1.localstorage"); | |
109 | |
110 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL( | |
111 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage"); | |
112 | |
113 struct StoragePartitionRemovalData { | |
114 uint32_t remove_mask = 0; | |
115 uint32_t quota_storage_remove_mask = 0; | |
116 base::Time remove_begin; | |
117 base::Time remove_end; | |
118 StoragePartition::OriginMatcherFunction origin_matcher; | |
119 StoragePartition::CookieMatcherFunction cookie_matcher; | |
120 | |
121 StoragePartitionRemovalData() {} | |
122 }; | |
123 | |
124 net::CanonicalCookie CreateCookieWithHost(const GURL& source) { | |
125 std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create( | |
126 source, "A", "1", std::string(), "/", base::Time::Now(), | |
127 base::Time::Now(), false, false, net::CookieSameSite::DEFAULT_MODE, | |
128 net::COOKIE_PRIORITY_MEDIUM)); | |
129 EXPECT_TRUE(cookie); | |
130 return *cookie; | |
131 } | |
132 | |
133 class TestStoragePartition : public StoragePartition { | |
134 public: | |
135 TestStoragePartition() {} | |
136 ~TestStoragePartition() override {} | |
137 | |
138 // content::StoragePartition implementation. | |
139 base::FilePath GetPath() override { return base::FilePath(); } | |
140 net::URLRequestContextGetter* GetURLRequestContext() override { | |
141 return nullptr; | |
142 } | |
143 net::URLRequestContextGetter* GetMediaURLRequestContext() override { | |
144 return nullptr; | |
145 } | |
146 storage::QuotaManager* GetQuotaManager() override { return nullptr; } | |
147 content::AppCacheService* GetAppCacheService() override { return nullptr; } | |
148 storage::FileSystemContext* GetFileSystemContext() override { | |
149 return nullptr; | |
150 } | |
151 storage::DatabaseTracker* GetDatabaseTracker() override { return nullptr; } | |
152 content::DOMStorageContext* GetDOMStorageContext() override { | |
153 return nullptr; | |
154 } | |
155 content::IndexedDBContext* GetIndexedDBContext() override { return nullptr; } | |
156 content::ServiceWorkerContext* GetServiceWorkerContext() override { | |
157 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 | |
174 void ClearDataForOrigin(uint32_t remove_mask, | |
175 uint32_t quota_storage_remove_mask, | |
176 const GURL& storage_origin, | |
177 net::URLRequestContextGetter* rq_context, | |
178 const base::Closure& callback) override { | |
179 BrowserThread::PostTask(BrowserThread::UI, | |
180 FROM_HERE, | |
181 base::Bind(&TestStoragePartition::AsyncRunCallback, | |
182 base::Unretained(this), | |
183 callback)); | |
184 } | |
185 | |
186 void ClearData(uint32_t remove_mask, | |
187 uint32_t quota_storage_remove_mask, | |
188 const GURL& storage_origin, | |
189 const OriginMatcherFunction& origin_matcher, | |
190 const base::Time begin, | |
191 const base::Time end, | |
192 const base::Closure& callback) override { | |
193 // Store stuff to verify parameters' correctness later. | |
194 storage_partition_removal_data_.remove_mask = remove_mask; | |
195 storage_partition_removal_data_.quota_storage_remove_mask = | |
196 quota_storage_remove_mask; | |
197 storage_partition_removal_data_.remove_begin = begin; | |
198 storage_partition_removal_data_.remove_end = end; | |
199 storage_partition_removal_data_.origin_matcher = origin_matcher; | |
200 | |
201 BrowserThread::PostTask( | |
202 BrowserThread::UI, | |
203 FROM_HERE, | |
204 base::Bind(&TestStoragePartition::AsyncRunCallback, | |
205 base::Unretained(this), callback)); | |
206 } | |
207 | |
208 void ClearData(uint32_t remove_mask, | |
209 uint32_t quota_storage_remove_mask, | |
210 const OriginMatcherFunction& origin_matcher, | |
211 const CookieMatcherFunction& cookie_matcher, | |
212 const base::Time begin, | |
213 const base::Time end, | |
214 const base::Closure& callback) override { | |
215 // Store stuff to verify parameters' correctness later. | |
216 storage_partition_removal_data_.remove_mask = remove_mask; | |
217 storage_partition_removal_data_.quota_storage_remove_mask = | |
218 quota_storage_remove_mask; | |
219 storage_partition_removal_data_.remove_begin = begin; | |
220 storage_partition_removal_data_.remove_end = end; | |
221 storage_partition_removal_data_.origin_matcher = origin_matcher; | |
222 storage_partition_removal_data_.cookie_matcher = cookie_matcher; | |
223 | |
224 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
225 base::Bind(&TestStoragePartition::AsyncRunCallback, | |
226 base::Unretained(this), callback)); | |
227 } | |
228 | |
229 void ClearHttpAndMediaCaches( | |
230 const base::Time begin, | |
231 const base::Time end, | |
232 const base::Callback<bool(const GURL&)>& url_matcher, | |
233 const base::Closure& callback) override { | |
234 // Not needed in this test. | |
235 } | |
236 | |
237 void Flush() override {} | |
238 | |
239 void ClearBluetoothAllowedDevicesMapForTesting() override {} | |
240 | |
241 StoragePartitionRemovalData GetStoragePartitionRemovalData() { | |
242 return storage_partition_removal_data_; | |
243 } | |
244 | |
245 private: | |
246 void AsyncRunCallback(const base::Closure& callback) { | |
247 callback.Run(); | |
248 } | |
249 | |
250 StoragePartitionRemovalData storage_partition_removal_data_; | |
251 | |
252 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); | |
253 }; | |
254 | |
255 // Custom matcher to test the equivalence of two URL filters. Since those are | |
256 // blackbox predicates, we can only approximate the equivalence by testing | |
257 // whether the filter give the same answer for several URLs. This is currently | |
258 // good enough for our testing purposes, to distinguish whitelists | |
259 // and blacklists, empty and non-empty filters and such. | |
260 // TODO(msramek): BrowsingDataRemover and some of its backends support URL | |
261 // 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 | |
263 // 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() | |
265 // in this matcher. | |
266 class ProbablySameFilterMatcher | |
267 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> { | |
268 public: | |
269 explicit ProbablySameFilterMatcher( | |
270 const base::Callback<bool(const GURL&)>& filter) | |
271 : to_match_(filter) { | |
272 } | |
273 | |
274 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, | |
275 MatchResultListener* listener) const { | |
276 if (filter.is_null() && to_match_.is_null()) | |
277 return true; | |
278 if (filter.is_null() != to_match_.is_null()) | |
279 return false; | |
280 | |
281 const GURL urls_to_test_[] = | |
282 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")}; | |
283 for (GURL url : urls_to_test_) { | |
284 if (filter.Run(url) != to_match_.Run(url)) { | |
285 if (listener) | |
286 *listener << "The filters differ on the URL " << url; | |
287 return false; | |
288 } | |
289 } | |
290 return true; | |
291 } | |
292 | |
293 virtual void DescribeTo(::std::ostream* os) const { | |
294 *os << "is probably the same url filter as " << &to_match_; | |
295 } | |
296 | |
297 virtual void DescribeNegationTo(::std::ostream* os) const { | |
298 *os << "is definitely NOT the same url filter as " << &to_match_; | |
299 } | |
300 | |
301 private: | |
302 const base::Callback<bool(const GURL&)>& to_match_; | |
303 }; | |
304 | |
305 inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter( | |
306 const base::Callback<bool(const GURL&)>& filter) { | |
307 return MakeMatcher(new ProbablySameFilterMatcher(filter)); | |
308 } | |
309 | |
310 base::Time AnHourAgo() { | |
311 return base::Time::Now() - base::TimeDelta::FromHours(1); | |
312 } | |
313 | |
314 } // namespace | |
315 | |
316 // Testers ------------------------------------------------------------------- | |
317 | |
318 class RemoveCookieTester { | |
319 public: | |
320 RemoveCookieTester() {} | |
321 | |
322 // Returns true, if the given cookie exists in the cookie store. | |
323 bool ContainsCookie() { | |
324 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | |
325 new content::MessageLoopRunner; | |
326 quit_closure_ = message_loop_runner->QuitClosure(); | |
327 get_cookie_success_ = false; | |
328 cookie_store_->GetCookiesWithOptionsAsync( | |
329 kOrigin1, net::CookieOptions(), | |
330 base::Bind(&RemoveCookieTester::GetCookieCallback, | |
331 base::Unretained(this))); | |
332 message_loop_runner->Run(); | |
333 return get_cookie_success_; | |
334 } | |
335 | |
336 void AddCookie() { | |
337 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | |
338 new content::MessageLoopRunner; | |
339 quit_closure_ = message_loop_runner->QuitClosure(); | |
340 cookie_store_->SetCookieWithOptionsAsync( | |
341 kOrigin1, "A=1", net::CookieOptions(), | |
342 base::Bind(&RemoveCookieTester::SetCookieCallback, | |
343 base::Unretained(this))); | |
344 message_loop_runner->Run(); | |
345 } | |
346 | |
347 protected: | |
348 void SetCookieStore(net::CookieStore* cookie_store) { | |
349 cookie_store_ = cookie_store; | |
350 } | |
351 | |
352 private: | |
353 void GetCookieCallback(const std::string& cookies) { | |
354 if (cookies == "A=1") { | |
355 get_cookie_success_ = true; | |
356 } else { | |
357 EXPECT_EQ("", cookies); | |
358 get_cookie_success_ = false; | |
359 } | |
360 quit_closure_.Run(); | |
361 } | |
362 | |
363 void SetCookieCallback(bool result) { | |
364 ASSERT_TRUE(result); | |
365 quit_closure_.Run(); | |
366 } | |
367 | |
368 bool get_cookie_success_ = false; | |
369 base::Closure quit_closure_; | |
370 | |
371 // CookieStore must out live |this|. | |
372 net::CookieStore* cookie_store_ = nullptr; | |
373 | |
374 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); | |
375 }; | |
376 | |
377 class RemoveChannelIDTester : public net::SSLConfigService::Observer { | |
378 public: | |
379 explicit RemoveChannelIDTester(BrowserContext* browser_context) { | |
380 net::URLRequestContext* url_request_context = | |
381 content::BrowserContext::GetDefaultStoragePartition(browser_context) | |
382 ->GetURLRequestContext()->GetURLRequestContext(); | |
383 channel_id_service_ = url_request_context-> channel_id_service(); | |
384 ssl_config_service_ = url_request_context->ssl_config_service(); | |
385 ssl_config_service_->AddObserver(this); | |
386 } | |
387 | |
388 ~RemoveChannelIDTester() override { | |
389 ssl_config_service_->RemoveObserver(this); | |
390 } | |
391 | |
392 int ChannelIDCount() { return channel_id_service_->channel_id_count(); } | |
393 | |
394 // 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. | |
396 void AddChannelIDWithTimes(const std::string& server_identifier, | |
397 base::Time creation_time) { | |
398 GetChannelIDStore()->SetChannelID( | |
399 base::MakeUnique<net::ChannelIDStore::ChannelID>( | |
400 server_identifier, creation_time, crypto::ECPrivateKey::Create())); | |
401 } | |
402 | |
403 // 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. | |
405 void AddChannelID(const std::string& server_identifier) { | |
406 base::Time now = base::Time::Now(); | |
407 AddChannelIDWithTimes(server_identifier, now); | |
408 } | |
409 | |
410 void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) { | |
411 GetChannelIDStore()->GetAllChannelIDs( | |
412 base::Bind(&RemoveChannelIDTester::GetAllChannelIDsCallback, | |
413 channel_ids)); | |
414 } | |
415 | |
416 net::ChannelIDStore* GetChannelIDStore() { | |
417 return channel_id_service_->GetChannelIDStore(); | |
418 } | |
419 | |
420 int ssl_config_changed_count() const { | |
421 return ssl_config_changed_count_; | |
422 } | |
423 | |
424 // net::SSLConfigService::Observer implementation: | |
425 void OnSSLConfigChanged() override { ssl_config_changed_count_++; } | |
426 | |
427 private: | |
428 static void GetAllChannelIDsCallback( | |
429 net::ChannelIDStore::ChannelIDList* dest, | |
430 const net::ChannelIDStore::ChannelIDList& result) { | |
431 *dest = result; | |
432 } | |
433 | |
434 net::ChannelIDService* channel_id_service_; | |
435 scoped_refptr<net::SSLConfigService> ssl_config_service_; | |
436 int ssl_config_changed_count_ = 0; | |
437 | |
438 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester); | |
439 }; | |
440 | |
441 class RemoveLocalStorageTester { | |
442 public: | |
443 explicit RemoveLocalStorageTester(BrowserContext* browser_context) | |
444 : browser_context_(browser_context) { | |
445 dom_storage_context_ = | |
446 content::BrowserContext::GetDefaultStoragePartition(browser_context_)-> | |
447 GetDOMStorageContext(); | |
448 } | |
449 | |
450 // Returns true, if the given origin URL exists. | |
451 bool DOMStorageExistsForOrigin(const GURL& origin) { | |
452 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | |
453 new content::MessageLoopRunner; | |
454 quit_closure_ = message_loop_runner->QuitClosure(); | |
455 GetLocalStorageUsage(); | |
456 message_loop_runner->Run(); | |
457 for (size_t i = 0; i < infos_.size(); ++i) { | |
458 if (origin == infos_[i].origin) | |
459 return true; | |
460 } | |
461 return false; | |
462 } | |
463 | |
464 void AddDOMStorageTestData() { | |
465 // Note: This test depends on details of how the dom_storage library | |
466 // stores data in the host file system. | |
467 base::FilePath storage_path = | |
468 browser_context_->GetPath().AppendASCII("Local Storage"); | |
469 base::CreateDirectory(storage_path); | |
470 | |
471 // Write some files. | |
472 base::WriteFile(storage_path.Append(kDomStorageOrigin1), nullptr, 0); | |
473 base::WriteFile(storage_path.Append(kDomStorageOrigin2), nullptr, 0); | |
474 base::WriteFile(storage_path.Append(kDomStorageOrigin3), nullptr, 0); | |
475 base::WriteFile(storage_path.Append(kDomStorageExt), nullptr, 0); | |
476 | |
477 // Tweak their dates. | |
478 base::Time now = base::Time::Now(); | |
479 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now); | |
480 | |
481 base::Time one_day_ago = now - base::TimeDelta::FromDays(1); | |
482 base::TouchFile(storage_path.Append(kDomStorageOrigin2), | |
483 one_day_ago, one_day_ago); | |
484 | |
485 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60); | |
486 base::TouchFile(storage_path.Append(kDomStorageOrigin3), | |
487 sixty_days_ago, sixty_days_ago); | |
488 | |
489 base::TouchFile(storage_path.Append(kDomStorageExt), now, now); | |
490 } | |
491 | |
492 private: | |
493 void GetLocalStorageUsage() { | |
494 dom_storage_context_->GetLocalStorageUsage( | |
495 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage, | |
496 base::Unretained(this))); | |
497 } | |
498 void OnGotLocalStorageUsage( | |
499 const std::vector<content::LocalStorageUsageInfo>& infos) { | |
500 infos_ = infos; | |
501 quit_closure_.Run(); | |
502 } | |
503 | |
504 // We don't own these pointers. | |
505 BrowserContext* browser_context_; | |
506 content::DOMStorageContext* dom_storage_context_ = nullptr; | |
507 | |
508 std::vector<content::LocalStorageUsageInfo> infos_; | |
509 base::Closure quit_closure_; | |
510 | |
511 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); | |
512 }; | |
513 | |
514 class RemoveDownloadsTester { | |
515 public: | |
516 explicit RemoveDownloadsTester(BrowserContext* browser_context) | |
517 : download_manager_(new content::MockDownloadManager()) { | |
518 content::BrowserContext::SetDownloadManagerForTesting(browser_context, | |
519 download_manager_); | |
520 EXPECT_EQ(download_manager_, | |
521 content::BrowserContext::GetDownloadManager(browser_context)); | |
522 EXPECT_CALL(*download_manager_, Shutdown()); | |
523 } | |
524 | |
525 ~RemoveDownloadsTester() {} | |
526 | |
527 content::MockDownloadManager* download_manager() { return download_manager_; } | |
528 | |
529 private: | |
530 content::MockDownloadManager* download_manager_; | |
531 | |
532 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester); | |
533 }; | |
534 | |
535 // Test Class ---------------------------------------------------------------- | |
536 | |
537 class BrowsingDataRemoverImplTest : public testing::Test { | |
538 public: | |
539 BrowsingDataRemoverImplTest() | |
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*>( | |
548 BrowsingDataRemoverFactory::GetForBrowserContext( | |
549 browser_context_.get())); | |
550 remover_->SetEmbedderDelegate(nullptr); | |
551 } | |
552 | |
553 ~BrowsingDataRemoverImplTest() override {} | |
554 | |
555 void TearDown() override { | |
556 mock_policy_ = nullptr; | |
557 | |
558 // BrowserContext contains a DOMStorageContext. BrowserContext's | |
559 // 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 | |
561 // destroyed, and that the message loop is cleared out, before destroying | |
562 // the threads and loop. Otherwise we leak memory. | |
563 browser_context_.reset(); | |
564 base::RunLoop().RunUntilIdle(); | |
565 } | |
566 | |
567 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin, | |
568 const base::Time& delete_end, | |
569 int remove_mask, | |
570 bool include_protected_origins) { | |
571 TestStoragePartition storage_partition; | |
572 remover_->OverrideStoragePartitionForTesting(&storage_partition); | |
573 | |
574 int origin_type_mask = BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB; | |
575 if (include_protected_origins) | |
576 origin_type_mask |= BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB; | |
577 | |
578 BrowsingDataRemoverCompletionObserver completion_observer(remover_); | |
579 remover_->RemoveAndReply( | |
580 delete_begin, delete_end, remove_mask, origin_type_mask, | |
581 &completion_observer); | |
582 completion_observer.BlockUntilCompletion(); | |
583 | |
584 // Save so we can verify later. | |
585 storage_partition_removal_data_ = | |
586 storage_partition.GetStoragePartitionRemovalData(); | |
587 } | |
588 | |
589 void BlockUntilOriginDataRemoved( | |
590 const base::Time& delete_begin, | |
591 const base::Time& delete_end, | |
592 int remove_mask, | |
593 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { | |
594 TestStoragePartition storage_partition; | |
595 remover_->OverrideStoragePartitionForTesting(&storage_partition); | |
596 | |
597 BrowsingDataRemoverCompletionObserver completion_observer(remover_); | |
598 remover_->RemoveWithFilterAndReply( | |
599 delete_begin, delete_end, remove_mask, | |
600 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
601 std::move(filter_builder), &completion_observer); | |
602 completion_observer.BlockUntilCompletion(); | |
603 | |
604 // Save so we can verify later. | |
605 storage_partition_removal_data_ = | |
606 storage_partition.GetStoragePartitionRemovalData(); | |
607 } | |
608 | |
609 BrowserContext* GetBrowserContext() { | |
610 return browser_context_.get(); | |
611 } | |
612 | |
613 void DestroyBrowserContext() { browser_context_.reset(); } | |
614 | |
615 const base::Time& GetBeginTime() { | |
616 return remover_->GetLastUsedBeginTime(); | |
617 } | |
618 | |
619 int GetRemovalMask() { | |
620 return remover_->GetLastUsedRemovalMask(); | |
621 } | |
622 | |
623 int GetOriginTypeMask() { | |
624 return remover_->GetLastUsedOriginTypeMask(); | |
625 } | |
626 | |
627 StoragePartitionRemovalData GetStoragePartitionRemovalData() { | |
628 return storage_partition_removal_data_; | |
629 } | |
630 | |
631 content::MockSpecialStoragePolicy* CreateMockPolicy() { | |
632 mock_policy_ = new content::MockSpecialStoragePolicy(); | |
633 return mock_policy_.get(); | |
634 } | |
635 | |
636 content::MockSpecialStoragePolicy* mock_policy() { | |
637 return mock_policy_.get(); | |
638 } | |
639 | |
640 bool Match(const GURL& origin, | |
641 int mask, | |
642 storage::SpecialStoragePolicy* policy) { | |
643 return remover_->DoesOriginMatchMask(mask, origin, policy); | |
644 } | |
645 | |
646 private: | |
647 // Cached pointer to BrowsingDataRemoverImpl for access to testing methods. | |
648 BrowsingDataRemoverImpl* remover_; | |
649 | |
650 content::TestBrowserThreadBundle thread_bundle_; | |
651 std::unique_ptr<BrowserContext> browser_context_; | |
652 | |
653 StoragePartitionRemovalData storage_partition_removal_data_; | |
654 | |
655 scoped_refptr<content::MockSpecialStoragePolicy> mock_policy_; | |
656 | |
657 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImplTest); | |
658 }; | |
659 | |
660 // Tests --------------------------------------------------------------------- | |
661 | |
662 TEST_F(BrowsingDataRemoverImplTest, RemoveCookieForever) { | |
663 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
664 BrowsingDataRemover::DATA_TYPE_COOKIES, false); | |
665 | |
666 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_COOKIES, GetRemovalMask()); | |
667 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
668 GetOriginTypeMask()); | |
669 | |
670 // Verify that storage partition was instructed to remove the cookies. | |
671 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
672 EXPECT_EQ(removal_data.remove_mask, | |
673 StoragePartition::REMOVE_DATA_MASK_COOKIES); | |
674 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
675 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
676 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
677 } | |
678 | |
679 TEST_F(BrowsingDataRemoverImplTest, RemoveCookieLastHour) { | |
680 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), | |
681 BrowsingDataRemover::DATA_TYPE_COOKIES, false); | |
682 | |
683 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_COOKIES, GetRemovalMask()); | |
684 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
685 GetOriginTypeMask()); | |
686 | |
687 // Verify that storage partition was instructed to remove the cookies. | |
688 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
689 EXPECT_EQ(removal_data.remove_mask, | |
690 StoragePartition::REMOVE_DATA_MASK_COOKIES); | |
691 // Removing with time period other than all time should not clear | |
692 // persistent storage data. | |
693 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
694 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT); | |
695 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
696 } | |
697 | |
698 TEST_F(BrowsingDataRemoverImplTest, RemoveCookiesDomainBlacklist) { | |
699 std::unique_ptr<BrowsingDataFilterBuilder> filter( | |
700 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST)); | |
701 filter->AddRegisterableDomain(kTestRegisterableDomain1); | |
702 filter->AddRegisterableDomain(kTestRegisterableDomain3); | |
703 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), | |
704 BrowsingDataRemover::DATA_TYPE_COOKIES, | |
705 std::move(filter)); | |
706 | |
707 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_COOKIES, GetRemovalMask()); | |
708 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
709 GetOriginTypeMask()); | |
710 | |
711 // Verify that storage partition was instructed to remove the cookies. | |
712 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
713 EXPECT_EQ(removal_data.remove_mask, | |
714 StoragePartition::REMOVE_DATA_MASK_COOKIES); | |
715 // Removing with time period other than all time should not clear | |
716 // persistent storage data. | |
717 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
718 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT); | |
719 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
720 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
721 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
722 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
723 // Even though it's a different origin, it's the same domain. | |
724 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin4, mock_policy())); | |
725 | |
726 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin1))); | |
727 EXPECT_TRUE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin2))); | |
728 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 | |
730 // scheme. | |
731 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin4))); | |
732 } | |
733 | |
734 // Test that removing cookies clears HTTP auth data. | |
735 TEST_F(BrowsingDataRemoverImplTest, ClearHttpAuthCache_RemoveCookies) { | |
736 net::HttpNetworkSession* http_session = | |
737 content::BrowserContext::GetDefaultStoragePartition(GetBrowserContext()) | |
738 ->GetURLRequestContext() | |
739 ->GetURLRequestContext() | |
740 ->http_transaction_factory() | |
741 ->GetSession(); | |
742 DCHECK(http_session); | |
743 | |
744 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache(); | |
745 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC, | |
746 "test challenge", | |
747 net::AuthCredentials(base::ASCIIToUTF16("foo"), | |
748 base::ASCIIToUTF16("bar")), | |
749 "/"); | |
750 CHECK(http_auth_cache->Lookup(kOrigin1, kTestRealm, | |
751 net::HttpAuth::AUTH_SCHEME_BASIC)); | |
752 | |
753 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
754 BrowsingDataRemover::DATA_TYPE_COOKIES, false); | |
755 | |
756 EXPECT_EQ(nullptr, http_auth_cache->Lookup(kOrigin1, kTestRealm, | |
757 net::HttpAuth::AUTH_SCHEME_BASIC)); | |
758 } | |
759 | |
760 TEST_F(BrowsingDataRemoverImplTest, RemoveChannelIDForever) { | |
761 RemoveChannelIDTester tester(GetBrowserContext()); | |
762 | |
763 tester.AddChannelID(kTestOrigin1); | |
764 EXPECT_EQ(0, tester.ssl_config_changed_count()); | |
765 EXPECT_EQ(1, tester.ChannelIDCount()); | |
766 | |
767 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
768 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS, | |
769 false); | |
770 | |
771 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS, GetRemovalMask()); | |
772 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
773 GetOriginTypeMask()); | |
774 EXPECT_EQ(1, tester.ssl_config_changed_count()); | |
775 EXPECT_EQ(0, tester.ChannelIDCount()); | |
776 } | |
777 | |
778 TEST_F(BrowsingDataRemoverImplTest, RemoveChannelIDLastHour) { | |
779 RemoveChannelIDTester tester(GetBrowserContext()); | |
780 | |
781 base::Time now = base::Time::Now(); | |
782 tester.AddChannelID(kTestOrigin1); | |
783 tester.AddChannelIDWithTimes(kTestOrigin2, | |
784 now - base::TimeDelta::FromHours(2)); | |
785 EXPECT_EQ(0, tester.ssl_config_changed_count()); | |
786 EXPECT_EQ(2, tester.ChannelIDCount()); | |
787 | |
788 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), | |
789 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS, | |
790 false); | |
791 | |
792 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS, GetRemovalMask()); | |
793 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
794 GetOriginTypeMask()); | |
795 EXPECT_EQ(1, tester.ssl_config_changed_count()); | |
796 ASSERT_EQ(1, tester.ChannelIDCount()); | |
797 net::ChannelIDStore::ChannelIDList channel_ids; | |
798 tester.GetChannelIDList(&channel_ids); | |
799 ASSERT_EQ(1U, channel_ids.size()); | |
800 EXPECT_EQ(kTestOrigin2, channel_ids.front().server_identifier()); | |
801 } | |
802 | |
803 TEST_F(BrowsingDataRemoverImplTest, RemoveChannelIDsForServerIdentifiers) { | |
804 RemoveChannelIDTester tester(GetBrowserContext()); | |
805 | |
806 tester.AddChannelID(kTestRegisterableDomain1); | |
807 tester.AddChannelID(kTestRegisterableDomain3); | |
808 EXPECT_EQ(2, tester.ChannelIDCount()); | |
809 | |
810 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder( | |
811 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); | |
812 filter_builder->AddRegisterableDomain(kTestRegisterableDomain1); | |
813 | |
814 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
815 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS, | |
816 std::move(filter_builder)); | |
817 | |
818 EXPECT_EQ(1, tester.ChannelIDCount()); | |
819 net::ChannelIDStore::ChannelIDList channel_ids; | |
820 tester.GetChannelIDList(&channel_ids); | |
821 EXPECT_EQ(kTestRegisterableDomain3, channel_ids.front().server_identifier()); | |
822 } | |
823 | |
824 TEST_F(BrowsingDataRemoverImplTest, RemoveUnprotectedLocalStorageForever) { | |
825 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); | |
826 // Protect kOrigin1. | |
827 policy->AddProtected(kOrigin1.GetOrigin()); | |
828 | |
829 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
830 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, | |
831 false); | |
832 | |
833 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); | |
834 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
835 GetOriginTypeMask()); | |
836 | |
837 // Verify that storage partition was instructed to remove the data correctly. | |
838 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
839 EXPECT_EQ(removal_data.remove_mask, | |
840 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); | |
841 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
842 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
843 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
844 | |
845 // Check origin matcher. | |
846 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
847 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
848 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
849 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); | |
850 } | |
851 | |
852 TEST_F(BrowsingDataRemoverImplTest, RemoveProtectedLocalStorageForever) { | |
853 // Protect kOrigin1. | |
854 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); | |
855 policy->AddProtected(kOrigin1.GetOrigin()); | |
856 | |
857 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
858 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, | |
859 true); | |
860 | |
861 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); | |
862 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | | |
863 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB, | |
864 GetOriginTypeMask()); | |
865 | |
866 // Verify that storage partition was instructed to remove the data correctly. | |
867 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
868 EXPECT_EQ(removal_data.remove_mask, | |
869 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); | |
870 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
871 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
872 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
873 | |
874 // Check origin matcher all http origin will match since we specified | |
875 // both protected and unprotected. | |
876 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
877 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
878 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
879 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); | |
880 } | |
881 | |
882 TEST_F(BrowsingDataRemoverImplTest, RemoveLocalStorageForLastWeek) { | |
883 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
884 CreateMockPolicy(); | |
885 #endif | |
886 | |
887 BlockUntilBrowsingDataRemoved( | |
888 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(), | |
889 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, false); | |
890 | |
891 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); | |
892 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
893 GetOriginTypeMask()); | |
894 | |
895 // Verify that storage partition was instructed to remove the data correctly. | |
896 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
897 EXPECT_EQ(removal_data.remove_mask, | |
898 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); | |
899 // Persistent storage won't be deleted. | |
900 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
901 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT); | |
902 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
903 | |
904 // Check origin matcher. | |
905 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
906 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
907 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
908 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); | |
909 } | |
910 | |
911 TEST_F(BrowsingDataRemoverImplTest, RemoveMultipleTypes) { | |
912 // Downloads should be deleted through the DownloadManager, assure it would | |
913 // be called. | |
914 RemoveDownloadsTester downloads_tester(GetBrowserContext()); | |
915 EXPECT_CALL(*downloads_tester.download_manager(), | |
916 RemoveDownloadsByURLAndTime(_, _, _)); | |
917 | |
918 int removal_mask = BrowsingDataRemover::DATA_TYPE_DOWNLOADS | | |
919 BrowsingDataRemover::DATA_TYPE_COOKIES; | |
920 | |
921 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
922 removal_mask, false); | |
923 | |
924 EXPECT_EQ(removal_mask, GetRemovalMask()); | |
925 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
926 GetOriginTypeMask()); | |
927 | |
928 // The cookie would be deleted throught the StorageParition, check if the | |
929 // partition was requested to remove cookie. | |
930 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
931 EXPECT_EQ(removal_data.remove_mask, | |
932 StoragePartition::REMOVE_DATA_MASK_COOKIES); | |
933 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
934 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
935 } | |
936 | |
937 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForeverBoth) { | |
938 BlockUntilBrowsingDataRemoved( | |
939 base::Time(), base::Time::Max(), | |
940 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
941 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
942 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
943 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
944 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
945 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
946 false); | |
947 | |
948 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
949 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
950 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
951 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
952 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
953 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
954 GetRemovalMask()); | |
955 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
956 GetOriginTypeMask()); | |
957 | |
958 // Verify storage partition related stuffs. | |
959 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
960 EXPECT_EQ(removal_data.remove_mask, | |
961 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
962 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
963 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
964 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
965 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
966 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
967 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
968 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
969 } | |
970 | |
971 TEST_F(BrowsingDataRemoverImplTest, | |
972 RemoveQuotaManagedDataForeverOnlyTemporary) { | |
973 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
974 CreateMockPolicy(); | |
975 #endif | |
976 | |
977 BlockUntilBrowsingDataRemoved( | |
978 base::Time(), base::Time::Max(), | |
979 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
980 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
981 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
982 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
983 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
984 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
985 false); | |
986 | |
987 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
988 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
989 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
990 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
991 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
992 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
993 GetRemovalMask()); | |
994 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
995 GetOriginTypeMask()); | |
996 | |
997 // Verify storage partition related stuffs. | |
998 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
999 | |
1000 EXPECT_EQ(removal_data.remove_mask, | |
1001 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
1002 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
1003 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
1004 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
1005 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
1006 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
1007 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
1008 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
1009 | |
1010 // Check that all related origin data would be removed, that is, origin | |
1011 // matcher would match these origin. | |
1012 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
1013 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
1014 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
1015 } | |
1016 | |
1017 TEST_F(BrowsingDataRemoverImplTest, | |
1018 RemoveQuotaManagedDataForeverOnlyPersistent) { | |
1019 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
1020 CreateMockPolicy(); | |
1021 #endif | |
1022 | |
1023 BlockUntilBrowsingDataRemoved( | |
1024 base::Time(), base::Time::Max(), | |
1025 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1026 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
1027 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1028 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1029 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1030 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
1031 false); | |
1032 | |
1033 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1034 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
1035 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1036 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1037 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1038 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
1039 GetRemovalMask()); | |
1040 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
1041 GetOriginTypeMask()); | |
1042 | |
1043 // Verify storage partition related stuffs. | |
1044 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
1045 | |
1046 EXPECT_EQ(removal_data.remove_mask, | |
1047 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
1048 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
1049 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
1050 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
1051 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
1052 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
1053 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
1054 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
1055 | |
1056 // Check that all related origin data would be removed, that is, origin | |
1057 // matcher would match these origin. | |
1058 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
1059 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
1060 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
1061 } | |
1062 | |
1063 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForeverNeither) { | |
1064 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
1065 CreateMockPolicy(); | |
1066 #endif | |
1067 | |
1068 BlockUntilBrowsingDataRemoved( | |
1069 base::Time(), base::Time::Max(), | |
1070 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1071 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
1072 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1073 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1074 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1075 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
1076 false); | |
1077 | |
1078 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1079 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
1080 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1081 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1082 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1083 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
1084 GetRemovalMask()); | |
1085 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
1086 GetOriginTypeMask()); | |
1087 | |
1088 // Verify storage partition related stuffs. | |
1089 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
1090 | |
1091 EXPECT_EQ(removal_data.remove_mask, | |
1092 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
1093 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
1094 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
1095 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
1096 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
1097 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
1098 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
1099 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
1100 | |
1101 // Check that all related origin data would be removed, that is, origin | |
1102 // matcher would match these origin. | |
1103 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
1104 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
1105 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
1106 } | |
1107 | |
1108 TEST_F(BrowsingDataRemoverImplTest, | |
1109 RemoveQuotaManagedDataForeverSpecificOrigin) { | |
1110 std::unique_ptr<BrowsingDataFilterBuilder> builder( | |
1111 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); | |
1112 builder->AddRegisterableDomain(kTestRegisterableDomain1); | |
1113 // Remove Origin 1. | |
1114 BlockUntilOriginDataRemoved( | |
1115 base::Time(), base::Time::Max(), | |
1116 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1117 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1118 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1119 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1120 BrowsingDataRemover::DATA_TYPE_INDEXED_DB | | |
1121 BrowsingDataRemover::DATA_TYPE_WEB_SQL, | |
1122 std::move(builder)); | |
1123 | |
1124 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1125 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1126 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1127 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1128 BrowsingDataRemover::DATA_TYPE_INDEXED_DB | | |
1129 BrowsingDataRemover::DATA_TYPE_WEB_SQL, | |
1130 GetRemovalMask()); | |
1131 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
1132 GetOriginTypeMask()); | |
1133 | |
1134 // Verify storage partition related stuffs. | |
1135 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
1136 | |
1137 EXPECT_EQ(removal_data.remove_mask, | |
1138 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
1139 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
1140 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
1141 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
1142 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
1143 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
1144 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
1145 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
1146 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
1147 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
1148 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
1149 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin4, mock_policy())); | |
1150 } | |
1151 | |
1152 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForLastHour) { | |
1153 BlockUntilBrowsingDataRemoved( | |
1154 AnHourAgo(), base::Time::Max(), | |
1155 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1156 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
1157 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1158 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1159 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1160 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
1161 false); | |
1162 | |
1163 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1164 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
1165 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1166 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1167 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1168 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
1169 GetRemovalMask()); | |
1170 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
1171 GetOriginTypeMask()); | |
1172 | |
1173 // Verify storage partition related stuffs. | |
1174 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
1175 | |
1176 EXPECT_EQ(removal_data.remove_mask, | |
1177 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
1178 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
1179 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
1180 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
1181 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
1182 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
1183 | |
1184 // Persistent data would be left out since we are not removing from | |
1185 // beginning of time. | |
1186 uint32_t expected_quota_mask = | |
1187 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; | |
1188 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask); | |
1189 // Check removal begin time. | |
1190 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
1191 } | |
1192 | |
1193 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForLastWeek) { | |
1194 BlockUntilBrowsingDataRemoved( | |
1195 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(), | |
1196 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1197 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
1198 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1199 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1200 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1201 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
1202 false); | |
1203 | |
1204 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1205 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
1206 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1207 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1208 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1209 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
1210 GetRemovalMask()); | |
1211 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
1212 GetOriginTypeMask()); | |
1213 | |
1214 // Verify storage partition related stuffs. | |
1215 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
1216 | |
1217 EXPECT_EQ(removal_data.remove_mask, | |
1218 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
1219 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
1220 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
1221 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
1222 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
1223 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
1224 | |
1225 // Persistent data would be left out since we are not removing from | |
1226 // beginning of time. | |
1227 uint32_t expected_quota_mask = | |
1228 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; | |
1229 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask); | |
1230 // Check removal begin time. | |
1231 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); | |
1232 } | |
1233 | |
1234 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedUnprotectedOrigins) { | |
1235 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); | |
1236 // Protect kOrigin1. | |
1237 policy->AddProtected(kOrigin1.GetOrigin()); | |
1238 | |
1239 BlockUntilBrowsingDataRemoved( | |
1240 base::Time(), base::Time::Max(), | |
1241 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1242 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
1243 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1244 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1245 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1246 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
1247 false); | |
1248 | |
1249 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1250 BrowsingDataRemover::DATA_TYPE_WEB_SQL | | |
1251 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1252 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1253 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1254 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, | |
1255 GetRemovalMask()); | |
1256 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
1257 GetOriginTypeMask()); | |
1258 | |
1259 // Verify storage partition related stuffs. | |
1260 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
1261 | |
1262 EXPECT_EQ(removal_data.remove_mask, | |
1263 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
1264 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
1265 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
1266 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
1267 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
1268 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
1269 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
1270 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
1271 | |
1272 // Check OriginMatcherFunction. | |
1273 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
1274 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
1275 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
1276 } | |
1277 | |
1278 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedSpecificOrigin) { | |
1279 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); | |
1280 // Protect kOrigin1. | |
1281 policy->AddProtected(kOrigin1.GetOrigin()); | |
1282 | |
1283 std::unique_ptr<BrowsingDataFilterBuilder> builder( | |
1284 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); | |
1285 builder->AddRegisterableDomain(kTestRegisterableDomain1); | |
1286 | |
1287 // Try to remove kOrigin1. Expect failure. | |
1288 BlockUntilOriginDataRemoved( | |
1289 base::Time(), base::Time::Max(), | |
1290 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1291 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1292 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1293 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1294 BrowsingDataRemover::DATA_TYPE_INDEXED_DB | | |
1295 BrowsingDataRemover::DATA_TYPE_WEB_SQL, | |
1296 std::move(builder)); | |
1297 | |
1298 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1299 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1300 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1301 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1302 BrowsingDataRemover::DATA_TYPE_INDEXED_DB | | |
1303 BrowsingDataRemover::DATA_TYPE_WEB_SQL, | |
1304 GetRemovalMask()); | |
1305 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
1306 GetOriginTypeMask()); | |
1307 | |
1308 // Verify storage partition related stuffs. | |
1309 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
1310 | |
1311 EXPECT_EQ(removal_data.remove_mask, | |
1312 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
1313 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
1314 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
1315 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
1316 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
1317 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
1318 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
1319 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
1320 | |
1321 // Check OriginMatcherFunction. | |
1322 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
1323 // Since we use the matcher function to validate origins now, this should | |
1324 // return false for the origins we're not trying to clear. | |
1325 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
1326 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
1327 } | |
1328 | |
1329 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedOrigins) { | |
1330 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); | |
1331 // Protect kOrigin1. | |
1332 policy->AddProtected(kOrigin1.GetOrigin()); | |
1333 | |
1334 // Try to remove kOrigin1. Expect success. | |
1335 BlockUntilBrowsingDataRemoved( | |
1336 base::Time(), base::Time::Max(), | |
1337 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1338 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1339 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1340 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1341 BrowsingDataRemover::DATA_TYPE_INDEXED_DB | | |
1342 BrowsingDataRemover::DATA_TYPE_WEB_SQL, | |
1343 true); | |
1344 | |
1345 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1346 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1347 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1348 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1349 BrowsingDataRemover::DATA_TYPE_INDEXED_DB | | |
1350 BrowsingDataRemover::DATA_TYPE_WEB_SQL, | |
1351 GetRemovalMask()); | |
1352 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB | | |
1353 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
1354 GetOriginTypeMask()); | |
1355 | |
1356 // Verify storage partition related stuffs. | |
1357 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
1358 | |
1359 EXPECT_EQ(removal_data.remove_mask, | |
1360 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
1361 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
1362 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
1363 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
1364 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
1365 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
1366 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
1367 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
1368 | |
1369 // Check OriginMatcherFunction, |kOrigin1| would match mask since we | |
1370 // would have 'protected' specified in origin_type_mask. | |
1371 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); | |
1372 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); | |
1373 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); | |
1374 } | |
1375 | |
1376 TEST_F(BrowsingDataRemoverImplTest, | |
1377 RemoveQuotaManagedIgnoreExtensionsAndDevTools) { | |
1378 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
1379 CreateMockPolicy(); | |
1380 #endif | |
1381 | |
1382 BlockUntilBrowsingDataRemoved( | |
1383 base::Time(), base::Time::Max(), | |
1384 BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1385 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1386 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1387 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1388 BrowsingDataRemover::DATA_TYPE_INDEXED_DB | | |
1389 BrowsingDataRemover::DATA_TYPE_WEB_SQL, | |
1390 false); | |
1391 | |
1392 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_APP_CACHE | | |
1393 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | | |
1394 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | | |
1395 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | | |
1396 BrowsingDataRemover::DATA_TYPE_INDEXED_DB | | |
1397 BrowsingDataRemover::DATA_TYPE_WEB_SQL, | |
1398 GetRemovalMask()); | |
1399 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
1400 GetOriginTypeMask()); | |
1401 | |
1402 // Verify storage partition related stuffs. | |
1403 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | |
1404 | |
1405 EXPECT_EQ(removal_data.remove_mask, | |
1406 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | |
1407 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | |
1408 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | |
1409 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | | |
1410 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | | |
1411 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); | |
1412 EXPECT_EQ(removal_data.quota_storage_remove_mask, | |
1413 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); | |
1414 | |
1415 // Check that extension and devtools data wouldn't be removed, that is, | |
1416 // origin matcher would not match these origin. | |
1417 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); | |
1418 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy())); | |
1419 } | |
1420 | |
1421 class InspectableCompletionObserver | |
1422 : public BrowsingDataRemoverCompletionObserver { | |
1423 public: | |
1424 explicit InspectableCompletionObserver(BrowsingDataRemover* remover) | |
1425 : BrowsingDataRemoverCompletionObserver(remover) {} | |
1426 ~InspectableCompletionObserver() override {} | |
1427 | |
1428 bool called() { return called_; } | |
1429 | |
1430 protected: | |
1431 void OnBrowsingDataRemoverDone() override { | |
1432 BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone(); | |
1433 called_ = true; | |
1434 } | |
1435 | |
1436 private: | |
1437 bool called_ = false; | |
1438 }; | |
1439 | |
1440 TEST_F(BrowsingDataRemoverImplTest, CompletionInhibition) { | |
1441 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | |
1442 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | |
1443 | |
1444 // The |completion_inhibitor| on the stack should prevent removal sessions | |
1445 // from completing until after ContinueToCompletion() is called. | |
1446 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); | |
1447 InspectableCompletionObserver completion_observer(remover); | |
1448 remover->RemoveAndReply( | |
1449 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, | |
1450 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer); | |
1451 | |
1452 // Process messages until the inhibitor is notified, and then some, to make | |
1453 // sure we do not complete asynchronously before ContinueToCompletion() is | |
1454 // called. | |
1455 completion_inhibitor.BlockUntilNearCompletion(); | |
1456 base::RunLoop().RunUntilIdle(); | |
1457 | |
1458 // Verify that the removal has not yet been completed and the observer has | |
1459 // not been called. | |
1460 EXPECT_TRUE(remover->is_removing()); | |
1461 EXPECT_FALSE(completion_observer.called()); | |
1462 | |
1463 // Now run the removal process until completion, and verify that observers are | |
1464 // now notified, and the notifications is sent out. | |
1465 completion_inhibitor.ContinueToCompletion(); | |
1466 completion_observer.BlockUntilCompletion(); | |
1467 | |
1468 EXPECT_FALSE(remover->is_removing()); | |
1469 EXPECT_TRUE(completion_observer.called()); | |
1470 } | |
1471 | |
1472 TEST_F(BrowsingDataRemoverImplTest, EarlyShutdown) { | |
1473 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | |
1474 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | |
1475 InspectableCompletionObserver completion_observer(remover); | |
1476 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); | |
1477 remover->RemoveAndReply( | |
1478 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, | |
1479 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer); | |
1480 | |
1481 completion_inhibitor.BlockUntilNearCompletion(); | |
1482 completion_inhibitor.Reset(); | |
1483 | |
1484 // Verify that the deletion has not yet been completed and the observer has | |
1485 // not been called. | |
1486 EXPECT_TRUE(remover->is_removing()); | |
1487 EXPECT_FALSE(completion_observer.called()); | |
1488 | |
1489 // Destroying the profile should trigger the notification. | |
1490 DestroyBrowserContext(); | |
1491 | |
1492 EXPECT_TRUE(completion_observer.called()); | |
1493 | |
1494 // Finishing after shutdown shouldn't break anything. | |
1495 completion_inhibitor.ContinueToCompletion(); | |
1496 completion_observer.BlockUntilCompletion(); | |
1497 } | |
1498 | |
1499 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByTimeOnly) { | |
1500 RemoveDownloadsTester tester(GetBrowserContext()); | |
1501 base::Callback<bool(const GURL&)> filter = | |
1502 BrowsingDataFilterBuilder::BuildNoopFilter(); | |
1503 | |
1504 EXPECT_CALL( | |
1505 *tester.download_manager(), | |
1506 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); | |
1507 | |
1508 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
1509 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | |
1510 false); | |
1511 } | |
1512 | |
1513 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByOrigin) { | |
1514 RemoveDownloadsTester tester(GetBrowserContext()); | |
1515 std::unique_ptr<BrowsingDataFilterBuilder> builder( | |
1516 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); | |
1517 builder->AddRegisterableDomain(kTestRegisterableDomain1); | |
1518 base::Callback<bool(const GURL&)> filter = builder->BuildGeneralFilter(); | |
1519 | |
1520 EXPECT_CALL( | |
1521 *tester.download_manager(), | |
1522 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); | |
1523 | |
1524 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
1525 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | |
1526 std::move(builder)); | |
1527 } | |
1528 | |
1529 class MultipleTasksObserver { | |
1530 public: | |
1531 // A simple implementation of BrowsingDataRemover::Observer. | |
1532 // MultipleTasksObserver will use several instances of Target to test | |
1533 // that completion callbacks are returned to the correct one. | |
1534 class Target : public BrowsingDataRemover::Observer { | |
1535 public: | |
1536 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover) | |
1537 : parent_(parent), | |
1538 observer_(this) { | |
1539 observer_.Add(remover); | |
1540 } | |
1541 ~Target() override {} | |
1542 | |
1543 void OnBrowsingDataRemoverDone() override { | |
1544 parent_->SetLastCalledTarget(this); | |
1545 } | |
1546 | |
1547 private: | |
1548 MultipleTasksObserver* parent_; | |
1549 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> | |
1550 observer_; | |
1551 }; | |
1552 | |
1553 explicit MultipleTasksObserver(BrowsingDataRemover* remover) | |
1554 : target_a_(this, remover), | |
1555 target_b_(this, remover), | |
1556 last_called_target_(nullptr) {} | |
1557 ~MultipleTasksObserver() {} | |
1558 | |
1559 void ClearLastCalledTarget() { | |
1560 last_called_target_ = nullptr; | |
1561 } | |
1562 | |
1563 Target* GetLastCalledTarget() { | |
1564 return last_called_target_; | |
1565 } | |
1566 | |
1567 Target* target_a() { return &target_a_; } | |
1568 Target* target_b() { return &target_b_; } | |
1569 | |
1570 private: | |
1571 void SetLastCalledTarget(Target* target) { | |
1572 DCHECK(!last_called_target_) | |
1573 << "Call ClearLastCalledTarget() before every removal task."; | |
1574 last_called_target_ = target; | |
1575 } | |
1576 | |
1577 Target target_a_; | |
1578 Target target_b_; | |
1579 Target* last_called_target_; | |
1580 }; | |
1581 | |
1582 TEST_F(BrowsingDataRemoverImplTest, MultipleTasks) { | |
1583 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | |
1584 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | |
1585 EXPECT_FALSE(remover->is_removing()); | |
1586 | |
1587 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_1( | |
1588 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); | |
1589 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_2( | |
1590 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST)); | |
1591 filter_builder_2->AddRegisterableDomain("example.com"); | |
1592 | |
1593 MultipleTasksObserver observer(remover); | |
1594 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); | |
1595 | |
1596 // Test several tasks with various configuration of masks, filters, and target | |
1597 // observers. | |
1598 std::list<BrowsingDataRemoverImpl::RemovalTask> tasks; | |
1599 tasks.emplace_back( | |
1600 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | |
1601 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
1602 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST), | |
1603 observer.target_a()); | |
1604 tasks.emplace_back( | |
1605 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, | |
1606 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB, | |
1607 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST), | |
1608 nullptr); | |
1609 tasks.emplace_back( | |
1610 base::Time::Now(), base::Time::Max(), | |
1611 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | |
1612 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | | |
1613 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB, | |
1614 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST), | |
1615 observer.target_b()); | |
1616 tasks.emplace_back(base::Time(), base::Time::UnixEpoch(), | |
1617 BrowsingDataRemover::DATA_TYPE_WEB_SQL, | |
1618 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, | |
1619 std::move(filter_builder_1), observer.target_b()); | |
1620 tasks.emplace_back(base::Time::UnixEpoch(), base::Time::Now(), | |
1621 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS, | |
1622 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | | |
1623 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB, | |
1624 std::move(filter_builder_2), nullptr); | |
1625 | |
1626 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) { | |
1627 // 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 | |
1629 // Remove.* instead. This also serves as a test that those methods are all | |
1630 // correctly reduced to RemoveInternal(). | |
1631 if (!task.observer && task.filter_builder->IsEmptyBlacklist()) { | |
1632 remover->Remove(task.delete_begin, task.delete_end, | |
1633 task.remove_mask, task.origin_type_mask); | |
1634 } else if (task.filter_builder->IsEmptyBlacklist()) { | |
1635 remover->RemoveAndReply(task.delete_begin, task.delete_end, | |
1636 task.remove_mask, task.origin_type_mask, | |
1637 task.observer); | |
1638 } else if (!task.observer) { | |
1639 remover->RemoveWithFilter(task.delete_begin, task.delete_end, | |
1640 task.remove_mask, task.origin_type_mask, | |
1641 std::move(task.filter_builder)); | |
1642 } else { | |
1643 remover->RemoveWithFilterAndReply(task.delete_begin, task.delete_end, | |
1644 task.remove_mask, task.origin_type_mask, | |
1645 std::move(task.filter_builder), | |
1646 task.observer); | |
1647 } | |
1648 } | |
1649 | |
1650 // Use the inhibitor to stop after every task and check the results. | |
1651 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) { | |
1652 EXPECT_TRUE(remover->is_removing()); | |
1653 observer.ClearLastCalledTarget(); | |
1654 | |
1655 // Finish the task execution synchronously. | |
1656 completion_inhibitor.BlockUntilNearCompletion(); | |
1657 completion_inhibitor.ContinueToCompletion(); | |
1658 | |
1659 // Observers, if any, should have been called by now (since we call | |
1660 // observers on the same thread). | |
1661 EXPECT_EQ(task.observer, observer.GetLastCalledTarget()); | |
1662 | |
1663 // TODO(msramek): If BrowsingDataRemover took ownership of the last used | |
1664 // filter builder and exposed it, we could also test it here. Make it so. | |
1665 EXPECT_EQ(task.remove_mask, GetRemovalMask()); | |
1666 EXPECT_EQ(task.origin_type_mask, GetOriginTypeMask()); | |
1667 EXPECT_EQ(task.delete_begin, GetBeginTime()); | |
1668 } | |
1669 | |
1670 EXPECT_FALSE(remover->is_removing()); | |
1671 } | |
1672 | |
1673 // The previous test, BrowsingDataRemoverTest.MultipleTasks, tests that the | |
1674 // 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 | |
1676 // the parameters. This test demonstrates that even running the tasks without | |
1677 // inhibition is executed correctly and doesn't crash. | |
1678 TEST_F(BrowsingDataRemoverImplTest, MultipleTasksInQuickSuccession) { | |
1679 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( | |
1680 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); | |
1681 EXPECT_FALSE(remover->is_removing()); | |
1682 | |
1683 int test_removal_masks[] = { | |
1684 BrowsingDataRemover::DATA_TYPE_COOKIES, | |
1685 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, | |
1686 BrowsingDataRemover::DATA_TYPE_COOKIES, | |
1687 BrowsingDataRemover::DATA_TYPE_COOKIES, | |
1688 BrowsingDataRemover::DATA_TYPE_COOKIES, | |
1689 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | |
1690 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | |
1691 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | |
1692 BrowsingDataRemover::DATA_TYPE_COOKIES | | |
1693 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | |
1694 BrowsingDataRemover::DATA_TYPE_COOKIES | | |
1695 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, | |
1696 BrowsingDataRemover::DATA_TYPE_COOKIES | | |
1697 BrowsingDataRemover::DATA_TYPE_DOWNLOADS | | |
1698 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, | |
1699 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, | |
1700 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, | |
1701 }; | |
1702 | |
1703 for (int removal_mask : test_removal_masks) { | |
1704 remover->Remove(base::Time(), base::Time::Max(), removal_mask, | |
1705 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB); | |
1706 } | |
1707 | |
1708 EXPECT_TRUE(remover->is_removing()); | |
1709 | |
1710 // Add one more deletion and wait for it. | |
1711 BlockUntilBrowsingDataRemoved( | |
1712 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, | |
1713 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB); | |
1714 | |
1715 EXPECT_FALSE(remover->is_removing()); | |
1716 } | |
OLD | NEW |