OLD | NEW |
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->ClearDataForRange( |
| 97 kAllQuotaRemoveMask, |
| 98 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 99 base::Time(), base::Time::Max(), cb); |
| 100 } |
| 101 |
| 102 void ClearQuotaDataWithOriginMatcher( |
| 103 content::StoragePartition* storage_partition, |
| 104 const GURL& remove_origin, |
| 105 const StoragePartition::OriginMatcherFunction& origin_matcher, |
| 106 const base::Time delete_begin, |
| 107 const base::Closure& cb) { |
| 108 storage_partition->ClearDataForOriginWithinRange( |
| 109 kAllQuotaRemoveMask, StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 110 remove_origin, origin_matcher, |
| 111 delete_begin, base::Time::Max(), cb); |
| 112 } |
| 113 |
| 114 void ClearQuotaDataForOrigin( |
| 115 content::StoragePartition* storage_partition, |
| 116 const GURL& remove_origin, |
| 117 const base::Time delete_begin, |
| 118 const base::Closure& cb) { |
| 119 ClearQuotaDataWithOriginMatcher( |
| 120 storage_partition, remove_origin, |
| 121 StoragePartition::OriginMatcherFunction(), delete_begin, cb); |
| 122 } |
| 123 |
| 124 void ClearQuotaDataForNonPersistent( |
| 125 content::StoragePartition* storage_partition, |
| 126 const base::Time delete_begin, |
| 127 const base::Closure& cb) { |
| 128 uint32 quota_storage_remove_mask_no_persistent = |
| 129 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL & |
| 130 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; |
| 131 storage_partition->ClearDataForRange( |
| 132 kAllQuotaRemoveMask, quota_storage_remove_mask_no_persistent, |
| 133 delete_begin, base::Time::Max(), cb); |
| 134 } |
48 | 135 |
49 } // namespace | 136 } // namespace |
50 | 137 |
| 138 class StoragePartitionImplTest : public testing::Test { |
| 139 public: |
| 140 StoragePartitionImplTest() |
| 141 : browser_context_(new TestBrowserContext()), |
| 142 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 143 } |
| 144 virtual ~StoragePartitionImplTest() {} |
| 145 |
| 146 quota::MockQuotaManager* GetMockManager() { |
| 147 if (!quota_manager_.get()) { |
| 148 quota_manager_ = new quota::MockQuotaManager( |
| 149 browser_context_->IsOffTheRecord(), |
| 150 browser_context_->GetPath(), |
| 151 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), |
| 152 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(), |
| 153 browser_context_->GetSpecialStoragePolicy()); |
| 154 } |
| 155 return quota_manager_.get(); |
| 156 } |
| 157 |
| 158 private: |
| 159 scoped_ptr<TestBrowserContext> browser_context_; |
| 160 scoped_refptr<quota::MockQuotaManager> quota_manager_; |
| 161 content::TestBrowserThreadBundle thread_bundle_; |
| 162 |
| 163 DISALLOW_COPY_AND_ASSIGN(StoragePartitionImplTest); |
| 164 }; |
| 165 |
51 class StoragePartitionShaderClearTest : public testing::Test { | 166 class StoragePartitionShaderClearTest : public testing::Test { |
52 public: | 167 public: |
53 StoragePartitionShaderClearTest() | 168 StoragePartitionShaderClearTest() |
54 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 169 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
55 } | 170 } |
56 | 171 |
57 virtual ~StoragePartitionShaderClearTest() {} | 172 virtual ~StoragePartitionShaderClearTest() {} |
58 | 173 |
59 const base::FilePath& cache_path() { return temp_dir_.path(); } | 174 const base::FilePath& cache_path() { return temp_dir_.path(); } |
60 | 175 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, | 217 StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, |
103 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 218 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
104 time, time, cb); | 219 time, time, cb); |
105 } | 220 } |
106 | 221 |
107 TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) { | 222 TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) { |
108 InitCache(); | 223 InitCache(); |
109 EXPECT_EQ(1u, Size()); | 224 EXPECT_EQ(1u, Size()); |
110 | 225 |
111 TestClosureCallback clear_cb; | 226 TestClosureCallback clear_cb; |
112 StoragePartitionImpl sp( | 227 StoragePartitionImpl storage_partition( |
113 cache_path(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 228 cache_path(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
114 base::MessageLoop::current()->PostTask( | 229 base::MessageLoop::current()->PostTask( |
115 FROM_HERE, base::Bind(&ClearData, &sp, clear_cb.callback())); | 230 FROM_HERE, base::Bind(&ClearData, &storage_partition, |
| 231 clear_cb.callback())); |
116 clear_cb.WaitForResult(); | 232 clear_cb.WaitForResult(); |
117 EXPECT_EQ(0u, Size()); | 233 EXPECT_EQ(0u, Size()); |
118 } | 234 } |
119 | 235 |
| 236 TEST_F(StoragePartitionImplTest, QuotaClientMaskGeneration) { |
| 237 EXPECT_EQ(quota::QuotaClient::kFileSystem, |
| 238 StoragePartitionImpl::GenerateQuotaClientMask( |
| 239 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS)); |
| 240 EXPECT_EQ(quota::QuotaClient::kDatabase, |
| 241 StoragePartitionImpl::GenerateQuotaClientMask( |
| 242 StoragePartition::REMOVE_DATA_MASK_WEBSQL)); |
| 243 EXPECT_EQ(quota::QuotaClient::kAppcache, |
| 244 StoragePartitionImpl::GenerateQuotaClientMask( |
| 245 StoragePartition::REMOVE_DATA_MASK_APPCACHE)); |
| 246 EXPECT_EQ(quota::QuotaClient::kIndexedDatabase, |
| 247 StoragePartitionImpl::GenerateQuotaClientMask( |
| 248 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); |
| 249 EXPECT_EQ(quota::QuotaClient::kFileSystem | |
| 250 quota::QuotaClient::kDatabase | |
| 251 quota::QuotaClient::kAppcache | |
| 252 quota::QuotaClient::kIndexedDatabase, |
| 253 StoragePartitionImpl::GenerateQuotaClientMask( |
| 254 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | |
| 255 StoragePartition::REMOVE_DATA_MASK_WEBSQL | |
| 256 StoragePartition::REMOVE_DATA_MASK_APPCACHE | |
| 257 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); |
| 258 } |
| 259 |
| 260 void PopulateTestQuotaManagedPersistentData(quota::MockQuotaManager* manager) { |
| 261 manager->AddOrigin(kOrigin2, kPersistent, kClientFile, base::Time()); |
| 262 manager->AddOrigin(kOrigin3, kPersistent, kClientFile, |
| 263 base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 264 |
| 265 EXPECT_FALSE(manager->OriginHasData(kOrigin1, kPersistent, kClientFile)); |
| 266 EXPECT_TRUE(manager->OriginHasData(kOrigin2, kPersistent, kClientFile)); |
| 267 EXPECT_TRUE(manager->OriginHasData(kOrigin3, kPersistent, kClientFile)); |
| 268 } |
| 269 |
| 270 void PopulateTestQuotaManagedTemporaryData(quota::MockQuotaManager* manager) { |
| 271 manager->AddOrigin(kOrigin1, kTemporary, kClientFile, base::Time::Now()); |
| 272 manager->AddOrigin(kOrigin3, kTemporary, kClientFile, |
| 273 base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 274 |
| 275 EXPECT_TRUE(manager->OriginHasData(kOrigin1, kTemporary, kClientFile)); |
| 276 EXPECT_FALSE(manager->OriginHasData(kOrigin2, kTemporary, kClientFile)); |
| 277 EXPECT_TRUE(manager->OriginHasData(kOrigin3, kTemporary, kClientFile)); |
| 278 } |
| 279 |
| 280 void PopulateTestQuotaManagedData(quota::MockQuotaManager* manager) { |
| 281 // Set up kOrigin1 with a temporary quota, kOrigin2 with a persistent |
| 282 // quota, and kOrigin3 with both. kOrigin1 is modified now, kOrigin2 |
| 283 // is modified at the beginning of time, and kOrigin3 is modified one day |
| 284 // ago. |
| 285 PopulateTestQuotaManagedPersistentData(manager); |
| 286 PopulateTestQuotaManagedTemporaryData(manager); |
| 287 } |
| 288 |
| 289 void PopulateTestQuotaManagedNonBrowsingData(quota::MockQuotaManager* manager) { |
| 290 manager->AddOrigin(kOriginDevTools, kTemporary, kClientFile, base::Time()); |
| 291 manager->AddOrigin(kOriginDevTools, kPersistent, kClientFile, base::Time()); |
| 292 } |
| 293 |
| 294 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverBoth) { |
| 295 PopulateTestQuotaManagedData(GetMockManager()); |
| 296 |
| 297 TestClosureCallback clear_cb; |
| 298 StoragePartitionImpl sp( |
| 299 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 300 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting( |
| 301 GetMockManager()); |
| 302 base::MessageLoop::current()->PostTask( |
| 303 FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback())); |
| 304 clear_cb.WaitForResult(); |
| 305 |
| 306 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 307 kClientFile)); |
| 308 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 309 kClientFile)); |
| 310 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 311 kClientFile)); |
| 312 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 313 kClientFile)); |
| 314 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 315 kClientFile)); |
| 316 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 317 kClientFile)); |
| 318 } |
| 319 |
| 320 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyTemporary) { |
| 321 PopulateTestQuotaManagedTemporaryData(GetMockManager()); |
| 322 |
| 323 TestClosureCallback clear_cb; |
| 324 StoragePartitionImpl sp( |
| 325 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 326 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting( |
| 327 GetMockManager()); |
| 328 base::MessageLoop::current()->PostTask( |
| 329 FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback())); |
| 330 clear_cb.WaitForResult(); |
| 331 |
| 332 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 333 kClientFile)); |
| 334 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 335 kClientFile)); |
| 336 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 337 kClientFile)); |
| 338 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 339 kClientFile)); |
| 340 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 341 kClientFile)); |
| 342 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 343 kClientFile)); |
| 344 } |
| 345 |
| 346 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyPersistent) { |
| 347 PopulateTestQuotaManagedPersistentData(GetMockManager()); |
| 348 |
| 349 TestClosureCallback clear_cb; |
| 350 StoragePartitionImpl sp( |
| 351 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 352 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting( |
| 353 GetMockManager()); |
| 354 base::MessageLoop::current()->PostTask( |
| 355 FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback())); |
| 356 clear_cb.WaitForResult(); |
| 357 |
| 358 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 359 kClientFile)); |
| 360 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 361 kClientFile)); |
| 362 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 363 kClientFile)); |
| 364 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 365 kClientFile)); |
| 366 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 367 kClientFile)); |
| 368 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 369 kClientFile)); |
| 370 } |
| 371 |
| 372 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverNeither) { |
| 373 TestClosureCallback clear_cb; |
| 374 StoragePartitionImpl sp( |
| 375 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 376 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting( |
| 377 GetMockManager()); |
| 378 base::MessageLoop::current()->PostTask( |
| 379 FROM_HERE, base::Bind(&ClearQuotaData, &sp, clear_cb.callback())); |
| 380 clear_cb.WaitForResult(); |
| 381 |
| 382 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 383 kClientFile)); |
| 384 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 385 kClientFile)); |
| 386 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 387 kClientFile)); |
| 388 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 389 kClientFile)); |
| 390 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 391 kClientFile)); |
| 392 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 393 kClientFile)); |
| 394 } |
| 395 |
| 396 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverSpecificOrigin) { |
| 397 PopulateTestQuotaManagedData(GetMockManager()); |
| 398 |
| 399 TestClosureCallback clear_cb; |
| 400 StoragePartitionImpl sp( |
| 401 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 402 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting( |
| 403 GetMockManager()); |
| 404 base::MessageLoop::current()->PostTask( |
| 405 FROM_HERE, base::Bind(&ClearQuotaDataForOrigin, |
| 406 &sp, kOrigin1, base::Time(), clear_cb.callback())); |
| 407 clear_cb.WaitForResult(); |
| 408 |
| 409 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 410 kClientFile)); |
| 411 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 412 kClientFile)); |
| 413 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 414 kClientFile)); |
| 415 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 416 kClientFile)); |
| 417 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 418 kClientFile)); |
| 419 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 420 kClientFile)); |
| 421 } |
| 422 |
| 423 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastHour) { |
| 424 PopulateTestQuotaManagedData(GetMockManager()); |
| 425 |
| 426 TestClosureCallback clear_cb; |
| 427 StoragePartitionImpl sp( |
| 428 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 429 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting( |
| 430 GetMockManager()); |
| 431 base::MessageLoop::current()->PostTask( |
| 432 FROM_HERE, base::Bind(&ClearQuotaDataForOrigin, |
| 433 &sp, GURL(), |
| 434 base::Time::Now() - base::TimeDelta::FromHours(1), |
| 435 clear_cb.callback())); |
| 436 clear_cb.WaitForResult(); |
| 437 |
| 438 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 439 kClientFile)); |
| 440 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 441 kClientFile)); |
| 442 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 443 kClientFile)); |
| 444 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 445 kClientFile)); |
| 446 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 447 kClientFile)); |
| 448 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 449 kClientFile)); |
| 450 } |
| 451 |
| 452 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastWeek) { |
| 453 PopulateTestQuotaManagedData(GetMockManager()); |
| 454 |
| 455 TestClosureCallback clear_cb; |
| 456 StoragePartitionImpl sp( |
| 457 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 458 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting( |
| 459 GetMockManager()); |
| 460 base::MessageLoop::current()->PostTask( |
| 461 FROM_HERE, base::Bind(&ClearQuotaDataForNonPersistent, |
| 462 &sp, |
| 463 base::Time::Now() - base::TimeDelta::FromDays(7), |
| 464 clear_cb.callback())); |
| 465 clear_cb.WaitForResult(); |
| 466 |
| 467 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 468 kClientFile)); |
| 469 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 470 kClientFile)); |
| 471 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 472 kClientFile)); |
| 473 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 474 kClientFile)); |
| 475 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 476 kClientFile)); |
| 477 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 478 kClientFile)); |
| 479 } |
| 480 |
| 481 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedUnprotectedOrigins) { |
| 482 // Protect kOrigin1. |
| 483 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy = |
| 484 new quota::MockSpecialStoragePolicy; |
| 485 mock_policy->AddProtected(kOrigin1.GetOrigin()); |
| 486 |
| 487 PopulateTestQuotaManagedData(GetMockManager()); |
| 488 |
| 489 TestClosureCallback clear_cb; |
| 490 StoragePartitionImpl sp( |
| 491 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 492 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting( |
| 493 GetMockManager()); |
| 494 static_cast<StoragePartitionImpl*>( |
| 495 &sp)->OverrideSpecialStoragePolicyForTesting(mock_policy); |
| 496 base::MessageLoop::current()->PostTask( |
| 497 FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher, |
| 498 &sp, GURL(), |
| 499 base::Bind(&DoesOriginMatchForUnprotectedWeb), |
| 500 base::Time(), clear_cb.callback())); |
| 501 clear_cb.WaitForResult(); |
| 502 |
| 503 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 504 kClientFile)); |
| 505 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 506 kClientFile)); |
| 507 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 508 kClientFile)); |
| 509 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 510 kClientFile)); |
| 511 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 512 kClientFile)); |
| 513 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 514 kClientFile)); |
| 515 } |
| 516 |
| 517 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedProtectedSpecificOrigin) { |
| 518 // Protect kOrigin1. |
| 519 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy = |
| 520 new quota::MockSpecialStoragePolicy; |
| 521 mock_policy->AddProtected(kOrigin1.GetOrigin()); |
| 522 |
| 523 PopulateTestQuotaManagedData(GetMockManager()); |
| 524 |
| 525 TestClosureCallback clear_cb; |
| 526 StoragePartitionImpl sp( |
| 527 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 528 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting( |
| 529 GetMockManager()); |
| 530 static_cast<StoragePartitionImpl*>( |
| 531 &sp)->OverrideSpecialStoragePolicyForTesting(mock_policy); |
| 532 |
| 533 // Try to remove kOrigin1. Expect failure. |
| 534 base::MessageLoop::current()->PostTask( |
| 535 FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher, |
| 536 &sp, kOrigin1, |
| 537 base::Bind(&DoesOriginMatchForUnprotectedWeb), |
| 538 base::Time(), clear_cb.callback())); |
| 539 clear_cb.WaitForResult(); |
| 540 |
| 541 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 542 kClientFile)); |
| 543 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 544 kClientFile)); |
| 545 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 546 kClientFile)); |
| 547 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 548 kClientFile)); |
| 549 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 550 kClientFile)); |
| 551 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 552 kClientFile)); |
| 553 } |
| 554 |
| 555 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedProtectedOrigins) { |
| 556 // Protect kOrigin1. |
| 557 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy = |
| 558 new quota::MockSpecialStoragePolicy; |
| 559 mock_policy->AddProtected(kOrigin1.GetOrigin()); |
| 560 |
| 561 PopulateTestQuotaManagedData(GetMockManager()); |
| 562 |
| 563 // Try to remove kOrigin1. Expect success. |
| 564 TestClosureCallback clear_cb; |
| 565 StoragePartitionImpl sp( |
| 566 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 567 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting( |
| 568 GetMockManager()); |
| 569 static_cast<StoragePartitionImpl*>( |
| 570 &sp)->OverrideSpecialStoragePolicyForTesting(mock_policy); |
| 571 base::MessageLoop::current()->PostTask( |
| 572 FROM_HERE, |
| 573 base::Bind(&ClearQuotaDataWithOriginMatcher, |
| 574 &sp, GURL(), |
| 575 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), |
| 576 base::Time(), clear_cb.callback())); |
| 577 clear_cb.WaitForResult(); |
| 578 |
| 579 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 580 kClientFile)); |
| 581 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 582 kClientFile)); |
| 583 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 584 kClientFile)); |
| 585 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 586 kClientFile)); |
| 587 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 588 kClientFile)); |
| 589 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 590 kClientFile)); |
| 591 } |
| 592 |
| 593 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedIgnoreDevTools) { |
| 594 PopulateTestQuotaManagedNonBrowsingData(GetMockManager()); |
| 595 |
| 596 TestClosureCallback clear_cb; |
| 597 StoragePartitionImpl sp( |
| 598 base::FilePath(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 599 static_cast<StoragePartitionImpl*>(&sp)->OverrideQuotaManagerForTesting( |
| 600 GetMockManager()); |
| 601 base::MessageLoop::current()->PostTask( |
| 602 FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher, |
| 603 &sp, GURL(), |
| 604 base::Bind(&DoesOriginMatchUnprotected), |
| 605 base::Time(), clear_cb.callback())); |
| 606 clear_cb.WaitForResult(); |
| 607 |
| 608 // Check that devtools data isn't removed. |
| 609 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kTemporary, |
| 610 kClientFile)); |
| 611 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kPersistent, |
| 612 kClientFile)); |
| 613 } |
| 614 |
120 } // namespace content | 615 } // namespace content |
OLD | NEW |