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/basictypes.h" | |
7 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
8 #include "base/file_path.h" | 9 #include "base/file_path.h" |
9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
10 #include "base/location.h" | 11 #include "base/location.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
14 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
15 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
16 #include "base/synchronization/condition_variable.h" | 17 #include "base/synchronization/condition_variable.h" |
17 #include "base/test/values_test_util.h" | 18 #include "base/test/values_test_util.h" |
18 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "sync/internal_api/public/base/node_ordinal.h" | |
20 #include "sync/protocol/bookmark_specifics.pb.h" | 22 #include "sync/protocol/bookmark_specifics.pb.h" |
21 #include "sync/syncable/directory_backing_store.h" | 23 #include "sync/syncable/directory_backing_store.h" |
22 #include "sync/syncable/directory_change_delegate.h" | 24 #include "sync/syncable/directory_change_delegate.h" |
23 #include "sync/syncable/in_memory_directory_backing_store.h" | 25 #include "sync/syncable/in_memory_directory_backing_store.h" |
24 #include "sync/syncable/metahandle_set.h" | 26 #include "sync/syncable/metahandle_set.h" |
25 #include "sync/syncable/mutable_entry.h" | 27 #include "sync/syncable/mutable_entry.h" |
26 #include "sync/syncable/on_disk_directory_backing_store.h" | 28 #include "sync/syncable/on_disk_directory_backing_store.h" |
27 #include "sync/syncable/read_transaction.h" | 29 #include "sync/syncable/read_transaction.h" |
28 #include "sync/syncable/syncable_proto_util.h" | 30 #include "sync/syncable/syncable_proto_util.h" |
29 #include "sync/syncable/syncable_util.h" | 31 #include "sync/syncable/syncable_util.h" |
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1359 EXPECT_TRUE(server_knows.good()); | 1361 EXPECT_TRUE(server_knows.good()); |
1360 | 1362 |
1361 Entry not_is_del(&trans, GET_BY_ID, not_is_del_id); | 1363 Entry not_is_del(&trans, GET_BY_ID, not_is_del_id); |
1362 EXPECT_TRUE(not_is_del.good()); | 1364 EXPECT_TRUE(not_is_del.good()); |
1363 | 1365 |
1364 Entry zombie(&trans, GET_BY_ID, zombie_id); | 1366 Entry zombie(&trans, GET_BY_ID, zombie_id); |
1365 EXPECT_FALSE(zombie.good()); | 1367 EXPECT_FALSE(zombie.good()); |
1366 } | 1368 } |
1367 } | 1369 } |
1368 | 1370 |
1371 TEST_F(SyncableDirectoryTest, OrdinalWithNullSurvivesSaveAndReload) { | |
1372 TestIdFactory id_factory; | |
1373 Id null_child_id; | |
1374 const char null_cstr[] = "\0null\0test"; | |
1375 std::string null_str(null_cstr, arraysize(null_cstr) - 1); | |
1376 NodeOrdinal null_ord = NodeOrdinal(null_str); | |
1377 | |
1378 { | |
1379 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | |
1380 | |
1381 MutableEntry parent(&trans, CREATE, id_factory.root(), "parent"); | |
1382 parent.Put(IS_DIR, true); | |
1383 parent.Put(IS_UNSYNCED, true); | |
1384 | |
1385 MutableEntry child(&trans, CREATE, parent.Get(ID), "child"); | |
1386 child.Put(IS_UNSYNCED, true); | |
1387 child.Put(SERVER_ORDINAL_IN_PARENT, null_ord); | |
1388 | |
1389 null_child_id = child.Get(ID); | |
1390 } | |
1391 | |
1392 EXPECT_EQ(OPENED, SimulateSaveAndReloadDir()); | |
1393 | |
1394 { | |
1395 ReadTransaction trans(FROM_HERE, dir_.get()); | |
1396 | |
1397 Entry null_ordinal_child(&trans, GET_BY_ID, null_child_id); | |
1398 EXPECT_TRUE( | |
1399 null_ord.Equals(null_ordinal_child.Get(SERVER_ORDINAL_IN_PARENT))); | |
1400 } | |
1401 | |
1402 } | |
1403 | |
1369 // An OnDirectoryBackingStore that can be set to always fail SaveChanges. | 1404 // An OnDirectoryBackingStore that can be set to always fail SaveChanges. |
1370 class TestBackingStore : public OnDiskDirectoryBackingStore { | 1405 class TestBackingStore : public OnDiskDirectoryBackingStore { |
1371 public: | 1406 public: |
1372 TestBackingStore(const std::string& dir_name, | 1407 TestBackingStore(const std::string& dir_name, |
1373 const FilePath& backing_filepath); | 1408 const FilePath& backing_filepath); |
1374 | 1409 |
1375 virtual ~TestBackingStore(); | 1410 virtual ~TestBackingStore(); |
1376 | 1411 |
1377 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot) | 1412 virtual bool SaveChanges(const Directory::SaveChangesSnapshot& snapshot) |
1378 OVERRIDE; | 1413 OVERRIDE; |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1707 << "String field #" << i << " changed during save/load"; | 1742 << "String field #" << i << " changed during save/load"; |
1708 } | 1743 } |
1709 for ( ; i < PROTO_FIELDS_END; ++i) { | 1744 for ( ; i < PROTO_FIELDS_END; ++i) { |
1710 EXPECT_EQ(create_pre_save.ref((ProtoField)i).SerializeAsString(), | 1745 EXPECT_EQ(create_pre_save.ref((ProtoField)i).SerializeAsString(), |
1711 create_post_save.ref((ProtoField)i).SerializeAsString()) | 1746 create_post_save.ref((ProtoField)i).SerializeAsString()) |
1712 << "Blob field #" << i << " changed during save/load"; | 1747 << "Blob field #" << i << " changed during save/load"; |
1713 EXPECT_EQ(update_pre_save.ref((ProtoField)i).SerializeAsString(), | 1748 EXPECT_EQ(update_pre_save.ref((ProtoField)i).SerializeAsString(), |
1714 update_post_save.ref((ProtoField)i).SerializeAsString()) | 1749 update_post_save.ref((ProtoField)i).SerializeAsString()) |
1715 << "Blob field #" << i << " changed during save/load"; | 1750 << "Blob field #" << i << " changed during save/load"; |
1716 } | 1751 } |
1752 for ( ; i < ORDINAL_FIELDS_END; ++i) { | |
1753 EXPECT_EQ(create_pre_save.ref((OrdinalField)i).ToInternalValue(), | |
1754 create_post_save.ref((OrdinalField)i).ToInternalValue()) | |
1755 << "Blob field #" << i << " changed during save/load"; | |
1756 EXPECT_EQ(update_pre_save.ref((OrdinalField)i).ToInternalValue(), | |
1757 update_post_save.ref((OrdinalField)i).ToInternalValue()) | |
1758 << "Blob field #" << i << " changed during save/load"; | |
1759 } | |
1760 | |
rlarocque
2012/10/08 20:48:38
nit: unnecessary whitespace.
| |
1717 } | 1761 } |
1718 | 1762 |
1719 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailure) { | 1763 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailure) { |
1720 int64 handle1 = 0; | 1764 int64 handle1 = 0; |
1721 // Set up an item using a regular, saveable directory. | 1765 // Set up an item using a regular, saveable directory. |
1722 { | 1766 { |
1723 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1767 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1724 | 1768 |
1725 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera"); | 1769 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera"); |
1726 ASSERT_TRUE(e1.good()); | 1770 ASSERT_TRUE(e1.good()); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2090 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 2134 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
2091 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 2135 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
2092 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); | 2136 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); |
2093 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); | 2137 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); |
2094 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); | 2138 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); |
2095 } | 2139 } |
2096 | 2140 |
2097 } // namespace | 2141 } // namespace |
2098 } // namespace syncable | 2142 } // namespace syncable |
2099 } // namespace syncer | 2143 } // namespace syncer |
OLD | NEW |