| 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/file_util.h" | 5 #include "base/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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 new ForceCloseDBCallbacks(idb_context, kTestOrigin); | 167 new ForceCloseDBCallbacks(idb_context, kTestOrigin); |
| 168 | 168 |
| 169 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks = | 169 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks = |
| 170 new ForceCloseDBCallbacks(idb_context, kTestOrigin); | 170 new ForceCloseDBCallbacks(idb_context, kTestOrigin); |
| 171 | 171 |
| 172 IndexedDBFactory* factory = idb_context->GetIDBFactory(); | 172 IndexedDBFactory* factory = idb_context->GetIDBFactory(); |
| 173 | 173 |
| 174 test_path = idb_context->GetFilePathForTesting( | 174 test_path = idb_context->GetFilePathForTesting( |
| 175 webkit_database::GetIdentifierFromOrigin(kTestOrigin)); | 175 webkit_database::GetIdentifierFromOrigin(kTestOrigin)); |
| 176 | 176 |
| 177 IndexedDBPendingConnection open_connection(open_callbacks, |
| 178 open_db_callbacks, |
| 179 0 /* child_process_id */, |
| 180 0 /* host_transaction_id */, |
| 181 0 /* version */); |
| 177 factory->Open(base::ASCIIToUTF16("opendb"), | 182 factory->Open(base::ASCIIToUTF16("opendb"), |
| 178 0, | 183 open_connection, |
| 179 0, | |
| 180 open_callbacks, | |
| 181 open_db_callbacks, | |
| 182 kTestOrigin, | 184 kTestOrigin, |
| 183 idb_context->data_path()); | 185 idb_context->data_path()); |
| 186 IndexedDBPendingConnection closed_connection(closed_callbacks, |
| 187 closed_db_callbacks, |
| 188 0 /* child_process_id */, |
| 189 0 /* host_transaction_id */, |
| 190 0 /* version */); |
| 184 factory->Open(base::ASCIIToUTF16("closeddb"), | 191 factory->Open(base::ASCIIToUTF16("closeddb"), |
| 185 0, | 192 closed_connection, |
| 186 0, | |
| 187 closed_callbacks, | |
| 188 closed_db_callbacks, | |
| 189 kTestOrigin, | 193 kTestOrigin, |
| 190 idb_context->data_path()); | 194 idb_context->data_path()); |
| 191 | 195 |
| 192 closed_callbacks->connection()->Close(); | 196 closed_callbacks->connection()->Close(); |
| 193 | 197 |
| 194 idb_context->TaskRunner()->PostTask( | 198 idb_context->TaskRunner()->PostTask( |
| 195 FROM_HERE, | 199 FROM_HERE, |
| 196 base::Bind( | 200 base::Bind( |
| 197 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); | 201 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); |
| 198 FlushIndexedDBTaskRunner(); | 202 FlushIndexedDBTaskRunner(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 244 |
| 241 scoped_refptr<IndexedDBContextImpl> context = new IndexedDBContextImpl( | 245 scoped_refptr<IndexedDBContextImpl> context = new IndexedDBContextImpl( |
| 242 temp_dir.path(), special_storage_policy_, NULL, task_runner_); | 246 temp_dir.path(), special_storage_policy_, NULL, task_runner_); |
| 243 | 247 |
| 244 scoped_refptr<IndexedDBFactory> factory = context->GetIDBFactory(); | 248 scoped_refptr<IndexedDBFactory> factory = context->GetIDBFactory(); |
| 245 | 249 |
| 246 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 250 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 247 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 251 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( |
| 248 new MockIndexedDBDatabaseCallbacks()); | 252 new MockIndexedDBDatabaseCallbacks()); |
| 249 const int64 transaction_id = 1; | 253 const int64 transaction_id = 1; |
| 250 factory->Open(base::ASCIIToUTF16("db"), | 254 IndexedDBPendingConnection connection( |
| 251 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION, | 255 callbacks, |
| 252 transaction_id, | 256 db_callbacks, |
| 253 callbacks, | 257 0 /* child_process_id */, |
| 254 db_callbacks, | 258 transaction_id, |
| 255 kTestOrigin, | 259 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); |
| 256 temp_dir.path()); | 260 factory->Open( |
| 261 base::ASCIIToUTF16("db"), connection, kTestOrigin, temp_dir.path()); |
| 257 | 262 |
| 258 EXPECT_TRUE(callbacks->connection()); | 263 EXPECT_TRUE(callbacks->connection()); |
| 259 | 264 |
| 260 // ConnectionOpened() is usually called by the dispatcher. | 265 // ConnectionOpened() is usually called by the dispatcher. |
| 261 context->ConnectionOpened(kTestOrigin, callbacks->connection()); | 266 context->ConnectionOpened(kTestOrigin, callbacks->connection()); |
| 262 | 267 |
| 263 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin)); | 268 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin)); |
| 264 | 269 |
| 265 // Simulate the write failure. | 270 // Simulate the write failure. |
| 266 callbacks->connection()->database()->TransactionCommitFailed(); | 271 callbacks->connection()->database()->TransactionCommitFailed(); |
| 267 | 272 |
| 268 EXPECT_TRUE(db_callbacks->forced_close_called()); | 273 EXPECT_TRUE(db_callbacks->forced_close_called()); |
| 269 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); | 274 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); |
| 270 } | 275 } |
| 271 | 276 |
| 272 } // namespace content | 277 } // namespace content |
| OLD | NEW |