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_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "content/browser/indexed_db/indexed_db.h" | 18 #include "content/browser/indexed_db/indexed_db.h" |
19 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 19 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
20 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 20 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
21 #include "content/browser/indexed_db/indexed_db_class_factory.h" | 21 #include "content/browser/indexed_db/indexed_db_class_factory.h" |
22 #include "content/browser/indexed_db/indexed_db_connection.h" | 22 #include "content/browser/indexed_db/indexed_db_connection.h" |
23 #include "content/browser/indexed_db/indexed_db_cursor.h" | 23 #include "content/browser/indexed_db/indexed_db_cursor.h" |
24 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" | 24 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" |
25 #include "content/browser/indexed_db/indexed_db_transaction.h" | 25 #include "content/browser/indexed_db/indexed_db_transaction.h" |
26 #include "content/browser/indexed_db/indexed_db_value.h" | 26 #include "content/browser/indexed_db/indexed_db_value.h" |
27 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" | 27 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" |
28 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" | 28 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" |
29 #include "content/browser/indexed_db/mock_indexed_db_factory.h" | 29 #include "content/browser/indexed_db/mock_indexed_db_factory.h" |
30 #include "content/public/test/test_browser_thread_bundle.h" | |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 | 32 |
32 using base::ASCIIToUTF16; | 33 using base::ASCIIToUTF16; |
33 | 34 |
34 namespace { | 35 namespace { |
35 const int kFakeChildProcessId = 0; | 36 const int kFakeChildProcessId = 0; |
36 } | 37 } |
37 | 38 |
38 namespace content { | 39 namespace content { |
39 | 40 |
(...skipping 10 matching lines...) Expand all Loading... | |
50 factory.get(), | 51 factory.get(), |
51 IndexedDBDatabase::Identifier(), | 52 IndexedDBDatabase::Identifier(), |
52 &s); | 53 &s); |
53 ASSERT_TRUE(s.ok()); | 54 ASSERT_TRUE(s.ok()); |
54 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 55 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
55 db = NULL; | 56 db = NULL; |
56 EXPECT_TRUE(backing_store->HasOneRef()); // local | 57 EXPECT_TRUE(backing_store->HasOneRef()); // local |
57 } | 58 } |
58 | 59 |
59 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) { | 60 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) { |
61 content::TestBrowserThreadBundle thread_bundle; | |
60 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 62 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
61 new IndexedDBFakeBackingStore(); | 63 new IndexedDBFakeBackingStore(); |
62 EXPECT_TRUE(backing_store->HasOneRef()); // local | 64 EXPECT_TRUE(backing_store->HasOneRef()); // local |
63 | 65 |
64 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); | 66 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); |
65 leveldb::Status s; | 67 leveldb::Status s; |
66 scoped_refptr<IndexedDBDatabase> db = | 68 scoped_refptr<IndexedDBDatabase> db = |
67 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 69 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
68 backing_store.get(), | 70 backing_store.get(), |
69 factory.get(), | 71 factory.get(), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 request2->connection()->ForceClose(); | 106 request2->connection()->ForceClose(); |
105 EXPECT_FALSE(request2->connection()->IsConnected()); | 107 EXPECT_FALSE(request2->connection()->IsConnected()); |
106 | 108 |
107 EXPECT_TRUE(backing_store->HasOneRef()); | 109 EXPECT_TRUE(backing_store->HasOneRef()); |
108 EXPECT_FALSE(db->backing_store()); | 110 EXPECT_FALSE(db->backing_store()); |
109 | 111 |
110 db = NULL; | 112 db = NULL; |
111 } | 113 } |
112 | 114 |
113 TEST(IndexedDBDatabaseTest, ForcedClose) { | 115 TEST(IndexedDBDatabaseTest, ForcedClose) { |
116 content::TestBrowserThreadBundle thread_bundle; | |
dcheng
2016/10/19 23:44:02
Not necessary in this CL, but having a test fixtur
| |
114 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 117 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
115 new IndexedDBFakeBackingStore(); | 118 new IndexedDBFakeBackingStore(); |
116 EXPECT_TRUE(backing_store->HasOneRef()); | 119 EXPECT_TRUE(backing_store->HasOneRef()); |
117 | 120 |
118 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); | 121 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); |
119 leveldb::Status s; | 122 leveldb::Status s; |
120 scoped_refptr<IndexedDBDatabase> database = | 123 scoped_refptr<IndexedDBDatabase> database = |
121 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 124 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
122 backing_store.get(), | 125 backing_store.get(), |
123 factory.get(), | 126 factory.get(), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 | 174 |
172 bool blocked_called_ = false; | 175 bool blocked_called_ = false; |
173 bool success_called_ = false; | 176 bool success_called_ = false; |
174 bool error_called_ = false; | 177 bool error_called_ = false; |
175 bool valid_ = true; | 178 bool valid_ = true; |
176 | 179 |
177 DISALLOW_COPY_AND_ASSIGN(MockCallbacks); | 180 DISALLOW_COPY_AND_ASSIGN(MockCallbacks); |
178 }; | 181 }; |
179 | 182 |
180 TEST(IndexedDBDatabaseTest, PendingDelete) { | 183 TEST(IndexedDBDatabaseTest, PendingDelete) { |
184 content::TestBrowserThreadBundle thread_bundle; | |
181 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 185 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
182 new IndexedDBFakeBackingStore(); | 186 new IndexedDBFakeBackingStore(); |
183 EXPECT_TRUE(backing_store->HasOneRef()); // local | 187 EXPECT_TRUE(backing_store->HasOneRef()); // local |
184 | 188 |
185 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); | 189 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); |
186 leveldb::Status s; | 190 leveldb::Status s; |
187 scoped_refptr<IndexedDBDatabase> db = | 191 scoped_refptr<IndexedDBDatabase> db = |
188 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 192 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
189 backing_store.get(), | 193 backing_store.get(), |
190 factory.get(), | 194 factory.get(), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 EXPECT_EQ(db->ConnectionCount(), 0UL); | 231 EXPECT_EQ(db->ConnectionCount(), 0UL); |
228 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); | 232 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); |
229 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); | 233 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
230 | 234 |
231 EXPECT_FALSE(db->backing_store()); | 235 EXPECT_FALSE(db->backing_store()); |
232 EXPECT_TRUE(backing_store->HasOneRef()); // local | 236 EXPECT_TRUE(backing_store->HasOneRef()); // local |
233 EXPECT_TRUE(request2->success_called()); | 237 EXPECT_TRUE(request2->success_called()); |
234 } | 238 } |
235 | 239 |
236 TEST(IndexedDBDatabaseTest, ConnectionRequestsNoLongerValid) { | 240 TEST(IndexedDBDatabaseTest, ConnectionRequestsNoLongerValid) { |
241 content::TestBrowserThreadBundle thread_bundle; | |
237 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 242 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
238 new IndexedDBFakeBackingStore(); | 243 new IndexedDBFakeBackingStore(); |
239 | 244 |
240 const int64_t transaction_id1 = 1; | 245 const int64_t transaction_id1 = 1; |
241 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); | 246 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); |
242 leveldb::Status s; | 247 leveldb::Status s; |
243 scoped_refptr<IndexedDBDatabase> db = IndexedDBDatabase::Create( | 248 scoped_refptr<IndexedDBDatabase> db = IndexedDBDatabase::Create( |
244 ASCIIToUTF16("db"), backing_store.get(), factory.get(), | 249 ASCIIToUTF16("db"), backing_store.get(), factory.get(), |
245 IndexedDBDatabase::Identifier(), &s); | 250 IndexedDBDatabase::Identifier(), &s); |
246 | 251 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; | 388 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; |
384 scoped_refptr<IndexedDBDatabase> db_; | 389 scoped_refptr<IndexedDBDatabase> db_; |
385 scoped_refptr<MockIndexedDBCallbacks> request_; | 390 scoped_refptr<MockIndexedDBCallbacks> request_; |
386 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_; | 391 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_; |
387 scoped_refptr<IndexedDBTransaction> transaction_; | 392 scoped_refptr<IndexedDBTransaction> transaction_; |
388 std::unique_ptr<IndexedDBConnection> connection_; | 393 std::unique_ptr<IndexedDBConnection> connection_; |
389 | 394 |
390 leveldb::Status commit_success_; | 395 leveldb::Status commit_success_; |
391 | 396 |
392 private: | 397 private: |
393 base::MessageLoop message_loop_; | |
394 scoped_refptr<MockIndexedDBFactory> factory_; | 398 scoped_refptr<MockIndexedDBFactory> factory_; |
399 content::TestBrowserThreadBundle thread_bundle_; | |
395 | 400 |
396 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest); | 401 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest); |
397 }; | 402 }; |
398 | 403 |
399 TEST_F(IndexedDBDatabaseOperationTest, CreateObjectStore) { | 404 TEST_F(IndexedDBDatabaseOperationTest, CreateObjectStore) { |
400 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); | 405 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); |
401 const int64_t store_id = 1001; | 406 const int64_t store_id = 1001; |
402 db_->CreateObjectStore(transaction_->id(), | 407 db_->CreateObjectStore(transaction_->id(), |
403 store_id, | 408 store_id, |
404 ASCIIToUTF16("store"), | 409 ASCIIToUTF16("store"), |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); | 522 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); |
518 | 523 |
519 // This will execute the Put then Delete. | 524 // This will execute the Put then Delete. |
520 RunPostedTasks(); | 525 RunPostedTasks(); |
521 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); | 526 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); |
522 | 527 |
523 transaction_->Commit(); // Cleans up the object hierarchy. | 528 transaction_->Commit(); // Cleans up the object hierarchy. |
524 } | 529 } |
525 | 530 |
526 } // namespace content | 531 } // namespace content |
OLD | NEW |