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