| 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" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks = | 184 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks = |
| 185 new ForceCloseDBCallbacks(idb_context, kTestOrigin); | 185 new ForceCloseDBCallbacks(idb_context, kTestOrigin); |
| 186 | 186 |
| 187 IndexedDBFactory* factory = idb_context->GetIDBFactory(); | 187 IndexedDBFactory* factory = idb_context->GetIDBFactory(); |
| 188 | 188 |
| 189 test_path = idb_context->GetFilePathForTesting(kTestOrigin); | 189 test_path = idb_context->GetFilePathForTesting(kTestOrigin); |
| 190 | 190 |
| 191 std::unique_ptr<IndexedDBPendingConnection> open_connection( | 191 std::unique_ptr<IndexedDBPendingConnection> open_connection( |
| 192 base::MakeUnique<IndexedDBPendingConnection>( | 192 base::MakeUnique<IndexedDBPendingConnection>( |
| 193 open_callbacks, open_db_callbacks, 0 /* child_process_id */, | 193 open_callbacks, open_db_callbacks, 0 /* child_process_id */, |
| 194 0 /* host_transaction_id */, 0 /* version */)); | 194 url::Origin(), 0 /* host_transaction_id */, 0 /* version */)); |
| 195 factory->Open(base::ASCIIToUTF16("opendb"), std::move(open_connection), | 195 factory->Open(base::ASCIIToUTF16("opendb"), std::move(open_connection), |
| 196 nullptr /* request_context */, Origin(kTestOrigin), | 196 nullptr /* request_context */, Origin(kTestOrigin), |
| 197 idb_context->data_path()); | 197 idb_context->data_path()); |
| 198 std::unique_ptr<IndexedDBPendingConnection> closed_connection( | 198 std::unique_ptr<IndexedDBPendingConnection> closed_connection( |
| 199 base::MakeUnique<IndexedDBPendingConnection>( | 199 base::MakeUnique<IndexedDBPendingConnection>( |
| 200 closed_callbacks, closed_db_callbacks, 0 /* child_process_id */, | 200 closed_callbacks, closed_db_callbacks, 0 /* child_process_id */, |
| 201 0 /* host_transaction_id */, 0 /* version */)); | 201 url::Origin(), 0 /* host_transaction_id */, 0 /* version */)); |
| 202 factory->Open(base::ASCIIToUTF16("closeddb"), std::move(closed_connection), | 202 factory->Open(base::ASCIIToUTF16("closeddb"), std::move(closed_connection), |
| 203 nullptr /* request_context */, Origin(kTestOrigin), | 203 nullptr /* request_context */, Origin(kTestOrigin), |
| 204 idb_context->data_path()); | 204 idb_context->data_path()); |
| 205 | 205 |
| 206 closed_callbacks->connection()->Close(); | 206 closed_callbacks->connection()->Close(); |
| 207 | 207 |
| 208 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. | 208 // TODO(jsbell): Remove static_cast<> when overloads are eliminated. |
| 209 idb_context->TaskRunner()->PostTask( | 209 idb_context->TaskRunner()->PostTask( |
| 210 FROM_HERE, | 210 FROM_HERE, |
| 211 base::Bind(static_cast<void (IndexedDBContextImpl::*)(const Origin&)>( | 211 base::Bind(static_cast<void (IndexedDBContextImpl::*)(const Origin&)>( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 262 |
| 263 scoped_refptr<IndexedDBFactoryImpl> factory = | 263 scoped_refptr<IndexedDBFactoryImpl> factory = |
| 264 static_cast<IndexedDBFactoryImpl*>(context->GetIDBFactory()); | 264 static_cast<IndexedDBFactoryImpl*>(context->GetIDBFactory()); |
| 265 | 265 |
| 266 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 266 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 267 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 267 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( |
| 268 new MockIndexedDBDatabaseCallbacks()); | 268 new MockIndexedDBDatabaseCallbacks()); |
| 269 const int64_t transaction_id = 1; | 269 const int64_t transaction_id = 1; |
| 270 std::unique_ptr<IndexedDBPendingConnection> connection( | 270 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 271 base::MakeUnique<IndexedDBPendingConnection>( | 271 base::MakeUnique<IndexedDBPendingConnection>( |
| 272 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, | 272 callbacks, db_callbacks, 0 /* child_process_id */, url::Origin(), |
| 273 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 273 transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
| 274 factory->Open(base::ASCIIToUTF16("db"), std::move(connection), | 274 factory->Open(base::ASCIIToUTF16("db"), std::move(connection), |
| 275 nullptr /* request_context */, Origin(kTestOrigin), | 275 nullptr /* request_context */, Origin(kTestOrigin), |
| 276 temp_dir.GetPath()); | 276 temp_dir.GetPath()); |
| 277 | 277 |
| 278 EXPECT_TRUE(callbacks->connection()); | 278 EXPECT_TRUE(callbacks->connection()); |
| 279 | 279 |
| 280 // ConnectionOpened() is usually called by the dispatcher. | 280 // ConnectionOpened() is usually called by the dispatcher. |
| 281 context->ConnectionOpened(kTestOrigin, callbacks->connection()); | 281 context->ConnectionOpened(kTestOrigin, callbacks->connection()); |
| 282 | 282 |
| 283 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin)); | 283 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin)); |
| 284 | 284 |
| 285 // Simulate the write failure. | 285 // Simulate the write failure. |
| 286 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); | 286 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); |
| 287 callbacks->connection()->database()->TransactionCommitFailed(status); | 287 callbacks->connection()->database()->TransactionCommitFailed(status); |
| 288 | 288 |
| 289 EXPECT_TRUE(db_callbacks->forced_close_called()); | 289 EXPECT_TRUE(db_callbacks->forced_close_called()); |
| 290 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); | 290 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); |
| 291 } | 291 } |
| 292 | 292 |
| 293 } // namespace content | 293 } // namespace content |
| OLD | NEW |