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 21 matching lines...) Expand all Loading... |
393 } | 415 } |
394 | 416 |
395 // A test fixture for syncable::Directory. Uses an in-memory database to keep | 417 // A test fixture for syncable::Directory. Uses an in-memory database to keep |
396 // the unit tests fast. | 418 // the unit tests fast. |
397 class SyncableDirectoryTest : public testing::Test { | 419 class SyncableDirectoryTest : public testing::Test { |
398 protected: | 420 protected: |
399 MessageLoop message_loop_; | 421 MessageLoop message_loop_; |
400 static const char kName[]; | 422 static const char kName[]; |
401 | 423 |
402 virtual void SetUp() { | 424 virtual void SetUp() { |
403 dir_.reset(new Directory(&encryptor_, &handler_, NULL, | 425 dir_.reset(new Directory(new InMemoryDirectoryBackingStore(kName), |
404 new InMemoryDirectoryBackingStore(kName))); | 426 &handler_, |
| 427 NULL, |
| 428 NULL, |
| 429 NULL)); |
405 ASSERT_TRUE(dir_.get()); | 430 ASSERT_TRUE(dir_.get()); |
406 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, | 431 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, |
407 NullTransactionObserver())); | 432 NullTransactionObserver())); |
408 ASSERT_TRUE(dir_->good()); | 433 ASSERT_TRUE(dir_->good()); |
409 } | 434 } |
410 | 435 |
411 virtual void TearDown() { | 436 virtual void TearDown() { |
412 if (dir_.get()) | 437 if (dir_.get()) |
413 dir_->SaveChanges(); | 438 dir_->SaveChanges(); |
414 dir_.reset(); | 439 dir_.reset(); |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 const std::string& dir_name, | 1432 const std::string& dir_name, |
1408 const FilePath& backing_filepath) { | 1433 const FilePath& backing_filepath) { |
1409 TestBackingStore* backing_store = | 1434 TestBackingStore* backing_store = |
1410 new TestBackingStore(dir_name, backing_filepath); | 1435 new TestBackingStore(dir_name, backing_filepath); |
1411 return new TestDirectory(encryptor, handler, backing_store); | 1436 return new TestDirectory(encryptor, handler, backing_store); |
1412 } | 1437 } |
1413 | 1438 |
1414 TestDirectory::TestDirectory(Encryptor* encryptor, | 1439 TestDirectory::TestDirectory(Encryptor* encryptor, |
1415 UnrecoverableErrorHandler* handler, | 1440 UnrecoverableErrorHandler* handler, |
1416 TestBackingStore* backing_store) | 1441 TestBackingStore* backing_store) |
1417 : Directory(encryptor, handler, NULL, backing_store), | 1442 : Directory(backing_store, handler, NULL, NULL, NULL), |
1418 backing_store_(backing_store) { | 1443 backing_store_(backing_store) { |
1419 } | 1444 } |
1420 | 1445 |
1421 TestDirectory::~TestDirectory() { } | 1446 TestDirectory::~TestDirectory() { } |
1422 | 1447 |
1423 TEST(OnDiskSyncableDirectory, FailInitialWrite) { | 1448 TEST(OnDiskSyncableDirectory, FailInitialWrite) { |
1424 FakeEncryptor encryptor; | 1449 FakeEncryptor encryptor; |
1425 TestUnrecoverableErrorHandler handler; | 1450 TestUnrecoverableErrorHandler handler; |
1426 ScopedTempDir temp_dir; | 1451 ScopedTempDir temp_dir; |
1427 FilePath file_path = temp_dir.path().Append( | 1452 FilePath file_path = temp_dir.path().Append( |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 sync_pb::EntitySpecifics specifics; | 1628 sync_pb::EntitySpecifics specifics; |
1604 specifics.mutable_bookmark()->set_favicon("PNG"); | 1629 specifics.mutable_bookmark()->set_favicon("PNG"); |
1605 specifics.mutable_bookmark()->set_url("http://nowhere"); | 1630 specifics.mutable_bookmark()->set_url("http://nowhere"); |
1606 create.Put(SPECIFICS, specifics); | 1631 create.Put(SPECIFICS, specifics); |
1607 create_pre_save = create.GetKernelCopy(); | 1632 create_pre_save = create.GetKernelCopy(); |
1608 update_pre_save = update.GetKernelCopy(); | 1633 update_pre_save = update.GetKernelCopy(); |
1609 create_id = create.Get(ID); | 1634 create_id = create.Get(ID); |
1610 } | 1635 } |
1611 | 1636 |
1612 dir_->SaveChanges(); | 1637 dir_->SaveChanges(); |
1613 dir_.reset(new Directory(&encryptor_, &handler_, NULL, | 1638 dir_.reset(new Directory(new OnDiskDirectoryBackingStore(kName, file_path_), |
1614 new OnDiskDirectoryBackingStore(kName, file_path_))); | 1639 &handler_, |
| 1640 NULL, |
| 1641 NULL, |
| 1642 NULL)); |
| 1643 |
1615 ASSERT_TRUE(dir_.get()); | 1644 ASSERT_TRUE(dir_.get()); |
1616 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, NullTransactionObserver())); | 1645 ASSERT_EQ(OPENED, dir_->Open(kName, &delegate_, NullTransactionObserver())); |
1617 ASSERT_TRUE(dir_->good()); | 1646 ASSERT_TRUE(dir_->good()); |
1618 | 1647 |
1619 { | 1648 { |
1620 ReadTransaction trans(FROM_HERE, dir_.get()); | 1649 ReadTransaction trans(FROM_HERE, dir_.get()); |
1621 Entry create(&trans, GET_BY_ID, create_id); | 1650 Entry create(&trans, GET_BY_ID, create_id); |
1622 EXPECT_EQ(1, CountEntriesWithName(&trans, trans.root_id(), create_name)); | 1651 EXPECT_EQ(1, CountEntriesWithName(&trans, trans.root_id(), create_name)); |
1623 Entry update(&trans, GET_BY_ID, update_id); | 1652 Entry update(&trans, GET_BY_ID, update_id); |
1624 create_post_save = create.GetKernelCopy(); | 1653 create_post_save = create.GetKernelCopy(); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1820 } | 1849 } |
1821 | 1850 |
1822 DirOpenResult SyncableDirectoryTest::ReloadDirImpl() { | 1851 DirOpenResult SyncableDirectoryTest::ReloadDirImpl() { |
1823 // Do some tricky things to preserve the backing store. | 1852 // Do some tricky things to preserve the backing store. |
1824 DirectoryBackingStore* saved_store = dir_->store_.release(); | 1853 DirectoryBackingStore* saved_store = dir_->store_.release(); |
1825 | 1854 |
1826 // Close the current directory. | 1855 // Close the current directory. |
1827 dir_->Close(); | 1856 dir_->Close(); |
1828 dir_.reset(); | 1857 dir_.reset(); |
1829 | 1858 |
1830 dir_.reset(new Directory(&encryptor_, &handler_, NULL, saved_store)); | 1859 dir_.reset(new Directory(saved_store, |
| 1860 &handler_, |
| 1861 NULL, |
| 1862 NULL, |
| 1863 NULL)); |
1831 DirOpenResult result = dir_->OpenImpl(kName, &delegate_, | 1864 DirOpenResult result = dir_->OpenImpl(kName, &delegate_, |
1832 NullTransactionObserver()); | 1865 NullTransactionObserver()); |
1833 | 1866 |
1834 // If something went wrong, we need to clear this member. If we don't, | 1867 // If something went wrong, we need to clear this member. If we don't, |
1835 // TearDown() will be guaranteed to crash when it calls SaveChanges(). | 1868 // TearDown() will be guaranteed to crash when it calls SaveChanges(). |
1836 if (result != OPENED) | 1869 if (result != OPENED) |
1837 dir_.reset(); | 1870 dir_.reset(); |
1838 | 1871 |
1839 return result; | 1872 return result; |
1840 } | 1873 } |
(...skipping 13 matching lines...) Expand all Loading... |
1854 ScopedTempDir temp_dir_; | 1887 ScopedTempDir temp_dir_; |
1855 FakeEncryptor encryptor_; | 1888 FakeEncryptor encryptor_; |
1856 TestUnrecoverableErrorHandler handler_; | 1889 TestUnrecoverableErrorHandler handler_; |
1857 NullDirectoryChangeDelegate delegate_; | 1890 NullDirectoryChangeDelegate delegate_; |
1858 }; | 1891 }; |
1859 | 1892 |
1860 TEST_F(SyncableDirectoryManagement, TestFileRelease) { | 1893 TEST_F(SyncableDirectoryManagement, TestFileRelease) { |
1861 FilePath path = temp_dir_.path().Append( | 1894 FilePath path = temp_dir_.path().Append( |
1862 Directory::kSyncDatabaseFilename); | 1895 Directory::kSyncDatabaseFilename); |
1863 | 1896 |
1864 syncable::Directory dir(&encryptor_, &handler_, NULL, | 1897 syncable::Directory dir(new OnDiskDirectoryBackingStore("ScopeTest", path), |
1865 new OnDiskDirectoryBackingStore("ScopeTest", path)); | 1898 &handler_, |
| 1899 NULL, |
| 1900 NULL, |
| 1901 NULL); |
1866 DirOpenResult result = | 1902 DirOpenResult result = |
1867 dir.Open("ScopeTest", &delegate_, NullTransactionObserver()); | 1903 dir.Open("ScopeTest", &delegate_, NullTransactionObserver()); |
1868 ASSERT_EQ(result, OPENED); | 1904 ASSERT_EQ(result, OPENED); |
1869 dir.Close(); | 1905 dir.Close(); |
1870 | 1906 |
1871 // Closing the directory should have released the backing database file. | 1907 // Closing the directory should have released the backing database file. |
1872 ASSERT_TRUE(file_util::Delete(path, true)); | 1908 ASSERT_TRUE(file_util::Delete(path, true)); |
1873 } | 1909 } |
1874 | 1910 |
1875 class StressTransactionsDelegate : public base::PlatformThread::Delegate { | 1911 class StressTransactionsDelegate : public base::PlatformThread::Delegate { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1916 }; | 1952 }; |
1917 | 1953 |
1918 TEST(SyncableDirectory, StressTransactions) { | 1954 TEST(SyncableDirectory, StressTransactions) { |
1919 MessageLoop message_loop; | 1955 MessageLoop message_loop; |
1920 ScopedTempDir temp_dir; | 1956 ScopedTempDir temp_dir; |
1921 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1957 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1922 FakeEncryptor encryptor; | 1958 FakeEncryptor encryptor; |
1923 TestUnrecoverableErrorHandler handler; | 1959 TestUnrecoverableErrorHandler handler; |
1924 NullDirectoryChangeDelegate delegate; | 1960 NullDirectoryChangeDelegate delegate; |
1925 std::string dirname = "stress"; | 1961 std::string dirname = "stress"; |
1926 Directory dir(&encryptor, &handler, NULL, | 1962 Directory dir(new InMemoryDirectoryBackingStore(dirname), |
1927 new InMemoryDirectoryBackingStore(dirname)); | 1963 &handler, |
| 1964 NULL, |
| 1965 NULL, |
| 1966 NULL); |
1928 dir.Open(dirname, &delegate, NullTransactionObserver()); | 1967 dir.Open(dirname, &delegate, NullTransactionObserver()); |
1929 | 1968 |
1930 const int kThreadCount = 7; | 1969 const int kThreadCount = 7; |
1931 base::PlatformThreadHandle threads[kThreadCount]; | 1970 base::PlatformThreadHandle threads[kThreadCount]; |
1932 scoped_ptr<StressTransactionsDelegate> thread_delegates[kThreadCount]; | 1971 scoped_ptr<StressTransactionsDelegate> thread_delegates[kThreadCount]; |
1933 | 1972 |
1934 for (int i = 0; i < kThreadCount; ++i) { | 1973 for (int i = 0; i < kThreadCount; ++i) { |
1935 thread_delegates[i].reset(new StressTransactionsDelegate(&dir, i)); | 1974 thread_delegates[i].reset(new StressTransactionsDelegate(&dir, i)); |
1936 ASSERT_TRUE(base::PlatformThread::Create( | 1975 ASSERT_TRUE(base::PlatformThread::Create( |
1937 0, thread_delegates[i].get(), &threads[i])); | 1976 0, thread_delegates[i].get(), &threads[i])); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 2078 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
2040 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 2079 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
2041 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); | 2080 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); |
2042 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); | 2081 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); |
2043 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); | 2082 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); |
2044 } | 2083 } |
2045 | 2084 |
2046 } // namespace | 2085 } // namespace |
2047 } // namespace syncable | 2086 } // namespace syncable |
2048 } // namespace syncer | 2087 } // namespace syncer |
OLD | NEW |