| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/test/test_simple_task_runner.h" | 15 #include "base/test/test_simple_task_runner.h" |
| 16 #include "content/browser/indexed_db/indexed_db_connection.h" | 16 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 17 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 17 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 18 #include "content/browser/indexed_db/indexed_db_factory_impl.h" | 18 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
| 19 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" | 19 #include "content/browser/indexed_db/mock_indexed_db_change_handler.h" |
| 20 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" | |
| 21 #include "content/browser/quota/mock_quota_manager_proxy.h" | 20 #include "content/browser/quota/mock_quota_manager_proxy.h" |
| 21 #include "net/url_request/url_request_context_getter.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" | 23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" |
| 24 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" | 24 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" |
| 25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 26 #include "url/origin.h" | 26 #include "url/origin.h" |
| 27 | 27 |
| 28 using base::ASCIIToUTF16; | 28 using base::ASCIIToUTF16; |
| 29 using url::Origin; | 29 using url::Origin; |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 bool* disk_full, | 218 bool* disk_full, |
| 219 leveldb::Status* s) override { | 219 leveldb::Status* s) override { |
| 220 *disk_full = true; | 220 *disk_full = true; |
| 221 *s = leveldb::Status::IOError("Disk is full"); | 221 *s = leveldb::Status::IOError("Disk is full"); |
| 222 return scoped_refptr<IndexedDBBackingStore>(); | 222 return scoped_refptr<IndexedDBBackingStore>(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 DISALLOW_COPY_AND_ASSIGN(DiskFullFactory); | 225 DISALLOW_COPY_AND_ASSIGN(DiskFullFactory); |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 #ifdef CJM_NEED_CALLBACK |
| 228 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks { | 229 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks { |
| 229 public: | 230 public: |
| 230 LookingForQuotaErrorMockCallbacks() | 231 LookingForQuotaErrorMockCallbacks() |
| 231 : IndexedDBCallbacks(nullptr, 0, 0), error_called_(false) {} | 232 : IndexedDBCallbacks(nullptr, 0, 0), error_called_(false) {} |
| 232 void OnError(const IndexedDBDatabaseError& error) override { | 233 void OnError(const IndexedDBDatabaseError& error) override { |
| 233 error_called_ = true; | 234 error_called_ = true; |
| 234 EXPECT_EQ(blink::WebIDBDatabaseExceptionQuotaError, error.code()); | 235 EXPECT_EQ(blink::WebIDBDatabaseExceptionQuotaError, error.code()); |
| 235 } | 236 } |
| 236 bool error_called() const { return error_called_; } | 237 bool error_called() const { return error_called_; } |
| 237 | 238 |
| 238 private: | 239 private: |
| 239 ~LookingForQuotaErrorMockCallbacks() override {} | 240 ~LookingForQuotaErrorMockCallbacks() override {} |
| 240 bool error_called_; | 241 bool error_called_; |
| 241 | 242 |
| 242 DISALLOW_COPY_AND_ASSIGN(LookingForQuotaErrorMockCallbacks); | 243 DISALLOW_COPY_AND_ASSIGN(LookingForQuotaErrorMockCallbacks); |
| 243 }; | 244 }; |
| 245 #endif |
| 244 | 246 |
| 245 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { | 247 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { |
| 246 const Origin origin(GURL("http://localhost:81")); | 248 const Origin origin(GURL("http://localhost:81")); |
| 247 base::ScopedTempDir temp_directory; | 249 base::ScopedTempDir temp_directory; |
| 248 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 250 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 249 | 251 |
| 250 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory(context()); | 252 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory(context()); |
| 253 #ifdef CJM_NEED_CALLBACK |
| 251 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = | 254 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = |
| 252 new LookingForQuotaErrorMockCallbacks; | 255 new LookingForQuotaErrorMockCallbacks; |
| 253 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks = | 256 scoped_refptr<IndexedDBChangeHandler> dummy_change_handler = |
| 254 new IndexedDBDatabaseCallbacks(nullptr, 0, 0); | 257 new IndexedDBChangeHandler(nullptr, 0, 0); |
| 255 const base::string16 name(ASCIIToUTF16("name")); | 258 const base::string16 name(ASCIIToUTF16("name")); |
| 256 std::unique_ptr<IndexedDBPendingConnection> connection( | 259 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 257 base::MakeUnique<IndexedDBPendingConnection>( | 260 base::MakeUnique<IndexedDBPendingConnection>( |
| 258 callbacks, dummy_database_callbacks, 0 /* child_process_id */, | 261 callbacks, dummy_change_handler, 0 /* child_process_id */, |
| 259 2 /* transaction_id */, 1 /* version */)); | 262 2 /* transaction_id */, 1 /* version */)); |
| 260 factory->Open(name, std::move(connection), nullptr /* request_context */, | 263 factory->Open(name, std::move(connection), nullptr /* request_context */, |
| 261 origin, temp_directory.path()); | 264 origin, temp_directory.path()); |
| 262 EXPECT_TRUE(callbacks->error_called()); | 265 EXPECT_TRUE(callbacks->error_called()); |
| 266 #endif |
| 263 } | 267 } |
| 264 | 268 |
| 265 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) { | 269 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) { |
| 266 const Origin origin(GURL("http://localhost:81")); | 270 const Origin origin(GURL("http://localhost:81")); |
| 267 | 271 |
| 268 base::ScopedTempDir temp_directory; | 272 base::ScopedTempDir temp_directory; |
| 269 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 273 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 270 | 274 |
| 275 #ifdef CJM_NEED_CALLBACK |
| 271 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 276 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 272 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 277 scoped_refptr<MockIndexedDBChangeHandler> change_handler( |
| 273 new MockIndexedDBDatabaseCallbacks()); | 278 new MockIndexedDBChangeHandler()); |
| 274 const int64_t transaction_id = 1; | 279 const int64_t transaction_id = 1; |
| 275 std::unique_ptr<IndexedDBPendingConnection> connection( | 280 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 276 base::MakeUnique<IndexedDBPendingConnection>( | 281 base::MakeUnique<IndexedDBPendingConnection>( |
| 277 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, | 282 callbacks, change_handler, 0 /* child_process_id */, transaction_id, |
| 278 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 283 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
| 279 factory()->Open(ASCIIToUTF16("db"), std::move(connection), | 284 factory()->Open(ASCIIToUTF16("db"), std::move(connection), |
| 280 nullptr /* request_context */, origin, temp_directory.path()); | 285 nullptr /* request_context */, origin, temp_directory.path()); |
| 281 | 286 |
| 282 EXPECT_TRUE(callbacks->connection()); | 287 EXPECT_TRUE(callbacks->connection()); |
| 283 | 288 |
| 284 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 289 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 285 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 290 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 286 | 291 |
| 287 callbacks->connection()->ForceClose(); | 292 callbacks->connection()->ForceClose(); |
| 288 | 293 |
| 289 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 294 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 290 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 295 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 296 #endif |
| 291 } | 297 } |
| 292 | 298 |
| 293 TEST_F(IndexedDBFactoryTest, BackingStoreReleaseDelayedOnClose) { | 299 TEST_F(IndexedDBFactoryTest, BackingStoreReleaseDelayedOnClose) { |
| 294 const Origin origin(GURL("http://localhost:81")); | 300 const Origin origin(GURL("http://localhost:81")); |
| 295 | 301 |
| 296 base::ScopedTempDir temp_directory; | 302 base::ScopedTempDir temp_directory; |
| 297 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 303 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 298 | 304 |
| 305 #ifdef CJM_NEED_CALLBACK |
| 299 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 306 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 300 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 307 scoped_refptr<MockIndexedDBChangeHandler> change_handler( |
| 301 new MockIndexedDBDatabaseCallbacks()); | 308 new MockIndexedDBChangeHandler()); |
| 302 const int64_t transaction_id = 1; | 309 const int64_t transaction_id = 1; |
| 303 std::unique_ptr<IndexedDBPendingConnection> connection( | 310 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 304 base::MakeUnique<IndexedDBPendingConnection>( | 311 base::MakeUnique<IndexedDBPendingConnection>( |
| 305 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, | 312 callbacks, change_handler, 0 /* child_process_id */, transaction_id, |
| 306 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 313 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
| 307 factory()->Open(ASCIIToUTF16("db"), std::move(connection), | 314 factory()->Open(ASCIIToUTF16("db"), std::move(connection), |
| 308 nullptr /* request_context */, origin, temp_directory.path()); | 315 nullptr /* request_context */, origin, temp_directory.path()); |
| 309 | 316 |
| 310 EXPECT_TRUE(callbacks->connection()); | 317 EXPECT_TRUE(callbacks->connection()); |
| 311 IndexedDBBackingStore* store = | 318 IndexedDBBackingStore* store = |
| 312 callbacks->connection()->database()->backing_store(); | 319 callbacks->connection()->database()->backing_store(); |
| 313 EXPECT_FALSE(store->HasOneRef()); // Factory and database. | 320 EXPECT_FALSE(store->HasOneRef()); // Factory and database. |
| 314 | 321 |
| 315 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 322 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 316 callbacks->connection()->Close(); | 323 callbacks->connection()->Close(); |
| 317 EXPECT_TRUE(store->HasOneRef()); // Factory. | 324 EXPECT_TRUE(store->HasOneRef()); // Factory. |
| 318 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 325 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 319 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); | 326 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); |
| 320 EXPECT_TRUE(store->close_timer()->IsRunning()); | 327 EXPECT_TRUE(store->close_timer()->IsRunning()); |
| 321 | 328 |
| 322 // Take a ref so it won't be destroyed out from under the test. | 329 // Take a ref so it won't be destroyed out from under the test. |
| 323 scoped_refptr<IndexedDBBackingStore> store_ref = store; | 330 scoped_refptr<IndexedDBBackingStore> store_ref = store; |
| 324 // Now simulate shutdown, which should stop the timer. | 331 // Now simulate shutdown, which should stop the timer. |
| 325 factory()->ContextDestroyed(); | 332 factory()->ContextDestroyed(); |
| 326 EXPECT_TRUE(store->HasOneRef()); // Local. | 333 EXPECT_TRUE(store->HasOneRef()); // Local. |
| 327 EXPECT_FALSE(store->close_timer()->IsRunning()); | 334 EXPECT_FALSE(store->close_timer()->IsRunning()); |
| 328 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 335 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 329 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 336 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 337 #endif |
| 330 } | 338 } |
| 331 | 339 |
| 332 TEST_F(IndexedDBFactoryTest, DeleteDatabaseClosesBackingStore) { | 340 TEST_F(IndexedDBFactoryTest, DeleteDatabaseClosesBackingStore) { |
| 333 const Origin origin(GURL("http://localhost:81")); | 341 const Origin origin(GURL("http://localhost:81")); |
| 334 | 342 |
| 335 base::ScopedTempDir temp_directory; | 343 base::ScopedTempDir temp_directory; |
| 336 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 344 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 337 | 345 |
| 338 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 346 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 339 | 347 |
| 348 #ifdef CJM_NEED_CALLBACK |
| 340 const bool expect_connection = false; | 349 const bool expect_connection = false; |
| 341 scoped_refptr<MockIndexedDBCallbacks> callbacks( | 350 scoped_refptr<MockIndexedDBCallbacks> callbacks( |
| 342 new MockIndexedDBCallbacks(expect_connection)); | 351 new MockIndexedDBCallbacks(expect_connection)); |
| 343 factory()->DeleteDatabase(ASCIIToUTF16("db"), nullptr /* request_context */, | 352 factory()->DeleteDatabase(ASCIIToUTF16("db"), nullptr /* request_context */, |
| 344 callbacks, origin, temp_directory.path()); | 353 callbacks, origin, temp_directory.path()); |
| 345 | 354 |
| 346 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 355 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 347 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); | 356 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); |
| 348 | 357 |
| 349 // Now simulate shutdown, which should stop the timer. | 358 // Now simulate shutdown, which should stop the timer. |
| 350 factory()->ContextDestroyed(); | 359 factory()->ContextDestroyed(); |
| 351 | 360 |
| 352 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 361 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 353 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 362 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 363 #endif |
| 354 } | 364 } |
| 355 | 365 |
| 356 TEST_F(IndexedDBFactoryTest, GetDatabaseNamesClosesBackingStore) { | 366 TEST_F(IndexedDBFactoryTest, GetDatabaseNamesClosesBackingStore) { |
| 357 const Origin origin(GURL("http://localhost:81")); | 367 const Origin origin(GURL("http://localhost:81")); |
| 358 | 368 |
| 359 base::ScopedTempDir temp_directory; | 369 base::ScopedTempDir temp_directory; |
| 360 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 370 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 361 | 371 |
| 362 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 372 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 363 | 373 |
| 374 #ifdef CJM_NEED_CALLBACK |
| 364 const bool expect_connection = false; | 375 const bool expect_connection = false; |
| 365 scoped_refptr<MockIndexedDBCallbacks> callbacks( | 376 scoped_refptr<MockIndexedDBCallbacks> callbacks( |
| 366 new MockIndexedDBCallbacks(expect_connection)); | 377 new MockIndexedDBCallbacks(expect_connection)); |
| 367 factory()->GetDatabaseNames(callbacks, origin, temp_directory.path(), | 378 factory()->GetDatabaseNames(callbacks, origin, temp_directory.path(), |
| 368 nullptr /* request_context */); | 379 nullptr /* request_context */); |
| 369 | 380 |
| 370 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 381 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 371 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); | 382 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); |
| 372 | 383 |
| 373 // Now simulate shutdown, which should stop the timer. | 384 // Now simulate shutdown, which should stop the timer. |
| 374 factory()->ContextDestroyed(); | 385 factory()->ContextDestroyed(); |
| 375 | 386 |
| 376 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 387 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 377 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 388 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 389 #endif |
| 378 } | 390 } |
| 379 | 391 |
| 380 TEST_F(IndexedDBFactoryTest, ForceCloseReleasesBackingStore) { | 392 TEST_F(IndexedDBFactoryTest, ForceCloseReleasesBackingStore) { |
| 381 const Origin origin(GURL("http://localhost:81")); | 393 const Origin origin(GURL("http://localhost:81")); |
| 382 | 394 |
| 383 base::ScopedTempDir temp_directory; | 395 base::ScopedTempDir temp_directory; |
| 384 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 396 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 385 | 397 |
| 398 #ifdef CJM_NEED_CALLBACK |
| 386 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 399 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 387 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 400 scoped_refptr<MockIndexedDBChangeHandler> change_handler( |
| 388 new MockIndexedDBDatabaseCallbacks()); | 401 new MockIndexedDBChangeHandler()); |
| 389 const int64_t transaction_id = 1; | 402 const int64_t transaction_id = 1; |
| 390 std::unique_ptr<IndexedDBPendingConnection> connection( | 403 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 391 base::MakeUnique<IndexedDBPendingConnection>( | 404 base::MakeUnique<IndexedDBPendingConnection>( |
| 392 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, | 405 callbacks, change_handler, 0 /* child_process_id */, transaction_id, |
| 393 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 406 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
| 394 factory()->Open(ASCIIToUTF16("db"), std::move(connection), | 407 factory()->Open(ASCIIToUTF16("db"), std::move(connection), |
| 395 nullptr /* request_context */, origin, temp_directory.path()); | 408 nullptr /* request_context */, origin, temp_directory.path()); |
| 396 | 409 |
| 397 EXPECT_TRUE(callbacks->connection()); | 410 EXPECT_TRUE(callbacks->connection()); |
| 398 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 411 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 399 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 412 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 400 | 413 |
| 401 callbacks->connection()->Close(); | 414 callbacks->connection()->Close(); |
| 402 | 415 |
| 403 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 416 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 404 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); | 417 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); |
| 405 | 418 |
| 406 factory()->ForceClose(origin); | 419 factory()->ForceClose(origin); |
| 407 | 420 |
| 408 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 421 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 409 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 422 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 410 | 423 |
| 411 // Ensure it is safe if the store is not open. | 424 // Ensure it is safe if the store is not open. |
| 412 factory()->ForceClose(origin); | 425 factory()->ForceClose(origin); |
| 426 #endif |
| 413 } | 427 } |
| 414 | 428 |
| 429 #ifdef CJM_NEED_CALLBACK |
| 415 class UpgradeNeededCallbacks : public MockIndexedDBCallbacks { | 430 class UpgradeNeededCallbacks : public MockIndexedDBCallbacks { |
| 416 public: | 431 public: |
| 417 UpgradeNeededCallbacks() {} | 432 UpgradeNeededCallbacks() {} |
| 418 | 433 |
| 419 void OnSuccess(std::unique_ptr<IndexedDBConnection> connection, | 434 void OnSuccess(std::unique_ptr<IndexedDBConnection> connection, |
| 420 const IndexedDBDatabaseMetadata& metadata) override { | 435 const IndexedDBDatabaseMetadata& metadata) override { |
| 421 EXPECT_TRUE(connection_.get()); | 436 EXPECT_TRUE(connection_.get()); |
| 422 EXPECT_FALSE(connection.get()); | 437 EXPECT_FALSE(connection.get()); |
| 423 } | 438 } |
| 424 | 439 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 444 saw_error_ = true; | 459 saw_error_ = true; |
| 445 } | 460 } |
| 446 bool saw_error() const { return saw_error_; } | 461 bool saw_error() const { return saw_error_; } |
| 447 | 462 |
| 448 private: | 463 private: |
| 449 ~ErrorCallbacks() override {} | 464 ~ErrorCallbacks() override {} |
| 450 bool saw_error_; | 465 bool saw_error_; |
| 451 | 466 |
| 452 DISALLOW_COPY_AND_ASSIGN(ErrorCallbacks); | 467 DISALLOW_COPY_AND_ASSIGN(ErrorCallbacks); |
| 453 }; | 468 }; |
| 469 #endif |
| 454 | 470 |
| 455 TEST_F(IndexedDBFactoryTest, DatabaseFailedOpen) { | 471 TEST_F(IndexedDBFactoryTest, DatabaseFailedOpen) { |
| 456 const Origin origin(GURL("http://localhost:81")); | 472 const Origin origin(GURL("http://localhost:81")); |
| 457 | 473 |
| 458 base::ScopedTempDir temp_directory; | 474 base::ScopedTempDir temp_directory; |
| 459 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 475 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 460 | 476 |
| 477 #ifdef CJM_NEED_CALLBACK |
| 461 const base::string16 db_name(ASCIIToUTF16("db")); | 478 const base::string16 db_name(ASCIIToUTF16("db")); |
| 462 const int64_t db_version = 2; | 479 const int64_t db_version = 2; |
| 463 const int64_t transaction_id = 1; | 480 const int64_t transaction_id = 1; |
| 464 scoped_refptr<IndexedDBDatabaseCallbacks> db_callbacks( | 481 scoped_refptr<IndexedDBChangeHandler> change_handler( |
| 465 new MockIndexedDBDatabaseCallbacks()); | 482 new MockIndexedDBChangeHandler()); |
| 466 | 483 |
| 467 // Open at version 2, then close. | 484 // Open at version 2, then close. |
| 468 { | 485 { |
| 469 scoped_refptr<MockIndexedDBCallbacks> callbacks( | 486 scoped_refptr<MockIndexedDBCallbacks> callbacks( |
| 470 new UpgradeNeededCallbacks()); | 487 new UpgradeNeededCallbacks()); |
| 471 std::unique_ptr<IndexedDBPendingConnection> connection( | 488 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 472 base::MakeUnique<IndexedDBPendingConnection>( | 489 base::MakeUnique<IndexedDBPendingConnection>( |
| 473 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, | 490 callbacks, change_handler, 0 /* child_process_id */, transaction_id, |
| 474 db_version)); | 491 db_version)); |
| 475 factory()->Open(db_name, std::move(connection), | 492 factory()->Open(db_name, std::move(connection), |
| 476 nullptr /* request_context */, origin, | 493 nullptr /* request_context */, origin, |
| 477 temp_directory.path()); | 494 temp_directory.path()); |
| 478 EXPECT_TRUE(factory()->IsDatabaseOpen(origin, db_name)); | 495 EXPECT_TRUE(factory()->IsDatabaseOpen(origin, db_name)); |
| 479 | 496 |
| 480 // Pump the message loop so the upgrade transaction can run. | 497 // Pump the message loop so the upgrade transaction can run. |
| 481 base::RunLoop().RunUntilIdle(); | 498 base::RunLoop().RunUntilIdle(); |
| 482 EXPECT_TRUE(callbacks->connection()); | 499 EXPECT_TRUE(callbacks->connection()); |
| 483 callbacks->connection()->database()->Commit(transaction_id); | 500 callbacks->connection()->database()->Commit(transaction_id); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 496 db_version - 1)); | 513 db_version - 1)); |
| 497 factory()->Open(db_name, std::move(connection), | 514 factory()->Open(db_name, std::move(connection), |
| 498 nullptr /* request_context */, origin, | 515 nullptr /* request_context */, origin, |
| 499 temp_directory.path()); | 516 temp_directory.path()); |
| 500 EXPECT_TRUE(callbacks->saw_error()); | 517 EXPECT_TRUE(callbacks->saw_error()); |
| 501 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); | 518 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); |
| 502 } | 519 } |
| 503 | 520 |
| 504 // Terminate all pending-close timers. | 521 // Terminate all pending-close timers. |
| 505 factory()->ForceClose(origin); | 522 factory()->ForceClose(origin); |
| 523 #endif |
| 506 } | 524 } |
| 507 | 525 |
| 508 } // namespace content | 526 } // namespace content |
| OLD | NEW |