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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 CloseBackingStore(backing_store->origin_url()); | 51 CloseBackingStore(backing_store->origin_url()); |
52 } | 52 } |
53 | 53 |
54 void TestReleaseBackingStore(IndexedDBBackingStore* backing_store, | 54 void TestReleaseBackingStore(IndexedDBBackingStore* backing_store, |
55 bool immediate) { | 55 bool immediate) { |
56 ReleaseBackingStore(backing_store->origin_url(), immediate); | 56 ReleaseBackingStore(backing_store->origin_url(), immediate); |
57 } | 57 } |
58 | 58 |
59 private: | 59 private: |
60 virtual ~MockIDBFactory() {} | 60 virtual ~MockIDBFactory() {} |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(MockIDBFactory); |
61 }; | 63 }; |
62 | 64 |
63 } // namespace | 65 } // namespace |
64 | 66 |
65 class IndexedDBFactoryTest : public testing::Test { | 67 class IndexedDBFactoryTest : public testing::Test { |
66 public: | 68 public: |
67 IndexedDBFactoryTest() { | 69 IndexedDBFactoryTest() { |
68 task_runner_ = new base::TestSimpleTaskRunner(); | 70 task_runner_ = new base::TestSimpleTaskRunner(); |
69 context_ = new IndexedDBContextImpl(base::FilePath(), | 71 context_ = new IndexedDBContextImpl(base::FilePath(), |
70 NULL /* special_storage_policy */, | 72 NULL /* special_storage_policy */, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( | 205 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( |
204 const GURL& origin_url, | 206 const GURL& origin_url, |
205 const base::FilePath& data_directory, | 207 const base::FilePath& data_directory, |
206 net::URLRequestContext* request_context, | 208 net::URLRequestContext* request_context, |
207 blink::WebIDBDataLoss* data_loss, | 209 blink::WebIDBDataLoss* data_loss, |
208 std::string* data_loss_message, | 210 std::string* data_loss_message, |
209 bool* disk_full) OVERRIDE { | 211 bool* disk_full) OVERRIDE { |
210 *disk_full = true; | 212 *disk_full = true; |
211 return scoped_refptr<IndexedDBBackingStore>(); | 213 return scoped_refptr<IndexedDBBackingStore>(); |
212 } | 214 } |
| 215 |
| 216 DISALLOW_COPY_AND_ASSIGN(DiskFullFactory); |
213 }; | 217 }; |
214 | 218 |
215 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks { | 219 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks { |
216 public: | 220 public: |
217 LookingForQuotaErrorMockCallbacks() | 221 LookingForQuotaErrorMockCallbacks() |
218 : IndexedDBCallbacks(NULL, 0, 0), error_called_(false) {} | 222 : IndexedDBCallbacks(NULL, 0, 0), error_called_(false) {} |
219 virtual void OnError(const IndexedDBDatabaseError& error) OVERRIDE { | 223 virtual void OnError(const IndexedDBDatabaseError& error) OVERRIDE { |
220 error_called_ = true; | 224 error_called_ = true; |
221 EXPECT_EQ(blink::WebIDBDatabaseExceptionQuotaError, error.code()); | 225 EXPECT_EQ(blink::WebIDBDatabaseExceptionQuotaError, error.code()); |
222 } | 226 } |
223 bool error_called() const { return error_called_; } | 227 bool error_called() const { return error_called_; } |
224 | 228 |
225 private: | 229 private: |
226 virtual ~LookingForQuotaErrorMockCallbacks() {} | 230 virtual ~LookingForQuotaErrorMockCallbacks() {} |
227 bool error_called_; | 231 bool error_called_; |
| 232 |
| 233 DISALLOW_COPY_AND_ASSIGN(LookingForQuotaErrorMockCallbacks); |
228 }; | 234 }; |
229 | 235 |
230 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { | 236 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { |
231 const GURL origin("http://localhost:81"); | 237 const GURL origin("http://localhost:81"); |
232 base::ScopedTempDir temp_directory; | 238 base::ScopedTempDir temp_directory; |
233 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 239 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
234 | 240 |
235 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory(context()); | 241 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory(context()); |
236 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = | 242 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = |
237 new LookingForQuotaErrorMockCallbacks; | 243 new LookingForQuotaErrorMockCallbacks; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 420 |
415 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 421 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
416 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 422 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
417 | 423 |
418 // Ensure it is safe if the store is not open. | 424 // Ensure it is safe if the store is not open. |
419 factory()->ForceClose(origin); | 425 factory()->ForceClose(origin); |
420 } | 426 } |
421 | 427 |
422 class UpgradeNeededCallbacks : public MockIndexedDBCallbacks { | 428 class UpgradeNeededCallbacks : public MockIndexedDBCallbacks { |
423 public: | 429 public: |
| 430 UpgradeNeededCallbacks() {} |
| 431 |
424 virtual void OnSuccess(scoped_ptr<IndexedDBConnection> connection, | 432 virtual void OnSuccess(scoped_ptr<IndexedDBConnection> connection, |
425 const IndexedDBDatabaseMetadata& metadata) OVERRIDE { | 433 const IndexedDBDatabaseMetadata& metadata) OVERRIDE { |
426 EXPECT_TRUE(connection_.get()); | 434 EXPECT_TRUE(connection_.get()); |
427 EXPECT_FALSE(connection.get()); | 435 EXPECT_FALSE(connection.get()); |
428 } | 436 } |
429 | 437 |
430 virtual void OnUpgradeNeeded( | 438 virtual void OnUpgradeNeeded( |
431 int64 old_version, | 439 int64 old_version, |
432 scoped_ptr<IndexedDBConnection> connection, | 440 scoped_ptr<IndexedDBConnection> connection, |
433 const content::IndexedDBDatabaseMetadata& metadata) OVERRIDE { | 441 const content::IndexedDBDatabaseMetadata& metadata) OVERRIDE { |
434 connection_ = connection.Pass(); | 442 connection_ = connection.Pass(); |
435 } | 443 } |
436 | 444 |
437 protected: | 445 protected: |
438 virtual ~UpgradeNeededCallbacks() {} | 446 virtual ~UpgradeNeededCallbacks() {} |
| 447 |
| 448 private: |
| 449 DISALLOW_COPY_AND_ASSIGN(UpgradeNeededCallbacks); |
439 }; | 450 }; |
440 | 451 |
441 class ErrorCallbacks : public MockIndexedDBCallbacks { | 452 class ErrorCallbacks : public MockIndexedDBCallbacks { |
442 public: | 453 public: |
443 ErrorCallbacks() : MockIndexedDBCallbacks(false), saw_error_(false) {} | 454 ErrorCallbacks() : MockIndexedDBCallbacks(false), saw_error_(false) {} |
444 | 455 |
445 virtual void OnError(const IndexedDBDatabaseError& error) OVERRIDE { | 456 virtual void OnError(const IndexedDBDatabaseError& error) OVERRIDE { |
446 saw_error_= true; | 457 saw_error_= true; |
447 } | 458 } |
448 bool saw_error() const { return saw_error_; } | 459 bool saw_error() const { return saw_error_; } |
449 | 460 |
450 private: | 461 private: |
451 virtual ~ErrorCallbacks() {} | 462 virtual ~ErrorCallbacks() {} |
452 bool saw_error_; | 463 bool saw_error_; |
| 464 |
| 465 DISALLOW_COPY_AND_ASSIGN(ErrorCallbacks); |
453 }; | 466 }; |
454 | 467 |
455 TEST_F(IndexedDBFactoryTest, DatabaseFailedOpen) { | 468 TEST_F(IndexedDBFactoryTest, DatabaseFailedOpen) { |
456 GURL origin("http://localhost:81"); | 469 GURL origin("http://localhost:81"); |
457 | 470 |
458 base::ScopedTempDir temp_directory; | 471 base::ScopedTempDir temp_directory; |
459 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 472 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
460 | 473 |
461 const base::string16 db_name(ASCIIToUTF16("db")); | 474 const base::string16 db_name(ASCIIToUTF16("db")); |
462 const int64 db_version = 2; | 475 const int64 db_version = 2; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 temp_directory.path()); | 518 temp_directory.path()); |
506 EXPECT_TRUE(callbacks->saw_error()); | 519 EXPECT_TRUE(callbacks->saw_error()); |
507 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); | 520 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); |
508 } | 521 } |
509 | 522 |
510 // Terminate all pending-close timers. | 523 // Terminate all pending-close timers. |
511 factory()->ForceClose(origin); | 524 factory()->ForceClose(origin); |
512 } | 525 } |
513 | 526 |
514 } // namespace content | 527 } // namespace content |
OLD | NEW |