| Index: content/browser/dom_storage/dom_storage_context_impl_unittest.cc
|
| diff --git a/content/browser/dom_storage/dom_storage_context_impl_unittest.cc b/content/browser/dom_storage/dom_storage_context_impl_unittest.cc
|
| index 1b8aa99d5b2c165b068bdd07132a3b4cf753c08a..0ad42f7538f50d2a296cf3f739b100b28934e7c7 100644
|
| --- a/content/browser/dom_storage/dom_storage_context_impl_unittest.cc
|
| +++ b/content/browser/dom_storage/dom_storage_context_impl_unittest.cc
|
| @@ -20,6 +20,8 @@
|
| #include "content/public/browser/session_storage_usage_info.h"
|
| #include "content/public/test/mock_special_storage_policy.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "url/gurl.h"
|
| +#include "url/origin.h"
|
|
|
| using base::ASCIIToUTF16;
|
|
|
| @@ -28,14 +30,15 @@ namespace content {
|
| class DOMStorageContextImplTest : public testing::Test {
|
| public:
|
| DOMStorageContextImplTest()
|
| - : kOrigin(GURL("http://dom_storage/")),
|
| - kKey(ASCIIToUTF16("key")),
|
| - kValue(ASCIIToUTF16("value")),
|
| - kDontIncludeFileInfo(false),
|
| - kDoIncludeFileInfo(true) {
|
| - }
|
| + : kOrigin(GURL("http://dom_storage/")),
|
| + kSuborigin(GURL("http-so://foobar.dom_storage/")),
|
| + kKey(ASCIIToUTF16("key")),
|
| + kValue(ASCIIToUTF16("value")),
|
| + kDontIncludeFileInfo(false),
|
| + kDoIncludeFileInfo(true) {}
|
|
|
| const GURL kOrigin;
|
| + const GURL kSuborigin;
|
| const base::string16 kKey;
|
| const base::string16 kValue;
|
| const bool kDontIncludeFileInfo;
|
| @@ -297,4 +300,95 @@ TEST_F(DOMStorageContextImplTest, PurgeMemory) {
|
| EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_cache_size);
|
| }
|
|
|
| +// Verifies that deleting the local storage for an origin will delete any
|
| +// suborigins also present, and similarly, deleting a suborigin will delete the
|
| +// physical origin as well.
|
| +TEST_F(DOMStorageContextImplTest, DeleteSuboriginLocalStorage) {
|
| + context_->Shutdown();
|
| + context_ =
|
| + new DOMStorageContextImpl(temp_dir_.GetPath(), temp_dir_.GetPath(),
|
| + storage_policy_.get(), task_runner_.get());
|
| +
|
| + DOMStorageNamespace* dom_namespace =
|
| + context_->GetStorageNamespace(kLocalStorageNamespaceId);
|
| + DOMStorageArea* origin_area = dom_namespace->OpenStorageArea(kOrigin);
|
| + DOMStorageArea* suborigin_area = dom_namespace->OpenStorageArea(kSuborigin);
|
| +
|
| + const base::string16 kOriginKey(ASCIIToUTF16("foo"));
|
| + const base::string16 kOriginValue(ASCIIToUTF16("bar"));
|
| + const base::string16 kSuboriginKey(ASCIIToUTF16("foz"));
|
| + const base::string16 kSuboriginValue(ASCIIToUTF16("baz"));
|
| + base::NullableString16 old_nullable_value;
|
| +
|
| + // Setup data for the first deletion (of the origin rather than the suborigin)
|
| + origin_area->SetItem(kOriginKey, kOriginValue, &old_nullable_value);
|
| + suborigin_area->SetItem(kSuboriginKey, kSuboriginValue, &old_nullable_value);
|
| +
|
| + base::NullableString16 read_value;
|
| + read_value = origin_area->GetItem(kOriginKey);
|
| + EXPECT_EQ(kOriginValue, read_value.string());
|
| + read_value = suborigin_area->GetItem(kSuboriginKey);
|
| + EXPECT_EQ(kSuboriginValue, read_value.string());
|
| +
|
| + // Deleting the data for the physical origin should delete the data in the
|
| + // suborigin as well.
|
| + context_->DeleteLocalStorageForPhysicalOrigin(kOrigin);
|
| +
|
| + read_value = origin_area->GetItem(kOriginKey);
|
| + EXPECT_TRUE(read_value.is_null());
|
| + read_value = suborigin_area->GetItem(kSuboriginKey);
|
| + EXPECT_TRUE(read_value.is_null());
|
| +
|
| + // Setup data again for the second deletion (of the suborigin rather than the
|
| + // origin)
|
| + origin_area->SetItem(kOriginKey, kOriginValue, &old_nullable_value);
|
| + suborigin_area->SetItem(kSuboriginKey, kSuboriginValue, &old_nullable_value);
|
| +
|
| + read_value = origin_area->GetItem(kOriginKey);
|
| + EXPECT_EQ(kOriginValue, read_value.string());
|
| + read_value = suborigin_area->GetItem(kSuboriginKey);
|
| + EXPECT_EQ(kSuboriginValue, read_value.string());
|
| +
|
| + // Delete the suborigin by physical origin this time. This should delete both
|
| + // the suborigin and physical origin.
|
| + context_->DeleteLocalStorageForPhysicalOrigin(kSuborigin);
|
| +
|
| + read_value = origin_area->GetItem(kOriginKey);
|
| + EXPECT_TRUE(read_value.is_null());
|
| + read_value = suborigin_area->GetItem(kSuboriginKey);
|
| + EXPECT_TRUE(read_value.is_null());
|
| +
|
| + // Setup data again for the third deletion, to test deleting the storage one
|
| + // at a time.
|
| + origin_area->SetItem(kOriginKey, kOriginValue, &old_nullable_value);
|
| + suborigin_area->SetItem(kSuboriginKey, kSuboriginValue, &old_nullable_value);
|
| +
|
| + read_value = origin_area->GetItem(kOriginKey);
|
| + EXPECT_EQ(kOriginValue, read_value.string());
|
| + read_value = suborigin_area->GetItem(kSuboriginKey);
|
| + EXPECT_EQ(kSuboriginValue, read_value.string());
|
| +
|
| + // Delete the origin only. This should leave the suborigin.
|
| + context_->DeleteLocalStorage(kOrigin);
|
| +
|
| + read_value = origin_area->GetItem(kOriginKey);
|
| + EXPECT_TRUE(read_value.is_null());
|
| + read_value = suborigin_area->GetItem(kSuboriginKey);
|
| + EXPECT_EQ(kSuboriginValue, read_value.string());
|
| +
|
| + // Put the origin value back so suborigin deletion can be tested.
|
| + origin_area->SetItem(kOriginKey, kOriginValue, &old_nullable_value);
|
| +
|
| + read_value = origin_area->GetItem(kOriginKey);
|
| + EXPECT_EQ(kOriginValue, read_value.string());
|
| +
|
| + // Delete the suborigin only. This should leave the origin.
|
| + context_->DeleteLocalStorage(kSuborigin);
|
| +
|
| + read_value = origin_area->GetItem(kOriginKey);
|
| + EXPECT_EQ(kOriginValue, read_value.string());
|
| + read_value = suborigin_area->GetItem(kSuboriginKey);
|
| + EXPECT_TRUE(read_value.is_null());
|
| +}
|
| +
|
| } // namespace content
|
|
|