| 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 <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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 UpgradeNeededCallbacks() {} | 420 UpgradeNeededCallbacks() {} |
| 421 | 421 |
| 422 void OnSuccess(std::unique_ptr<IndexedDBConnection> connection, | 422 void OnSuccess(std::unique_ptr<IndexedDBConnection> connection, |
| 423 const IndexedDBDatabaseMetadata& metadata) override { | 423 const IndexedDBDatabaseMetadata& metadata) override { |
| 424 EXPECT_TRUE(connection_.get()); | 424 EXPECT_TRUE(connection_.get()); |
| 425 EXPECT_FALSE(connection.get()); | 425 EXPECT_FALSE(connection.get()); |
| 426 } | 426 } |
| 427 | 427 |
| 428 void OnUpgradeNeeded(int64_t old_version, | 428 void OnUpgradeNeeded(int64_t old_version, |
| 429 std::unique_ptr<IndexedDBConnection> connection, | 429 std::unique_ptr<IndexedDBConnection> connection, |
| 430 IndexedDBTransaction* transaction, |
| 430 const content::IndexedDBDatabaseMetadata& metadata, | 431 const content::IndexedDBDatabaseMetadata& metadata, |
| 431 const IndexedDBDataLossInfo& data_loss_info) override { | 432 const IndexedDBDataLossInfo& data_loss_info) override { |
| 433 transaction_ = transaction; |
| 432 connection_ = std::move(connection); | 434 connection_ = std::move(connection); |
| 433 } | 435 } |
| 434 | 436 |
| 437 IndexedDBTransaction* transaction() const { return transaction_; } |
| 438 |
| 435 protected: | 439 protected: |
| 436 ~UpgradeNeededCallbacks() override {} | 440 ~UpgradeNeededCallbacks() override {} |
| 437 | 441 |
| 438 private: | 442 private: |
| 443 IndexedDBTransaction* transaction_ = nullptr; |
| 444 |
| 439 DISALLOW_COPY_AND_ASSIGN(UpgradeNeededCallbacks); | 445 DISALLOW_COPY_AND_ASSIGN(UpgradeNeededCallbacks); |
| 440 }; | 446 }; |
| 441 | 447 |
| 442 class ErrorCallbacks : public MockIndexedDBCallbacks { | 448 class ErrorCallbacks : public MockIndexedDBCallbacks { |
| 443 public: | 449 public: |
| 444 ErrorCallbacks() : MockIndexedDBCallbacks(false), saw_error_(false) {} | 450 ErrorCallbacks() : MockIndexedDBCallbacks(false), saw_error_(false) {} |
| 445 | 451 |
| 446 void OnError(const IndexedDBDatabaseError& error) override { | 452 void OnError(const IndexedDBDatabaseError& error) override { |
| 447 saw_error_ = true; | 453 saw_error_ = true; |
| 448 } | 454 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 462 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 468 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 463 | 469 |
| 464 const base::string16 db_name(ASCIIToUTF16("db")); | 470 const base::string16 db_name(ASCIIToUTF16("db")); |
| 465 const int64_t db_version = 2; | 471 const int64_t db_version = 2; |
| 466 const int64_t transaction_id = 1; | 472 const int64_t transaction_id = 1; |
| 467 scoped_refptr<IndexedDBDatabaseCallbacks> db_callbacks( | 473 scoped_refptr<IndexedDBDatabaseCallbacks> db_callbacks( |
| 468 new MockIndexedDBDatabaseCallbacks()); | 474 new MockIndexedDBDatabaseCallbacks()); |
| 469 | 475 |
| 470 // Open at version 2, then close. | 476 // Open at version 2, then close. |
| 471 { | 477 { |
| 472 scoped_refptr<MockIndexedDBCallbacks> callbacks( | 478 scoped_refptr<UpgradeNeededCallbacks> callbacks( |
| 473 new UpgradeNeededCallbacks()); | 479 new UpgradeNeededCallbacks()); |
| 474 std::unique_ptr<IndexedDBPendingConnection> connection( | 480 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 475 base::MakeUnique<IndexedDBPendingConnection>( | 481 base::MakeUnique<IndexedDBPendingConnection>( |
| 476 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, | 482 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, |
| 477 db_version)); | 483 db_version)); |
| 478 factory()->Open(db_name, std::move(connection), | 484 factory()->Open(db_name, std::move(connection), |
| 479 nullptr /* request_context */, origin, | 485 nullptr /* request_context */, origin, |
| 480 temp_directory.GetPath()); | 486 temp_directory.GetPath()); |
| 481 EXPECT_TRUE(factory()->IsDatabaseOpen(origin, db_name)); | 487 EXPECT_TRUE(factory()->IsDatabaseOpen(origin, db_name)); |
| 482 | 488 |
| 483 // Pump the message loop so the upgrade transaction can run. | 489 // Pump the message loop so the upgrade transaction can run. |
| 484 base::RunLoop().RunUntilIdle(); | 490 base::RunLoop().RunUntilIdle(); |
| 485 EXPECT_TRUE(callbacks->connection()); | 491 EXPECT_TRUE(callbacks->connection()); |
| 486 callbacks->connection()->database()->Commit(transaction_id); | 492 EXPECT_NE(callbacks->transaction(), nullptr); |
| 493 callbacks->connection()->database()->Commit(callbacks->transaction()); |
| 487 | 494 |
| 488 callbacks->connection()->Close(); | 495 callbacks->connection()->Close(); |
| 489 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); | 496 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); |
| 490 } | 497 } |
| 491 | 498 |
| 492 // Open at version < 2, which will fail; ensure factory doesn't retain | 499 // Open at version < 2, which will fail; ensure factory doesn't retain |
| 493 // the database object. | 500 // the database object. |
| 494 { | 501 { |
| 495 scoped_refptr<ErrorCallbacks> callbacks(new ErrorCallbacks()); | 502 scoped_refptr<ErrorCallbacks> callbacks(new ErrorCallbacks()); |
| 496 std::unique_ptr<IndexedDBPendingConnection> connection( | 503 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 497 base::MakeUnique<IndexedDBPendingConnection>( | 504 base::MakeUnique<IndexedDBPendingConnection>( |
| 498 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, | 505 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, |
| 499 db_version - 1)); | 506 db_version - 1)); |
| 500 factory()->Open(db_name, std::move(connection), | 507 factory()->Open(db_name, std::move(connection), |
| 501 nullptr /* request_context */, origin, | 508 nullptr /* request_context */, origin, |
| 502 temp_directory.GetPath()); | 509 temp_directory.GetPath()); |
| 503 EXPECT_TRUE(callbacks->saw_error()); | 510 EXPECT_TRUE(callbacks->saw_error()); |
| 504 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); | 511 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); |
| 505 } | 512 } |
| 506 | 513 |
| 507 // Terminate all pending-close timers. | 514 // Terminate all pending-close timers. |
| 508 factory()->ForceClose(origin); | 515 factory()->ForceClose(origin); |
| 509 } | 516 } |
| 510 | 517 |
| 511 } // namespace content | 518 } // namespace content |
| OLD | NEW |