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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "content/browser/dom_storage/dom_storage_area.h" | 15 #include "content/browser/dom_storage/dom_storage_area.h" |
16 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 16 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
17 #include "content/browser/dom_storage/dom_storage_namespace.h" | 17 #include "content/browser/dom_storage/dom_storage_namespace.h" |
18 #include "content/browser/dom_storage/dom_storage_task_runner.h" | 18 #include "content/browser/dom_storage/dom_storage_task_runner.h" |
19 #include "content/public/browser/local_storage_usage_info.h" | 19 #include "content/public/browser/local_storage_usage_info.h" |
20 #include "content/public/browser/session_storage_usage_info.h" | 20 #include "content/public/browser/session_storage_usage_info.h" |
21 #include "content/public/test/mock_special_storage_policy.h" | 21 #include "content/public/test/mock_special_storage_policy.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "url/gurl.h" |
| 24 #include "url/origin.h" |
23 | 25 |
24 using base::ASCIIToUTF16; | 26 using base::ASCIIToUTF16; |
25 | 27 |
26 namespace content { | 28 namespace content { |
27 | 29 |
28 class DOMStorageContextImplTest : public testing::Test { | 30 class DOMStorageContextImplTest : public testing::Test { |
29 public: | 31 public: |
30 DOMStorageContextImplTest() | 32 DOMStorageContextImplTest() |
31 : kOrigin(GURL("http://dom_storage/")), | 33 : kOrigin(GURL("http://dom_storage/")), |
| 34 kSuborigin(GURL("http-so://foobar.dom_storage/")), |
32 kKey(ASCIIToUTF16("key")), | 35 kKey(ASCIIToUTF16("key")), |
33 kValue(ASCIIToUTF16("value")), | 36 kValue(ASCIIToUTF16("value")), |
34 kDontIncludeFileInfo(false), | 37 kDontIncludeFileInfo(false), |
35 kDoIncludeFileInfo(true) { | 38 kDoIncludeFileInfo(true) { |
36 } | 39 } |
37 | 40 |
38 const GURL kOrigin; | 41 const GURL kOrigin; |
| 42 const GURL kSuborigin; |
39 const base::string16 kKey; | 43 const base::string16 kKey; |
40 const base::string16 kValue; | 44 const base::string16 kValue; |
41 const bool kDontIncludeFileInfo; | 45 const bool kDontIncludeFileInfo; |
42 const bool kDoIncludeFileInfo; | 46 const bool kDoIncludeFileInfo; |
43 | 47 |
44 void SetUp() override { | 48 void SetUp() override { |
45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 49 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
46 storage_policy_ = new MockSpecialStoragePolicy; | 50 storage_policy_ = new MockSpecialStoragePolicy; |
47 task_runner_ = | 51 task_runner_ = |
48 new MockDOMStorageTaskRunner(base::ThreadTaskRunnerHandle::Get().get()); | 52 new MockDOMStorageTaskRunner(base::ThreadTaskRunnerHandle::Get().get()); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 // Call commit directly instead of posting task. | 294 // Call commit directly instead of posting task. |
291 area2->CommitChanges(area2->commit_batch_.get()); | 295 area2->CommitChanges(area2->commit_batch_.get()); |
292 area2->commit_batch_ = nullptr; | 296 area2->commit_batch_ = nullptr; |
293 | 297 |
294 // PURGE_AGGRESSIVE clears the cache in the open area. | 298 // PURGE_AGGRESSIVE clears the cache in the open area. |
295 EXPECT_NE(0u, dom_namespace->GetUsageStatistics().total_cache_size); | 299 EXPECT_NE(0u, dom_namespace->GetUsageStatistics().total_cache_size); |
296 context_->PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE); | 300 context_->PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE); |
297 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_cache_size); | 301 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_cache_size); |
298 } | 302 } |
299 | 303 |
| 304 // Verifies that deleting the local storage for an origin will delete any |
| 305 // suborigins also present, and similarly, deleting a suborigin will delete the |
| 306 // physical origin as well. |
| 307 TEST_F(DOMStorageContextImplTest, DeleteSuboriginLocalStorage) { |
| 308 context_->Shutdown(); |
| 309 context_ = |
| 310 new DOMStorageContextImpl(temp_dir_.GetPath(), temp_dir_.GetPath(), |
| 311 storage_policy_.get(), task_runner_.get()); |
| 312 |
| 313 DOMStorageNamespace* dom_namespace = |
| 314 context_->GetStorageNamespace(kLocalStorageNamespaceId); |
| 315 DOMStorageArea* origin_area = dom_namespace->OpenStorageArea(kOrigin); |
| 316 DOMStorageArea* suborigin_area = dom_namespace->OpenStorageArea(kSuborigin); |
| 317 |
| 318 const base::string16 kOriginKey(ASCIIToUTF16("foo")); |
| 319 const base::string16 kOriginValue(ASCIIToUTF16("bar")); |
| 320 const base::string16 kSuboriginKey(ASCIIToUTF16("foz")); |
| 321 const base::string16 kSuboriginValue(ASCIIToUTF16("baz")); |
| 322 base::NullableString16 old_nullable_value; |
| 323 |
| 324 // Setup data for the first deletion (of the origin rather than the suborigin) |
| 325 origin_area->SetItem(kOriginKey, kOriginValue, &old_nullable_value); |
| 326 suborigin_area->SetItem(kSuboriginKey, kSuboriginValue, &old_nullable_value); |
| 327 |
| 328 base::NullableString16 read_value; |
| 329 read_value = origin_area->GetItem(kOriginKey); |
| 330 EXPECT_EQ(kOriginValue, read_value.string()); |
| 331 read_value = suborigin_area->GetItem(kSuboriginKey); |
| 332 EXPECT_EQ(kSuboriginValue, read_value.string()); |
| 333 |
| 334 // Deleting the data for the origin should delete the data in the suborigin as |
| 335 // well. |
| 336 context_->DeleteLocalStorage(kOrigin); |
| 337 |
| 338 read_value = origin_area->GetItem(kOriginKey); |
| 339 EXPECT_TRUE(read_value.is_null()); |
| 340 read_value = suborigin_area->GetItem(kSuboriginKey); |
| 341 EXPECT_TRUE(read_value.is_null()); |
| 342 |
| 343 // Setup data again for the second deletion (of the suborigin rather than the |
| 344 // origin) |
| 345 origin_area->SetItem(kOriginKey, kOriginValue, &old_nullable_value); |
| 346 suborigin_area->SetItem(kSuboriginKey, kSuboriginValue, &old_nullable_value); |
| 347 |
| 348 read_value = origin_area->GetItem(kOriginKey); |
| 349 EXPECT_EQ(kOriginValue, read_value.string()); |
| 350 read_value = suborigin_area->GetItem(kSuboriginKey); |
| 351 EXPECT_EQ(kSuboriginValue, read_value.string()); |
| 352 |
| 353 // Delete the suborigin this time which should also delete the origin. |
| 354 context_->DeleteLocalStorage(kSuborigin); |
| 355 |
| 356 read_value = origin_area->GetItem(kOriginKey); |
| 357 EXPECT_TRUE(read_value.is_null()); |
| 358 read_value = suborigin_area->GetItem(kSuboriginKey); |
| 359 EXPECT_TRUE(read_value.is_null()); |
| 360 } |
| 361 |
300 } // namespace content | 362 } // namespace content |
OLD | NEW |