| 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/test/test_simple_task_runner.h" | 11 #include "base/test/test_simple_task_runner.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
| 14 #include "content/browser/indexed_db/indexed_db_connection.h" | 14 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 15 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 15 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 16 #include "content/browser/indexed_db/indexed_db_factory_impl.h" | 16 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
| 17 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" | 17 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" |
| 18 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" | 18 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" |
| 19 #include "content/browser/quota/mock_quota_manager_proxy.h" | 19 #include "content/browser/quota/mock_quota_manager_proxy.h" |
| 20 #include "content/public/browser/storage_partition.h" | 20 #include "content/public/browser/storage_partition.h" |
| 21 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
| 22 #include "content/public/test/mock_special_storage_policy.h" | 22 #include "content/public/test/mock_special_storage_policy.h" |
| 23 #include "content/public/test/test_browser_context.h" | 23 #include "content/public/test/test_browser_context.h" |
| 24 #include "storage/browser/quota/quota_manager.h" | 24 #include "storage/browser/quota/quota_manager.h" |
| 25 #include "storage/browser/quota/special_storage_policy.h" | 25 #include "storage/browser/quota/special_storage_policy.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "url/origin.h" |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 | 30 |
| 30 class IndexedDBTest : public testing::Test { | 31 class IndexedDBTest : public testing::Test { |
| 31 public: | 32 public: |
| 32 const GURL kNormalOrigin; | 33 const GURL kNormalOrigin; |
| 33 const GURL kSessionOnlyOrigin; | 34 const GURL kSessionOnlyOrigin; |
| 34 | 35 |
| 35 IndexedDBTest() | 36 IndexedDBTest() |
| 36 : kNormalOrigin("http://normal/"), | 37 : kNormalOrigin("http://normal/"), |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 188 |
| 188 IndexedDBFactory* factory = idb_context->GetIDBFactory(); | 189 IndexedDBFactory* factory = idb_context->GetIDBFactory(); |
| 189 | 190 |
| 190 test_path = idb_context->GetFilePathForTesting(kTestOrigin); | 191 test_path = idb_context->GetFilePathForTesting(kTestOrigin); |
| 191 | 192 |
| 192 IndexedDBPendingConnection open_connection(open_callbacks, | 193 IndexedDBPendingConnection open_connection(open_callbacks, |
| 193 open_db_callbacks, | 194 open_db_callbacks, |
| 194 0 /* child_process_id */, | 195 0 /* child_process_id */, |
| 195 0 /* host_transaction_id */, | 196 0 /* host_transaction_id */, |
| 196 0 /* version */); | 197 0 /* version */); |
| 197 factory->Open(base::ASCIIToUTF16("opendb"), | 198 factory->Open(base::ASCIIToUTF16("opendb"), open_connection, |
| 198 open_connection, | 199 NULL /* request_context */, url::Origin(kTestOrigin), |
| 199 NULL /* request_context */, | |
| 200 kTestOrigin, | |
| 201 idb_context->data_path()); | 200 idb_context->data_path()); |
| 202 IndexedDBPendingConnection closed_connection(closed_callbacks, | 201 IndexedDBPendingConnection closed_connection(closed_callbacks, |
| 203 closed_db_callbacks, | 202 closed_db_callbacks, |
| 204 0 /* child_process_id */, | 203 0 /* child_process_id */, |
| 205 0 /* host_transaction_id */, | 204 0 /* host_transaction_id */, |
| 206 0 /* version */); | 205 0 /* version */); |
| 207 factory->Open(base::ASCIIToUTF16("closeddb"), | 206 factory->Open(base::ASCIIToUTF16("closeddb"), closed_connection, |
| 208 closed_connection, | 207 NULL /* request_context */, url::Origin(kTestOrigin), |
| 209 NULL /* request_context */, | |
| 210 kTestOrigin, | |
| 211 idb_context->data_path()); | 208 idb_context->data_path()); |
| 212 | 209 |
| 213 closed_callbacks->connection()->Close(); | 210 closed_callbacks->connection()->Close(); |
| 214 | 211 |
| 215 idb_context->TaskRunner()->PostTask( | 212 idb_context->TaskRunner()->PostTask( |
| 216 FROM_HERE, | 213 FROM_HERE, |
| 217 base::Bind( | 214 base::Bind( |
| 218 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); | 215 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); |
| 219 FlushIndexedDBTaskRunner(); | 216 FlushIndexedDBTaskRunner(); |
| 220 message_loop_.RunUntilIdle(); | 217 message_loop_.RunUntilIdle(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 scoped_refptr<IndexedDBFactoryImpl> factory = | 263 scoped_refptr<IndexedDBFactoryImpl> factory = |
| 267 static_cast<IndexedDBFactoryImpl*>(context->GetIDBFactory()); | 264 static_cast<IndexedDBFactoryImpl*>(context->GetIDBFactory()); |
| 268 | 265 |
| 269 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 266 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 270 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 267 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( |
| 271 new MockIndexedDBDatabaseCallbacks()); | 268 new MockIndexedDBDatabaseCallbacks()); |
| 272 const int64_t transaction_id = 1; | 269 const int64_t transaction_id = 1; |
| 273 IndexedDBPendingConnection connection( | 270 IndexedDBPendingConnection connection( |
| 274 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, | 271 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, |
| 275 IndexedDBDatabaseMetadata::DEFAULT_VERSION); | 272 IndexedDBDatabaseMetadata::DEFAULT_VERSION); |
| 276 factory->Open(base::ASCIIToUTF16("db"), | 273 factory->Open(base::ASCIIToUTF16("db"), connection, |
| 277 connection, | 274 NULL /* request_context */, url::Origin(kTestOrigin), |
| 278 NULL /* request_context */, | |
| 279 kTestOrigin, | |
| 280 temp_dir.path()); | 275 temp_dir.path()); |
| 281 | 276 |
| 282 EXPECT_TRUE(callbacks->connection()); | 277 EXPECT_TRUE(callbacks->connection()); |
| 283 | 278 |
| 284 // ConnectionOpened() is usually called by the dispatcher. | 279 // ConnectionOpened() is usually called by the dispatcher. |
| 285 context->ConnectionOpened(kTestOrigin, callbacks->connection()); | 280 context->ConnectionOpened(kTestOrigin, callbacks->connection()); |
| 286 | 281 |
| 287 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin)); | 282 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin)); |
| 288 | 283 |
| 289 // Simulate the write failure. | 284 // Simulate the write failure. |
| 290 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); | 285 leveldb::Status status = leveldb::Status::IOError("Simulated failure"); |
| 291 callbacks->connection()->database()->TransactionCommitFailed(status); | 286 callbacks->connection()->database()->TransactionCommitFailed(status); |
| 292 | 287 |
| 293 EXPECT_TRUE(db_callbacks->forced_close_called()); | 288 EXPECT_TRUE(db_callbacks->forced_close_called()); |
| 294 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); | 289 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); |
| 295 } | 290 } |
| 296 | 291 |
| 297 } // namespace content | 292 } // namespace content |
| OLD | NEW |