| 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/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
| 10 #include "content/browser/indexed_db/indexed_db_connection.h" | 10 #include "content/browser/indexed_db/indexed_db_connection.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 // Create the scope which will ensure we run the destructor of the context | 62 // Create the scope which will ensure we run the destructor of the context |
| 63 // which should trigger the clean up. | 63 // which should trigger the clean up. |
| 64 { | 64 { |
| 65 scoped_refptr<IndexedDBContextImpl> idb_context = | 65 scoped_refptr<IndexedDBContextImpl> idb_context = |
| 66 new IndexedDBContextImpl(temp_dir.path(), | 66 new IndexedDBContextImpl(temp_dir.path(), |
| 67 special_storage_policy_.get(), | 67 special_storage_policy_.get(), |
| 68 NULL, | 68 NULL, |
| 69 task_runner_.get()); | 69 task_runner_.get()); |
| 70 | 70 |
| 71 normal_path = idb_context->GetFilePathForTesting( | 71 normal_path = idb_context->GetFilePath(kNormalOrigin); |
| 72 storage::GetIdentifierFromOrigin(kNormalOrigin)); | 72 session_only_path = idb_context->GetFilePath(kSessionOnlyOrigin); |
| 73 session_only_path = idb_context->GetFilePathForTesting( | |
| 74 storage::GetIdentifierFromOrigin(kSessionOnlyOrigin)); | |
| 75 ASSERT_TRUE(base::CreateDirectory(normal_path)); | 73 ASSERT_TRUE(base::CreateDirectory(normal_path)); |
| 76 ASSERT_TRUE(base::CreateDirectory(session_only_path)); | 74 ASSERT_TRUE(base::CreateDirectory(session_only_path)); |
| 77 FlushIndexedDBTaskRunner(); | 75 FlushIndexedDBTaskRunner(); |
| 78 message_loop_.RunUntilIdle(); | 76 message_loop_.RunUntilIdle(); |
| 79 } | 77 } |
| 80 | 78 |
| 81 FlushIndexedDBTaskRunner(); | 79 FlushIndexedDBTaskRunner(); |
| 82 message_loop_.RunUntilIdle(); | 80 message_loop_.RunUntilIdle(); |
| 83 | 81 |
| 84 EXPECT_TRUE(base::DirectoryExists(normal_path)); | 82 EXPECT_TRUE(base::DirectoryExists(normal_path)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 98 // With the levelDB backend, these are directories. | 96 // With the levelDB backend, these are directories. |
| 99 scoped_refptr<IndexedDBContextImpl> idb_context = | 97 scoped_refptr<IndexedDBContextImpl> idb_context = |
| 100 new IndexedDBContextImpl(temp_dir.path(), | 98 new IndexedDBContextImpl(temp_dir.path(), |
| 101 special_storage_policy_.get(), | 99 special_storage_policy_.get(), |
| 102 NULL, | 100 NULL, |
| 103 task_runner_.get()); | 101 task_runner_.get()); |
| 104 | 102 |
| 105 // Save session state. This should bypass the destruction-time deletion. | 103 // Save session state. This should bypass the destruction-time deletion. |
| 106 idb_context->SetForceKeepSessionState(); | 104 idb_context->SetForceKeepSessionState(); |
| 107 | 105 |
| 108 normal_path = idb_context->GetFilePathForTesting( | 106 normal_path = idb_context->GetFilePath(kNormalOrigin); |
| 109 storage::GetIdentifierFromOrigin(kNormalOrigin)); | 107 session_only_path = idb_context->GetFilePath(kSessionOnlyOrigin); |
| 110 session_only_path = idb_context->GetFilePathForTesting( | |
| 111 storage::GetIdentifierFromOrigin(kSessionOnlyOrigin)); | |
| 112 ASSERT_TRUE(base::CreateDirectory(normal_path)); | 108 ASSERT_TRUE(base::CreateDirectory(normal_path)); |
| 113 ASSERT_TRUE(base::CreateDirectory(session_only_path)); | 109 ASSERT_TRUE(base::CreateDirectory(session_only_path)); |
| 114 message_loop_.RunUntilIdle(); | 110 message_loop_.RunUntilIdle(); |
| 115 } | 111 } |
| 116 | 112 |
| 117 // Make sure we wait until the destructor has run. | 113 // Make sure we wait until the destructor has run. |
| 118 message_loop_.RunUntilIdle(); | 114 message_loop_.RunUntilIdle(); |
| 119 | 115 |
| 120 // No data was cleared because of SetForceKeepSessionState. | 116 // No data was cleared because of SetForceKeepSessionState. |
| 121 EXPECT_TRUE(base::DirectoryExists(normal_path)); | 117 EXPECT_TRUE(base::DirectoryExists(normal_path)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 task_runner_.get()); | 170 task_runner_.get()); |
| 175 | 171 |
| 176 scoped_refptr<ForceCloseDBCallbacks> open_callbacks = | 172 scoped_refptr<ForceCloseDBCallbacks> open_callbacks = |
| 177 new ForceCloseDBCallbacks(idb_context, kTestOrigin); | 173 new ForceCloseDBCallbacks(idb_context, kTestOrigin); |
| 178 | 174 |
| 179 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks = | 175 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks = |
| 180 new ForceCloseDBCallbacks(idb_context, kTestOrigin); | 176 new ForceCloseDBCallbacks(idb_context, kTestOrigin); |
| 181 | 177 |
| 182 IndexedDBFactory* factory = idb_context->GetIDBFactory(); | 178 IndexedDBFactory* factory = idb_context->GetIDBFactory(); |
| 183 | 179 |
| 184 test_path = idb_context->GetFilePathForTesting( | 180 test_path = idb_context->GetFilePath(kTestOrigin); |
| 185 storage::GetIdentifierFromOrigin(kTestOrigin)); | |
| 186 | 181 |
| 187 IndexedDBPendingConnection open_connection(open_callbacks, | 182 IndexedDBPendingConnection open_connection(open_callbacks, |
| 188 open_db_callbacks, | 183 open_db_callbacks, |
| 189 0 /* child_process_id */, | 184 0 /* child_process_id */, |
| 190 0 /* host_transaction_id */, | 185 0 /* host_transaction_id */, |
| 191 0 /* version */); | 186 0 /* version */); |
| 192 factory->Open(base::ASCIIToUTF16("opendb"), | 187 factory->Open(base::ASCIIToUTF16("opendb"), |
| 193 open_connection, | 188 open_connection, |
| 194 NULL /* request_context */, | 189 NULL /* request_context */, |
| 195 kTestOrigin, | 190 kTestOrigin, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 224 } | 219 } |
| 225 | 220 |
| 226 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) { | 221 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) { |
| 227 base::ScopedTempDir temp_dir; | 222 base::ScopedTempDir temp_dir; |
| 228 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 223 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 229 const GURL kTestOrigin("http://test/"); | 224 const GURL kTestOrigin("http://test/"); |
| 230 | 225 |
| 231 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( | 226 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( |
| 232 temp_dir.path(), special_storage_policy_.get(), NULL, task_runner_.get()); | 227 temp_dir.path(), special_storage_policy_.get(), NULL, task_runner_.get()); |
| 233 | 228 |
| 234 base::FilePath test_path = idb_context->GetFilePathForTesting( | 229 base::FilePath test_path = idb_context->GetFilePath(kTestOrigin); |
| 235 storage::GetIdentifierFromOrigin(kTestOrigin)); | |
| 236 ASSERT_TRUE(base::CreateDirectory(test_path)); | 230 ASSERT_TRUE(base::CreateDirectory(test_path)); |
| 237 | 231 |
| 238 scoped_ptr<LevelDBLock> lock = | 232 scoped_ptr<LevelDBLock> lock = |
| 239 LevelDBDatabase::LockForTesting(test_path); | 233 LevelDBDatabase::LockForTesting(test_path); |
| 240 ASSERT_TRUE(lock); | 234 ASSERT_TRUE(lock); |
| 241 | 235 |
| 242 idb_context->TaskRunner()->PostTask( | 236 idb_context->TaskRunner()->PostTask( |
| 243 FROM_HERE, | 237 FROM_HERE, |
| 244 base::Bind( | 238 base::Bind( |
| 245 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); | 239 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 279 |
| 286 // Simulate the write failure. | 280 // Simulate the write failure. |
| 287 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); | 281 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); |
| 288 callbacks->connection()->database()->TransactionCommitFailed(status); | 282 callbacks->connection()->database()->TransactionCommitFailed(status); |
| 289 | 283 |
| 290 EXPECT_TRUE(db_callbacks->forced_close_called()); | 284 EXPECT_TRUE(db_callbacks->forced_close_called()); |
| 291 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); | 285 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); |
| 292 } | 286 } |
| 293 | 287 |
| 294 } // namespace content | 288 } // namespace content |
| OLD | NEW |