| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 ScopedTempDir temp_dir_; | 99 ScopedTempDir temp_dir_; |
| 100 NullDirectoryChangeDelegate delegate_; | 100 NullDirectoryChangeDelegate delegate_; |
| 101 FakeEncryptor encryptor_; | 101 FakeEncryptor encryptor_; |
| 102 TestUnrecoverableErrorHandler handler_; | 102 TestUnrecoverableErrorHandler handler_; |
| 103 FilePath db_path_; | 103 FilePath db_path_; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 const char SyncableGeneralTest::kIndexTestName[] = "IndexTest"; | 106 const char SyncableGeneralTest::kIndexTestName[] = "IndexTest"; |
| 107 | 107 |
| 108 TEST_F(SyncableGeneralTest, General) { | 108 TEST_F(SyncableGeneralTest, General) { |
| 109 Directory dir(&encryptor_, &handler_, NULL, | 109 Directory dir(new InMemoryDirectoryBackingStore("SimpleTest"), |
| 110 new InMemoryDirectoryBackingStore("SimpleTest")); | 110 &handler_, |
| 111 NULL, |
| 112 NULL, |
| 113 NULL); |
| 114 |
| 111 ASSERT_EQ(OPENED, dir.Open( | 115 ASSERT_EQ(OPENED, dir.Open( |
| 112 "SimpleTest", &delegate_, NullTransactionObserver())); | 116 "SimpleTest", &delegate_, NullTransactionObserver())); |
| 113 | 117 |
| 114 int64 root_metahandle; | 118 int64 root_metahandle; |
| 115 { | 119 { |
| 116 ReadTransaction rtrans(FROM_HERE, &dir); | 120 ReadTransaction rtrans(FROM_HERE, &dir); |
| 117 Entry e(&rtrans, GET_BY_ID, rtrans.root_id()); | 121 Entry e(&rtrans, GET_BY_ID, rtrans.root_id()); |
| 118 ASSERT_TRUE(e.good()); | 122 ASSERT_TRUE(e.good()); |
| 119 root_metahandle = e.Get(META_HANDLE); | 123 root_metahandle = e.Get(META_HANDLE); |
| 120 } | 124 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); | 204 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); |
| 201 e.Put(IS_DEL, true); | 205 e.Put(IS_DEL, true); |
| 202 | 206 |
| 203 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), name)); | 207 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), name)); |
| 204 } | 208 } |
| 205 | 209 |
| 206 dir.SaveChanges(); | 210 dir.SaveChanges(); |
| 207 } | 211 } |
| 208 | 212 |
| 209 TEST_F(SyncableGeneralTest, ChildrenOps) { | 213 TEST_F(SyncableGeneralTest, ChildrenOps) { |
| 210 Directory dir(&encryptor_, &handler_, NULL, | 214 Directory dir(new InMemoryDirectoryBackingStore("SimpleTest"), |
| 211 new InMemoryDirectoryBackingStore("SimpleTest")); | 215 &handler_, |
| 216 NULL, |
| 217 NULL, |
| 218 NULL); |
| 212 ASSERT_EQ(OPENED, dir.Open( | 219 ASSERT_EQ(OPENED, dir.Open( |
| 213 "SimpleTest", &delegate_, NullTransactionObserver())); | 220 "SimpleTest", &delegate_, NullTransactionObserver())); |
| 214 | 221 |
| 215 int64 written_metahandle; | 222 int64 written_metahandle; |
| 216 const Id id = TestIdFactory::FromNumber(99); | 223 const Id id = TestIdFactory::FromNumber(99); |
| 217 std::string name = "Jeff"; | 224 std::string name = "Jeff"; |
| 218 { | 225 { |
| 219 ReadTransaction rtrans(FROM_HERE, &dir); | 226 ReadTransaction rtrans(FROM_HERE, &dir); |
| 220 Entry e(&rtrans, GET_BY_ID, id); | 227 Entry e(&rtrans, GET_BY_ID, id); |
| 221 ASSERT_FALSE(e.good()); // Hasn't been written yet. | 228 ASSERT_FALSE(e.good()); // Hasn't been written yet. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 281 |
| 275 TEST_F(SyncableGeneralTest, ClientIndexRebuildsProperly) { | 282 TEST_F(SyncableGeneralTest, ClientIndexRebuildsProperly) { |
| 276 int64 written_metahandle; | 283 int64 written_metahandle; |
| 277 TestIdFactory factory; | 284 TestIdFactory factory; |
| 278 const Id id = factory.NewServerId(); | 285 const Id id = factory.NewServerId(); |
| 279 std::string name = "cheesepuffs"; | 286 std::string name = "cheesepuffs"; |
| 280 std::string tag = "dietcoke"; | 287 std::string tag = "dietcoke"; |
| 281 | 288 |
| 282 // Test creating a new meta entry. | 289 // Test creating a new meta entry. |
| 283 { | 290 { |
| 284 Directory dir(&encryptor_, &handler_, NULL, | 291 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_), |
| 285 new OnDiskDirectoryBackingStore(kIndexTestName, db_path_)); | 292 &handler_, |
| 293 NULL, |
| 294 NULL, |
| 295 NULL); |
| 286 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, | 296 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, |
| 287 NullTransactionObserver())); | 297 NullTransactionObserver())); |
| 288 { | 298 { |
| 289 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); | 299 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); |
| 290 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); | 300 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); |
| 291 ASSERT_TRUE(me.good()); | 301 ASSERT_TRUE(me.good()); |
| 292 me.Put(ID, id); | 302 me.Put(ID, id); |
| 293 me.Put(BASE_VERSION, 1); | 303 me.Put(BASE_VERSION, 1); |
| 294 me.Put(UNIQUE_CLIENT_TAG, tag); | 304 me.Put(UNIQUE_CLIENT_TAG, tag); |
| 295 written_metahandle = me.Get(META_HANDLE); | 305 written_metahandle = me.Get(META_HANDLE); |
| 296 } | 306 } |
| 297 dir.SaveChanges(); | 307 dir.SaveChanges(); |
| 298 } | 308 } |
| 299 | 309 |
| 300 // The DB was closed. Now reopen it. This will cause index regeneration. | 310 // The DB was closed. Now reopen it. This will cause index regeneration. |
| 301 { | 311 { |
| 302 Directory dir(&encryptor_, &handler_, NULL, | 312 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_), |
| 303 new OnDiskDirectoryBackingStore(kIndexTestName, db_path_)); | 313 &handler_, |
| 314 NULL, |
| 315 NULL, |
| 316 NULL); |
| 304 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, | 317 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, |
| 305 &delegate_, NullTransactionObserver())); | 318 &delegate_, NullTransactionObserver())); |
| 306 | 319 |
| 307 ReadTransaction trans(FROM_HERE, &dir); | 320 ReadTransaction trans(FROM_HERE, &dir); |
| 308 Entry me(&trans, GET_BY_CLIENT_TAG, tag); | 321 Entry me(&trans, GET_BY_CLIENT_TAG, tag); |
| 309 ASSERT_TRUE(me.good()); | 322 ASSERT_TRUE(me.good()); |
| 310 EXPECT_EQ(me.Get(ID), id); | 323 EXPECT_EQ(me.Get(ID), id); |
| 311 EXPECT_EQ(me.Get(BASE_VERSION), 1); | 324 EXPECT_EQ(me.Get(BASE_VERSION), 1); |
| 312 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), tag); | 325 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), tag); |
| 313 EXPECT_EQ(me.Get(META_HANDLE), written_metahandle); | 326 EXPECT_EQ(me.Get(META_HANDLE), written_metahandle); |
| 314 } | 327 } |
| 315 } | 328 } |
| 316 | 329 |
| 317 TEST_F(SyncableGeneralTest, ClientIndexRebuildsDeletedProperly) { | 330 TEST_F(SyncableGeneralTest, ClientIndexRebuildsDeletedProperly) { |
| 318 TestIdFactory factory; | 331 TestIdFactory factory; |
| 319 const Id id = factory.NewServerId(); | 332 const Id id = factory.NewServerId(); |
| 320 std::string tag = "dietcoke"; | 333 std::string tag = "dietcoke"; |
| 321 | 334 |
| 322 // Test creating a deleted, unsynced, server meta entry. | 335 // Test creating a deleted, unsynced, server meta entry. |
| 323 { | 336 { |
| 324 Directory dir(&encryptor_, &handler_, NULL, | 337 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_), |
| 325 new OnDiskDirectoryBackingStore(kIndexTestName, db_path_)); | 338 &handler_, |
| 339 NULL, |
| 340 NULL, |
| 341 NULL); |
| 326 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, | 342 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, |
| 327 NullTransactionObserver())); | 343 NullTransactionObserver())); |
| 328 { | 344 { |
| 329 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); | 345 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); |
| 330 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "deleted"); | 346 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "deleted"); |
| 331 ASSERT_TRUE(me.good()); | 347 ASSERT_TRUE(me.good()); |
| 332 me.Put(ID, id); | 348 me.Put(ID, id); |
| 333 me.Put(BASE_VERSION, 1); | 349 me.Put(BASE_VERSION, 1); |
| 334 me.Put(UNIQUE_CLIENT_TAG, tag); | 350 me.Put(UNIQUE_CLIENT_TAG, tag); |
| 335 me.Put(IS_DEL, true); | 351 me.Put(IS_DEL, true); |
| 336 me.Put(IS_UNSYNCED, true); // Or it might be purged. | 352 me.Put(IS_UNSYNCED, true); // Or it might be purged. |
| 337 } | 353 } |
| 338 dir.SaveChanges(); | 354 dir.SaveChanges(); |
| 339 } | 355 } |
| 340 | 356 |
| 341 // The DB was closed. Now reopen it. This will cause index regeneration. | 357 // The DB was closed. Now reopen it. This will cause index regeneration. |
| 342 // Should still be present and valid in the client tag index. | 358 // Should still be present and valid in the client tag index. |
| 343 { | 359 { |
| 344 Directory dir(&encryptor_, &handler_, NULL, | 360 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_), |
| 345 new OnDiskDirectoryBackingStore(kIndexTestName, db_path_)); | 361 &handler_, |
| 362 NULL, |
| 363 NULL, |
| 364 NULL); |
| 346 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, | 365 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, |
| 347 NullTransactionObserver())); | 366 NullTransactionObserver())); |
| 348 | 367 |
| 349 ReadTransaction trans(FROM_HERE, &dir); | 368 ReadTransaction trans(FROM_HERE, &dir); |
| 350 Entry me(&trans, GET_BY_CLIENT_TAG, tag); | 369 Entry me(&trans, GET_BY_CLIENT_TAG, tag); |
| 351 ASSERT_TRUE(me.good()); | 370 ASSERT_TRUE(me.good()); |
| 352 EXPECT_EQ(me.Get(ID), id); | 371 EXPECT_EQ(me.Get(ID), id); |
| 353 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), tag); | 372 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), tag); |
| 354 EXPECT_TRUE(me.Get(IS_DEL)); | 373 EXPECT_TRUE(me.Get(IS_DEL)); |
| 355 EXPECT_TRUE(me.Get(IS_UNSYNCED)); | 374 EXPECT_TRUE(me.Get(IS_UNSYNCED)); |
| 356 } | 375 } |
| 357 } | 376 } |
| 358 | 377 |
| 359 TEST_F(SyncableGeneralTest, ToValue) { | 378 TEST_F(SyncableGeneralTest, ToValue) { |
| 360 Directory dir(&encryptor_, &handler_, NULL, | 379 Directory dir(new InMemoryDirectoryBackingStore("SimpleTest"), |
| 361 new InMemoryDirectoryBackingStore("SimpleTest")); | 380 &handler_, |
| 381 NULL, |
| 382 NULL, |
| 383 NULL); |
| 362 ASSERT_EQ(OPENED, dir.Open( | 384 ASSERT_EQ(OPENED, dir.Open( |
| 363 "SimpleTest", &delegate_, NullTransactionObserver())); | 385 "SimpleTest", &delegate_, NullTransactionObserver())); |
| 364 | 386 |
| 365 const Id id = TestIdFactory::FromNumber(99); | 387 const Id id = TestIdFactory::FromNumber(99); |
| 366 { | 388 { |
| 367 ReadTransaction rtrans(FROM_HERE, &dir); | 389 ReadTransaction rtrans(FROM_HERE, &dir); |
| 368 Entry e(&rtrans, GET_BY_ID, id); | 390 Entry e(&rtrans, GET_BY_ID, id); |
| 369 EXPECT_FALSE(e.good()); // Hasn't been written yet. | 391 EXPECT_FALSE(e.good()); // Hasn't been written yet. |
| 370 | 392 |
| 371 scoped_ptr<DictionaryValue> value(e.ToValue()); | 393 scoped_ptr<DictionaryValue> value(e.ToValue()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 400 UnsaveableBackingStore(const std::string& dir_name, | 422 UnsaveableBackingStore(const std::string& dir_name, |
| 401 const FilePath& backing_filepath) | 423 const FilePath& backing_filepath) |
| 402 : OnDiskDirectoryBackingStore(dir_name, backing_filepath) { } | 424 : OnDiskDirectoryBackingStore(dir_name, backing_filepath) { } |
| 403 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot) { | 425 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot) { |
| 404 return false; | 426 return false; |
| 405 } | 427 } |
| 406 }; | 428 }; |
| 407 | 429 |
| 408 TestUnsaveableDirectory(const std::string& dir_name, | 430 TestUnsaveableDirectory(const std::string& dir_name, |
| 409 const FilePath& backing_filepath) | 431 const FilePath& backing_filepath) |
| 410 : Directory(&encryptor_, &handler_, NULL, | 432 : Directory(new UnsaveableBackingStore(dir_name, backing_filepath), |
| 411 new UnsaveableBackingStore(dir_name, backing_filepath)) {} | 433 &handler_, |
| 434 NULL, |
| 435 NULL, |
| 436 NULL) {} |
| 412 private: | 437 private: |
| 413 FakeEncryptor encryptor_; | 438 FakeEncryptor encryptor_; |
| 414 TestUnrecoverableErrorHandler handler_; | 439 TestUnrecoverableErrorHandler handler_; |
| 415 }; | 440 }; |
| 416 | 441 |
| 417 // A test fixture for syncable::Directory. Uses an in-memory database to keep | 442 // A test fixture for syncable::Directory. Uses an in-memory database to keep |
| 418 // the unit tests fast. | 443 // the unit tests fast. |
| 419 class SyncableDirectoryTest : public testing::Test { | 444 class SyncableDirectoryTest : public testing::Test { |
| 420 protected: | 445 protected: |
| 421 MessageLoop message_loop_; | 446 MessageLoop message_loop_; |
| 422 static const char kName[]; | 447 static const char kName[]; |
| 423 | 448 |
| 424 virtual void SetUp() { | 449 virtual void SetUp() { |
| 425 dir_.reset(new Directory(&encryptor_, &handler_, NULL, | 450 dir_.reset(new Directory(new InMemoryDirectoryBackingStore(kName), |
| 426 new InMemoryDirectoryBackingStore(kName))); | 451 &handler_, |
| 452 NULL, |
| 453 NULL, |
| 454 NULL)); |
| 427 ASSERT_TRUE(dir_.get()); | 455 ASSERT_TRUE(dir_.get()); |
| 428 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, | 456 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, |
| 429 NullTransactionObserver())); | 457 NullTransactionObserver())); |
| 430 ASSERT_TRUE(dir_->good()); | 458 ASSERT_TRUE(dir_->good()); |
| 431 } | 459 } |
| 432 | 460 |
| 433 virtual void TearDown() { | 461 virtual void TearDown() { |
| 434 if (dir_.get()) | 462 if (dir_.get()) |
| 435 dir_->SaveChanges(); | 463 dir_->SaveChanges(); |
| 436 dir_.reset(); | 464 dir_.reset(); |
| (...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 // A variant of SyncableDirectoryTest that uses a real sqlite database. | 1364 // A variant of SyncableDirectoryTest that uses a real sqlite database. |
| 1337 class OnDiskSyncableDirectoryTest : public SyncableDirectoryTest { | 1365 class OnDiskSyncableDirectoryTest : public SyncableDirectoryTest { |
| 1338 protected: | 1366 protected: |
| 1339 // SetUp() is called before each test case is run. | 1367 // SetUp() is called before each test case is run. |
| 1340 // The sqlite3 DB is deleted before each test is run. | 1368 // The sqlite3 DB is deleted before each test is run. |
| 1341 virtual void SetUp() { | 1369 virtual void SetUp() { |
| 1342 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 1370 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 1343 file_path_ = temp_dir_.path().Append( | 1371 file_path_ = temp_dir_.path().Append( |
| 1344 FILE_PATH_LITERAL("Test.sqlite3")); | 1372 FILE_PATH_LITERAL("Test.sqlite3")); |
| 1345 file_util::Delete(file_path_, true); | 1373 file_util::Delete(file_path_, true); |
| 1346 dir_.reset(new Directory(&encryptor_, &handler_, NULL, | 1374 dir_.reset(new Directory(new OnDiskDirectoryBackingStore(kName, file_path_), |
| 1347 new OnDiskDirectoryBackingStore(kName, file_path_))); | 1375 &handler_, |
| 1376 NULL, |
| 1377 NULL, |
| 1378 NULL)); |
| 1348 ASSERT_TRUE(dir_.get()); | 1379 ASSERT_TRUE(dir_.get()); |
| 1349 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, | 1380 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, |
| 1350 NullTransactionObserver())); | 1381 NullTransactionObserver())); |
| 1351 ASSERT_TRUE(dir_->good()); | 1382 ASSERT_TRUE(dir_->good()); |
| 1352 } | 1383 } |
| 1353 | 1384 |
| 1354 virtual void TearDown() { | 1385 virtual void TearDown() { |
| 1355 // This also closes file handles. | 1386 // This also closes file handles. |
| 1356 dir_->SaveChanges(); | 1387 dir_->SaveChanges(); |
| 1357 dir_.reset(); | 1388 dir_.reset(); |
| 1358 file_util::Delete(file_path_, true); | 1389 file_util::Delete(file_path_, true); |
| 1359 } | 1390 } |
| 1360 | 1391 |
| 1361 void ReloadDir() { | 1392 void ReloadDir() { |
| 1362 dir_.reset(new Directory(&encryptor_, &handler_, NULL, | 1393 dir_.reset(new Directory( |
| 1363 new OnDiskDirectoryBackingStore(kName, file_path_))); | 1394 new OnDiskDirectoryBackingStore(kName, file_path_), |
| 1395 &handler_, |
| 1396 NULL, |
| 1397 NULL, |
| 1398 NULL)); |
| 1364 ASSERT_TRUE(dir_.get()); | 1399 ASSERT_TRUE(dir_.get()); |
| 1365 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, | 1400 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, |
| 1366 NullTransactionObserver())); | 1401 NullTransactionObserver())); |
| 1367 } | 1402 } |
| 1368 | 1403 |
| 1369 void SaveAndReloadDir() { | 1404 void SaveAndReloadDir() { |
| 1370 dir_->SaveChanges(); | 1405 dir_->SaveChanges(); |
| 1371 ReloadDir(); | 1406 ReloadDir(); |
| 1372 } | 1407 } |
| 1373 | 1408 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 sync_pb::EntitySpecifics specifics; | 1545 sync_pb::EntitySpecifics specifics; |
| 1511 specifics.mutable_bookmark()->set_favicon("PNG"); | 1546 specifics.mutable_bookmark()->set_favicon("PNG"); |
| 1512 specifics.mutable_bookmark()->set_url("http://nowhere"); | 1547 specifics.mutable_bookmark()->set_url("http://nowhere"); |
| 1513 create.Put(SPECIFICS, specifics); | 1548 create.Put(SPECIFICS, specifics); |
| 1514 create_pre_save = create.GetKernelCopy(); | 1549 create_pre_save = create.GetKernelCopy(); |
| 1515 update_pre_save = update.GetKernelCopy(); | 1550 update_pre_save = update.GetKernelCopy(); |
| 1516 create_id = create.Get(ID); | 1551 create_id = create.Get(ID); |
| 1517 } | 1552 } |
| 1518 | 1553 |
| 1519 dir_->SaveChanges(); | 1554 dir_->SaveChanges(); |
| 1520 dir_.reset(new Directory(&encryptor_, &handler_, NULL, | 1555 dir_.reset(new Directory(new OnDiskDirectoryBackingStore(kName, file_path_), |
| 1521 new OnDiskDirectoryBackingStore(kName, file_path_))); | 1556 &handler_, |
| 1557 NULL, |
| 1558 NULL, |
| 1559 NULL)); |
| 1560 |
| 1522 ASSERT_TRUE(dir_.get()); | 1561 ASSERT_TRUE(dir_.get()); |
| 1523 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, NullTransactionObserver())); | 1562 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, NullTransactionObserver())); |
| 1524 ASSERT_TRUE(dir_->good()); | 1563 ASSERT_TRUE(dir_->good()); |
| 1525 | 1564 |
| 1526 { | 1565 { |
| 1527 ReadTransaction trans(FROM_HERE, dir_.get()); | 1566 ReadTransaction trans(FROM_HERE, dir_.get()); |
| 1528 Entry create(&trans, GET_BY_ID, create_id); | 1567 Entry create(&trans, GET_BY_ID, create_id); |
| 1529 EXPECT_EQ(1, CountEntriesWithName(&trans, trans.root_id(), create_name)); | 1568 EXPECT_EQ(1, CountEntriesWithName(&trans, trans.root_id(), create_name)); |
| 1530 Entry update(&trans, GET_BY_ID, update_id); | 1569 Entry update(&trans, GET_BY_ID, update_id); |
| 1531 create_post_save = create.GetKernelCopy(); | 1570 create_post_save = create.GetKernelCopy(); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 if (!dir_->SaveChanges()) | 1760 if (!dir_->SaveChanges()) |
| 1722 return FAILED_IN_UNITTEST; | 1761 return FAILED_IN_UNITTEST; |
| 1723 | 1762 |
| 1724 // Do some tricky things to preserve the backing store. | 1763 // Do some tricky things to preserve the backing store. |
| 1725 DirectoryBackingStore* saved_store = dir_->store_.release(); | 1764 DirectoryBackingStore* saved_store = dir_->store_.release(); |
| 1726 | 1765 |
| 1727 // Close the current directory. | 1766 // Close the current directory. |
| 1728 dir_->Close(); | 1767 dir_->Close(); |
| 1729 dir_.reset(); | 1768 dir_.reset(); |
| 1730 | 1769 |
| 1731 dir_.reset(new Directory(&encryptor_, &handler_, NULL, saved_store)); | 1770 dir_.reset(new Directory(saved_store, |
| 1771 &handler_, |
| 1772 NULL, |
| 1773 NULL, |
| 1774 NULL)); |
| 1732 DirOpenResult result = dir_->OpenImpl(kName, &delegate_, | 1775 DirOpenResult result = dir_->OpenImpl(kName, &delegate_, |
| 1733 NullTransactionObserver()); | 1776 NullTransactionObserver()); |
| 1734 | 1777 |
| 1735 // If something went wrong, we need to clear this member. If we don't, | 1778 // If something went wrong, we need to clear this member. If we don't, |
| 1736 // TearDown() will be guaranteed to crash when it calls SaveChanges(). | 1779 // TearDown() will be guaranteed to crash when it calls SaveChanges(). |
| 1737 if (result != OPENED) | 1780 if (result != OPENED) |
| 1738 dir_.reset(); | 1781 dir_.reset(); |
| 1739 | 1782 |
| 1740 return result; | 1783 return result; |
| 1741 } | 1784 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1755 ScopedTempDir temp_dir_; | 1798 ScopedTempDir temp_dir_; |
| 1756 FakeEncryptor encryptor_; | 1799 FakeEncryptor encryptor_; |
| 1757 TestUnrecoverableErrorHandler handler_; | 1800 TestUnrecoverableErrorHandler handler_; |
| 1758 NullDirectoryChangeDelegate delegate_; | 1801 NullDirectoryChangeDelegate delegate_; |
| 1759 }; | 1802 }; |
| 1760 | 1803 |
| 1761 TEST_F(SyncableDirectoryManagement, TestFileRelease) { | 1804 TEST_F(SyncableDirectoryManagement, TestFileRelease) { |
| 1762 FilePath path = temp_dir_.path().Append( | 1805 FilePath path = temp_dir_.path().Append( |
| 1763 Directory::kSyncDatabaseFilename); | 1806 Directory::kSyncDatabaseFilename); |
| 1764 | 1807 |
| 1765 syncable::Directory dir(&encryptor_, &handler_, NULL, | 1808 syncable::Directory dir(new OnDiskDirectoryBackingStore("ScopeTest", path), |
| 1766 new OnDiskDirectoryBackingStore("ScopeTest", path)); | 1809 &handler_, |
| 1810 NULL, |
| 1811 NULL, |
| 1812 NULL); |
| 1767 DirOpenResult result = | 1813 DirOpenResult result = |
| 1768 dir.Open("ScopeTest", &delegate_, NullTransactionObserver()); | 1814 dir.Open("ScopeTest", &delegate_, NullTransactionObserver()); |
| 1769 ASSERT_EQ(result, OPENED); | 1815 ASSERT_EQ(result, OPENED); |
| 1770 dir.Close(); | 1816 dir.Close(); |
| 1771 | 1817 |
| 1772 // Closing the directory should have released the backing database file. | 1818 // Closing the directory should have released the backing database file. |
| 1773 ASSERT_TRUE(file_util::Delete(path, true)); | 1819 ASSERT_TRUE(file_util::Delete(path, true)); |
| 1774 } | 1820 } |
| 1775 | 1821 |
| 1776 class StressTransactionsDelegate : public base::PlatformThread::Delegate { | 1822 class StressTransactionsDelegate : public base::PlatformThread::Delegate { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1817 }; | 1863 }; |
| 1818 | 1864 |
| 1819 TEST(SyncableDirectory, StressTransactions) { | 1865 TEST(SyncableDirectory, StressTransactions) { |
| 1820 MessageLoop message_loop; | 1866 MessageLoop message_loop; |
| 1821 ScopedTempDir temp_dir; | 1867 ScopedTempDir temp_dir; |
| 1822 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1868 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1823 FakeEncryptor encryptor; | 1869 FakeEncryptor encryptor; |
| 1824 TestUnrecoverableErrorHandler handler; | 1870 TestUnrecoverableErrorHandler handler; |
| 1825 NullDirectoryChangeDelegate delegate; | 1871 NullDirectoryChangeDelegate delegate; |
| 1826 std::string dirname = "stress"; | 1872 std::string dirname = "stress"; |
| 1827 Directory dir(&encryptor, &handler, NULL, | 1873 Directory dir(new InMemoryDirectoryBackingStore(dirname), |
| 1828 new InMemoryDirectoryBackingStore(dirname)); | 1874 &handler, |
| 1875 NULL, |
| 1876 NULL, |
| 1877 NULL); |
| 1829 dir.Open(dirname, &delegate, NullTransactionObserver()); | 1878 dir.Open(dirname, &delegate, NullTransactionObserver()); |
| 1830 | 1879 |
| 1831 const int kThreadCount = 7; | 1880 const int kThreadCount = 7; |
| 1832 base::PlatformThreadHandle threads[kThreadCount]; | 1881 base::PlatformThreadHandle threads[kThreadCount]; |
| 1833 scoped_ptr<StressTransactionsDelegate> thread_delegates[kThreadCount]; | 1882 scoped_ptr<StressTransactionsDelegate> thread_delegates[kThreadCount]; |
| 1834 | 1883 |
| 1835 for (int i = 0; i < kThreadCount; ++i) { | 1884 for (int i = 0; i < kThreadCount; ++i) { |
| 1836 thread_delegates[i].reset(new StressTransactionsDelegate(&dir, i)); | 1885 thread_delegates[i].reset(new StressTransactionsDelegate(&dir, i)); |
| 1837 ASSERT_TRUE(base::PlatformThread::Create( | 1886 ASSERT_TRUE(base::PlatformThread::Create( |
| 1838 0, thread_delegates[i].get(), &threads[i])); | 1887 0, thread_delegates[i].get(), &threads[i])); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1940 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1989 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
| 1941 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1990 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
| 1942 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); | 1991 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); |
| 1943 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); | 1992 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); |
| 1944 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); | 1993 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); |
| 1945 } | 1994 } |
| 1946 | 1995 |
| 1947 } // namespace | 1996 } // namespace |
| 1948 } // namespace syncable | 1997 } // namespace syncable |
| 1949 } // namespace syncer | 1998 } // namespace syncer |
| OLD | NEW |