| 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/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 virtual void TearDown() { | 50 virtual void TearDown() { |
| 51 MessageLoop::current()->RunAllPending(); | 51 MessageLoop::current()->RunAllPending(); |
| 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(), FilePath(), NULL, NULL); |
| 58 std::vector<DomStorageContext::UsageInfo> infos; | 58 std::vector<DomStorageContext::UsageInfo> infos; |
| 59 context->GetUsageInfo(&infos, kDontIncludeFileInfo); | 59 context->GetUsageInfo(&infos, kDontIncludeFileInfo); |
| 60 EXPECT_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 ScopedTempDir temp_dir_; | 65 ScopedTempDir temp_dir_; |
| 66 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy_; | 66 scoped_refptr<quota::MockSpecialStoragePolicy> storage_policy_; |
| 67 scoped_refptr<MockDomStorageTaskRunner> task_runner_; | 67 scoped_refptr<MockDomStorageTaskRunner> task_runner_; |
| 68 scoped_refptr<DomStorageContext> context_; | 68 scoped_refptr<DomStorageContext> context_; |
| 69 DISALLOW_COPY_AND_ASSIGN(DomStorageContextTest); | 69 DISALLOW_COPY_AND_ASSIGN(DomStorageContextTest); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 TEST_F(DomStorageContextTest, Basics) { | 72 TEST_F(DomStorageContextTest, Basics) { |
| 73 // This test doesn't do much, checks that the constructor | 73 // This test doesn't do much, checks that the constructor |
| 74 // initializes members properly and that invoking methods | 74 // initializes members properly and that invoking methods |
| 75 // on a newly created object w/o any data on disk do no harm. | 75 // on a newly created object w/o any data on disk do no harm. |
| 76 EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory()); | 76 EXPECT_EQ(temp_dir_.path(), context_->localstorage_directory()); |
| 77 EXPECT_EQ(FilePath(), context_->sessionstorage_directory()); | 77 EXPECT_EQ(FilePath(), context_->sessionstorage_directory()); |
| 78 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get()); | 78 EXPECT_EQ(storage_policy_.get(), context_->special_storage_policy_.get()); |
| 79 context_->PurgeMemory(); | 79 context_->PurgeMemory(); |
| 80 context_->DeleteOrigin(GURL("http://chromium.org/")); | 80 context_->DeleteOrigin(GURL("http://chromium.org/")); |
| 81 context_->DeleteDataModifiedSince(base::Time::Now()); | |
| 82 const int kFirstSessionStorageNamespaceId = 1; | 81 const int kFirstSessionStorageNamespaceId = 1; |
| 83 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)); | 82 EXPECT_TRUE(context_->GetStorageNamespace(kLocalStorageNamespaceId)); |
| 84 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId)); | 83 EXPECT_FALSE(context_->GetStorageNamespace(kFirstSessionStorageNamespaceId)); |
| 85 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId()); | 84 EXPECT_EQ(kFirstSessionStorageNamespaceId, context_->AllocateSessionId()); |
| 86 std::vector<DomStorageContext::UsageInfo> infos; | 85 std::vector<DomStorageContext::UsageInfo> infos; |
| 87 context_->GetUsageInfo(&infos, kDontIncludeFileInfo); | 86 context_->GetUsageInfo(&infos, kDontIncludeFileInfo); |
| 88 EXPECT_TRUE(infos.empty()); | 87 EXPECT_TRUE(infos.empty()); |
| 89 context_->Shutdown(); | 88 context_->Shutdown(); |
| 90 } | 89 } |
| 91 | 90 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 context_->SetClearLocalState(true); | 172 context_->SetClearLocalState(true); |
| 174 context_->SaveSessionState(); // Should override clear behavior. | 173 context_->SaveSessionState(); // Should override clear behavior. |
| 175 context_->Shutdown(); | 174 context_->Shutdown(); |
| 176 context_ = NULL; | 175 context_ = NULL; |
| 177 MessageLoop::current()->RunAllPending(); | 176 MessageLoop::current()->RunAllPending(); |
| 178 | 177 |
| 179 VerifySingleOriginRemains(kSessionOnlyOrigin); | 178 VerifySingleOriginRemains(kSessionOnlyOrigin); |
| 180 } | 179 } |
| 181 | 180 |
| 182 } // namespace dom_storage | 181 } // namespace dom_storage |
| OLD | NEW |