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

Side by Side Diff: chrome/browser/sync/engine/syncapi_unittest.cc

Issue 593094: Add unique hashing to sync API. (Closed)
Patch Set: New unit test, review fixes. Created 10 years, 10 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
OLDNEW
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"
11 #include "chrome/browser/sync/engine/syncapi.h" 12 #include "chrome/browser/sync/engine/syncapi.h"
12 #include "chrome/browser/sync/syncable/directory_manager.h" 13 #include "chrome/browser/sync/syncable/directory_manager.h"
13 #include "chrome/browser/sync/syncable/syncable.h" 14 #include "chrome/browser/sync/syncable/syncable.h"
14 #include "chrome/test/sync/engine/test_directory_setter_upper.h" 15 #include "chrome/test/sync/engine/test_directory_setter_upper.h"
15 16
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace sync_api { 19 namespace sync_api {
19 20
20 class SyncApiTest : public testing::Test { 21 class SyncApiTest : public testing::Test {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 EXPECT_EQ(root_node.GetFirstChildId(), 0); 62 EXPECT_EQ(root_node.GetFirstChildId(), 0);
62 63
63 WriteNode wnode(&trans); 64 WriteNode wnode(&trans);
64 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS, 65 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS,
65 root_node, "testtag")); 66 root_node, "testtag"));
66 wnode.SetIsFolder(false); 67 wnode.SetIsFolder(false);
67 } 68 }
68 { 69 {
69 ReadTransaction trans(&share_); 70 ReadTransaction trans(&share_);
70 ReadNode node(&trans); 71 ReadNode node(&trans);
71 EXPECT_TRUE(node.InitByClientTagLookup("testtag")); 72 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS,
73 "testtag"));
72 74
73 ReadNode root_node(&trans); 75 ReadNode root_node(&trans);
74 root_node.InitByRootLookup(); 76 root_node.InitByRootLookup();
75 EXPECT_NE(node.GetId(), 0); 77 EXPECT_NE(node.GetId(), 0);
76 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId()); 78 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId());
77 } 79 }
78 } 80 }
79 81
82 namespace {
83 std::string HashToHex(const std::string& hash) {
ncarter (slow) 2010/02/18 01:05:40 De-indent.
chron 2010/02/18 01:09:32 Done.
84 return HexEncode(hash.data(), hash.length());
85 }
86 } // namespace
87
88 TEST_F(SyncApiTest, GenerateSyncableHash) {
89 EXPECT_EQ("3B2697579984CEB3D2E306E8826B4ABD17DE9002",
90 HashToHex(BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, "tag1")));
91 EXPECT_EQ("88D150B511506FE219727D642942446430E42ECE",
92 HashToHex(
93 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, "tag1")));
94 EXPECT_EQ("80ED5C3D941768CEF7B073AF480FAD282285B39F",
95 HashToHex(BaseNode::GenerateSyncableHash(syncable::AUTOFILL, "tag1")));
96 EXPECT_EQ("0347982075CCD7F8D5C0A0C3A75D94A76D0890A6",
97 HashToHex(BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, "tag2")));
98 EXPECT_EQ("5D8C6417B6E14B8788B52B45822388014DB7B302",
99 HashToHex(
100 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, "tag2")));
101 EXPECT_EQ("185896CE8E4D1A18CB94DF8EC827E1CB6F032534",
102 HashToHex(BaseNode::GenerateSyncableHash(syncable::AUTOFILL, "tag2")));
103 }
104
105 TEST_F(SyncApiTest, ModelTypesSiloed) {
106 {
107 WriteTransaction trans(&share_);
108 ReadNode root_node(&trans);
109 root_node.InitByRootLookup();
110 EXPECT_EQ(root_node.GetFirstChildId(), 0);
111
112 WriteNode bookmarknode(&trans);
113 EXPECT_TRUE(bookmarknode.InitUniqueByCreation(syncable::BOOKMARKS,
114 root_node, "collideme"));
115 bookmarknode.SetIsFolder(false);
116
117 WriteNode prefnode(&trans);
118 EXPECT_TRUE(prefnode.InitUniqueByCreation(syncable::PREFERENCES,
119 root_node, "collideme"));
120 prefnode.SetIsFolder(false);
121
122 WriteNode autofillnode(&trans);
123 EXPECT_TRUE(autofillnode.InitUniqueByCreation(syncable::AUTOFILL,
124 root_node, "collideme"));
125 autofillnode.SetIsFolder(false);
126 }
127 {
128 ReadTransaction trans(&share_);
129
130 ReadNode bookmarknode(&trans);
131 EXPECT_TRUE(bookmarknode.InitByClientTagLookup(syncable::BOOKMARKS,
132 "collideme"));
133
134 ReadNode prefnode(&trans);
135 EXPECT_TRUE(prefnode.InitByClientTagLookup(syncable::PREFERENCES,
136 "collideme"));
137
138 ReadNode autofillnode(&trans);
139 EXPECT_TRUE(autofillnode.InitByClientTagLookup(syncable::AUTOFILL,
140 "collideme"));
141
142 EXPECT_NE(bookmarknode.GetId(), prefnode.GetId());
143 EXPECT_NE(autofillnode.GetId(), prefnode.GetId());
144 EXPECT_NE(bookmarknode.GetId(), autofillnode.GetId());
145 }
146 }
147
80 TEST_F(SyncApiTest, ReadMissingTagsFails) { 148 TEST_F(SyncApiTest, ReadMissingTagsFails) {
81 { 149 {
82 ReadTransaction trans(&share_); 150 ReadTransaction trans(&share_);
83 ReadNode node(&trans); 151 ReadNode node(&trans);
84 EXPECT_FALSE(node.InitByClientTagLookup("testtag")); 152 EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS,
153 "testtag"));
85 } 154 }
86 { 155 {
87 WriteTransaction trans(&share_); 156 WriteTransaction trans(&share_);
88 WriteNode node(&trans); 157 WriteNode node(&trans);
89 EXPECT_FALSE(node.InitByClientTagLookup("testtag")); 158 EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS,
159 "testtag"));
90 } 160 }
91 } 161 }
92 162
93 // TODO(chron): Hook this all up to the server and write full integration tests 163 // TODO(chron): Hook this all up to the server and write full integration tests
94 // for update->undelete behavior. 164 // for update->undelete behavior.
95 TEST_F(SyncApiTest, TestDeleteBehavior) { 165 TEST_F(SyncApiTest, TestDeleteBehavior) {
96 166
97 int64 node_id; 167 int64 node_id;
98 int64 folder_id; 168 int64 folder_id;
99 std::wstring test_title(L"test1"); 169 std::wstring test_title(L"test1");
(...skipping 15 matching lines...) Expand all
115 wnode.SetIsFolder(false); 185 wnode.SetIsFolder(false);
116 wnode.SetTitle(test_title); 186 wnode.SetTitle(test_title);
117 187
118 node_id = wnode.GetId(); 188 node_id = wnode.GetId();
119 } 189 }
120 190
121 // Ensure we can delete something with a tag. 191 // Ensure we can delete something with a tag.
122 { 192 {
123 WriteTransaction trans(&share_); 193 WriteTransaction trans(&share_);
124 WriteNode wnode(&trans); 194 WriteNode wnode(&trans);
125 EXPECT_TRUE(wnode.InitByClientTagLookup("testtag")); 195 EXPECT_TRUE(wnode.InitByClientTagLookup(syncable::BOOKMARKS,
196 "testtag"));
126 EXPECT_FALSE(wnode.GetIsFolder()); 197 EXPECT_FALSE(wnode.GetIsFolder());
127 EXPECT_EQ(wnode.GetTitle(), test_title); 198 EXPECT_EQ(wnode.GetTitle(), test_title);
128 199
129 wnode.Remove(); 200 wnode.Remove();
130 } 201 }
131 202
132 // Lookup of a node which was deleted should return failure, 203 // Lookup of a node which was deleted should return failure,
133 // but have found some data about the node. 204 // but have found some data about the node.
134 { 205 {
135 ReadTransaction trans(&share_); 206 ReadTransaction trans(&share_);
136 ReadNode node(&trans); 207 ReadNode node(&trans);
137 EXPECT_FALSE(node.InitByClientTagLookup("testtag")); 208 EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS,
209 "testtag"));
138 // Note that for proper function of this API this doesn't need to be 210 // Note that for proper function of this API this doesn't need to be
139 // filled, we're checking just to make sure the DB worked in this test. 211 // filled, we're checking just to make sure the DB worked in this test.
140 EXPECT_EQ(node.GetTitle(), test_title); 212 EXPECT_EQ(node.GetTitle(), test_title);
141 } 213 }
142 214
143 { 215 {
144 WriteTransaction trans(&share_); 216 WriteTransaction trans(&share_);
145 ReadNode folder_node(&trans); 217 ReadNode folder_node(&trans);
146 EXPECT_TRUE(folder_node.InitByIdLookup(folder_id)); 218 EXPECT_TRUE(folder_node.InitByIdLookup(folder_id));
147 219
148 WriteNode wnode(&trans); 220 WriteNode wnode(&trans);
149 // This will undelete the tag. 221 // This will undelete the tag.
150 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS, 222 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS,
151 folder_node, "testtag")); 223 folder_node, "testtag"));
152 EXPECT_EQ(wnode.GetIsFolder(), false); 224 EXPECT_EQ(wnode.GetIsFolder(), false);
153 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); 225 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId());
154 EXPECT_EQ(wnode.GetId(), node_id); 226 EXPECT_EQ(wnode.GetId(), node_id);
155 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared 227 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared
156 wnode.SetTitle(test_title); 228 wnode.SetTitle(test_title);
157 } 229 }
158 230
159 // Now look up should work. 231 // Now look up should work.
160 { 232 {
161 ReadTransaction trans(&share_); 233 ReadTransaction trans(&share_);
162 ReadNode node(&trans); 234 ReadNode node(&trans);
163 EXPECT_TRUE(node.InitByClientTagLookup("testtag")); 235 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS,
236 "testtag"));
164 EXPECT_EQ(node.GetTitle(), test_title); 237 EXPECT_EQ(node.GetTitle(), test_title);
165 EXPECT_EQ(node.GetModelType(), syncable::BOOKMARKS); 238 EXPECT_EQ(node.GetModelType(), syncable::BOOKMARKS);
166 } 239 }
167 } 240 }
168 241
169 } // namespace browser_sync 242 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698