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..02fba76f1470ece248af1e3184ea65b6ea4ab7bb 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; |
@@ -29,6 +31,7 @@ class DOMStorageContextImplTest : public testing::Test { |
public: |
DOMStorageContextImplTest() |
: kOrigin(GURL("http://dom_storage/")), |
+ kSuborigin(GURL("http-so://foobar.dom_storage/")), |
kKey(ASCIIToUTF16("key")), |
kValue(ASCIIToUTF16("value")), |
kDontIncludeFileInfo(false), |
@@ -36,6 +39,7 @@ class DOMStorageContextImplTest : public testing::Test { |
} |
const GURL kOrigin; |
+ const GURL kSuborigin; |
const base::string16 kKey; |
const base::string16 kValue; |
const bool kDontIncludeFileInfo; |
@@ -297,4 +301,62 @@ 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 origin should delete the data in the suborigin as |
+ // well. |
+ context_->DeleteLocalStorage(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 this time which should also delete the origin. |
+ context_->DeleteLocalStorage(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()); |
+} |
+ |
} // namespace content |