| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
| 6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
| 7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
| 8 | 8 |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 11 #include "base/string_util.h" | |
| 12 #include "chrome/browser/sync/engine/syncapi.h" | 11 #include "chrome/browser/sync/engine/syncapi.h" |
| 13 #include "chrome/browser/sync/syncable/directory_manager.h" | 12 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 14 #include "chrome/browser/sync/syncable/syncable.h" | 13 #include "chrome/browser/sync/syncable/syncable.h" |
| 15 #include "chrome/test/sync/engine/test_directory_setter_upper.h" | 14 #include "chrome/test/sync/engine/test_directory_setter_upper.h" |
| 16 | 15 |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 17 |
| 19 namespace sync_api { | 18 namespace sync_api { |
| 20 | 19 |
| 21 class SyncApiTest : public testing::Test { | 20 class SyncApiTest : public testing::Test { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, | 71 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, |
| 73 "testtag")); | 72 "testtag")); |
| 74 | 73 |
| 75 ReadNode root_node(&trans); | 74 ReadNode root_node(&trans); |
| 76 root_node.InitByRootLookup(); | 75 root_node.InitByRootLookup(); |
| 77 EXPECT_NE(node.GetId(), 0); | 76 EXPECT_NE(node.GetId(), 0); |
| 78 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId()); | 77 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId()); |
| 79 } | 78 } |
| 80 } | 79 } |
| 81 | 80 |
| 82 namespace { | 81 TEST_F(SyncApiTest, GenerateSyncableHash) { |
| 83 std::string HashToHex(const std::string& hash) { | 82 EXPECT_EQ("OyaXV5mEzrPS4wbogmtKvRfekAI=", |
| 84 return HexEncode(hash.data(), hash.length()); | 83 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, "tag1")); |
| 85 } | 84 EXPECT_EQ("iNFQtRFQb+IZcn1kKUJEZDDkLs4=", |
| 86 } // namespace | 85 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, "tag1")); |
| 86 EXPECT_EQ("gO1cPZQXaM73sHOvSA+tKCKFs58=", |
| 87 BaseNode::GenerateSyncableHash(syncable::AUTOFILL, "tag1")); |
| 87 | 88 |
| 88 // TODO(chron): Finalize the hash format. Renable test. http://crbug.com/36827 | 89 EXPECT_EQ("A0eYIHXM1/jVwKDDp12Up20IkKY=", |
| 89 TEST_F(SyncApiTest, DISABLED_GenerateSyncableHash) { | 90 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, "tag2")); |
| 90 /* | 91 EXPECT_EQ("XYxkF7bhS4eItStFgiOIAU23swI=", |
| 91 EXPECT_EQ("3B2697579984CEB3D2E306E8826B4ABD17DE9002", | 92 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, "tag2")); |
| 92 HashToHex(BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, "tag1"))); | 93 EXPECT_EQ("GFiWzo5NGhjLlN+OyCfhy28DJTQ=", |
| 93 EXPECT_EQ("88D150B511506FE219727D642942446430E42ECE", | 94 BaseNode::GenerateSyncableHash(syncable::AUTOFILL, "tag2")); |
| 94 HashToHex( | |
| 95 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, "tag1"))); | |
| 96 EXPECT_EQ("80ED5C3D941768CEF7B073AF480FAD282285B39F", | |
| 97 HashToHex(BaseNode::GenerateSyncableHash(syncable::AUTOFILL, "tag1"))); | |
| 98 EXPECT_EQ("0347982075CCD7F8D5C0A0C3A75D94A76D0890A6", | |
| 99 HashToHex(BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, "tag2"))); | |
| 100 EXPECT_EQ("5D8C6417B6E14B8788B52B45822388014DB7B302", | |
| 101 HashToHex( | |
| 102 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, "tag2"))); | |
| 103 EXPECT_EQ("185896CE8E4D1A18CB94DF8EC827E1CB6F032534", | |
| 104 HashToHex(BaseNode::GenerateSyncableHash(syncable::AUTOFILL, "tag2"))); | |
| 105 */ | |
| 106 } | 95 } |
| 107 | 96 |
| 108 TEST_F(SyncApiTest, ModelTypesSiloed) { | 97 TEST_F(SyncApiTest, ModelTypesSiloed) { |
| 109 { | 98 { |
| 110 WriteTransaction trans(&share_); | 99 WriteTransaction trans(&share_); |
| 111 ReadNode root_node(&trans); | 100 ReadNode root_node(&trans); |
| 112 root_node.InitByRootLookup(); | 101 root_node.InitByRootLookup(); |
| 113 EXPECT_EQ(root_node.GetFirstChildId(), 0); | 102 EXPECT_EQ(root_node.GetFirstChildId(), 0); |
| 114 | 103 |
| 115 WriteNode bookmarknode(&trans); | 104 WriteNode bookmarknode(&trans); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 ReadTransaction trans(&share_); | 225 ReadTransaction trans(&share_); |
| 237 ReadNode node(&trans); | 226 ReadNode node(&trans); |
| 238 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, | 227 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, |
| 239 "testtag")); | 228 "testtag")); |
| 240 EXPECT_EQ(node.GetTitle(), test_title); | 229 EXPECT_EQ(node.GetTitle(), test_title); |
| 241 EXPECT_EQ(node.GetModelType(), syncable::BOOKMARKS); | 230 EXPECT_EQ(node.GetModelType(), syncable::BOOKMARKS); |
| 242 } | 231 } |
| 243 } | 232 } |
| 244 | 233 |
| 245 } // namespace browser_sync | 234 } // namespace browser_sync |
| OLD | NEW |