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

Side by Side Diff: content/browser/storage_partition_impl_unittest.cc

Issue 37843003: BrowsingDataRemover, (re)use StoragePartition deletion code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Combine functions. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/files/scoped_temp_dir.h" 5 #include "base/files/scoped_temp_dir.h"
6 #include "base/message_loop/message_loop_proxy.h" 6 #include "base/message_loop/message_loop_proxy.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/gpu/shader_disk_cache.h" 10 #include "content/browser/gpu/shader_disk_cache.h"
11 #include "content/browser/storage_partition_impl.h" 11 #include "content/browser/storage_partition_impl.h"
12 #include "content/public/browser/storage_partition.h" 12 #include "content/public/browser/storage_partition.h"
13 #include "content/public/test/test_browser_context.h"
14 #include "content/public/test/test_browser_thread.h"
13 #include "content/public/test/test_browser_thread_bundle.h" 15 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "net/base/test_completion_callback.h" 16 #include "net/base/test_completion_callback.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webkit/browser/quota/mock_quota_manager.h"
19 #include "webkit/browser/quota/mock_special_storage_policy.h"
20 #include "webkit/browser/quota/quota_manager.h"
16 21
17 namespace content { 22 namespace content {
18 namespace { 23 namespace {
19 24
25 const int kDefaultClientId = 42;
26 const char kCacheKey[] = "key";
27 const char kCacheValue[] = "cached value";
28
29 const char kTestOrigin1[] = "http://host1:1/";
30 const char kTestOrigin2[] = "http://host2:1/";
31 const char kTestOrigin3[] = "http://host3:1/";
32 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
33
34 const GURL kOrigin1(kTestOrigin1);
35 const GURL kOrigin2(kTestOrigin2);
36 const GURL kOrigin3(kTestOrigin3);
37 const GURL kOriginDevTools(kTestOriginDevTools);
38
39 const quota::StorageType kTemporary = quota::kStorageTypeTemporary;
40 const quota::StorageType kPersistent = quota::kStorageTypePersistent;
41
42 const quota::QuotaClient::ID kClientFile = quota::QuotaClient::kFileSystem;
43
44 const uint32 kAllQuotaRemoveMask =
45 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB |
46 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
47 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
48 StoragePartition::REMOVE_DATA_MASK_APPCACHE;
49
20 class TestClosureCallback { 50 class TestClosureCallback {
21 public: 51 public:
22 TestClosureCallback() 52 TestClosureCallback()
23 : callback_(base::Bind( 53 : callback_(base::Bind(
24 &TestClosureCallback::StopWaiting, base::Unretained(this))) { 54 &TestClosureCallback::StopWaiting, base::Unretained(this))) {
25 } 55 }
26 56
27 void WaitForResult() { 57 void WaitForResult() {
28 wait_run_loop_.reset(new base::RunLoop()); 58 wait_run_loop_.reset(new base::RunLoop());
29 wait_run_loop_->Run(); 59 wait_run_loop_->Run();
30 } 60 }
31 61
32 const base::Closure& callback() { return callback_; } 62 const base::Closure& callback() { return callback_; }
33 63
34 private: 64 private:
35 void StopWaiting() { 65 void StopWaiting() {
36 wait_run_loop_->Quit(); 66 wait_run_loop_->Quit();
37 } 67 }
38 68
39 base::Closure callback_; 69 base::Closure callback_;
40 scoped_ptr<base::RunLoop> wait_run_loop_; 70 scoped_ptr<base::RunLoop> wait_run_loop_;
41 71
42 DISALLOW_COPY_AND_ASSIGN(TestClosureCallback); 72 DISALLOW_COPY_AND_ASSIGN(TestClosureCallback);
43 }; 73 };
44 74
45 const int kDefaultClientId = 42; 75 bool DoesOriginMatchForUnprotectedWeb(
46 const char kCacheKey[] = "key"; 76 const GURL& origin,
47 const char kCacheValue[] = "cached value"; 77 quota::SpecialStoragePolicy* special_storage_policy) {
78 // This is used for tests where we are clearing UNPROTECTED_WEB data.
79 return !special_storage_policy->IsStorageProtected(origin.GetOrigin());
80 }
81
82 bool DoesOriginMatchForBothProtectedAndUnprotectedWeb(
83 const GURL& origin,
84 quota::SpecialStoragePolicy* special_storage_policy) {
85 return true;
86 }
87
88 bool DoesOriginMatchUnprotected(
89 const GURL& origin,
90 quota::SpecialStoragePolicy* special_storage_policy) {
91 return origin.GetOrigin().scheme() != kOriginDevTools.scheme();
92 }
93
94 void ClearQuotaData(content::StoragePartition* storage_partition,
95 const base::Closure& cb) {
96 storage_partition->ClearData(
97 kAllQuotaRemoveMask,
98 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
99 NULL, StoragePartition::OriginMatcherFunction(),
100 base::Time(), base::Time::Max(), cb);
101 }
102
103 void ClearQuotaDataWithOriginMatcher(
104 content::StoragePartition* storage_partition,
105 const GURL& remove_origin,
106 const StoragePartition::OriginMatcherFunction& origin_matcher,
107 const base::Time delete_begin,
108 const base::Closure& cb) {
109 storage_partition->ClearData(kAllQuotaRemoveMask,
110 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
111 &remove_origin, origin_matcher, delete_begin,
112 base::Time::Max(), cb);
113 }
114
115 void ClearQuotaDataForOrigin(
116 content::StoragePartition* storage_partition,
117 const GURL& remove_origin,
118 const base::Time delete_begin,
119 const base::Closure& cb) {
120 ClearQuotaDataWithOriginMatcher(
121 storage_partition, remove_origin,
122 StoragePartition::OriginMatcherFunction(), delete_begin, cb);
123 }
124
125 void ClearQuotaDataForNonPersistent(
126 content::StoragePartition* storage_partition,
127 const base::Time delete_begin,
128 const base::Closure& cb) {
129 uint32 quota_storage_remove_mask_no_persistent =
130 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL &
131 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
132 storage_partition->ClearData(
133 kAllQuotaRemoveMask, quota_storage_remove_mask_no_persistent,
134 NULL, StoragePartition::OriginMatcherFunction(),
135 delete_begin, base::Time::Max(), cb);
136 }
48 137
49 } // namespace 138 } // namespace
50 139
140 class StoragePartitionImplTest : public testing::Test {
141 public:
142 StoragePartitionImplTest()
143 : browser_context_(new TestBrowserContext()),
144 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
145 }
146 virtual ~StoragePartitionImplTest() {}
147
148 quota::MockQuotaManager* GetMockManager() {
149 if (!quota_manager_.get()) {
150 quota_manager_ = new quota::MockQuotaManager(
151 browser_context_->IsOffTheRecord(),
152 browser_context_->GetPath(),
153 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(),
154 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(),
155 browser_context_->GetSpecialStoragePolicy());
156 }
157 return quota_manager_.get();
158 }
159
160 private:
161 scoped_ptr<TestBrowserContext> browser_context_;
162 scoped_refptr<quota::MockQuotaManager> quota_manager_;
163 content::TestBrowserThreadBundle thread_bundle_;
164
165 DISALLOW_COPY_AND_ASSIGN(StoragePartitionImplTest);
166 };
167
51 class StoragePartitionShaderClearTest : public testing::Test { 168 class StoragePartitionShaderClearTest : public testing::Test {
52 public: 169 public:
53 StoragePartitionShaderClearTest() 170 StoragePartitionShaderClearTest()
54 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 171 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
55 } 172 }
56 173
57 virtual ~StoragePartitionShaderClearTest() {} 174 virtual ~StoragePartitionShaderClearTest() {}
58 175
59 const base::FilePath& cache_path() { return temp_dir_.path(); } 176 const base::FilePath& cache_path() { return temp_dir_.path(); }
60 177
(...skipping 30 matching lines...) Expand all
91 208
92 base::ScopedTempDir temp_dir_; 209 base::ScopedTempDir temp_dir_;
93 content::TestBrowserThreadBundle thread_bundle_; 210 content::TestBrowserThreadBundle thread_bundle_;
94 211
95 scoped_refptr<ShaderDiskCache> cache_; 212 scoped_refptr<ShaderDiskCache> cache_;
96 }; 213 };
97 214
98 void ClearData(content::StoragePartitionImpl* sp, 215 void ClearData(content::StoragePartitionImpl* sp,
99 const base::Closure& cb) { 216 const base::Closure& cb) {
100 base::Time time; 217 base::Time time;
101 sp->ClearDataForRange( 218 sp->ClearData(
102 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, 219 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE,
103 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, 220 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
221 NULL, StoragePartition::OriginMatcherFunction(),
104 time, time, cb); 222 time, time, cb);
105 } 223 }
106 224
107 TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) { 225 TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) {
108 InitCache(); 226 InitCache();
109 EXPECT_EQ(1u, Size()); 227 EXPECT_EQ(1u, Size());
110 228
111 TestClosureCallback clear_cb; 229 TestClosureCallback clear_cb;
112 StoragePartitionImpl sp( 230 StoragePartitionImpl storage_partition(
113 cache_path(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 231 cache_path(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
114 base::MessageLoop::current()->PostTask( 232 base::MessageLoop::current()->PostTask(
115 FROM_HERE, base::Bind(&ClearData, &sp, clear_cb.callback())); 233 FROM_HERE, base::Bind(&ClearData, &storage_partition,
234 clear_cb.callback()));
116 clear_cb.WaitForResult(); 235 clear_cb.WaitForResult();
117 EXPECT_EQ(0u, Size()); 236 EXPECT_EQ(0u, Size());
118 } 237 }
119 238
239 TEST_F(StoragePartitionImplTest, QuotaClientMaskGeneration) {
240 EXPECT_EQ(quota::QuotaClient::kFileSystem,
241 StoragePartitionImpl::GenerateQuotaClientMask(
242 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS));
243 EXPECT_EQ(quota::QuotaClient::kDatabase,
244 StoragePartitionImpl::GenerateQuotaClientMask(
245 StoragePartition::REMOVE_DATA_MASK_WEBSQL));
246 EXPECT_EQ(quota::QuotaClient::kAppcache,
247 StoragePartitionImpl::GenerateQuotaClientMask(
248 StoragePartition::REMOVE_DATA_MASK_APPCACHE));
249 EXPECT_EQ(quota::QuotaClient::kIndexedDatabase,
250 StoragePartitionImpl::GenerateQuotaClientMask(
251 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
252 EXPECT_EQ(quota::QuotaClient::kFileSystem |
253 quota::QuotaClient::kDatabase |
254 quota::QuotaClient::kAppcache |
255 quota::QuotaClient::kIndexedDatabase,
256 StoragePartitionImpl::GenerateQuotaClientMask(
257 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
258 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
259 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
260 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
261 }
262
263 void PopulateTestQuotaManagedPersistentData(quota::MockQuotaManager* manager) {
264 manager->AddOrigin(kOrigin2, kPersistent, kClientFile, base::Time());
265 manager->AddOrigin(kOrigin3, kPersistent, kClientFile,
266 base::Time::Now() - base::TimeDelta::FromDays(1));
267
268 EXPECT_FALSE(manager->OriginHasData(kOrigin1, kPersistent, kClientFile));
269 EXPECT_TRUE(manager->OriginHasData(kOrigin2, kPersistent, kClientFile));
270 EXPECT_TRUE(manager->OriginHasData(kOrigin3, kPersistent, kClientFile));
271 }
272
273 void PopulateTestQuotaManagedTemporaryData(quota::MockQuotaManager* manager) {
274 manager->AddOrigin(kOrigin1, kTemporary, kClientFile, base::Time::Now());
275 manager->AddOrigin(kOrigin3, kTemporary, kClientFile,
276 base::Time::Now() - base::TimeDelta::FromDays(1));
277
278 EXPECT_TRUE(manager->OriginHasData(kOrigin1, kTemporary, kClientFile));
279 EXPECT_FALSE(manager->OriginHasData(kOrigin2, kTemporary, kClientFile));
280 EXPECT_TRUE(manager->OriginHasData(kOrigin3, kTemporary, kClientFile));
281 }
282
283 void PopulateTestQuotaManagedData(quota::MockQuotaManager* manager) {
284 // Set up kOrigin1 with a temporary quota, kOrigin2 with a persistent
285 // quota, and kOrigin3 with both. kOrigin1 is modified now, kOrigin2
286 // is modified at the beginning of time, and kOrigin3 is modified one day
287 // ago.
288 PopulateTestQuotaManagedPersistentData(manager);
289 PopulateTestQuotaManagedTemporaryData(manager);
290 }
291
292 void PopulateTestQuotaManagedNonBrowsingData(quota::MockQuotaManager* manager) {
293 manager->AddOrigin(kOriginDevTools, kTemporary, kClientFile, base::Time());
294 manager->AddOrigin(kOriginDevTools, kPersistent, kClientFile, base::Time());
295 }
296
297 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverBoth) {
298 PopulateTestQuotaManagedData(GetMockManager());
299
300 TestClosureCallback clear_cb;
301 StoragePartitionImpl sp(
302 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
303 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
304 GetMockManager());
305 base::MessageLoop::current()->PostTask(
306 FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback()));
307 clear_cb.WaitForResult();
308
309 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
310 kClientFile));
311 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
312 kClientFile));
313 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
314 kClientFile));
315 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
316 kClientFile));
317 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
318 kClientFile));
319 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
320 kClientFile));
321 }
322
323 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
324 PopulateTestQuotaManagedTemporaryData(GetMockManager());
325
326 TestClosureCallback clear_cb;
327 StoragePartitionImpl sp(
328 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
329 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
330 GetMockManager());
331 base::MessageLoop::current()->PostTask(
332 FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback()));
333 clear_cb.WaitForResult();
334
335 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
336 kClientFile));
337 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
338 kClientFile));
339 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
340 kClientFile));
341 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
342 kClientFile));
343 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
344 kClientFile));
345 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
346 kClientFile));
347 }
348
349 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
350 PopulateTestQuotaManagedPersistentData(GetMockManager());
351
352 TestClosureCallback clear_cb;
353 StoragePartitionImpl sp(
354 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
355 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
356 GetMockManager());
357 base::MessageLoop::current()->PostTask(
358 FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback()));
359 clear_cb.WaitForResult();
360
361 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
362 kClientFile));
363 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
364 kClientFile));
365 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
366 kClientFile));
367 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
368 kClientFile));
369 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
370 kClientFile));
371 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
372 kClientFile));
373 }
374
375 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverNeither) {
376 TestClosureCallback clear_cb;
377 StoragePartitionImpl sp(
378 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
379 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
380 GetMockManager());
381 base::MessageLoop::current()->PostTask(
382 FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback()));
383 clear_cb.WaitForResult();
384
385 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
386 kClientFile));
387 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
388 kClientFile));
389 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
390 kClientFile));
391 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
392 kClientFile));
393 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
394 kClientFile));
395 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
396 kClientFile));
397 }
398
399 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
400 PopulateTestQuotaManagedData(GetMockManager());
401
402 TestClosureCallback clear_cb;
403 StoragePartitionImpl sp(
404 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
405 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
406 GetMockManager());
407 base::MessageLoop::current()->PostTask(
408 FROM_HERE, base::Bind(&ClearQuotaDataForOrigin,
409 &sp, kOrigin1, base::Time(), clear_cb.callback()));
410 clear_cb.WaitForResult();
411
412 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
413 kClientFile));
414 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
415 kClientFile));
416 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
417 kClientFile));
418 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
419 kClientFile));
420 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
421 kClientFile));
422 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
423 kClientFile));
424 }
425
426 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastHour) {
427 PopulateTestQuotaManagedData(GetMockManager());
428
429 TestClosureCallback clear_cb;
430 StoragePartitionImpl sp(
431 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
432 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
433 GetMockManager());
434 base::MessageLoop::current()->PostTask(
435 FROM_HERE, base::Bind(&ClearQuotaDataForOrigin,
436 &sp, GURL(),
437 base::Time::Now() - base::TimeDelta::FromHours(1),
438 clear_cb.callback()));
439 clear_cb.WaitForResult();
440
441 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
442 kClientFile));
443 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
444 kClientFile));
445 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
446 kClientFile));
447 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
448 kClientFile));
449 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
450 kClientFile));
451 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
452 kClientFile));
453 }
454
455 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastWeek) {
456 PopulateTestQuotaManagedData(GetMockManager());
457
458 TestClosureCallback clear_cb;
459 StoragePartitionImpl sp(
460 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
461 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
462 GetMockManager());
463 base::MessageLoop::current()->PostTask(
464 FROM_HERE, base::Bind(&ClearQuotaDataForNonPersistent,
465 &sp,
466 base::Time::Now() - base::TimeDelta::FromDays(7),
467 clear_cb.callback()));
468 clear_cb.WaitForResult();
469
470 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
471 kClientFile));
472 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
473 kClientFile));
474 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
475 kClientFile));
476 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
477 kClientFile));
478 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
479 kClientFile));
480 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
481 kClientFile));
482 }
483
484 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedUnprotectedOrigins) {
485 // Protect kOrigin1.
486 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy =
487 new quota::MockSpecialStoragePolicy;
488 mock_policy->AddProtected(kOrigin1.GetOrigin());
489
490 PopulateTestQuotaManagedData(GetMockManager());
491
492 TestClosureCallback clear_cb;
493 StoragePartitionImpl sp(
494 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
495 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
496 GetMockManager());
497 static_cast<StoragePartitionImpl*>(
498 &sp)->OverrideSpecialStoragePolicyForTesting(mock_policy);
499 base::MessageLoop::current()->PostTask(
500 FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher,
501 &sp, GURL(),
502 base::Bind(&DoesOriginMatchForUnprotectedWeb),
503 base::Time(), clear_cb.callback()));
504 clear_cb.WaitForResult();
505
506 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
507 kClientFile));
508 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
509 kClientFile));
510 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
511 kClientFile));
512 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
513 kClientFile));
514 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
515 kClientFile));
516 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
517 kClientFile));
518 }
519
520 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedProtectedSpecificOrigin) {
521 // Protect kOrigin1.
522 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy =
523 new quota::MockSpecialStoragePolicy;
524 mock_policy->AddProtected(kOrigin1.GetOrigin());
525
526 PopulateTestQuotaManagedData(GetMockManager());
527
528 TestClosureCallback clear_cb;
529 StoragePartitionImpl sp(
530 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
531 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
532 GetMockManager());
533 static_cast<StoragePartitionImpl*>(
534 &sp)->OverrideSpecialStoragePolicyForTesting(mock_policy);
535
536 // Try to remove kOrigin1. Expect failure.
537 base::MessageLoop::current()->PostTask(
538 FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher,
539 &sp, kOrigin1,
540 base::Bind(&DoesOriginMatchForUnprotectedWeb),
541 base::Time(), clear_cb.callback()));
542 clear_cb.WaitForResult();
543
544 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
545 kClientFile));
546 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
547 kClientFile));
548 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
549 kClientFile));
550 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
551 kClientFile));
552 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
553 kClientFile));
554 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
555 kClientFile));
556 }
557
558 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedProtectedOrigins) {
559 // Protect kOrigin1.
560 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy =
561 new quota::MockSpecialStoragePolicy;
562 mock_policy->AddProtected(kOrigin1.GetOrigin());
563
564 PopulateTestQuotaManagedData(GetMockManager());
565
566 // Try to remove kOrigin1. Expect success.
567 TestClosureCallback clear_cb;
568 StoragePartitionImpl sp(
569 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
570 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
571 GetMockManager());
572 static_cast<StoragePartitionImpl*>(
573 &sp)->OverrideSpecialStoragePolicyForTesting(mock_policy);
574 base::MessageLoop::current()->PostTask(
575 FROM_HERE,
576 base::Bind(&ClearQuotaDataWithOriginMatcher,
577 &sp, GURL(),
578 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb),
579 base::Time(), clear_cb.callback()));
580 clear_cb.WaitForResult();
581
582 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
583 kClientFile));
584 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
585 kClientFile));
586 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
587 kClientFile));
588 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
589 kClientFile));
590 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
591 kClientFile));
592 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
593 kClientFile));
594 }
595
596 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedIgnoreDevTools) {
597 PopulateTestQuotaManagedNonBrowsingData(GetMockManager());
598
599 TestClosureCallback clear_cb;
600 StoragePartitionImpl sp(
601 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
602 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting(
603 GetMockManager());
604 base::MessageLoop::current()->PostTask(
605 FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher,
606 &sp, GURL(),
607 base::Bind(&DoesOriginMatchUnprotected),
608 base::Time(), clear_cb.callback()));
609 clear_cb.WaitForResult();
610
611 // Check that devtools data isn't removed.
612 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kTemporary,
613 kClientFile));
614 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kPersistent,
615 kClientFile));
616 }
617
120 } // namespace content 618 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698