Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: webkit/browser/dom_storage/dom_storage_area_unittest.cc

Issue 15984016: Call scoped_refptr<T>::get() rather than relying on implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value)); 151 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value));
152 ASSERT_TRUE(old_value.is_null()); 152 ASSERT_TRUE(old_value.is_null());
153 153
154 // Check that saving a value has still left us without a backing database. 154 // Check that saving a value has still left us without a backing database.
155 EXPECT_EQ(NULL, area->backing_.get()); 155 EXPECT_EQ(NULL, area->backing_.get());
156 EXPECT_FALSE(file_util::PathExists(kExpectedOriginFilePath)); 156 EXPECT_FALSE(file_util::PathExists(kExpectedOriginFilePath));
157 } 157 }
158 158
159 // This should set up a DomStorageArea that is correctly backed to disk. 159 // This should set up a DomStorageArea that is correctly backed to disk.
160 { 160 {
161 scoped_refptr<DomStorageArea> area( 161 scoped_refptr<DomStorageArea> area(new DomStorageArea(
162 new DomStorageArea(kOrigin, 162 kOrigin,
163 temp_dir.path(), 163 temp_dir.path(),
164 new MockDomStorageTaskRunner(base::MessageLoopProxy::current()))); 164 new MockDomStorageTaskRunner(base::MessageLoopProxy::current().get())));
165 165
166 EXPECT_TRUE(area->backing_.get()); 166 EXPECT_TRUE(area->backing_.get());
167 DomStorageDatabase* database = static_cast<LocalStorageDatabaseAdapter*>( 167 DomStorageDatabase* database = static_cast<LocalStorageDatabaseAdapter*>(
168 area->backing_.get())->db_.get(); 168 area->backing_.get())->db_.get();
169 EXPECT_FALSE(database->IsOpen()); 169 EXPECT_FALSE(database->IsOpen());
170 EXPECT_FALSE(area->is_initial_import_done_); 170 EXPECT_FALSE(area->is_initial_import_done_);
171 171
172 // Inject an in-memory db to speed up the test. 172 // Inject an in-memory db to speed up the test.
173 // We will verify that something is written into the database but not 173 // We will verify that something is written into the database but not
174 // that a file is written to disk - DOMStorageDatabase unit tests cover 174 // that a file is written to disk - DOMStorageDatabase unit tests cover
(...skipping 23 matching lines...) Expand all
198 area->backing_->ReadAllValues(&values); 198 area->backing_->ReadAllValues(&values);
199 EXPECT_EQ(1u, values.size()); 199 EXPECT_EQ(1u, values.size());
200 EXPECT_EQ(kValue, values[kKey].string()); 200 EXPECT_EQ(kValue, values[kKey].string());
201 } 201 }
202 } 202 }
203 203
204 TEST_F(DomStorageAreaTest, CommitTasks) { 204 TEST_F(DomStorageAreaTest, CommitTasks) {
205 base::ScopedTempDir temp_dir; 205 base::ScopedTempDir temp_dir;
206 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 206 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
207 207
208 scoped_refptr<DomStorageArea> area( 208 scoped_refptr<DomStorageArea> area(new DomStorageArea(
209 new DomStorageArea(kOrigin, 209 kOrigin,
210 temp_dir.path(), 210 temp_dir.path(),
211 new MockDomStorageTaskRunner(base::MessageLoopProxy::current()))); 211 new MockDomStorageTaskRunner(base::MessageLoopProxy::current().get())));
212 // Inject an in-memory db to speed up the test. 212 // Inject an in-memory db to speed up the test.
213 area->backing_.reset(new LocalStorageDatabaseAdapter()); 213 area->backing_.reset(new LocalStorageDatabaseAdapter());
214 214
215 // Unrelated to commits, but while we're here, see that querying Length() 215 // Unrelated to commits, but while we're here, see that querying Length()
216 // causes the backing database to be opened and presumably read from. 216 // causes the backing database to be opened and presumably read from.
217 EXPECT_FALSE(area->is_initial_import_done_); 217 EXPECT_FALSE(area->is_initial_import_done_);
218 EXPECT_EQ(0u, area->Length()); 218 EXPECT_EQ(0u, area->Length());
219 EXPECT_TRUE(area->is_initial_import_done_); 219 EXPECT_TRUE(area->is_initial_import_done_);
220 220
221 ValuesMap values; 221 ValuesMap values;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 values.clear(); 276 values.clear();
277 area->backing_->ReadAllValues(&values); 277 area->backing_->ReadAllValues(&values);
278 EXPECT_EQ(2u, values.size()); 278 EXPECT_EQ(2u, values.size());
279 EXPECT_EQ(kValue, values[kKey].string()); 279 EXPECT_EQ(kValue, values[kKey].string());
280 EXPECT_EQ(kValue2, values[kKey2].string()); 280 EXPECT_EQ(kValue2, values[kKey2].string());
281 } 281 }
282 282
283 TEST_F(DomStorageAreaTest, CommitChangesAtShutdown) { 283 TEST_F(DomStorageAreaTest, CommitChangesAtShutdown) {
284 base::ScopedTempDir temp_dir; 284 base::ScopedTempDir temp_dir;
285 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 285 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
286 scoped_refptr<DomStorageArea> area( 286 scoped_refptr<DomStorageArea> area(new DomStorageArea(
287 new DomStorageArea(kOrigin, 287 kOrigin,
288 temp_dir.path(), 288 temp_dir.path(),
289 new MockDomStorageTaskRunner(base::MessageLoopProxy::current()))); 289 new MockDomStorageTaskRunner(base::MessageLoopProxy::current().get())));
290 290
291 // Inject an in-memory db to speed up the test and also to verify 291 // Inject an in-memory db to speed up the test and also to verify
292 // the final changes are commited in it's dtor. 292 // the final changes are commited in it's dtor.
293 static_cast<LocalStorageDatabaseAdapter*>(area->backing_.get())->db_.reset( 293 static_cast<LocalStorageDatabaseAdapter*>(area->backing_.get())->db_.reset(
294 new VerifyChangesCommittedDatabase()); 294 new VerifyChangesCommittedDatabase());
295 295
296 ValuesMap values; 296 ValuesMap values;
297 NullableString16 old_value; 297 NullableString16 old_value;
298 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value)); 298 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value));
299 EXPECT_TRUE(area->HasUncommittedChanges()); 299 EXPECT_TRUE(area->HasUncommittedChanges());
300 area->backing_->ReadAllValues(&values); 300 area->backing_->ReadAllValues(&values);
301 EXPECT_TRUE(values.empty()); // not committed yet 301 EXPECT_TRUE(values.empty()); // not committed yet
302 area->Shutdown(); 302 area->Shutdown();
303 base::MessageLoop::current()->RunUntilIdle(); 303 base::MessageLoop::current()->RunUntilIdle();
304 EXPECT_TRUE(area->HasOneRef()); 304 EXPECT_TRUE(area->HasOneRef());
305 EXPECT_FALSE(area->backing_.get()); 305 EXPECT_FALSE(area->backing_.get());
306 // The VerifyChangesCommittedDatabase destructor verifies values 306 // The VerifyChangesCommittedDatabase destructor verifies values
307 // were committed. 307 // were committed.
308 } 308 }
309 309
310 TEST_F(DomStorageAreaTest, DeleteOrigin) { 310 TEST_F(DomStorageAreaTest, DeleteOrigin) {
311 base::ScopedTempDir temp_dir; 311 base::ScopedTempDir temp_dir;
312 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 312 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
313 scoped_refptr<DomStorageArea> area( 313 scoped_refptr<DomStorageArea> area(new DomStorageArea(
314 new DomStorageArea(kOrigin, 314 kOrigin,
315 temp_dir.path(), 315 temp_dir.path(),
316 new MockDomStorageTaskRunner(base::MessageLoopProxy::current()))); 316 new MockDomStorageTaskRunner(base::MessageLoopProxy::current().get())));
317 317
318 // This test puts files on disk. 318 // This test puts files on disk.
319 base::FilePath db_file_path = static_cast<LocalStorageDatabaseAdapter*>( 319 base::FilePath db_file_path = static_cast<LocalStorageDatabaseAdapter*>(
320 area->backing_.get())->db_->file_path(); 320 area->backing_.get())->db_->file_path();
321 base::FilePath db_journal_file_path = 321 base::FilePath db_journal_file_path =
322 DomStorageDatabase::GetJournalFilePath(db_file_path); 322 DomStorageDatabase::GetJournalFilePath(db_file_path);
323 323
324 // Nothing bad should happen when invoked w/o any files on disk. 324 // Nothing bad should happen when invoked w/o any files on disk.
325 area->DeleteOrigin(); 325 area->DeleteOrigin();
326 EXPECT_FALSE(file_util::PathExists(db_file_path)); 326 EXPECT_FALSE(file_util::PathExists(db_file_path));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // was called, the file will linger until the shutdown time. 364 // was called, the file will linger until the shutdown time.
365 EXPECT_TRUE(file_util::PathExists(db_file_path)); 365 EXPECT_TRUE(file_util::PathExists(db_file_path));
366 area->Shutdown(); 366 area->Shutdown();
367 base::MessageLoop::current()->RunUntilIdle(); 367 base::MessageLoop::current()->RunUntilIdle();
368 EXPECT_FALSE(file_util::PathExists(db_file_path)); 368 EXPECT_FALSE(file_util::PathExists(db_file_path));
369 } 369 }
370 370
371 TEST_F(DomStorageAreaTest, PurgeMemory) { 371 TEST_F(DomStorageAreaTest, PurgeMemory) {
372 base::ScopedTempDir temp_dir; 372 base::ScopedTempDir temp_dir;
373 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 373 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
374 scoped_refptr<DomStorageArea> area( 374 scoped_refptr<DomStorageArea> area(new DomStorageArea(
375 new DomStorageArea(kOrigin, 375 kOrigin,
376 temp_dir.path(), 376 temp_dir.path(),
377 new MockDomStorageTaskRunner(base::MessageLoopProxy::current()))); 377 new MockDomStorageTaskRunner(base::MessageLoopProxy::current().get())));
378 378
379 // Inject an in-memory db to speed up the test. 379 // Inject an in-memory db to speed up the test.
380 area->backing_.reset(new LocalStorageDatabaseAdapter()); 380 area->backing_.reset(new LocalStorageDatabaseAdapter());
381 381
382 // Unowned ptrs we use to verify that 'purge' has happened. 382 // Unowned ptrs we use to verify that 'purge' has happened.
383 DomStorageDatabase* original_backing = 383 DomStorageDatabase* original_backing =
384 static_cast<LocalStorageDatabaseAdapter*>( 384 static_cast<LocalStorageDatabaseAdapter*>(
385 area->backing_.get())->db_.get(); 385 area->backing_.get())->db_.get();
386 DomStorageMap* original_map = area->map_.get(); 386 DomStorageMap* original_map = area->map_.get();
387 387
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 EXPECT_EQ( 464 EXPECT_EQ(
465 base::FilePath().AppendASCII("-journal"), 465 base::FilePath().AppendASCII("-journal"),
466 DomStorageDatabase::GetJournalFilePath(base::FilePath())); 466 DomStorageDatabase::GetJournalFilePath(base::FilePath()));
467 EXPECT_EQ( 467 EXPECT_EQ(
468 base::FilePath().AppendASCII(".extensiononly-journal"), 468 base::FilePath().AppendASCII(".extensiononly-journal"),
469 DomStorageDatabase::GetJournalFilePath( 469 DomStorageDatabase::GetJournalFilePath(
470 base::FilePath().AppendASCII(".extensiononly"))); 470 base::FilePath().AppendASCII(".extensiononly")));
471 } 471 }
472 472
473 } // namespace dom_storage 473 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/browser/database/database_tracker_unittest.cc ('k') | webkit/browser/dom_storage/dom_storage_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698