OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 const GURL kOrigin; | 31 const GURL kOrigin; |
32 const string16 kKey; | 32 const string16 kKey; |
33 const string16 kValue; | 33 const string16 kValue; |
34 const string16 kKey2; | 34 const string16 kKey2; |
35 const string16 kValue2; | 35 const string16 kValue2; |
36 | 36 |
37 // Method used in the CommitTasks test case. | 37 // Method used in the CommitTasks test case. |
38 void InjectedCommitSequencingTask(DomStorageArea* area) { | 38 void InjectedCommitSequencingTask(DomStorageArea* area) { |
39 // At this point the OnCommitTimer has run. | 39 // At this point the OnCommitTimer has run. |
40 // Verify that it put a commit in flight. | 40 // Verify that it put a commit in flight. |
41 EXPECT_TRUE(area->in_flight_commit_batch_.get()); | 41 EXPECT_EQ(1, area->commit_batches_in_flight_); |
42 EXPECT_FALSE(area->commit_batch_.get()); | 42 EXPECT_FALSE(area->commit_batch_.get()); |
43 EXPECT_TRUE(area->HasUncommittedChanges()); | 43 EXPECT_TRUE(area->HasUncommittedChanges()); |
44 // Make additional change and verify that a new commit batch | 44 // Make additional change and verify that a new commit batch |
45 // is created for that change. | 45 // is created for that change. |
46 NullableString16 old_value; | 46 NullableString16 old_value; |
47 EXPECT_TRUE(area->SetItem(kKey2, kValue2, &old_value)); | 47 EXPECT_TRUE(area->SetItem(kKey2, kValue2, &old_value)); |
48 EXPECT_TRUE(area->commit_batch_.get()); | 48 EXPECT_TRUE(area->commit_batch_.get()); |
49 EXPECT_TRUE(area->in_flight_commit_batch_.get()); | 49 EXPECT_EQ(1, area->commit_batches_in_flight_); |
50 EXPECT_TRUE(area->HasUncommittedChanges()); | 50 EXPECT_TRUE(area->HasUncommittedChanges()); |
51 } | 51 } |
52 | 52 |
53 // Class used in the CommitChangesAtShutdown test case. | 53 // Class used in the CommitChangesAtShutdown test case. |
54 class VerifyChangesCommittedDatabase : public DomStorageDatabase { | 54 class VerifyChangesCommittedDatabase : public DomStorageDatabase { |
55 public: | 55 public: |
56 VerifyChangesCommittedDatabase() {} | 56 VerifyChangesCommittedDatabase() {} |
57 virtual ~VerifyChangesCommittedDatabase() { | 57 virtual ~VerifyChangesCommittedDatabase() { |
58 const string16 kKey(ASCIIToUTF16("key")); | 58 const string16 kKey(ASCIIToUTF16("key")); |
59 const string16 kValue(ASCIIToUTF16("value")); | 59 const string16 kValue(ASCIIToUTF16("value")); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // that a file is written to disk - DOMStorageDatabase unit tests cover | 167 // that a file is written to disk - DOMStorageDatabase unit tests cover |
168 // that. | 168 // that. |
169 area->backing_.reset(new DomStorageDatabase()); | 169 area->backing_.reset(new DomStorageDatabase()); |
170 | 170 |
171 // Need to write something to ensure that the database is created. | 171 // Need to write something to ensure that the database is created. |
172 NullableString16 old_value; | 172 NullableString16 old_value; |
173 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value)); | 173 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value)); |
174 ASSERT_TRUE(old_value.is_null()); | 174 ASSERT_TRUE(old_value.is_null()); |
175 EXPECT_TRUE(area->is_initial_import_done_); | 175 EXPECT_TRUE(area->is_initial_import_done_); |
176 EXPECT_TRUE(area->commit_batch_.get()); | 176 EXPECT_TRUE(area->commit_batch_.get()); |
177 EXPECT_FALSE(area->in_flight_commit_batch_.get()); | 177 EXPECT_EQ(0, area->commit_batches_in_flight_); |
178 | 178 |
179 MessageLoop::current()->RunAllPending(); | 179 MessageLoop::current()->RunAllPending(); |
180 | 180 |
181 EXPECT_FALSE(area->commit_batch_.get()); | 181 EXPECT_FALSE(area->commit_batch_.get()); |
182 EXPECT_FALSE(area->in_flight_commit_batch_.get()); | 182 EXPECT_EQ(0, area->commit_batches_in_flight_); |
183 EXPECT_TRUE(area->backing_->IsOpen()); | 183 EXPECT_TRUE(area->backing_->IsOpen()); |
184 EXPECT_EQ(1u, area->Length()); | 184 EXPECT_EQ(1u, area->Length()); |
185 EXPECT_EQ(kValue, area->GetItem(kKey).string()); | 185 EXPECT_EQ(kValue, area->GetItem(kKey).string()); |
186 | 186 |
187 // Verify the content made it to the in memory database. | 187 // Verify the content made it to the in memory database. |
188 ValuesMap values; | 188 ValuesMap values; |
189 area->backing_->ReadAllValues(&values); | 189 area->backing_->ReadAllValues(&values); |
190 EXPECT_EQ(1u, values.size()); | 190 EXPECT_EQ(1u, values.size()); |
191 EXPECT_EQ(kValue, values[kKey].string()); | 191 EXPECT_EQ(kValue, values[kKey].string()); |
192 } | 192 } |
(...skipping 26 matching lines...) Expand all Loading... |
219 EXPECT_TRUE(area->commit_batch_.get()); | 219 EXPECT_TRUE(area->commit_batch_.get()); |
220 EXPECT_FALSE(area->commit_batch_->clear_all_first); | 220 EXPECT_FALSE(area->commit_batch_->clear_all_first); |
221 EXPECT_EQ(1u, area->commit_batch_->changed_values.size()); | 221 EXPECT_EQ(1u, area->commit_batch_->changed_values.size()); |
222 EXPECT_TRUE(area->SetItem(kKey2, kValue2, &old_value)); | 222 EXPECT_TRUE(area->SetItem(kKey2, kValue2, &old_value)); |
223 EXPECT_TRUE(area->commit_batch_.get()); | 223 EXPECT_TRUE(area->commit_batch_.get()); |
224 EXPECT_FALSE(area->commit_batch_->clear_all_first); | 224 EXPECT_FALSE(area->commit_batch_->clear_all_first); |
225 EXPECT_EQ(2u, area->commit_batch_->changed_values.size()); | 225 EXPECT_EQ(2u, area->commit_batch_->changed_values.size()); |
226 MessageLoop::current()->RunAllPending(); | 226 MessageLoop::current()->RunAllPending(); |
227 EXPECT_FALSE(area->HasUncommittedChanges()); | 227 EXPECT_FALSE(area->HasUncommittedChanges()); |
228 EXPECT_FALSE(area->commit_batch_.get()); | 228 EXPECT_FALSE(area->commit_batch_.get()); |
229 EXPECT_FALSE(area->in_flight_commit_batch_.get()); | 229 EXPECT_EQ(0, area->commit_batches_in_flight_); |
230 // Verify the changes made it to the database. | 230 // Verify the changes made it to the database. |
231 values.clear(); | 231 values.clear(); |
232 area->backing_->ReadAllValues(&values); | 232 area->backing_->ReadAllValues(&values); |
233 EXPECT_EQ(2u, values.size()); | 233 EXPECT_EQ(2u, values.size()); |
234 EXPECT_EQ(kValue, values[kKey].string()); | 234 EXPECT_EQ(kValue, values[kKey].string()); |
235 EXPECT_EQ(kValue2, values[kKey2].string()); | 235 EXPECT_EQ(kValue2, values[kKey2].string()); |
236 | 236 |
237 // See that clear is handled properly. | 237 // See that clear is handled properly. |
238 EXPECT_TRUE(area->Clear()); | 238 EXPECT_TRUE(area->Clear()); |
239 EXPECT_TRUE(area->commit_batch_.get()); | 239 EXPECT_TRUE(area->commit_batch_.get()); |
240 EXPECT_TRUE(area->commit_batch_->clear_all_first); | 240 EXPECT_TRUE(area->commit_batch_->clear_all_first); |
241 EXPECT_TRUE(area->commit_batch_->changed_values.empty()); | 241 EXPECT_TRUE(area->commit_batch_->changed_values.empty()); |
242 MessageLoop::current()->RunAllPending(); | 242 MessageLoop::current()->RunAllPending(); |
243 EXPECT_FALSE(area->commit_batch_.get()); | 243 EXPECT_FALSE(area->commit_batch_.get()); |
244 EXPECT_FALSE(area->in_flight_commit_batch_.get()); | 244 EXPECT_EQ(0, area->commit_batches_in_flight_); |
245 // Verify the changes made it to the database. | 245 // Verify the changes made it to the database. |
246 values.clear(); | 246 values.clear(); |
247 area->backing_->ReadAllValues(&values); | 247 area->backing_->ReadAllValues(&values); |
248 EXPECT_TRUE(values.empty()); | 248 EXPECT_TRUE(values.empty()); |
249 | 249 |
250 // See that if changes accrue while a commit is "in flight" | 250 // See that if changes accrue while a commit is "in flight" |
251 // those will also get committed. | 251 // those will also get committed. |
252 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value)); | 252 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value)); |
253 EXPECT_TRUE(area->HasUncommittedChanges()); | 253 EXPECT_TRUE(area->HasUncommittedChanges()); |
254 // At this point the OnCommitTimer task has been posted. We inject | 254 // At this point the OnCommitTimer task has been posted. We inject |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 EXPECT_EQ( | 442 EXPECT_EQ( |
443 FilePath().AppendASCII("-journal"), | 443 FilePath().AppendASCII("-journal"), |
444 DomStorageDatabase::GetJournalFilePath(FilePath())); | 444 DomStorageDatabase::GetJournalFilePath(FilePath())); |
445 EXPECT_EQ( | 445 EXPECT_EQ( |
446 FilePath().AppendASCII(".extensiononly-journal"), | 446 FilePath().AppendASCII(".extensiononly-journal"), |
447 DomStorageDatabase::GetJournalFilePath( | 447 DomStorageDatabase::GetJournalFilePath( |
448 FilePath().AppendASCII(".extensiononly"))); | 448 FilePath().AppendASCII(".extensiononly"))); |
449 } | 449 } |
450 | 450 |
451 } // namespace dom_storage | 451 } // namespace dom_storage |
OLD | NEW |