| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 const string16 kValue; | 35 const string16 kValue; |
| 36 const bool kDontIncludeFileInfo; | 36 const bool kDontIncludeFileInfo; |
| 37 const bool kDoIncludeFileInfo; | 37 const bool kDoIncludeFileInfo; |
| 38 | 38 |
| 39 virtual void SetUp() { | 39 virtual void SetUp() { |
| 40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 41 storage_policy_ = new quota::MockSpecialStoragePolicy; | 41 storage_policy_ = new quota::MockSpecialStoragePolicy; |
| 42 task_runner_ = new MockDomStorageTaskRunner( | 42 task_runner_ = new MockDomStorageTaskRunner( |
| 43 base::MessageLoopProxy::current()); | 43 base::MessageLoopProxy::current()); |
| 44 context_ = new DomStorageContext(temp_dir_.path(), | 44 context_ = new DomStorageContext(temp_dir_.path(), |
| 45 FilePath(), | 45 base::FilePath(), |
| 46 storage_policy_, | 46 storage_policy_, |
| 47 task_runner_); | 47 task_runner_); |
| 48 } | 48 } |
| 49 | 49 |
| 50 virtual void TearDown() { | 50 virtual void TearDown() { |
| 51 MessageLoop::current()->RunUntilIdle(); | 51 MessageLoop::current()->RunUntilIdle(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void VerifySingleOriginRemains(const GURL& origin) { | 54 void VerifySingleOriginRemains(const GURL& origin) { |
| 55 // Use a new instance to examine the contexts of temp_dir_. | 55 // Use a new instance to examine the contexts of temp_dir_. |
| 56 scoped_refptr<DomStorageContext> context = | 56 scoped_refptr<DomStorageContext> context = |
| 57 new DomStorageContext(temp_dir_.path(), FilePath(), NULL, NULL); | 57 new DomStorageContext(temp_dir_.path(), base::FilePath(), NULL, NULL); |
| 58 std::vector<LocalStorageUsageInfo> infos; | 58 std::vector<LocalStorageUsageInfo> infos; |
| 59 context->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); | 59 context->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); |
| 60 ASSERT_EQ(1u, infos.size()); | 60 ASSERT_EQ(1u, infos.size()); |
| 61 EXPECT_EQ(origin, infos[0].origin); | 61 EXPECT_EQ(origin, infos[0].origin); |
| 62 } | 62 } |
| 63 | 63 |
| 64 protected: | 64 protected: |
| 65 MessageLoop message_loop_; | 65 MessageLoop message_loop_; |
| 66 base::ScopedTempDir temp_dir_; | 66 base::ScopedTempDir temp_dir_; |
| 67 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy_; | 67 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy_; |
| 68 scoped_refptr<MockDomStorageTaskRunner> task_runner_; | 68 scoped_refptr<MockDomStorageTaskRunner> task_runner_; |
| 69 scoped_refptr<DomStorageContext> context_; | 69 scoped_refptr<DomStorageContext> context_; |
| 70 DISALLOW_COPY_AND_ASSIGN(DomStorageContextTest); | 70 DISALLOW_COPY_AND_ASSIGN(DomStorageContextTest); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 TEST_F(DomStorageContextTest, Basics) { | 73 TEST_F(DomStorageContextTest, Basics) { |
| 74 // This test doesn't do much, checks that the constructor | 74 // This test doesn't do much, checks that the constructor |
| 75 // initializes members properly and that invoking methods | 75 // initializes members properly and that invoking methods |
| 76 // on a newly created object w/o any data on disk do no harm. | 76 // on a newly created object w/o any data on disk do no harm. |
| 77 EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory()); | 77 EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory()); |
| 78 EXPECT_EQ(FilePath(), context_->sessionstorage_directory()); | 78 EXPECT_EQ(base::FilePath(), context_->sessionstorage_directory()); |
| 79 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get()); | 79 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get()); |
| 80 context_->PurgeMemory(); | 80 context_->PurgeMemory(); |
| 81 context_->DeleteLocalStorage(GURL("http://chromium.org/")); | 81 context_->DeleteLocalStorage(GURL("http://chromium.org/")); |
| 82 const int kFirstSessionStorageNamespaceId = 1; | 82 const int kFirstSessionStorageNamespaceId = 1; |
| 83 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)); | 83 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)); |
| 84 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId)); | 84 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId)); |
| 85 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId()); | 85 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId()); |
| 86 std::vector<LocalStorageUsageInfo> infos; | 86 std::vector<LocalStorageUsageInfo> infos; |
| 87 context_->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); | 87 context_->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); |
| 88 EXPECT_TRUE(infos.empty()); | 88 EXPECT_TRUE(infos.empty()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 101 // to ensure data is written to disk. | 101 // to ensure data is written to disk. |
| 102 NullableString16 old_value; | 102 NullableString16 old_value; |
| 103 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)-> | 103 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)-> |
| 104 OpenStorageArea(kOrigin)->SetItem(kKey, kValue, &old_value)); | 104 OpenStorageArea(kOrigin)->SetItem(kKey, kValue, &old_value)); |
| 105 context_->Shutdown(); | 105 context_->Shutdown(); |
| 106 context_ = NULL; | 106 context_ = NULL; |
| 107 MessageLoop::current()->RunUntilIdle(); | 107 MessageLoop::current()->RunUntilIdle(); |
| 108 | 108 |
| 109 // Create a new context that points to the same directory, see that | 109 // Create a new context that points to the same directory, see that |
| 110 // it knows about the origin that we stored data for. | 110 // it knows about the origin that we stored data for. |
| 111 context_ = new DomStorageContext(temp_dir_.path(), FilePath(), NULL, NULL); | 111 context_ = new DomStorageContext(temp_dir_.path(), base::FilePath(), NULL, NUL
L); |
| 112 context_->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); | 112 context_->GetLocalStorageUsage(&infos, kDontIncludeFileInfo); |
| 113 EXPECT_EQ(1u, infos.size()); | 113 EXPECT_EQ(1u, infos.size()); |
| 114 EXPECT_EQ(kOrigin, infos[0].origin); | 114 EXPECT_EQ(kOrigin, infos[0].origin); |
| 115 EXPECT_EQ(0u, infos[0].data_size); | 115 EXPECT_EQ(0u, infos[0].data_size); |
| 116 EXPECT_EQ(base::Time(), infos[0].last_modified); | 116 EXPECT_EQ(base::Time(), infos[0].last_modified); |
| 117 infos.clear(); | 117 infos.clear(); |
| 118 context_->GetLocalStorageUsage(&infos, kDoIncludeFileInfo); | 118 context_->GetLocalStorageUsage(&infos, kDoIncludeFileInfo); |
| 119 EXPECT_EQ(1u, infos.size()); | 119 EXPECT_EQ(1u, infos.size()); |
| 120 EXPECT_EQ(kOrigin, infos[0].origin); | 120 EXPECT_EQ(kOrigin, infos[0].origin); |
| 121 EXPECT_NE(0u, infos[0].data_size); | 121 EXPECT_NE(0u, infos[0].data_size); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 area = dom_namespace->OpenStorageArea(kOrigin); | 253 area = dom_namespace->OpenStorageArea(kOrigin); |
| 254 read_value = area->GetItem(kKey); | 254 read_value = area->GetItem(kKey); |
| 255 EXPECT_TRUE(read_value.is_null()); | 255 EXPECT_TRUE(read_value.is_null()); |
| 256 dom_namespace->CloseStorageArea(area); | 256 dom_namespace->CloseStorageArea(area); |
| 257 context_->Shutdown(); | 257 context_->Shutdown(); |
| 258 context_ = NULL; | 258 context_ = NULL; |
| 259 MessageLoop::current()->RunUntilIdle(); | 259 MessageLoop::current()->RunUntilIdle(); |
| 260 } | 260 } |
| 261 | 261 |
| 262 } // namespace dom_storage | 262 } // namespace dom_storage |
| OLD | NEW |