| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/indexed_db/indexed_db_factory.h" | 5 #include "content/browser/indexed_db/indexed_db_factory.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 211 |
| 212 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { | 212 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { |
| 213 const GURL origin("http://localhost:81"); | 213 const GURL origin("http://localhost:81"); |
| 214 | 214 |
| 215 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory; | 215 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory; |
| 216 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = | 216 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = |
| 217 new LookingForQuotaErrorMockCallbacks; | 217 new LookingForQuotaErrorMockCallbacks; |
| 218 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks = | 218 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks = |
| 219 new IndexedDBDatabaseCallbacks(NULL, 0, 0); | 219 new IndexedDBDatabaseCallbacks(NULL, 0, 0); |
| 220 const base::string16 name(ASCIIToUTF16("name")); | 220 const base::string16 name(ASCIIToUTF16("name")); |
| 221 factory->Open(name, | 221 IndexedDBPendingConnection connection(callbacks, |
| 222 1, /* version */ | 222 dummy_database_callbacks, |
| 223 2, /* transaction_id */ | 223 0, /* child_process_id */ |
| 224 callbacks, | 224 2, /* transaction_id */ |
| 225 dummy_database_callbacks, | 225 1 /* version */); |
| 226 origin, | 226 factory->Open( |
| 227 base::FilePath(FILE_PATH_LITERAL("/dummy"))); | 227 name, connection, origin, base::FilePath(FILE_PATH_LITERAL("/dummy"))); |
| 228 } | 228 } |
| 229 | 229 |
| 230 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) { | 230 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) { |
| 231 GURL origin("http://localhost:81"); | 231 GURL origin("http://localhost:81"); |
| 232 | 232 |
| 233 base::ScopedTempDir temp_directory; | 233 base::ScopedTempDir temp_directory; |
| 234 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 234 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 235 | 235 |
| 236 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); | 236 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); |
| 237 | 237 |
| 238 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 238 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 239 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 239 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( |
| 240 new MockIndexedDBDatabaseCallbacks()); | 240 new MockIndexedDBDatabaseCallbacks()); |
| 241 const int64 transaction_id = 1; | 241 const int64 transaction_id = 1; |
| 242 factory->Open(ASCIIToUTF16("db"), | 242 IndexedDBPendingConnection connection( |
| 243 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION, | 243 callbacks, |
| 244 transaction_id, | 244 db_callbacks, |
| 245 callbacks, | 245 0, /* child_process_id */ |
| 246 db_callbacks, | 246 transaction_id, |
| 247 origin, | 247 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); |
| 248 temp_directory.path()); | 248 factory->Open(ASCIIToUTF16("db"), connection, origin, temp_directory.path()); |
| 249 | 249 |
| 250 EXPECT_TRUE(callbacks->connection()); | 250 EXPECT_TRUE(callbacks->connection()); |
| 251 | 251 |
| 252 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); | 252 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); |
| 253 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin)); | 253 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin)); |
| 254 | 254 |
| 255 callbacks->connection()->ForceClose(); | 255 callbacks->connection()->ForceClose(); |
| 256 | 256 |
| 257 EXPECT_FALSE(factory->IsBackingStoreOpen(origin)); | 257 EXPECT_FALSE(factory->IsBackingStoreOpen(origin)); |
| 258 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin)); | 258 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin)); |
| 259 } | 259 } |
| 260 | 260 |
| 261 TEST_F(IndexedDBFactoryTest, BackingStoreReleaseDelayedOnClose) { | 261 TEST_F(IndexedDBFactoryTest, BackingStoreReleaseDelayedOnClose) { |
| 262 GURL origin("http://localhost:81"); | 262 GURL origin("http://localhost:81"); |
| 263 | 263 |
| 264 base::ScopedTempDir temp_directory; | 264 base::ScopedTempDir temp_directory; |
| 265 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 265 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 266 | 266 |
| 267 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); | 267 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); |
| 268 | 268 |
| 269 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 269 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 270 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 270 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( |
| 271 new MockIndexedDBDatabaseCallbacks()); | 271 new MockIndexedDBDatabaseCallbacks()); |
| 272 const int64 transaction_id = 1; | 272 const int64 transaction_id = 1; |
| 273 factory->Open(ASCIIToUTF16("db"), | 273 IndexedDBPendingConnection connection( |
| 274 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION, | 274 callbacks, |
| 275 transaction_id, | 275 db_callbacks, |
| 276 callbacks, | 276 0, /* child_process_id */ |
| 277 db_callbacks, | 277 transaction_id, |
| 278 origin, | 278 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); |
| 279 temp_directory.path()); | 279 factory->Open(ASCIIToUTF16("db"), connection, origin, temp_directory.path()); |
| 280 | 280 |
| 281 EXPECT_TRUE(callbacks->connection()); | 281 EXPECT_TRUE(callbacks->connection()); |
| 282 IndexedDBBackingStore* store = | 282 IndexedDBBackingStore* store = |
| 283 callbacks->connection()->database()->backing_store(); | 283 callbacks->connection()->database()->backing_store(); |
| 284 EXPECT_FALSE(store->HasOneRef()); // Factory and database. | 284 EXPECT_FALSE(store->HasOneRef()); // Factory and database. |
| 285 | 285 |
| 286 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); | 286 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); |
| 287 callbacks->connection()->Close(); | 287 callbacks->connection()->Close(); |
| 288 EXPECT_TRUE(store->HasOneRef()); // Factory. | 288 EXPECT_TRUE(store->HasOneRef()); // Factory. |
| 289 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); | 289 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 358 |
| 359 base::ScopedTempDir temp_directory; | 359 base::ScopedTempDir temp_directory; |
| 360 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 360 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 361 | 361 |
| 362 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); | 362 scoped_refptr<IndexedDBFactory> factory = new IndexedDBFactory(NULL); |
| 363 | 363 |
| 364 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 364 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 365 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 365 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( |
| 366 new MockIndexedDBDatabaseCallbacks()); | 366 new MockIndexedDBDatabaseCallbacks()); |
| 367 const int64 transaction_id = 1; | 367 const int64 transaction_id = 1; |
| 368 factory->Open(ASCIIToUTF16("db"), | 368 IndexedDBPendingConnection connection( |
| 369 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION, | 369 callbacks, |
| 370 transaction_id, | 370 db_callbacks, |
| 371 callbacks, | 371 0, /* child_process_id */ |
| 372 db_callbacks, | 372 transaction_id, |
| 373 origin, | 373 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); |
| 374 temp_directory.path()); | 374 factory->Open(ASCIIToUTF16("db"), connection, origin, temp_directory.path()); |
| 375 | 375 |
| 376 EXPECT_TRUE(callbacks->connection()); | 376 EXPECT_TRUE(callbacks->connection()); |
| 377 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); | 377 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); |
| 378 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin)); | 378 EXPECT_FALSE(factory->IsBackingStorePendingClose(origin)); |
| 379 | 379 |
| 380 callbacks->connection()->Close(); | 380 callbacks->connection()->Close(); |
| 381 | 381 |
| 382 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); | 382 EXPECT_TRUE(factory->IsBackingStoreOpen(origin)); |
| 383 EXPECT_TRUE(factory->IsBackingStorePendingClose(origin)); | 383 EXPECT_TRUE(factory->IsBackingStorePendingClose(origin)); |
| 384 | 384 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 const base::string16 db_name(ASCIIToUTF16("db")); | 435 const base::string16 db_name(ASCIIToUTF16("db")); |
| 436 const int64 db_version = 2; | 436 const int64 db_version = 2; |
| 437 const int64 transaction_id = 1; | 437 const int64 transaction_id = 1; |
| 438 scoped_refptr<IndexedDBDatabaseCallbacks> db_callbacks( | 438 scoped_refptr<IndexedDBDatabaseCallbacks> db_callbacks( |
| 439 new MockIndexedDBDatabaseCallbacks()); | 439 new MockIndexedDBDatabaseCallbacks()); |
| 440 | 440 |
| 441 // Open at version 2, then close. | 441 // Open at version 2, then close. |
| 442 { | 442 { |
| 443 scoped_refptr<MockIndexedDBCallbacks> callbacks( | 443 scoped_refptr<MockIndexedDBCallbacks> callbacks( |
| 444 new UpgradeNeededCallbacks()); | 444 new UpgradeNeededCallbacks()); |
| 445 factory->Open(db_name, | 445 IndexedDBPendingConnection connection(callbacks, |
| 446 db_version, | 446 db_callbacks, |
| 447 transaction_id, | 447 0, /* child_process_id */ |
| 448 callbacks, | 448 transaction_id, |
| 449 db_callbacks, | 449 db_version); |
| 450 origin, | 450 factory->Open(db_name, connection, origin, temp_directory.path()); |
| 451 temp_directory.path()); | |
| 452 EXPECT_TRUE(factory->IsDatabaseOpen(origin, db_name)); | 451 EXPECT_TRUE(factory->IsDatabaseOpen(origin, db_name)); |
| 453 | 452 |
| 454 // Pump the message loop so the upgrade transaction can run. | 453 // Pump the message loop so the upgrade transaction can run. |
| 455 base::MessageLoop::current()->RunUntilIdle(); | 454 base::MessageLoop::current()->RunUntilIdle(); |
| 456 EXPECT_TRUE(callbacks->connection()); | 455 EXPECT_TRUE(callbacks->connection()); |
| 457 callbacks->connection()->database()->Commit(transaction_id); | 456 callbacks->connection()->database()->Commit(transaction_id); |
| 458 | 457 |
| 459 callbacks->connection()->Close(); | 458 callbacks->connection()->Close(); |
| 460 EXPECT_FALSE(factory->IsDatabaseOpen(origin, db_name)); | 459 EXPECT_FALSE(factory->IsDatabaseOpen(origin, db_name)); |
| 461 } | 460 } |
| 462 | 461 |
| 463 // Open at version < 2, which will fail; ensure factory doesn't retain | 462 // Open at version < 2, which will fail; ensure factory doesn't retain |
| 464 // the database object. | 463 // the database object. |
| 465 { | 464 { |
| 466 scoped_refptr<IndexedDBCallbacks> callbacks(new ErrorCallbacks()); | 465 scoped_refptr<IndexedDBCallbacks> callbacks(new ErrorCallbacks()); |
| 467 factory->Open(db_name, | 466 IndexedDBPendingConnection connection(callbacks, |
| 468 db_version - 1, | 467 db_callbacks, |
| 469 transaction_id, | 468 0, /* child_process_id */ |
| 470 callbacks, | 469 transaction_id, |
| 471 db_callbacks, | 470 db_version - 1); |
| 472 origin, | 471 factory->Open(db_name, connection, origin, temp_directory.path()); |
| 473 temp_directory.path()); | |
| 474 EXPECT_FALSE(factory->IsDatabaseOpen(origin, db_name)); | 472 EXPECT_FALSE(factory->IsDatabaseOpen(origin, db_name)); |
| 475 } | 473 } |
| 476 | 474 |
| 477 // Terminate all pending-close timers. | 475 // Terminate all pending-close timers. |
| 478 factory->ForceClose(origin); | 476 factory->ForceClose(origin); |
| 479 } | 477 } |
| 480 | 478 |
| 481 } // namespace content | 479 } // namespace content |
| OLD | NEW |