| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" |
| 11 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
| 12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 13 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
| 14 #include "content/browser/indexed_db/indexed_db_connection.h" | 15 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 15 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 16 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 16 #include "content/browser/indexed_db/indexed_db_factory_impl.h" | 17 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
| 17 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" | 18 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" |
| 18 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" | 19 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" |
| 19 #include "content/browser/quota/mock_quota_manager_proxy.h" | 20 #include "content/browser/quota/mock_quota_manager_proxy.h" |
| 20 #include "content/public/browser/storage_partition.h" | 21 #include "content/public/browser/storage_partition.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 new IndexedDBContextImpl(temp_dir.path(), | 80 new IndexedDBContextImpl(temp_dir.path(), |
| 80 special_storage_policy_.get(), | 81 special_storage_policy_.get(), |
| 81 quota_manager_proxy_.get(), | 82 quota_manager_proxy_.get(), |
| 82 task_runner_.get()); | 83 task_runner_.get()); |
| 83 | 84 |
| 84 normal_path = idb_context->GetFilePathForTesting(kNormalOrigin); | 85 normal_path = idb_context->GetFilePathForTesting(kNormalOrigin); |
| 85 session_only_path = idb_context->GetFilePathForTesting(kSessionOnlyOrigin); | 86 session_only_path = idb_context->GetFilePathForTesting(kSessionOnlyOrigin); |
| 86 ASSERT_TRUE(base::CreateDirectory(normal_path)); | 87 ASSERT_TRUE(base::CreateDirectory(normal_path)); |
| 87 ASSERT_TRUE(base::CreateDirectory(session_only_path)); | 88 ASSERT_TRUE(base::CreateDirectory(session_only_path)); |
| 88 FlushIndexedDBTaskRunner(); | 89 FlushIndexedDBTaskRunner(); |
| 89 message_loop_.RunUntilIdle(); | 90 base::RunLoop().RunUntilIdle(); |
| 90 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); | 91 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 FlushIndexedDBTaskRunner(); | 94 FlushIndexedDBTaskRunner(); |
| 94 message_loop_.RunUntilIdle(); | 95 base::RunLoop().RunUntilIdle(); |
| 95 | 96 |
| 96 EXPECT_TRUE(base::DirectoryExists(normal_path)); | 97 EXPECT_TRUE(base::DirectoryExists(normal_path)); |
| 97 EXPECT_FALSE(base::DirectoryExists(session_only_path)); | 98 EXPECT_FALSE(base::DirectoryExists(session_only_path)); |
| 98 } | 99 } |
| 99 | 100 |
| 100 TEST_F(IndexedDBTest, SetForceKeepSessionState) { | 101 TEST_F(IndexedDBTest, SetForceKeepSessionState) { |
| 101 base::ScopedTempDir temp_dir; | 102 base::ScopedTempDir temp_dir; |
| 102 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 103 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 103 | 104 |
| 104 base::FilePath normal_path; | 105 base::FilePath normal_path; |
| 105 base::FilePath session_only_path; | 106 base::FilePath session_only_path; |
| 106 | 107 |
| 107 // Create the scope which will ensure we run the destructor of the context. | 108 // Create the scope which will ensure we run the destructor of the context. |
| 108 { | 109 { |
| 109 // Create some indexedDB paths. | 110 // Create some indexedDB paths. |
| 110 // With the levelDB backend, these are directories. | 111 // With the levelDB backend, these are directories. |
| 111 scoped_refptr<IndexedDBContextImpl> idb_context = | 112 scoped_refptr<IndexedDBContextImpl> idb_context = |
| 112 new IndexedDBContextImpl(temp_dir.path(), | 113 new IndexedDBContextImpl(temp_dir.path(), |
| 113 special_storage_policy_.get(), | 114 special_storage_policy_.get(), |
| 114 quota_manager_proxy_.get(), | 115 quota_manager_proxy_.get(), |
| 115 task_runner_.get()); | 116 task_runner_.get()); |
| 116 | 117 |
| 117 // Save session state. This should bypass the destruction-time deletion. | 118 // Save session state. This should bypass the destruction-time deletion. |
| 118 idb_context->SetForceKeepSessionState(); | 119 idb_context->SetForceKeepSessionState(); |
| 119 | 120 |
| 120 normal_path = idb_context->GetFilePathForTesting(kNormalOrigin); | 121 normal_path = idb_context->GetFilePathForTesting(kNormalOrigin); |
| 121 session_only_path = idb_context->GetFilePathForTesting(kSessionOnlyOrigin); | 122 session_only_path = idb_context->GetFilePathForTesting(kSessionOnlyOrigin); |
| 122 ASSERT_TRUE(base::CreateDirectory(normal_path)); | 123 ASSERT_TRUE(base::CreateDirectory(normal_path)); |
| 123 ASSERT_TRUE(base::CreateDirectory(session_only_path)); | 124 ASSERT_TRUE(base::CreateDirectory(session_only_path)); |
| 124 message_loop_.RunUntilIdle(); | 125 base::RunLoop().RunUntilIdle(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 // Make sure we wait until the destructor has run. | 128 // Make sure we wait until the destructor has run. |
| 128 message_loop_.RunUntilIdle(); | 129 base::RunLoop().RunUntilIdle(); |
| 129 | 130 |
| 130 // No data was cleared because of SetForceKeepSessionState. | 131 // No data was cleared because of SetForceKeepSessionState. |
| 131 EXPECT_TRUE(base::DirectoryExists(normal_path)); | 132 EXPECT_TRUE(base::DirectoryExists(normal_path)); |
| 132 EXPECT_TRUE(base::DirectoryExists(session_only_path)); | 133 EXPECT_TRUE(base::DirectoryExists(session_only_path)); |
| 133 } | 134 } |
| 134 | 135 |
| 135 class ForceCloseDBCallbacks : public IndexedDBCallbacks { | 136 class ForceCloseDBCallbacks : public IndexedDBCallbacks { |
| 136 public: | 137 public: |
| 137 ForceCloseDBCallbacks(scoped_refptr<IndexedDBContextImpl> idb_context, | 138 ForceCloseDBCallbacks(scoped_refptr<IndexedDBContextImpl> idb_context, |
| 138 const Origin& origin) | 139 const Origin& origin) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 211 |
| 211 closed_callbacks->connection()->Close(); | 212 closed_callbacks->connection()->Close(); |
| 212 | 213 |
| 213 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. | 214 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. |
| 214 idb_context->TaskRunner()->PostTask( | 215 idb_context->TaskRunner()->PostTask( |
| 215 FROM_HERE, | 216 FROM_HERE, |
| 216 base::Bind(static_cast<void (IndexedDBContextImpl::*)(const Origin&)>( | 217 base::Bind(static_cast<void (IndexedDBContextImpl::*)(const Origin&)>( |
| 217 &IndexedDBContextImpl::DeleteForOrigin), | 218 &IndexedDBContextImpl::DeleteForOrigin), |
| 218 idb_context, kTestOrigin)); | 219 idb_context, kTestOrigin)); |
| 219 FlushIndexedDBTaskRunner(); | 220 FlushIndexedDBTaskRunner(); |
| 220 message_loop_.RunUntilIdle(); | 221 base::RunLoop().RunUntilIdle(); |
| 221 } | 222 } |
| 222 | 223 |
| 223 // Make sure we wait until the destructor has run. | 224 // Make sure we wait until the destructor has run. |
| 224 message_loop_.RunUntilIdle(); | 225 base::RunLoop().RunUntilIdle(); |
| 225 | 226 |
| 226 EXPECT_TRUE(open_db_callbacks->forced_close_called()); | 227 EXPECT_TRUE(open_db_callbacks->forced_close_called()); |
| 227 EXPECT_FALSE(closed_db_callbacks->forced_close_called()); | 228 EXPECT_FALSE(closed_db_callbacks->forced_close_called()); |
| 228 EXPECT_FALSE(base::DirectoryExists(test_path)); | 229 EXPECT_FALSE(base::DirectoryExists(test_path)); |
| 229 } | 230 } |
| 230 | 231 |
| 231 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) { | 232 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) { |
| 232 base::ScopedTempDir temp_dir; | 233 base::ScopedTempDir temp_dir; |
| 233 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 234 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 234 const Origin kTestOrigin(GURL("http://test/")); | 235 const Origin kTestOrigin(GURL("http://test/")); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 290 |
| 290 // Simulate the write failure. | 291 // Simulate the write failure. |
| 291 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); | 292 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); |
| 292 callbacks->connection()->database()->TransactionCommitFailed(status); | 293 callbacks->connection()->database()->TransactionCommitFailed(status); |
| 293 | 294 |
| 294 EXPECT_TRUE(db_callbacks->forced_close_called()); | 295 EXPECT_TRUE(db_callbacks->forced_close_called()); |
| 295 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); | 296 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); |
| 296 } | 297 } |
| 297 | 298 |
| 298 } // namespace content | 299 } // namespace content |
| OLD | NEW |