| 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/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 44 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 45 storage_policy_ = new MockSpecialStoragePolicy; | 45 storage_policy_ = new MockSpecialStoragePolicy; |
| 46 task_runner_ = | 46 task_runner_ = |
| 47 new MockDOMStorageTaskRunner(base::ThreadTaskRunnerHandle::Get().get()); | 47 new MockDOMStorageTaskRunner(base::ThreadTaskRunnerHandle::Get().get()); |
| 48 context_ = new DOMStorageContextImpl(temp_dir_.path(), | 48 context_ = new DOMStorageContextImpl(temp_dir_.path(), |
| 49 base::FilePath(), | 49 base::FilePath(), |
| 50 storage_policy_.get(), | 50 storage_policy_.get(), |
| 51 task_runner_.get()); | 51 task_runner_.get()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void TearDown() override { base::MessageLoop::current()->RunUntilIdle(); } | 54 void TearDown() override { |
| 55 if (context_) |
| 56 context_->Shutdown(); |
| 57 base::MessageLoop::current()->RunUntilIdle(); |
| 58 } |
| 55 | 59 |
| 56 void VerifySingleOriginRemains(const GURL& origin) { | 60 void VerifySingleOriginRemains(const GURL& origin) { |
| 57 // Use a new instance to examine the contexts of temp_dir_. | 61 // Use a new instance to examine the contexts of temp_dir_. |
| 58 scoped_refptr<DOMStorageContextImpl> context = | 62 scoped_refptr<DOMStorageContextImpl> context = |
| 59 new DOMStorageContextImpl(temp_dir_.path(), base::FilePath(), | 63 new DOMStorageContextImpl(temp_dir_.path(), base::FilePath(), |
| 60 NULL, NULL); | 64 NULL, NULL); |
| 61 std::vector<LocalStorageUsageInfo> infos; | 65 std::vector<LocalStorageUsageInfo> infos; |
| 62 context->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); | 66 context->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); |
| 63 ASSERT_EQ(1u, infos.size()); | 67 ASSERT_EQ(1u, infos.size()); |
| 64 EXPECT_EQ(origin, infos[0].origin); | 68 EXPECT_EQ(origin, infos[0].origin); |
| 69 context->Shutdown(); |
| 65 } | 70 } |
| 66 | 71 |
| 67 int session_id_offset() { return context_->session_id_offset_; } | 72 int session_id_offset() { return context_->session_id_offset_; } |
| 68 | 73 |
| 69 protected: | 74 protected: |
| 70 base::MessageLoop message_loop_; | 75 base::MessageLoop message_loop_; |
| 71 base::ScopedTempDir temp_dir_; | 76 base::ScopedTempDir temp_dir_; |
| 72 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; | 77 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; |
| 73 scoped_refptr<MockDOMStorageTaskRunner> task_runner_; | 78 scoped_refptr<MockDOMStorageTaskRunner> task_runner_; |
| 74 scoped_refptr<DOMStorageContextImpl> context_; | 79 scoped_refptr<DOMStorageContextImpl> context_; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 ASSERT_TRUE(dom_namespace); | 193 ASSERT_TRUE(dom_namespace); |
| 189 EXPECT_EQ(kClonedPersistentId, | 194 EXPECT_EQ(kClonedPersistentId, |
| 190 cloned_dom_namespace->persistent_namespace_id()); | 195 cloned_dom_namespace->persistent_namespace_id()); |
| 191 // Verify that the areas inherit the persistent ID. | 196 // Verify that the areas inherit the persistent ID. |
| 192 DOMStorageArea* cloned_area = cloned_dom_namespace->OpenStorageArea(kOrigin); | 197 DOMStorageArea* cloned_area = cloned_dom_namespace->OpenStorageArea(kOrigin); |
| 193 EXPECT_EQ(kClonedPersistentId, cloned_area->persistent_namespace_id_); | 198 EXPECT_EQ(kClonedPersistentId, cloned_area->persistent_namespace_id_); |
| 194 } | 199 } |
| 195 | 200 |
| 196 TEST_F(DOMStorageContextImplTest, DeleteSessionStorage) { | 201 TEST_F(DOMStorageContextImplTest, DeleteSessionStorage) { |
| 197 // Create a DOMStorageContextImpl which will save sessionStorage on disk. | 202 // Create a DOMStorageContextImpl which will save sessionStorage on disk. |
| 203 context_->Shutdown(); |
| 198 context_ = new DOMStorageContextImpl(temp_dir_.path(), | 204 context_ = new DOMStorageContextImpl(temp_dir_.path(), |
| 199 temp_dir_.path(), | 205 temp_dir_.path(), |
| 200 storage_policy_.get(), | 206 storage_policy_.get(), |
| 201 task_runner_.get()); | 207 task_runner_.get()); |
| 202 context_->SetSaveSessionStorageOnDisk(); | 208 context_->SetSaveSessionStorageOnDisk(); |
| 203 ASSERT_EQ(temp_dir_.path(), context_->sessionstorage_directory()); | 209 ASSERT_EQ(temp_dir_.path(), context_->sessionstorage_directory()); |
| 204 | 210 |
| 205 // Write data. | 211 // Write data. |
| 206 const int kSessionStorageNamespaceId = 1 + session_id_offset(); | 212 const int kSessionStorageNamespaceId = 1 + session_id_offset(); |
| 207 const std::string kPersistentId = "persistent"; | 213 const std::string kPersistentId = "persistent"; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 area = dom_namespace->OpenStorageArea(kOrigin); | 262 area = dom_namespace->OpenStorageArea(kOrigin); |
| 257 read_value = area->GetItem(kKey); | 263 read_value = area->GetItem(kKey); |
| 258 EXPECT_TRUE(read_value.is_null()); | 264 EXPECT_TRUE(read_value.is_null()); |
| 259 dom_namespace->CloseStorageArea(area); | 265 dom_namespace->CloseStorageArea(area); |
| 260 context_->Shutdown(); | 266 context_->Shutdown(); |
| 261 context_ = NULL; | 267 context_ = NULL; |
| 262 base::MessageLoop::current()->RunUntilIdle(); | 268 base::MessageLoop::current()->RunUntilIdle(); |
| 263 } | 269 } |
| 264 | 270 |
| 265 } // namespace content | 271 } // namespace content |
| OLD | NEW |