| 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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // Use a new instance to examine the contexts of temp_dir_. | 56 // Use a new instance to examine the contexts of temp_dir_. |
| 57 scoped_refptr<DOMStorageContextImpl> context = | 57 scoped_refptr<DOMStorageContextImpl> context = |
| 58 new DOMStorageContextImpl(temp_dir_.path(), base::FilePath(), | 58 new DOMStorageContextImpl(temp_dir_.path(), base::FilePath(), |
| 59 NULL, NULL); | 59 NULL, NULL); |
| 60 std::vector<LocalStorageUsageInfo> infos; | 60 std::vector<LocalStorageUsageInfo> infos; |
| 61 context->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); | 61 context->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); |
| 62 ASSERT_EQ(1u, infos.size()); | 62 ASSERT_EQ(1u, infos.size()); |
| 63 EXPECT_EQ(origin, infos[0].origin); | 63 EXPECT_EQ(origin, infos[0].origin); |
| 64 } | 64 } |
| 65 | 65 |
| 66 int session_id_offset() { return context_->session_id_offset_; } |
| 67 |
| 66 protected: | 68 protected: |
| 67 base::MessageLoop message_loop_; | 69 base::MessageLoop message_loop_; |
| 68 base::ScopedTempDir temp_dir_; | 70 base::ScopedTempDir temp_dir_; |
| 69 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; | 71 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; |
| 70 scoped_refptr<MockDOMStorageTaskRunner> task_runner_; | 72 scoped_refptr<MockDOMStorageTaskRunner> task_runner_; |
| 71 scoped_refptr<DOMStorageContextImpl> context_; | 73 scoped_refptr<DOMStorageContextImpl> context_; |
| 72 DISALLOW_COPY_AND_ASSIGN(DOMStorageContextImplTest); | 74 DISALLOW_COPY_AND_ASSIGN(DOMStorageContextImplTest); |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 TEST_F(DOMStorageContextImplTest, Basics) { | 77 TEST_F(DOMStorageContextImplTest, Basics) { |
| 76 // This test doesn't do much, checks that the constructor | 78 // This test doesn't do much, checks that the constructor |
| 77 // initializes members properly and that invoking methods | 79 // initializes members properly and that invoking methods |
| 78 // on a newly created object w/o any data on disk do no harm. | 80 // on a newly created object w/o any data on disk do no harm. |
| 79 EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory()); | 81 EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory()); |
| 80 EXPECT_EQ(base::FilePath(), context_->sessionstorage_directory()); | 82 EXPECT_EQ(base::FilePath(), context_->sessionstorage_directory()); |
| 81 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get()); | 83 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get()); |
| 82 context_->DeleteLocalStorage(GURL("http://chromium.org/")); | 84 context_->DeleteLocalStorage(GURL("http://chromium.org/")); |
| 83 const int kFirstSessionStorageNamespaceId = 1; | 85 const int kFirstSessionStorageNamespaceId = 1 + session_id_offset(); |
| 84 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)); | 86 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)); |
| 85 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId)); | 87 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId)); |
| 86 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId()); | 88 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId()); |
| 87 std::vector<LocalStorageUsageInfo> infos; | 89 std::vector<LocalStorageUsageInfo> infos; |
| 88 context_->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); | 90 context_->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); |
| 89 EXPECT_TRUE(infos.empty()); | 91 EXPECT_TRUE(infos.empty()); |
| 90 context_->Shutdown(); | 92 context_->Shutdown(); |
| 91 } | 93 } |
| 92 | 94 |
| 93 TEST_F(DOMStorageContextImplTest, UsageInfo) { | 95 TEST_F(DOMStorageContextImplTest, UsageInfo) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 OpenStorageArea(kSessionOnlyOrigin)->SetItem(kKey, kValue, &old_value)); | 157 OpenStorageArea(kSessionOnlyOrigin)->SetItem(kKey, kValue, &old_value)); |
| 156 context_->SetForceKeepSessionState(); // Should override clear behavior. | 158 context_->SetForceKeepSessionState(); // Should override clear behavior. |
| 157 context_->Shutdown(); | 159 context_->Shutdown(); |
| 158 context_ = NULL; | 160 context_ = NULL; |
| 159 base::MessageLoop::current()->RunUntilIdle(); | 161 base::MessageLoop::current()->RunUntilIdle(); |
| 160 | 162 |
| 161 VerifySingleOriginRemains(kSessionOnlyOrigin); | 163 VerifySingleOriginRemains(kSessionOnlyOrigin); |
| 162 } | 164 } |
| 163 | 165 |
| 164 TEST_F(DOMStorageContextImplTest, PersistentIds) { | 166 TEST_F(DOMStorageContextImplTest, PersistentIds) { |
| 165 const int kFirstSessionStorageNamespaceId = 1; | 167 const int kFirstSessionStorageNamespaceId = 1 + session_id_offset(); |
| 166 const std::string kPersistentId = "persistent"; | 168 const std::string kPersistentId = "persistent"; |
| 167 context_->CreateSessionNamespace(kFirstSessionStorageNamespaceId, | 169 context_->CreateSessionNamespace(kFirstSessionStorageNamespaceId, |
| 168 kPersistentId); | 170 kPersistentId); |
| 169 DOMStorageNamespace* dom_namespace = | 171 DOMStorageNamespace* dom_namespace = |
| 170 context_->GetStorageNamespace(kFirstSessionStorageNamespaceId); | 172 context_->GetStorageNamespace(kFirstSessionStorageNamespaceId); |
| 171 ASSERT_TRUE(dom_namespace); | 173 ASSERT_TRUE(dom_namespace); |
| 172 EXPECT_EQ(kPersistentId, dom_namespace->persistent_namespace_id()); | 174 EXPECT_EQ(kPersistentId, dom_namespace->persistent_namespace_id()); |
| 173 // Verify that the areas inherit the persistent ID. | 175 // Verify that the areas inherit the persistent ID. |
| 174 DOMStorageArea* area = dom_namespace->OpenStorageArea(kOrigin); | 176 DOMStorageArea* area = dom_namespace->OpenStorageArea(kOrigin); |
| 175 EXPECT_EQ(kPersistentId, area->persistent_namespace_id_); | 177 EXPECT_EQ(kPersistentId, area->persistent_namespace_id_); |
| 176 | 178 |
| 177 // Verify that the persistent IDs are handled correctly when cloning. | 179 // Verify that the persistent IDs are handled correctly when cloning. |
| 178 const int kClonedSessionStorageNamespaceId = 2; | 180 const int kClonedSessionStorageNamespaceId = 2 + session_id_offset(); |
| 179 const std::string kClonedPersistentId = "cloned"; | 181 const std::string kClonedPersistentId = "cloned"; |
| 180 context_->CloneSessionNamespace(kFirstSessionStorageNamespaceId, | 182 context_->CloneSessionNamespace(kFirstSessionStorageNamespaceId, |
| 181 kClonedSessionStorageNamespaceId, | 183 kClonedSessionStorageNamespaceId, |
| 182 kClonedPersistentId); | 184 kClonedPersistentId); |
| 183 DOMStorageNamespace* cloned_dom_namespace = | 185 DOMStorageNamespace* cloned_dom_namespace = |
| 184 context_->GetStorageNamespace(kClonedSessionStorageNamespaceId); | 186 context_->GetStorageNamespace(kClonedSessionStorageNamespaceId); |
| 185 ASSERT_TRUE(dom_namespace); | 187 ASSERT_TRUE(dom_namespace); |
| 186 EXPECT_EQ(kClonedPersistentId, | 188 EXPECT_EQ(kClonedPersistentId, |
| 187 cloned_dom_namespace->persistent_namespace_id()); | 189 cloned_dom_namespace->persistent_namespace_id()); |
| 188 // Verify that the areas inherit the persistent ID. | 190 // Verify that the areas inherit the persistent ID. |
| 189 DOMStorageArea* cloned_area = cloned_dom_namespace->OpenStorageArea(kOrigin); | 191 DOMStorageArea* cloned_area = cloned_dom_namespace->OpenStorageArea(kOrigin); |
| 190 EXPECT_EQ(kClonedPersistentId, cloned_area->persistent_namespace_id_); | 192 EXPECT_EQ(kClonedPersistentId, cloned_area->persistent_namespace_id_); |
| 191 } | 193 } |
| 192 | 194 |
| 193 TEST_F(DOMStorageContextImplTest, DeleteSessionStorage) { | 195 TEST_F(DOMStorageContextImplTest, DeleteSessionStorage) { |
| 194 // Create a DOMStorageContextImpl which will save sessionStorage on disk. | 196 // Create a DOMStorageContextImpl which will save sessionStorage on disk. |
| 195 context_ = new DOMStorageContextImpl(temp_dir_.path(), | 197 context_ = new DOMStorageContextImpl(temp_dir_.path(), |
| 196 temp_dir_.path(), | 198 temp_dir_.path(), |
| 197 storage_policy_.get(), | 199 storage_policy_.get(), |
| 198 task_runner_.get()); | 200 task_runner_.get()); |
| 199 context_->SetSaveSessionStorageOnDisk(); | 201 context_->SetSaveSessionStorageOnDisk(); |
| 200 ASSERT_EQ(temp_dir_.path(), context_->sessionstorage_directory()); | 202 ASSERT_EQ(temp_dir_.path(), context_->sessionstorage_directory()); |
| 201 | 203 |
| 202 // Write data. | 204 // Write data. |
| 203 const int kSessionStorageNamespaceId = 1; | 205 const int kSessionStorageNamespaceId = 1 + session_id_offset(); |
| 204 const std::string kPersistentId = "persistent"; | 206 const std::string kPersistentId = "persistent"; |
| 205 context_->CreateSessionNamespace(kSessionStorageNamespaceId, | 207 context_->CreateSessionNamespace(kSessionStorageNamespaceId, |
| 206 kPersistentId); | 208 kPersistentId); |
| 207 DOMStorageNamespace* dom_namespace = | 209 DOMStorageNamespace* dom_namespace = |
| 208 context_->GetStorageNamespace(kSessionStorageNamespaceId); | 210 context_->GetStorageNamespace(kSessionStorageNamespaceId); |
| 209 DOMStorageArea* area = dom_namespace->OpenStorageArea(kOrigin); | 211 DOMStorageArea* area = dom_namespace->OpenStorageArea(kOrigin); |
| 210 const base::string16 kKey(ASCIIToUTF16("foo")); | 212 const base::string16 kKey(ASCIIToUTF16("foo")); |
| 211 const base::string16 kValue(ASCIIToUTF16("bar")); | 213 const base::string16 kValue(ASCIIToUTF16("bar")); |
| 212 base::NullableString16 old_nullable_value; | 214 base::NullableString16 old_nullable_value; |
| 213 area->SetItem(kKey, kValue, &old_nullable_value); | 215 area->SetItem(kKey, kValue, &old_nullable_value); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 area = dom_namespace->OpenStorageArea(kOrigin); | 255 area = dom_namespace->OpenStorageArea(kOrigin); |
| 254 read_value = area->GetItem(kKey); | 256 read_value = area->GetItem(kKey); |
| 255 EXPECT_TRUE(read_value.is_null()); | 257 EXPECT_TRUE(read_value.is_null()); |
| 256 dom_namespace->CloseStorageArea(area); | 258 dom_namespace->CloseStorageArea(area); |
| 257 context_->Shutdown(); | 259 context_->Shutdown(); |
| 258 context_ = NULL; | 260 context_ = NULL; |
| 259 base::MessageLoop::current()->RunUntilIdle(); | 261 base::MessageLoop::current()->RunUntilIdle(); |
| 260 } | 262 } |
| 261 | 263 |
| 262 } // namespace content | 264 } // namespace content |
| OLD | NEW |