| 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 25 matching lines...) Expand all Loading... |
| 36 public: | 36 public: |
| 37 explicit MockIDBFactory(IndexedDBContextImpl* context) | 37 explicit MockIDBFactory(IndexedDBContextImpl* context) |
| 38 : IndexedDBFactoryImpl(context) {} | 38 : IndexedDBFactoryImpl(context) {} |
| 39 scoped_refptr<IndexedDBBackingStore> TestOpenBackingStore( | 39 scoped_refptr<IndexedDBBackingStore> TestOpenBackingStore( |
| 40 const Origin& origin, | 40 const Origin& origin, |
| 41 const base::FilePath& data_directory) { | 41 const base::FilePath& data_directory) { |
| 42 IndexedDBDataLossInfo data_loss_info; | 42 IndexedDBDataLossInfo data_loss_info; |
| 43 bool disk_full; | 43 bool disk_full; |
| 44 leveldb::Status s; | 44 leveldb::Status s; |
| 45 scoped_refptr<IndexedDBBackingStore> backing_store = | 45 scoped_refptr<IndexedDBBackingStore> backing_store = |
| 46 OpenBackingStore(origin, data_directory, NULL /* request_context */, | 46 OpenBackingStore(origin, data_directory, nullptr /* request_context */, |
| 47 &data_loss_info, &disk_full, &s); | 47 &data_loss_info, &disk_full, &s); |
| 48 EXPECT_EQ(blink::WebIDBDataLossNone, data_loss_info.status); | 48 EXPECT_EQ(blink::WebIDBDataLossNone, data_loss_info.status); |
| 49 return backing_store; | 49 return backing_store; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void TestCloseBackingStore(IndexedDBBackingStore* backing_store) { | 52 void TestCloseBackingStore(IndexedDBBackingStore* backing_store) { |
| 53 CloseBackingStore(backing_store->origin()); | 53 CloseBackingStore(backing_store->origin()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void TestReleaseBackingStore(IndexedDBBackingStore* backing_store, | 56 void TestReleaseBackingStore(IndexedDBBackingStore* backing_store, |
| 57 bool immediate) { | 57 bool immediate) { |
| 58 ReleaseBackingStore(backing_store->origin(), immediate); | 58 ReleaseBackingStore(backing_store->origin(), immediate); |
| 59 } | 59 } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 ~MockIDBFactory() override {} | 62 ~MockIDBFactory() override {} |
| 63 | 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(MockIDBFactory); | 64 DISALLOW_COPY_AND_ASSIGN(MockIDBFactory); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 } // namespace | 67 } // namespace |
| 68 | 68 |
| 69 class IndexedDBFactoryTest : public testing::Test { | 69 class IndexedDBFactoryTest : public testing::Test { |
| 70 public: | 70 public: |
| 71 IndexedDBFactoryTest() { | 71 IndexedDBFactoryTest() { |
| 72 task_runner_ = new base::TestSimpleTaskRunner(); | 72 task_runner_ = new base::TestSimpleTaskRunner(); |
| 73 quota_manager_proxy_ = new MockQuotaManagerProxy(nullptr, nullptr); | 73 quota_manager_proxy_ = new MockQuotaManagerProxy(nullptr, nullptr); |
| 74 context_ = new IndexedDBContextImpl( | 74 context_ = new IndexedDBContextImpl( |
| 75 base::FilePath(), NULL /* special_storage_policy */, | 75 base::FilePath(), nullptr /* special_storage_policy */, |
| 76 quota_manager_proxy_.get(), task_runner_.get()); | 76 quota_manager_proxy_.get(), task_runner_.get()); |
| 77 idb_factory_ = new MockIDBFactory(context_.get()); | 77 idb_factory_ = new MockIDBFactory(context_.get()); |
| 78 } | 78 } |
| 79 ~IndexedDBFactoryTest() override { | 79 ~IndexedDBFactoryTest() override { |
| 80 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); | 80 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 protected: | 83 protected: |
| 84 // For timers to post events. | 84 // For timers to post events. |
| 85 base::MessageLoop loop_; | 85 base::MessageLoop loop_; |
| 86 | 86 |
| 87 MockIDBFactory* factory() const { return idb_factory_.get(); } | 87 MockIDBFactory* factory() const { return idb_factory_.get(); } |
| 88 void clear_factory() { idb_factory_ = NULL; } | 88 void clear_factory() { idb_factory_ = nullptr; } |
| 89 IndexedDBContextImpl* context() const { return context_.get(); } | 89 IndexedDBContextImpl* context() const { return context_.get(); } |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 92 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 93 scoped_refptr<IndexedDBContextImpl> context_; | 93 scoped_refptr<IndexedDBContextImpl> context_; |
| 94 scoped_refptr<MockIDBFactory> idb_factory_; | 94 scoped_refptr<MockIDBFactory> idb_factory_; |
| 95 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; | 95 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; |
| 96 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactoryTest); | 96 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactoryTest); |
| 97 }; | 97 }; |
| 98 | 98 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 112 scoped_refptr<IndexedDBBackingStore> disk_store3 = | 112 scoped_refptr<IndexedDBBackingStore> disk_store3 = |
| 113 factory()->TestOpenBackingStore(origin2, temp_directory.path()); | 113 factory()->TestOpenBackingStore(origin2, temp_directory.path()); |
| 114 | 114 |
| 115 factory()->TestCloseBackingStore(disk_store1.get()); | 115 factory()->TestCloseBackingStore(disk_store1.get()); |
| 116 factory()->TestCloseBackingStore(disk_store3.get()); | 116 factory()->TestCloseBackingStore(disk_store3.get()); |
| 117 | 117 |
| 118 EXPECT_FALSE(disk_store1->HasOneRef()); | 118 EXPECT_FALSE(disk_store1->HasOneRef()); |
| 119 EXPECT_FALSE(disk_store2->HasOneRef()); | 119 EXPECT_FALSE(disk_store2->HasOneRef()); |
| 120 EXPECT_TRUE(disk_store3->HasOneRef()); | 120 EXPECT_TRUE(disk_store3->HasOneRef()); |
| 121 | 121 |
| 122 disk_store2 = NULL; | 122 disk_store2 = nullptr; |
| 123 EXPECT_TRUE(disk_store1->HasOneRef()); | 123 EXPECT_TRUE(disk_store1->HasOneRef()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 TEST_F(IndexedDBFactoryTest, BackingStoreLazyClose) { | 126 TEST_F(IndexedDBFactoryTest, BackingStoreLazyClose) { |
| 127 const Origin origin(GURL("http://localhost:81")); | 127 const Origin origin(GURL("http://localhost:81")); |
| 128 | 128 |
| 129 base::ScopedTempDir temp_directory; | 129 base::ScopedTempDir temp_directory; |
| 130 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 130 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 131 scoped_refptr<IndexedDBBackingStore> store = | 131 scoped_refptr<IndexedDBBackingStore> store = |
| 132 factory()->TestOpenBackingStore(origin, temp_directory.path()); | 132 factory()->TestOpenBackingStore(origin, temp_directory.path()); |
| 133 | 133 |
| 134 // Give up the local refptr so that the factory has the only | 134 // Give up the local refptr so that the factory has the only |
| 135 // outstanding reference. | 135 // outstanding reference. |
| 136 IndexedDBBackingStore* store_ptr = store.get(); | 136 IndexedDBBackingStore* store_ptr = store.get(); |
| 137 store = NULL; | 137 store = nullptr; |
| 138 EXPECT_FALSE(store_ptr->close_timer()->IsRunning()); | 138 EXPECT_FALSE(store_ptr->close_timer()->IsRunning()); |
| 139 factory()->TestReleaseBackingStore(store_ptr, false); | 139 factory()->TestReleaseBackingStore(store_ptr, false); |
| 140 EXPECT_TRUE(store_ptr->close_timer()->IsRunning()); | 140 EXPECT_TRUE(store_ptr->close_timer()->IsRunning()); |
| 141 | 141 |
| 142 factory()->TestOpenBackingStore(origin, temp_directory.path()); | 142 factory()->TestOpenBackingStore(origin, temp_directory.path()); |
| 143 EXPECT_FALSE(store_ptr->close_timer()->IsRunning()); | 143 EXPECT_FALSE(store_ptr->close_timer()->IsRunning()); |
| 144 factory()->TestReleaseBackingStore(store_ptr, false); | 144 factory()->TestReleaseBackingStore(store_ptr, false); |
| 145 EXPECT_TRUE(store_ptr->close_timer()->IsRunning()); | 145 EXPECT_TRUE(store_ptr->close_timer()->IsRunning()); |
| 146 | 146 |
| 147 // Take back a ref ptr and ensure that the actual close | 147 // Take back a ref ptr and ensure that the actual close |
| (...skipping 22 matching lines...) Expand all Loading... |
| 170 | 170 |
| 171 EXPECT_FALSE(mem_store1->HasOneRef()); | 171 EXPECT_FALSE(mem_store1->HasOneRef()); |
| 172 EXPECT_FALSE(mem_store2->HasOneRef()); | 172 EXPECT_FALSE(mem_store2->HasOneRef()); |
| 173 EXPECT_FALSE(mem_store3->HasOneRef()); | 173 EXPECT_FALSE(mem_store3->HasOneRef()); |
| 174 | 174 |
| 175 clear_factory(); | 175 clear_factory(); |
| 176 EXPECT_FALSE(mem_store1->HasOneRef()); // mem_store1 and 2 | 176 EXPECT_FALSE(mem_store1->HasOneRef()); // mem_store1 and 2 |
| 177 EXPECT_FALSE(mem_store2->HasOneRef()); // mem_store1 and 2 | 177 EXPECT_FALSE(mem_store2->HasOneRef()); // mem_store1 and 2 |
| 178 EXPECT_TRUE(mem_store3->HasOneRef()); | 178 EXPECT_TRUE(mem_store3->HasOneRef()); |
| 179 | 179 |
| 180 mem_store2 = NULL; | 180 mem_store2 = nullptr; |
| 181 EXPECT_TRUE(mem_store1->HasOneRef()); | 181 EXPECT_TRUE(mem_store1->HasOneRef()); |
| 182 } | 182 } |
| 183 | 183 |
| 184 TEST_F(IndexedDBFactoryTest, RejectLongOrigins) { | 184 TEST_F(IndexedDBFactoryTest, RejectLongOrigins) { |
| 185 base::ScopedTempDir temp_directory; | 185 base::ScopedTempDir temp_directory; |
| 186 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 186 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 187 const base::FilePath base_path = temp_directory.path(); | 187 const base::FilePath base_path = temp_directory.path(); |
| 188 | 188 |
| 189 int limit = base::GetMaximumPathComponentLength(base_path); | 189 int limit = base::GetMaximumPathComponentLength(base_path); |
| 190 EXPECT_GT(limit, 0); | 190 EXPECT_GT(limit, 0); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 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 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks { | 228 class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks { |
| 229 public: | 229 public: |
| 230 LookingForQuotaErrorMockCallbacks() | 230 LookingForQuotaErrorMockCallbacks() |
| 231 : IndexedDBCallbacks(NULL, 0, 0), error_called_(false) {} | 231 : IndexedDBCallbacks(nullptr, 0, 0), error_called_(false) {} |
| 232 void OnError(const IndexedDBDatabaseError& error) override { | 232 void OnError(const IndexedDBDatabaseError& error) override { |
| 233 error_called_ = true; | 233 error_called_ = true; |
| 234 EXPECT_EQ(blink::WebIDBDatabaseExceptionQuotaError, error.code()); | 234 EXPECT_EQ(blink::WebIDBDatabaseExceptionQuotaError, error.code()); |
| 235 } | 235 } |
| 236 bool error_called() const { return error_called_; } | 236 bool error_called() const { return error_called_; } |
| 237 | 237 |
| 238 private: | 238 private: |
| 239 ~LookingForQuotaErrorMockCallbacks() override {} | 239 ~LookingForQuotaErrorMockCallbacks() override {} |
| 240 bool error_called_; | 240 bool error_called_; |
| 241 | 241 |
| 242 DISALLOW_COPY_AND_ASSIGN(LookingForQuotaErrorMockCallbacks); | 242 DISALLOW_COPY_AND_ASSIGN(LookingForQuotaErrorMockCallbacks); |
| 243 }; | 243 }; |
| 244 | 244 |
| 245 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { | 245 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { |
| 246 const Origin origin(GURL("http://localhost:81")); | 246 const Origin origin(GURL("http://localhost:81")); |
| 247 base::ScopedTempDir temp_directory; | 247 base::ScopedTempDir temp_directory; |
| 248 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 248 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 249 | 249 |
| 250 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory(context()); | 250 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory(context()); |
| 251 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = | 251 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = |
| 252 new LookingForQuotaErrorMockCallbacks; | 252 new LookingForQuotaErrorMockCallbacks; |
| 253 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks = | 253 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks = |
| 254 new IndexedDBDatabaseCallbacks(NULL, 0, 0); | 254 new IndexedDBDatabaseCallbacks(nullptr, 0, 0); |
| 255 const base::string16 name(ASCIIToUTF16("name")); | 255 const base::string16 name(ASCIIToUTF16("name")); |
| 256 std::unique_ptr<IndexedDBPendingConnection> connection( | 256 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 257 new IndexedDBPendingConnection(callbacks, dummy_database_callbacks, | 257 base::MakeUnique<IndexedDBPendingConnection>( |
| 258 0, /* child_process_id */ | 258 callbacks, dummy_database_callbacks, 0 /* child_process_id */, |
| 259 2, /* transaction_id */ | 259 2 /* transaction_id */, 1 /* version */)); |
| 260 1 /* version */)); | 260 factory->Open(name, std::move(connection), nullptr /* request_context */, |
| 261 factory->Open(name, std::move(connection), NULL /* request_context */, origin, | 261 origin, temp_directory.path()); |
| 262 temp_directory.path()); | |
| 263 EXPECT_TRUE(callbacks->error_called()); | 262 EXPECT_TRUE(callbacks->error_called()); |
| 264 } | 263 } |
| 265 | 264 |
| 266 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) { | 265 TEST_F(IndexedDBFactoryTest, BackingStoreReleasedOnForcedClose) { |
| 267 const Origin origin(GURL("http://localhost:81")); | 266 const Origin origin(GURL("http://localhost:81")); |
| 268 | 267 |
| 269 base::ScopedTempDir temp_directory; | 268 base::ScopedTempDir temp_directory; |
| 270 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 269 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 271 | 270 |
| 272 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 271 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 273 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 272 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( |
| 274 new MockIndexedDBDatabaseCallbacks()); | 273 new MockIndexedDBDatabaseCallbacks()); |
| 275 const int64_t transaction_id = 1; | 274 const int64_t transaction_id = 1; |
| 276 std::unique_ptr<IndexedDBPendingConnection> connection( | 275 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 277 new IndexedDBPendingConnection( | 276 base::MakeUnique<IndexedDBPendingConnection>( |
| 278 callbacks, db_callbacks, 0, /* child_process_id */ | 277 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, |
| 279 transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 278 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
| 280 factory()->Open(ASCIIToUTF16("db"), std::move(connection), | 279 factory()->Open(ASCIIToUTF16("db"), std::move(connection), |
| 281 NULL /* request_context */, origin, temp_directory.path()); | 280 nullptr /* request_context */, origin, temp_directory.path()); |
| 282 | 281 |
| 283 EXPECT_TRUE(callbacks->connection()); | 282 EXPECT_TRUE(callbacks->connection()); |
| 284 | 283 |
| 285 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 284 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 286 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 285 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 287 | 286 |
| 288 callbacks->connection()->ForceClose(); | 287 callbacks->connection()->ForceClose(); |
| 289 | 288 |
| 290 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 289 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 291 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 290 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 292 } | 291 } |
| 293 | 292 |
| 294 TEST_F(IndexedDBFactoryTest, BackingStoreReleaseDelayedOnClose) { | 293 TEST_F(IndexedDBFactoryTest, BackingStoreReleaseDelayedOnClose) { |
| 295 const Origin origin(GURL("http://localhost:81")); | 294 const Origin origin(GURL("http://localhost:81")); |
| 296 | 295 |
| 297 base::ScopedTempDir temp_directory; | 296 base::ScopedTempDir temp_directory; |
| 298 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 297 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 299 | 298 |
| 300 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 299 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 301 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 300 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( |
| 302 new MockIndexedDBDatabaseCallbacks()); | 301 new MockIndexedDBDatabaseCallbacks()); |
| 303 const int64_t transaction_id = 1; | 302 const int64_t transaction_id = 1; |
| 304 std::unique_ptr<IndexedDBPendingConnection> connection( | 303 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 305 new IndexedDBPendingConnection( | 304 base::MakeUnique<IndexedDBPendingConnection>( |
| 306 callbacks, db_callbacks, 0, /* child_process_id */ | 305 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, |
| 307 transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 306 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
| 308 factory()->Open(ASCIIToUTF16("db"), std::move(connection), | 307 factory()->Open(ASCIIToUTF16("db"), std::move(connection), |
| 309 NULL /* request_context */, origin, temp_directory.path()); | 308 nullptr /* request_context */, origin, temp_directory.path()); |
| 310 | 309 |
| 311 EXPECT_TRUE(callbacks->connection()); | 310 EXPECT_TRUE(callbacks->connection()); |
| 312 IndexedDBBackingStore* store = | 311 IndexedDBBackingStore* store = |
| 313 callbacks->connection()->database()->backing_store(); | 312 callbacks->connection()->database()->backing_store(); |
| 314 EXPECT_FALSE(store->HasOneRef()); // Factory and database. | 313 EXPECT_FALSE(store->HasOneRef()); // Factory and database. |
| 315 | 314 |
| 316 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 315 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 317 callbacks->connection()->Close(); | 316 callbacks->connection()->Close(); |
| 318 EXPECT_TRUE(store->HasOneRef()); // Factory. | 317 EXPECT_TRUE(store->HasOneRef()); // Factory. |
| 319 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 318 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 334 const Origin origin(GURL("http://localhost:81")); | 333 const Origin origin(GURL("http://localhost:81")); |
| 335 | 334 |
| 336 base::ScopedTempDir temp_directory; | 335 base::ScopedTempDir temp_directory; |
| 337 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 336 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 338 | 337 |
| 339 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 338 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 340 | 339 |
| 341 const bool expect_connection = false; | 340 const bool expect_connection = false; |
| 342 scoped_refptr<MockIndexedDBCallbacks> callbacks( | 341 scoped_refptr<MockIndexedDBCallbacks> callbacks( |
| 343 new MockIndexedDBCallbacks(expect_connection)); | 342 new MockIndexedDBCallbacks(expect_connection)); |
| 344 factory()->DeleteDatabase(ASCIIToUTF16("db"), NULL /* request_context */, | 343 factory()->DeleteDatabase(ASCIIToUTF16("db"), nullptr /* request_context */, |
| 345 callbacks, origin, temp_directory.path()); | 344 callbacks, origin, temp_directory.path()); |
| 346 | 345 |
| 347 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 346 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 348 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); | 347 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); |
| 349 | 348 |
| 350 // Now simulate shutdown, which should stop the timer. | 349 // Now simulate shutdown, which should stop the timer. |
| 351 factory()->ContextDestroyed(); | 350 factory()->ContextDestroyed(); |
| 352 | 351 |
| 353 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 352 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 354 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 353 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 355 } | 354 } |
| 356 | 355 |
| 357 TEST_F(IndexedDBFactoryTest, GetDatabaseNamesClosesBackingStore) { | 356 TEST_F(IndexedDBFactoryTest, GetDatabaseNamesClosesBackingStore) { |
| 358 const Origin origin(GURL("http://localhost:81")); | 357 const Origin origin(GURL("http://localhost:81")); |
| 359 | 358 |
| 360 base::ScopedTempDir temp_directory; | 359 base::ScopedTempDir temp_directory; |
| 361 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 360 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 362 | 361 |
| 363 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 362 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 364 | 363 |
| 365 const bool expect_connection = false; | 364 const bool expect_connection = false; |
| 366 scoped_refptr<MockIndexedDBCallbacks> callbacks( | 365 scoped_refptr<MockIndexedDBCallbacks> callbacks( |
| 367 new MockIndexedDBCallbacks(expect_connection)); | 366 new MockIndexedDBCallbacks(expect_connection)); |
| 368 factory()->GetDatabaseNames(callbacks, origin, temp_directory.path(), | 367 factory()->GetDatabaseNames(callbacks, origin, temp_directory.path(), |
| 369 NULL /* request_context */); | 368 nullptr /* request_context */); |
| 370 | 369 |
| 371 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 370 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 372 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); | 371 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); |
| 373 | 372 |
| 374 // Now simulate shutdown, which should stop the timer. | 373 // Now simulate shutdown, which should stop the timer. |
| 375 factory()->ContextDestroyed(); | 374 factory()->ContextDestroyed(); |
| 376 | 375 |
| 377 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); | 376 EXPECT_FALSE(factory()->IsBackingStoreOpen(origin)); |
| 378 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 377 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 379 } | 378 } |
| 380 | 379 |
| 381 TEST_F(IndexedDBFactoryTest, ForceCloseReleasesBackingStore) { | 380 TEST_F(IndexedDBFactoryTest, ForceCloseReleasesBackingStore) { |
| 382 const Origin origin(GURL("http://localhost:81")); | 381 const Origin origin(GURL("http://localhost:81")); |
| 383 | 382 |
| 384 base::ScopedTempDir temp_directory; | 383 base::ScopedTempDir temp_directory; |
| 385 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); | 384 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); |
| 386 | 385 |
| 387 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); | 386 scoped_refptr<MockIndexedDBCallbacks> callbacks(new MockIndexedDBCallbacks()); |
| 388 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( | 387 scoped_refptr<MockIndexedDBDatabaseCallbacks> db_callbacks( |
| 389 new MockIndexedDBDatabaseCallbacks()); | 388 new MockIndexedDBDatabaseCallbacks()); |
| 390 const int64_t transaction_id = 1; | 389 const int64_t transaction_id = 1; |
| 391 std::unique_ptr<IndexedDBPendingConnection> connection( | 390 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 392 new IndexedDBPendingConnection( | 391 base::MakeUnique<IndexedDBPendingConnection>( |
| 393 callbacks, db_callbacks, 0, /* child_process_id */ | 392 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, |
| 394 transaction_id, IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 393 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
| 395 factory()->Open(ASCIIToUTF16("db"), std::move(connection), | 394 factory()->Open(ASCIIToUTF16("db"), std::move(connection), |
| 396 NULL /* request_context */, origin, temp_directory.path()); | 395 nullptr /* request_context */, origin, temp_directory.path()); |
| 397 | 396 |
| 398 EXPECT_TRUE(callbacks->connection()); | 397 EXPECT_TRUE(callbacks->connection()); |
| 399 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 398 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 400 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); | 399 EXPECT_FALSE(factory()->IsBackingStorePendingClose(origin)); |
| 401 | 400 |
| 402 callbacks->connection()->Close(); | 401 callbacks->connection()->Close(); |
| 403 | 402 |
| 404 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); | 403 EXPECT_TRUE(factory()->IsBackingStoreOpen(origin)); |
| 405 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); | 404 EXPECT_TRUE(factory()->IsBackingStorePendingClose(origin)); |
| 406 | 405 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 const int64_t db_version = 2; | 462 const int64_t db_version = 2; |
| 464 const int64_t transaction_id = 1; | 463 const int64_t transaction_id = 1; |
| 465 scoped_refptr<IndexedDBDatabaseCallbacks> db_callbacks( | 464 scoped_refptr<IndexedDBDatabaseCallbacks> db_callbacks( |
| 466 new MockIndexedDBDatabaseCallbacks()); | 465 new MockIndexedDBDatabaseCallbacks()); |
| 467 | 466 |
| 468 // Open at version 2, then close. | 467 // Open at version 2, then close. |
| 469 { | 468 { |
| 470 scoped_refptr<MockIndexedDBCallbacks> callbacks( | 469 scoped_refptr<MockIndexedDBCallbacks> callbacks( |
| 471 new UpgradeNeededCallbacks()); | 470 new UpgradeNeededCallbacks()); |
| 472 std::unique_ptr<IndexedDBPendingConnection> connection( | 471 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 473 new IndexedDBPendingConnection(callbacks, db_callbacks, | 472 base::MakeUnique<IndexedDBPendingConnection>( |
| 474 0, /* child_process_id */ | 473 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, |
| 475 transaction_id, db_version)); | 474 db_version)); |
| 476 factory()->Open(db_name, std::move(connection), NULL /* request_context */, | 475 factory()->Open(db_name, std::move(connection), |
| 477 origin, temp_directory.path()); | 476 nullptr /* request_context */, origin, |
| 477 temp_directory.path()); |
| 478 EXPECT_TRUE(factory()->IsDatabaseOpen(origin, db_name)); | 478 EXPECT_TRUE(factory()->IsDatabaseOpen(origin, db_name)); |
| 479 | 479 |
| 480 // Pump the message loop so the upgrade transaction can run. | 480 // Pump the message loop so the upgrade transaction can run. |
| 481 base::RunLoop().RunUntilIdle(); | 481 base::RunLoop().RunUntilIdle(); |
| 482 EXPECT_TRUE(callbacks->connection()); | 482 EXPECT_TRUE(callbacks->connection()); |
| 483 callbacks->connection()->database()->Commit(transaction_id); | 483 callbacks->connection()->database()->Commit(transaction_id); |
| 484 | 484 |
| 485 callbacks->connection()->Close(); | 485 callbacks->connection()->Close(); |
| 486 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); | 486 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); |
| 487 } | 487 } |
| 488 | 488 |
| 489 // Open at version < 2, which will fail; ensure factory doesn't retain | 489 // Open at version < 2, which will fail; ensure factory doesn't retain |
| 490 // the database object. | 490 // the database object. |
| 491 { | 491 { |
| 492 scoped_refptr<ErrorCallbacks> callbacks(new ErrorCallbacks()); | 492 scoped_refptr<ErrorCallbacks> callbacks(new ErrorCallbacks()); |
| 493 std::unique_ptr<IndexedDBPendingConnection> connection( | 493 std::unique_ptr<IndexedDBPendingConnection> connection( |
| 494 new IndexedDBPendingConnection(callbacks, db_callbacks, | 494 base::MakeUnique<IndexedDBPendingConnection>( |
| 495 0, /* child_process_id */ | 495 callbacks, db_callbacks, 0 /* child_process_id */, transaction_id, |
| 496 transaction_id, db_version - 1)); | 496 db_version - 1)); |
| 497 factory()->Open(db_name, std::move(connection), NULL /* request_context */, | 497 factory()->Open(db_name, std::move(connection), |
| 498 origin, temp_directory.path()); | 498 nullptr /* request_context */, origin, |
| 499 temp_directory.path()); |
| 499 EXPECT_TRUE(callbacks->saw_error()); | 500 EXPECT_TRUE(callbacks->saw_error()); |
| 500 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); | 501 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); |
| 501 } | 502 } |
| 502 | 503 |
| 503 // Terminate all pending-close timers. | 504 // Terminate all pending-close timers. |
| 504 factory()->ForceClose(origin); | 505 factory()->ForceClose(origin); |
| 505 } | 506 } |
| 506 | 507 |
| 507 } // namespace content | 508 } // namespace content |
| OLD | NEW |