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 <memory> |
8 #include <set> | 9 #include <set> |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
11 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "content/browser/indexed_db/indexed_db.h" | 19 #include "content/browser/indexed_db/indexed_db.h" |
19 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 20 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
20 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 21 #include "content/browser/indexed_db/indexed_db_change_handler.h" |
21 #include "content/browser/indexed_db/indexed_db_class_factory.h" | 22 #include "content/browser/indexed_db/indexed_db_class_factory.h" |
22 #include "content/browser/indexed_db/indexed_db_connection.h" | 23 #include "content/browser/indexed_db/indexed_db_connection.h" |
23 #include "content/browser/indexed_db/indexed_db_cursor.h" | 24 #include "content/browser/indexed_db/indexed_db_cursor.h" |
24 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" | 25 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" |
| 26 #include "content/browser/indexed_db/indexed_db_open_request_observer.h" |
| 27 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
| 28 #include "content/browser/indexed_db/indexed_db_pending_delete.h" |
25 #include "content/browser/indexed_db/indexed_db_transaction.h" | 29 #include "content/browser/indexed_db/indexed_db_transaction.h" |
26 #include "content/browser/indexed_db/indexed_db_value.h" | 30 #include "content/browser/indexed_db/indexed_db_value.h" |
27 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" | 31 #include "content/browser/indexed_db/mock_callback_factory.h" |
28 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" | 32 #include "content/browser/indexed_db/mock_indexed_db_change_handler.h" |
29 #include "content/browser/indexed_db/mock_indexed_db_factory.h" | 33 #include "content/browser/indexed_db/mock_indexed_db_factory.h" |
| 34 #include "content/browser/indexed_db/mock_indexed_db_open_request_observer.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
31 | 36 |
32 using base::ASCIIToUTF16; | 37 using base::ASCIIToUTF16; |
33 | 38 |
34 namespace { | 39 namespace { |
35 const int kFakeChildProcessId = 0; | 40 const int kFakeChildProcessId = 0; |
36 } | 41 } |
37 | 42 |
38 namespace content { | 43 namespace content { |
39 | 44 |
(...skipping 25 matching lines...) Expand all Loading... |
65 leveldb::Status s; | 70 leveldb::Status s; |
66 scoped_refptr<IndexedDBDatabase> db = | 71 scoped_refptr<IndexedDBDatabase> db = |
67 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 72 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
68 backing_store.get(), | 73 backing_store.get(), |
69 factory.get(), | 74 factory.get(), |
70 IndexedDBDatabase::Identifier(), | 75 IndexedDBDatabase::Identifier(), |
71 &s); | 76 &s); |
72 ASSERT_TRUE(s.ok()); | 77 ASSERT_TRUE(s.ok()); |
73 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 78 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
74 | 79 |
75 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); | 80 MockCallbackFactory callback_factory1; |
76 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( | 81 scoped_refptr<MockIndexedDBChangeHandler> change_handler1( |
77 new MockIndexedDBDatabaseCallbacks()); | 82 new MockIndexedDBChangeHandler()); |
78 const int64_t transaction_id1 = 1; | 83 const int64_t transaction_id1 = 1; |
| 84 scoped_refptr<MockIndexedDBOpenRequestObserver> open_observer1 = |
| 85 new MockIndexedDBOpenRequestObserver(); |
| 86 // TODO(cmumford): No idea if I can use an empty origin. |
| 87 const url::Origin origin; |
79 std::unique_ptr<IndexedDBPendingConnection> connection1( | 88 std::unique_ptr<IndexedDBPendingConnection> connection1( |
80 base::MakeUnique<IndexedDBPendingConnection>( | 89 base::MakeUnique<IndexedDBPendingConnection>( |
81 request1, callbacks1, kFakeChildProcessId, transaction_id1, | 90 callback_factory1.CreateOpenCallback(), change_handler1, |
82 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 91 open_observer1, kFakeChildProcessId, transaction_id1, |
| 92 IndexedDBDatabaseMetadata::DEFAULT_VERSION, origin)); |
83 db->OpenConnection(std::move(connection1)); | 93 db->OpenConnection(std::move(connection1)); |
84 | 94 |
85 EXPECT_FALSE(backing_store->HasOneRef()); // db, connection count > 0 | 95 EXPECT_FALSE(backing_store->HasOneRef()); // db, connection count > 0 |
86 | 96 |
87 scoped_refptr<MockIndexedDBCallbacks> request2(new MockIndexedDBCallbacks()); | 97 scoped_refptr<MockIndexedDBOpenRequestObserver> open_observer2 = |
88 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks2( | 98 new MockIndexedDBOpenRequestObserver(); |
89 new MockIndexedDBDatabaseCallbacks()); | 99 scoped_refptr<MockIndexedDBChangeHandler> change_handler2( |
| 100 new MockIndexedDBChangeHandler()); |
90 const int64_t transaction_id2 = 2; | 101 const int64_t transaction_id2 = 2; |
| 102 MockCallbackFactory callback_factory2; |
91 std::unique_ptr<IndexedDBPendingConnection> connection2( | 103 std::unique_ptr<IndexedDBPendingConnection> connection2( |
92 base::MakeUnique<IndexedDBPendingConnection>( | 104 base::MakeUnique<IndexedDBPendingConnection>( |
93 request2, callbacks2, kFakeChildProcessId, transaction_id2, | 105 callback_factory2.CreateOpenCallback(), change_handler2, |
94 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 106 open_observer2, kFakeChildProcessId, transaction_id2, |
| 107 IndexedDBDatabaseMetadata::DEFAULT_VERSION, origin)); |
95 db->OpenConnection(std::move(connection2)); | 108 db->OpenConnection(std::move(connection2)); |
96 | 109 |
97 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection | 110 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection |
98 | 111 |
99 request1->connection()->ForceClose(); | 112 callback_factory1.connection()->ForceClose(); |
100 EXPECT_FALSE(request1->connection()->IsConnected()); | 113 EXPECT_FALSE(callback_factory1.connection()->IsConnected()); |
101 | 114 |
102 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection | 115 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection |
103 | 116 |
104 request2->connection()->ForceClose(); | 117 callback_factory2.connection()->ForceClose(); |
105 EXPECT_FALSE(request2->connection()->IsConnected()); | 118 EXPECT_FALSE(callback_factory2.connection()->IsConnected()); |
106 | 119 |
107 EXPECT_TRUE(backing_store->HasOneRef()); | 120 EXPECT_TRUE(backing_store->HasOneRef()); |
108 EXPECT_FALSE(db->backing_store()); | 121 EXPECT_FALSE(db->backing_store()); |
109 | 122 |
110 db = NULL; | 123 db = NULL; |
111 } | 124 } |
112 | 125 |
113 TEST(IndexedDBDatabaseTest, ForcedClose) { | 126 TEST(IndexedDBDatabaseTest, ForcedClose) { |
114 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 127 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
115 new IndexedDBFakeBackingStore(); | 128 new IndexedDBFakeBackingStore(); |
116 EXPECT_TRUE(backing_store->HasOneRef()); | 129 EXPECT_TRUE(backing_store->HasOneRef()); |
117 | 130 |
118 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); | 131 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); |
119 leveldb::Status s; | 132 leveldb::Status s; |
120 scoped_refptr<IndexedDBDatabase> database = | 133 scoped_refptr<IndexedDBDatabase> database = |
121 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 134 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
122 backing_store.get(), | 135 backing_store.get(), |
123 factory.get(), | 136 factory.get(), |
124 IndexedDBDatabase::Identifier(), | 137 IndexedDBDatabase::Identifier(), |
125 &s); | 138 &s); |
126 ASSERT_TRUE(s.ok()); | 139 ASSERT_TRUE(s.ok()); |
127 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 140 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
128 | 141 |
129 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks( | 142 scoped_refptr<MockIndexedDBChangeHandler> change_handler( |
130 new MockIndexedDBDatabaseCallbacks()); | 143 new MockIndexedDBChangeHandler()); |
131 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks()); | 144 MockCallbackFactory callback_factory; |
132 const int64_t upgrade_transaction_id = 3; | 145 const int64_t upgrade_transaction_id = 3; |
| 146 // TODO(cmumford): No idea if I can use an empty origin. |
| 147 const url::Origin test_origin; |
| 148 scoped_refptr<MockIndexedDBOpenRequestObserver> open_observer = |
| 149 new MockIndexedDBOpenRequestObserver(); |
133 std::unique_ptr<IndexedDBPendingConnection> connection( | 150 std::unique_ptr<IndexedDBPendingConnection> connection( |
134 base::MakeUnique<IndexedDBPendingConnection>( | 151 base::MakeUnique<IndexedDBPendingConnection>( |
135 request, callbacks, kFakeChildProcessId, upgrade_transaction_id, | 152 callback_factory.CreateOpenCallback(), change_handler, open_observer, |
136 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 153 kFakeChildProcessId, upgrade_transaction_id, |
| 154 IndexedDBDatabaseMetadata::DEFAULT_VERSION, test_origin)); |
137 database->OpenConnection(std::move(connection)); | 155 database->OpenConnection(std::move(connection)); |
138 EXPECT_EQ(database.get(), request->connection()->database()); | 156 EXPECT_EQ(database.get(), callback_factory.connection()->database()); |
139 | 157 |
140 const int64_t transaction_id = 123; | 158 const int64_t transaction_id = 123; |
141 const std::vector<int64_t> scope; | 159 const std::vector<int64_t> scope; |
142 database->CreateTransaction(transaction_id, | 160 database->CreateTransaction(transaction_id, callback_factory.connection(), |
143 request->connection(), | 161 scope, blink::WebIDBTransactionModeReadOnly); |
144 scope, | |
145 blink::WebIDBTransactionModeReadOnly); | |
146 | 162 |
147 request->connection()->ForceClose(); | 163 callback_factory.connection()->ForceClose(); |
148 | 164 |
149 EXPECT_TRUE(backing_store->HasOneRef()); // local | 165 EXPECT_TRUE(backing_store->HasOneRef()); // local |
150 EXPECT_TRUE(callbacks->abort_called()); | 166 EXPECT_TRUE(change_handler->abort_called()); |
151 } | 167 } |
152 | 168 |
153 class MockDeleteCallbacks : public IndexedDBCallbacks { | |
154 public: | |
155 MockDeleteCallbacks() | |
156 : IndexedDBCallbacks(NULL, 0, 0), | |
157 blocked_called_(false), | |
158 success_called_(false) {} | |
159 | |
160 void OnBlocked(int64_t existing_version) override { blocked_called_ = true; } | |
161 void OnSuccess(int64_t result) override { success_called_ = true; } | |
162 | |
163 bool blocked_called() const { return blocked_called_; } | |
164 bool success_called() const { return success_called_; } | |
165 | |
166 private: | |
167 ~MockDeleteCallbacks() override {} | |
168 | |
169 bool blocked_called_; | |
170 bool success_called_; | |
171 | |
172 DISALLOW_COPY_AND_ASSIGN(MockDeleteCallbacks); | |
173 }; | |
174 | |
175 TEST(IndexedDBDatabaseTest, PendingDelete) { | 169 TEST(IndexedDBDatabaseTest, PendingDelete) { |
176 scoped_refptr<IndexedDBFakeBackingStore> backing_store = | 170 scoped_refptr<IndexedDBFakeBackingStore> backing_store = |
177 new IndexedDBFakeBackingStore(); | 171 new IndexedDBFakeBackingStore(); |
178 EXPECT_TRUE(backing_store->HasOneRef()); // local | 172 EXPECT_TRUE(backing_store->HasOneRef()); // local |
179 | 173 |
180 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); | 174 scoped_refptr<MockIndexedDBFactory> factory = new MockIndexedDBFactory(); |
181 leveldb::Status s; | 175 leveldb::Status s; |
182 scoped_refptr<IndexedDBDatabase> db = | 176 scoped_refptr<IndexedDBDatabase> db = |
183 IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 177 IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
184 backing_store.get(), | 178 backing_store.get(), |
185 factory.get(), | 179 factory.get(), |
186 IndexedDBDatabase::Identifier(), | 180 IndexedDBDatabase::Identifier(), |
187 &s); | 181 &s); |
188 ASSERT_TRUE(s.ok()); | 182 ASSERT_TRUE(s.ok()); |
189 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 183 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
190 | 184 |
191 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); | 185 MockCallbackFactory callback_factory; |
192 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( | 186 scoped_refptr<MockIndexedDBOpenRequestObserver> open_observer1 = |
193 new MockIndexedDBDatabaseCallbacks()); | 187 new MockIndexedDBOpenRequestObserver(); |
| 188 scoped_refptr<MockIndexedDBChangeHandler> open_change_handler( |
| 189 new MockIndexedDBChangeHandler()); |
194 const int64_t transaction_id1 = 1; | 190 const int64_t transaction_id1 = 1; |
| 191 // TODO(cmumford): No idea if I can use an empty origin. |
| 192 const url::Origin test_origin; |
195 std::unique_ptr<IndexedDBPendingConnection> connection( | 193 std::unique_ptr<IndexedDBPendingConnection> connection( |
196 base::MakeUnique<IndexedDBPendingConnection>( | 194 base::MakeUnique<IndexedDBPendingConnection>( |
197 request1, callbacks1, kFakeChildProcessId, transaction_id1, | 195 callback_factory.CreateOpenCallback(), open_change_handler, |
198 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 196 open_observer1, kFakeChildProcessId, transaction_id1, |
| 197 IndexedDBDatabaseMetadata::DEFAULT_VERSION, test_origin)); |
199 db->OpenConnection(std::move(connection)); | 198 db->OpenConnection(std::move(connection)); |
200 | 199 |
201 EXPECT_EQ(db->ConnectionCount(), 1UL); | 200 EXPECT_EQ(db->ConnectionCount(), 1UL); |
202 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); | 201 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); |
203 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); | 202 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
204 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 203 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
205 | 204 |
206 scoped_refptr<MockDeleteCallbacks> request2(new MockDeleteCallbacks()); | 205 scoped_refptr<MockIndexedDBOpenRequestObserver> delete_observer = |
207 db->DeleteDatabase(request2); | 206 new MockIndexedDBOpenRequestObserver(); |
| 207 scoped_refptr<MockIndexedDBChangeHandler> delete_change_handler( |
| 208 new MockIndexedDBChangeHandler()); |
| 209 std::unique_ptr<IndexedDBPendingDelete> pending_delete( |
| 210 new IndexedDBPendingDelete(callback_factory.CreateDeleteCallback(), |
| 211 delete_change_handler, delete_observer)); |
| 212 db->DeleteDatabase(std::move(pending_delete)); |
208 EXPECT_EQ(db->ConnectionCount(), 1UL); | 213 EXPECT_EQ(db->ConnectionCount(), 1UL); |
209 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); | 214 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); |
210 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); | 215 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
211 | 216 |
212 EXPECT_FALSE(request2->blocked_called()); | 217 EXPECT_FALSE(delete_observer->blocked_called()); |
213 db->VersionChangeIgnored(); | 218 db->VersionChangeIgnored(); |
214 EXPECT_TRUE(request2->blocked_called()); | 219 EXPECT_TRUE(delete_observer->blocked_called()); |
215 EXPECT_EQ(db->ConnectionCount(), 1UL); | 220 EXPECT_EQ(db->ConnectionCount(), 1UL); |
216 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); | 221 EXPECT_EQ(db->ActiveOpenDeleteCount(), 1UL); |
217 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); | 222 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
218 | 223 |
219 EXPECT_FALSE(backing_store->HasOneRef()); // local and db | 224 EXPECT_FALSE(backing_store->HasOneRef()); // local and db |
220 | 225 |
221 db->Close(request1->connection(), true /* forced */); | 226 db->Close(callback_factory.connection(), true /* forced */); |
222 EXPECT_EQ(db->ConnectionCount(), 0UL); | 227 EXPECT_EQ(db->ConnectionCount(), 0UL); |
223 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); | 228 EXPECT_EQ(db->ActiveOpenDeleteCount(), 0UL); |
224 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); | 229 EXPECT_EQ(db->PendingOpenDeleteCount(), 0UL); |
225 | 230 |
226 EXPECT_FALSE(db->backing_store()); | 231 EXPECT_FALSE(db->backing_store()); |
227 EXPECT_TRUE(backing_store->HasOneRef()); // local | 232 EXPECT_TRUE(backing_store->HasOneRef()); // local |
228 EXPECT_TRUE(request2->success_called()); | 233 EXPECT_TRUE(callback_factory.delete_result_called()); |
229 } | 234 } |
230 | 235 |
| 236 #ifdef CJM_IMPLEMENT_PUT |
231 void DummyOperation(IndexedDBTransaction* transaction) { | 237 void DummyOperation(IndexedDBTransaction* transaction) { |
232 } | 238 } |
233 | 239 |
234 class IndexedDBDatabaseOperationTest : public testing::Test { | 240 class IndexedDBDatabaseOperationTest : public testing::Test { |
235 public: | 241 public: |
236 IndexedDBDatabaseOperationTest() | 242 IndexedDBDatabaseOperationTest() |
237 : commit_success_(leveldb::Status::OK()), | 243 : commit_success_(leveldb::Status::OK()), |
238 factory_(new MockIndexedDBFactory()) {} | 244 factory_(new MockIndexedDBFactory()) {} |
239 | 245 |
240 void SetUp() override { | 246 void SetUp() override { |
241 backing_store_ = new IndexedDBFakeBackingStore(); | 247 backing_store_ = new IndexedDBFakeBackingStore(); |
242 leveldb::Status s; | 248 leveldb::Status s; |
243 db_ = IndexedDBDatabase::Create(ASCIIToUTF16("db"), | 249 db_ = IndexedDBDatabase::Create(ASCIIToUTF16("db"), |
244 backing_store_.get(), | 250 backing_store_.get(), |
245 factory_.get(), | 251 factory_.get(), |
246 IndexedDBDatabase::Identifier(), | 252 IndexedDBDatabase::Identifier(), |
247 &s); | 253 &s); |
248 ASSERT_TRUE(s.ok()); | 254 ASSERT_TRUE(s.ok()); |
249 | 255 |
250 request_ = new MockIndexedDBCallbacks(); | 256 request_ = new MockIndexedDBCallbacks(); |
251 callbacks_ = new MockIndexedDBDatabaseCallbacks(); | 257 scoped_refptr<MockIndexedDBChangeHandler> change_handler( |
| 258 new MockIndexedDBChangeHandler()); |
252 const int64_t transaction_id = 1; | 259 const int64_t transaction_id = 1; |
253 std::unique_ptr<IndexedDBPendingConnection> connection( | 260 std::unique_ptr<IndexedDBPendingConnection> connection( |
254 base::MakeUnique<IndexedDBPendingConnection>( | 261 base::MakeUnique<IndexedDBPendingConnection>( |
255 request_, callbacks_, kFakeChildProcessId, transaction_id, | 262 request_, callbacks_, kFakeChildProcessId, transaction_id, |
256 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); | 263 IndexedDBDatabaseMetadata::DEFAULT_VERSION)); |
257 db_->OpenConnection(std::move(connection)); | 264 db_->OpenConnection(std::move(connection)); |
258 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata().version); | 265 EXPECT_EQ(IndexedDBDatabaseMetadata::NO_VERSION, db_->metadata().version); |
259 | 266 |
260 connection_ = base::MakeUnique<IndexedDBConnection>(db_, callbacks_); | 267 connection_ = base::MakeUnique<IndexedDBConnection>(db_, callbacks_); |
261 transaction_ = IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( | 268 transaction_ = IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( |
262 transaction_id, connection_->GetWeakPtr(), | 269 transaction_id, connection_->GetWeakPtr(), |
263 std::set<int64_t>() /*scope*/, | 270 std::set<int64_t>() /*scope*/, |
264 blink::WebIDBTransactionModeVersionChange, | 271 blink::WebIDBTransactionModeVersionChange, |
265 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_)); | 272 new IndexedDBFakeBackingStore::FakeTransaction(commit_success_)); |
266 db_->TransactionCreated(transaction_.get()); | 273 db_->TransactionCreated(transaction_.get()); |
267 | 274 |
268 // Add a dummy task which takes the place of the VersionChangeOperation | 275 // Add a dummy task which takes the place of the VersionChangeOperation |
269 // which kicks off the upgrade. This ensures that the transaction has | 276 // which kicks off the upgrade. This ensures that the transaction has |
270 // processed at least one task before the CreateObjectStore call. | 277 // processed at least one task before the CreateObjectStore call. |
271 transaction_->ScheduleTask(base::Bind(&DummyOperation)); | 278 transaction_->ScheduleTask(base::Bind(&DummyOperation)); |
272 } | 279 } |
273 | 280 |
274 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); } | 281 void RunPostedTasks() { base::RunLoop().RunUntilIdle(); } |
275 | 282 |
276 protected: | 283 protected: |
277 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; | 284 scoped_refptr<IndexedDBFakeBackingStore> backing_store_; |
278 scoped_refptr<IndexedDBDatabase> db_; | 285 scoped_refptr<IndexedDBDatabase> db_; |
279 scoped_refptr<MockIndexedDBCallbacks> request_; | 286 scoped_refptr<MockIndexedDBCallbacks> request_; |
280 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks_; | 287 scoped_refptr<MockIndexedDBChangeHandler> change_handler_; |
281 scoped_refptr<IndexedDBTransaction> transaction_; | 288 scoped_refptr<IndexedDBTransaction> transaction_; |
282 std::unique_ptr<IndexedDBConnection> connection_; | 289 std::unique_ptr<IndexedDBConnection> connection_; |
283 | 290 |
284 leveldb::Status commit_success_; | 291 leveldb::Status commit_success_; |
285 | 292 |
286 private: | 293 private: |
287 base::MessageLoop message_loop_; | 294 base::MessageLoop message_loop_; |
288 scoped_refptr<MockIndexedDBFactory> factory_; | 295 scoped_refptr<MockIndexedDBFactory> factory_; |
289 | 296 |
290 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest); | 297 DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 db_->DeleteObjectStore(transaction_->id(), | 416 db_->DeleteObjectStore(transaction_->id(), |
410 store_id); | 417 store_id); |
411 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); | 418 EXPECT_EQ(1ULL, db_->metadata().object_stores.size()); |
412 | 419 |
413 // This will execute the Put then Delete. | 420 // This will execute the Put then Delete. |
414 RunPostedTasks(); | 421 RunPostedTasks(); |
415 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); | 422 EXPECT_EQ(0ULL, db_->metadata().object_stores.size()); |
416 | 423 |
417 transaction_->Commit(); // Cleans up the object hierarchy. | 424 transaction_->Commit(); // Cleans up the object hierarchy. |
418 } | 425 } |
| 426 #endif |
419 | 427 |
420 } // namespace content | 428 } // namespace content |
OLD | NEW |