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

Side by Side Diff: sync/internal_api/sync_manager_impl_unittest.cc

Issue 265853004: Revert of Keep track of which attachments are referenced by which sync entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « sync/internal_api/public/write_node.h ('k') | sync/internal_api/write_node.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 // 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 <cstddef> 9 #include <cstddef>
10 #include <map> 10 #include <map>
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 public: 203 public:
204 virtual void SetUp() { 204 virtual void SetUp() {
205 test_user_share_.SetUp(); 205 test_user_share_.SetUp();
206 } 206 }
207 207
208 virtual void TearDown() { 208 virtual void TearDown() {
209 test_user_share_.TearDown(); 209 test_user_share_.TearDown();
210 } 210 }
211 211
212 protected: 212 protected:
213 // Create an entry with the given |model_type|, |client_tag| and
214 // |attachment_metadata|.
215 void CreateEntryWithAttachmentMetadata(
216 const ModelType& model_type,
217 const std::string& client_tag,
218 const sync_pb::AttachmentMetadata& attachment_metadata);
219
220 // Attempts to load the entry specified by |model_type| and |client_tag| and
221 // returns the lookup result code.
222 BaseNode::InitByLookupResult LookupEntryByClientTag(
223 const ModelType& model_type,
224 const std::string& client_tag);
225
226 // Replace the entry specified by |model_type| and |client_tag| with a
227 // tombstone.
228 void ReplaceWithTombstone(const ModelType& model_type,
229 const std::string& client_tag);
230
231 // Save changes to the Directory, destroy it then reload it.
232 bool ReloadDir();
233
234 UserShare* user_share();
235 syncable::Directory* dir();
236 SyncEncryptionHandler* encryption_handler();
237
238 private:
239 base::MessageLoop message_loop_; 213 base::MessageLoop message_loop_;
240 TestUserShare test_user_share_; 214 TestUserShare test_user_share_;
241 }; 215 };
242 216
243 UserShare* SyncApiTest::user_share() {
244 return test_user_share_.user_share();
245 }
246
247 syncable::Directory* SyncApiTest::dir() {
248 return test_user_share_.user_share()->directory.get();
249 }
250
251 SyncEncryptionHandler* SyncApiTest::encryption_handler() {
252 return test_user_share_.encryption_handler();
253 }
254
255 bool SyncApiTest::ReloadDir() {
256 return test_user_share_.Reload();
257 }
258
259 void SyncApiTest::CreateEntryWithAttachmentMetadata(
260 const ModelType& model_type,
261 const std::string& client_tag,
262 const sync_pb::AttachmentMetadata& attachment_metadata) {
263 syncer::WriteTransaction trans(FROM_HERE, user_share());
264 syncer::ReadNode root_node(&trans);
265 root_node.InitByRootLookup();
266 syncer::WriteNode node(&trans);
267 ASSERT_EQ(node.InitUniqueByCreation(model_type, root_node, client_tag),
268 syncer::WriteNode::INIT_SUCCESS);
269 node.SetAttachmentMetadata(attachment_metadata);
270 }
271
272 BaseNode::InitByLookupResult SyncApiTest::LookupEntryByClientTag(
273 const ModelType& model_type,
274 const std::string& client_tag) {
275 syncer::ReadTransaction trans(FROM_HERE, user_share());
276 syncer::ReadNode node(&trans);
277 return node.InitByClientTagLookup(model_type, client_tag);
278 }
279
280 void SyncApiTest::ReplaceWithTombstone(const ModelType& model_type,
281 const std::string& client_tag) {
282 syncer::WriteTransaction trans(FROM_HERE, user_share());
283 syncer::WriteNode node(&trans);
284 ASSERT_EQ(node.InitByClientTagLookup(model_type, client_tag),
285 syncer::WriteNode::INIT_OK);
286 node.Tombstone();
287 }
288
289 TEST_F(SyncApiTest, SanityCheckTest) { 217 TEST_F(SyncApiTest, SanityCheckTest) {
290 { 218 {
291 ReadTransaction trans(FROM_HERE, user_share()); 219 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
292 EXPECT_TRUE(trans.GetWrappedTrans()); 220 EXPECT_TRUE(trans.GetWrappedTrans());
293 } 221 }
294 { 222 {
295 WriteTransaction trans(FROM_HERE, user_share()); 223 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
296 EXPECT_TRUE(trans.GetWrappedTrans()); 224 EXPECT_TRUE(trans.GetWrappedTrans());
297 } 225 }
298 { 226 {
299 // No entries but root should exist 227 // No entries but root should exist
300 ReadTransaction trans(FROM_HERE, user_share()); 228 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
301 ReadNode node(&trans); 229 ReadNode node(&trans);
302 // Metahandle 1 can be root, sanity check 2 230 // Metahandle 1 can be root, sanity check 2
303 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, node.InitByIdLookup(2)); 231 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, node.InitByIdLookup(2));
304 } 232 }
305 } 233 }
306 234
307 TEST_F(SyncApiTest, BasicTagWrite) { 235 TEST_F(SyncApiTest, BasicTagWrite) {
308 { 236 {
309 ReadTransaction trans(FROM_HERE, user_share()); 237 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
310 ReadNode root_node(&trans); 238 ReadNode root_node(&trans);
311 root_node.InitByRootLookup(); 239 root_node.InitByRootLookup();
312 EXPECT_EQ(root_node.GetFirstChildId(), 0); 240 EXPECT_EQ(root_node.GetFirstChildId(), 0);
313 } 241 }
314 242
315 ignore_result(MakeNode(user_share(), BOOKMARKS, "testtag")); 243 ignore_result(MakeNode(test_user_share_.user_share(),
244 BOOKMARKS, "testtag"));
316 245
317 { 246 {
318 ReadTransaction trans(FROM_HERE, user_share()); 247 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
319 ReadNode node(&trans); 248 ReadNode node(&trans);
320 EXPECT_EQ(BaseNode::INIT_OK, 249 EXPECT_EQ(BaseNode::INIT_OK,
321 node.InitByClientTagLookup(BOOKMARKS, "testtag")); 250 node.InitByClientTagLookup(BOOKMARKS, "testtag"));
322 251
323 ReadNode root_node(&trans); 252 ReadNode root_node(&trans);
324 root_node.InitByRootLookup(); 253 root_node.InitByRootLookup();
325 EXPECT_NE(node.GetId(), 0); 254 EXPECT_NE(node.GetId(), 0);
326 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId()); 255 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId());
327 } 256 }
328 } 257 }
329 258
330 TEST_F(SyncApiTest, ModelTypesSiloed) { 259 TEST_F(SyncApiTest, ModelTypesSiloed) {
331 { 260 {
332 WriteTransaction trans(FROM_HERE, user_share()); 261 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
333 ReadNode root_node(&trans); 262 ReadNode root_node(&trans);
334 root_node.InitByRootLookup(); 263 root_node.InitByRootLookup();
335 EXPECT_EQ(root_node.GetFirstChildId(), 0); 264 EXPECT_EQ(root_node.GetFirstChildId(), 0);
336 } 265 }
337 266
338 ignore_result(MakeNode(user_share(), BOOKMARKS, "collideme")); 267 ignore_result(MakeNode(test_user_share_.user_share(),
339 ignore_result(MakeNode(user_share(), PREFERENCES, "collideme")); 268 BOOKMARKS, "collideme"));
340 ignore_result(MakeNode(user_share(), AUTOFILL, "collideme")); 269 ignore_result(MakeNode(test_user_share_.user_share(),
270 PREFERENCES, "collideme"));
271 ignore_result(MakeNode(test_user_share_.user_share(),
272 AUTOFILL, "collideme"));
341 273
342 { 274 {
343 ReadTransaction trans(FROM_HERE, user_share()); 275 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
344 276
345 ReadNode bookmarknode(&trans); 277 ReadNode bookmarknode(&trans);
346 EXPECT_EQ(BaseNode::INIT_OK, 278 EXPECT_EQ(BaseNode::INIT_OK,
347 bookmarknode.InitByClientTagLookup(BOOKMARKS, 279 bookmarknode.InitByClientTagLookup(BOOKMARKS,
348 "collideme")); 280 "collideme"));
349 281
350 ReadNode prefnode(&trans); 282 ReadNode prefnode(&trans);
351 EXPECT_EQ(BaseNode::INIT_OK, 283 EXPECT_EQ(BaseNode::INIT_OK,
352 prefnode.InitByClientTagLookup(PREFERENCES, 284 prefnode.InitByClientTagLookup(PREFERENCES,
353 "collideme")); 285 "collideme"));
354 286
355 ReadNode autofillnode(&trans); 287 ReadNode autofillnode(&trans);
356 EXPECT_EQ(BaseNode::INIT_OK, 288 EXPECT_EQ(BaseNode::INIT_OK,
357 autofillnode.InitByClientTagLookup(AUTOFILL, 289 autofillnode.InitByClientTagLookup(AUTOFILL,
358 "collideme")); 290 "collideme"));
359 291
360 EXPECT_NE(bookmarknode.GetId(), prefnode.GetId()); 292 EXPECT_NE(bookmarknode.GetId(), prefnode.GetId());
361 EXPECT_NE(autofillnode.GetId(), prefnode.GetId()); 293 EXPECT_NE(autofillnode.GetId(), prefnode.GetId());
362 EXPECT_NE(bookmarknode.GetId(), autofillnode.GetId()); 294 EXPECT_NE(bookmarknode.GetId(), autofillnode.GetId());
363 } 295 }
364 } 296 }
365 297
366 TEST_F(SyncApiTest, ReadMissingTagsFails) { 298 TEST_F(SyncApiTest, ReadMissingTagsFails) {
367 { 299 {
368 ReadTransaction trans(FROM_HERE, user_share()); 300 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
369 ReadNode node(&trans); 301 ReadNode node(&trans);
370 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, 302 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD,
371 node.InitByClientTagLookup(BOOKMARKS, 303 node.InitByClientTagLookup(BOOKMARKS,
372 "testtag")); 304 "testtag"));
373 } 305 }
374 { 306 {
375 WriteTransaction trans(FROM_HERE, user_share()); 307 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
376 WriteNode node(&trans); 308 WriteNode node(&trans);
377 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, 309 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD,
378 node.InitByClientTagLookup(BOOKMARKS, 310 node.InitByClientTagLookup(BOOKMARKS,
379 "testtag")); 311 "testtag"));
380 } 312 }
381 } 313 }
382 314
383 // TODO(chron): Hook this all up to the server and write full integration tests 315 // TODO(chron): Hook this all up to the server and write full integration tests
384 // for update->undelete behavior. 316 // for update->undelete behavior.
385 TEST_F(SyncApiTest, TestDeleteBehavior) { 317 TEST_F(SyncApiTest, TestDeleteBehavior) {
386 int64 node_id; 318 int64 node_id;
387 int64 folder_id; 319 int64 folder_id;
388 std::string test_title("test1"); 320 std::string test_title("test1");
389 321
390 { 322 {
391 WriteTransaction trans(FROM_HERE, user_share()); 323 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
392 ReadNode root_node(&trans); 324 ReadNode root_node(&trans);
393 root_node.InitByRootLookup(); 325 root_node.InitByRootLookup();
394 326
395 // we'll use this spare folder later 327 // we'll use this spare folder later
396 WriteNode folder_node(&trans); 328 WriteNode folder_node(&trans);
397 EXPECT_TRUE(folder_node.InitBookmarkByCreation(root_node, NULL)); 329 EXPECT_TRUE(folder_node.InitBookmarkByCreation(root_node, NULL));
398 folder_id = folder_node.GetId(); 330 folder_id = folder_node.GetId();
399 331
400 WriteNode wnode(&trans); 332 WriteNode wnode(&trans);
401 WriteNode::InitUniqueByCreationResult result = 333 WriteNode::InitUniqueByCreationResult result =
402 wnode.InitUniqueByCreation(BOOKMARKS, root_node, "testtag"); 334 wnode.InitUniqueByCreation(BOOKMARKS, root_node, "testtag");
403 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 335 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
404 wnode.SetIsFolder(false); 336 wnode.SetIsFolder(false);
405 wnode.SetTitle(test_title); 337 wnode.SetTitle(test_title);
406 338
407 node_id = wnode.GetId(); 339 node_id = wnode.GetId();
408 } 340 }
409 341
410 // Ensure we can delete something with a tag. 342 // Ensure we can delete something with a tag.
411 { 343 {
412 WriteTransaction trans(FROM_HERE, user_share()); 344 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
413 WriteNode wnode(&trans); 345 WriteNode wnode(&trans);
414 EXPECT_EQ(BaseNode::INIT_OK, 346 EXPECT_EQ(BaseNode::INIT_OK,
415 wnode.InitByClientTagLookup(BOOKMARKS, 347 wnode.InitByClientTagLookup(BOOKMARKS,
416 "testtag")); 348 "testtag"));
417 EXPECT_FALSE(wnode.GetIsFolder()); 349 EXPECT_FALSE(wnode.GetIsFolder());
418 EXPECT_EQ(wnode.GetTitle(), test_title); 350 EXPECT_EQ(wnode.GetTitle(), test_title);
419 351
420 wnode.Tombstone(); 352 wnode.Tombstone();
421 } 353 }
422 354
423 // Lookup of a node which was deleted should return failure, 355 // Lookup of a node which was deleted should return failure,
424 // but have found some data about the node. 356 // but have found some data about the node.
425 { 357 {
426 ReadTransaction trans(FROM_HERE, user_share()); 358 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
427 ReadNode node(&trans); 359 ReadNode node(&trans);
428 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, 360 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL,
429 node.InitByClientTagLookup(BOOKMARKS, 361 node.InitByClientTagLookup(BOOKMARKS,
430 "testtag")); 362 "testtag"));
431 // Note that for proper function of this API this doesn't need to be 363 // Note that for proper function of this API this doesn't need to be
432 // filled, we're checking just to make sure the DB worked in this test. 364 // filled, we're checking just to make sure the DB worked in this test.
433 EXPECT_EQ(node.GetTitle(), test_title); 365 EXPECT_EQ(node.GetTitle(), test_title);
434 } 366 }
435 367
436 { 368 {
437 WriteTransaction trans(FROM_HERE, user_share()); 369 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
438 ReadNode folder_node(&trans); 370 ReadNode folder_node(&trans);
439 EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id)); 371 EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id));
440 372
441 WriteNode wnode(&trans); 373 WriteNode wnode(&trans);
442 // This will undelete the tag. 374 // This will undelete the tag.
443 WriteNode::InitUniqueByCreationResult result = 375 WriteNode::InitUniqueByCreationResult result =
444 wnode.InitUniqueByCreation(BOOKMARKS, folder_node, "testtag"); 376 wnode.InitUniqueByCreation(BOOKMARKS, folder_node, "testtag");
445 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 377 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
446 EXPECT_EQ(wnode.GetIsFolder(), false); 378 EXPECT_EQ(wnode.GetIsFolder(), false);
447 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); 379 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId());
448 EXPECT_EQ(wnode.GetId(), node_id); 380 EXPECT_EQ(wnode.GetId(), node_id);
449 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared 381 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared
450 wnode.SetTitle(test_title); 382 wnode.SetTitle(test_title);
451 } 383 }
452 384
453 // Now look up should work. 385 // Now look up should work.
454 { 386 {
455 ReadTransaction trans(FROM_HERE, user_share()); 387 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
456 ReadNode node(&trans); 388 ReadNode node(&trans);
457 EXPECT_EQ(BaseNode::INIT_OK, 389 EXPECT_EQ(BaseNode::INIT_OK,
458 node.InitByClientTagLookup(BOOKMARKS, 390 node.InitByClientTagLookup(BOOKMARKS,
459 "testtag")); 391 "testtag"));
460 EXPECT_EQ(node.GetTitle(), test_title); 392 EXPECT_EQ(node.GetTitle(), test_title);
461 EXPECT_EQ(node.GetModelType(), BOOKMARKS); 393 EXPECT_EQ(node.GetModelType(), BOOKMARKS);
462 } 394 }
463 } 395 }
464 396
465 TEST_F(SyncApiTest, WriteAndReadPassword) { 397 TEST_F(SyncApiTest, WriteAndReadPassword) {
466 KeyParams params = {"localhost", "username", "passphrase"}; 398 KeyParams params = {"localhost", "username", "passphrase"};
467 { 399 {
468 ReadTransaction trans(FROM_HERE, user_share()); 400 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
469 trans.GetCryptographer()->AddKey(params); 401 trans.GetCryptographer()->AddKey(params);
470 } 402 }
471 { 403 {
472 WriteTransaction trans(FROM_HERE, user_share()); 404 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
473 ReadNode root_node(&trans); 405 ReadNode root_node(&trans);
474 root_node.InitByRootLookup(); 406 root_node.InitByRootLookup();
475 407
476 WriteNode password_node(&trans); 408 WriteNode password_node(&trans);
477 WriteNode::InitUniqueByCreationResult result = 409 WriteNode::InitUniqueByCreationResult result =
478 password_node.InitUniqueByCreation(PASSWORDS, 410 password_node.InitUniqueByCreation(PASSWORDS,
479 root_node, "foo"); 411 root_node, "foo");
480 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 412 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
481 sync_pb::PasswordSpecificsData data; 413 sync_pb::PasswordSpecificsData data;
482 data.set_password_value("secret"); 414 data.set_password_value("secret");
483 password_node.SetPasswordSpecifics(data); 415 password_node.SetPasswordSpecifics(data);
484 } 416 }
485 { 417 {
486 ReadTransaction trans(FROM_HERE, user_share()); 418 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
487 ReadNode root_node(&trans); 419 ReadNode root_node(&trans);
488 root_node.InitByRootLookup(); 420 root_node.InitByRootLookup();
489 421
490 ReadNode password_node(&trans); 422 ReadNode password_node(&trans);
491 EXPECT_EQ(BaseNode::INIT_OK, 423 EXPECT_EQ(BaseNode::INIT_OK,
492 password_node.InitByClientTagLookup(PASSWORDS, "foo")); 424 password_node.InitByClientTagLookup(PASSWORDS, "foo"));
493 const sync_pb::PasswordSpecificsData& data = 425 const sync_pb::PasswordSpecificsData& data =
494 password_node.GetPasswordSpecifics(); 426 password_node.GetPasswordSpecifics();
495 EXPECT_EQ("secret", data.password_value()); 427 EXPECT_EQ("secret", data.password_value());
496 } 428 }
497 } 429 }
498 430
499 TEST_F(SyncApiTest, WriteEncryptedTitle) { 431 TEST_F(SyncApiTest, WriteEncryptedTitle) {
500 KeyParams params = {"localhost", "username", "passphrase"}; 432 KeyParams params = {"localhost", "username", "passphrase"};
501 { 433 {
502 ReadTransaction trans(FROM_HERE, user_share()); 434 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
503 trans.GetCryptographer()->AddKey(params); 435 trans.GetCryptographer()->AddKey(params);
504 } 436 }
505 encryption_handler()->EnableEncryptEverything(); 437 test_user_share_.encryption_handler()->EnableEncryptEverything();
506 int bookmark_id; 438 int bookmark_id;
507 { 439 {
508 WriteTransaction trans(FROM_HERE, user_share()); 440 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
509 ReadNode root_node(&trans); 441 ReadNode root_node(&trans);
510 root_node.InitByRootLookup(); 442 root_node.InitByRootLookup();
511 443
512 WriteNode bookmark_node(&trans); 444 WriteNode bookmark_node(&trans);
513 ASSERT_TRUE(bookmark_node.InitBookmarkByCreation(root_node, NULL)); 445 ASSERT_TRUE(bookmark_node.InitBookmarkByCreation(root_node, NULL));
514 bookmark_id = bookmark_node.GetId(); 446 bookmark_id = bookmark_node.GetId();
515 bookmark_node.SetTitle("foo"); 447 bookmark_node.SetTitle("foo");
516 448
517 WriteNode pref_node(&trans); 449 WriteNode pref_node(&trans);
518 WriteNode::InitUniqueByCreationResult result = 450 WriteNode::InitUniqueByCreationResult result =
519 pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar"); 451 pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar");
520 ASSERT_EQ(WriteNode::INIT_SUCCESS, result); 452 ASSERT_EQ(WriteNode::INIT_SUCCESS, result);
521 pref_node.SetTitle("bar"); 453 pref_node.SetTitle("bar");
522 } 454 }
523 { 455 {
524 ReadTransaction trans(FROM_HERE, user_share()); 456 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
525 ReadNode root_node(&trans); 457 ReadNode root_node(&trans);
526 root_node.InitByRootLookup(); 458 root_node.InitByRootLookup();
527 459
528 ReadNode bookmark_node(&trans); 460 ReadNode bookmark_node(&trans);
529 ASSERT_EQ(BaseNode::INIT_OK, bookmark_node.InitByIdLookup(bookmark_id)); 461 ASSERT_EQ(BaseNode::INIT_OK, bookmark_node.InitByIdLookup(bookmark_id));
530 EXPECT_EQ("foo", bookmark_node.GetTitle()); 462 EXPECT_EQ("foo", bookmark_node.GetTitle());
531 EXPECT_EQ(kEncryptedString, 463 EXPECT_EQ(kEncryptedString,
532 bookmark_node.GetEntry()->GetNonUniqueName()); 464 bookmark_node.GetEntry()->GetNonUniqueName());
533 465
534 ReadNode pref_node(&trans); 466 ReadNode pref_node(&trans);
535 ASSERT_EQ(BaseNode::INIT_OK, 467 ASSERT_EQ(BaseNode::INIT_OK,
536 pref_node.InitByClientTagLookup(PREFERENCES, 468 pref_node.InitByClientTagLookup(PREFERENCES,
537 "bar")); 469 "bar"));
538 EXPECT_EQ(kEncryptedString, pref_node.GetTitle()); 470 EXPECT_EQ(kEncryptedString, pref_node.GetTitle());
539 } 471 }
540 } 472 }
541 473
542 TEST_F(SyncApiTest, BaseNodeSetSpecifics) { 474 TEST_F(SyncApiTest, BaseNodeSetSpecifics) {
543 int64 child_id = MakeNode(user_share(), BOOKMARKS, "testtag"); 475 int64 child_id = MakeNode(test_user_share_.user_share(),
544 WriteTransaction trans(FROM_HERE, user_share()); 476 BOOKMARKS, "testtag");
477 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
545 WriteNode node(&trans); 478 WriteNode node(&trans);
546 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); 479 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id));
547 480
548 sync_pb::EntitySpecifics entity_specifics; 481 sync_pb::EntitySpecifics entity_specifics;
549 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); 482 entity_specifics.mutable_bookmark()->set_url("http://www.google.com");
550 483
551 EXPECT_NE(entity_specifics.SerializeAsString(), 484 EXPECT_NE(entity_specifics.SerializeAsString(),
552 node.GetEntitySpecifics().SerializeAsString()); 485 node.GetEntitySpecifics().SerializeAsString());
553 node.SetEntitySpecifics(entity_specifics); 486 node.SetEntitySpecifics(entity_specifics);
554 EXPECT_EQ(entity_specifics.SerializeAsString(), 487 EXPECT_EQ(entity_specifics.SerializeAsString(),
555 node.GetEntitySpecifics().SerializeAsString()); 488 node.GetEntitySpecifics().SerializeAsString());
556 } 489 }
557 490
558 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) { 491 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) {
559 int64 child_id = MakeNode(user_share(), BOOKMARKS, "testtag"); 492 int64 child_id = MakeNode(test_user_share_.user_share(),
560 WriteTransaction trans(FROM_HERE, user_share()); 493 BOOKMARKS, "testtag");
494 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
561 WriteNode node(&trans); 495 WriteNode node(&trans);
562 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); 496 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id));
563 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); 497 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty());
564 498
565 sync_pb::EntitySpecifics entity_specifics; 499 sync_pb::EntitySpecifics entity_specifics;
566 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); 500 entity_specifics.mutable_bookmark()->set_url("http://www.google.com");
567 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100); 501 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100);
568 node.SetEntitySpecifics(entity_specifics); 502 node.SetEntitySpecifics(entity_specifics);
569 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); 503 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty());
570 504
571 entity_specifics.mutable_unknown_fields()->Clear(); 505 entity_specifics.mutable_unknown_fields()->Clear();
572 node.SetEntitySpecifics(entity_specifics); 506 node.SetEntitySpecifics(entity_specifics);
573 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); 507 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty());
574 } 508 }
575 509
576 TEST_F(SyncApiTest, EmptyTags) { 510 TEST_F(SyncApiTest, EmptyTags) {
577 WriteTransaction trans(FROM_HERE, user_share()); 511 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
578 ReadNode root_node(&trans); 512 ReadNode root_node(&trans);
579 root_node.InitByRootLookup(); 513 root_node.InitByRootLookup();
580 WriteNode node(&trans); 514 WriteNode node(&trans);
581 std::string empty_tag; 515 std::string empty_tag;
582 WriteNode::InitUniqueByCreationResult result = 516 WriteNode::InitUniqueByCreationResult result =
583 node.InitUniqueByCreation(TYPED_URLS, root_node, empty_tag); 517 node.InitUniqueByCreation(TYPED_URLS, root_node, empty_tag);
584 EXPECT_NE(WriteNode::INIT_SUCCESS, result); 518 EXPECT_NE(WriteNode::INIT_SUCCESS, result);
585 EXPECT_EQ(BaseNode::INIT_FAILED_PRECONDITION, 519 EXPECT_EQ(BaseNode::INIT_FAILED_PRECONDITION,
586 node.InitByTagLookup(empty_tag)); 520 node.InitByTagLookup(empty_tag));
587 } 521 }
588 522
589 // Test counting nodes when the type's root node has no children. 523 // Test counting nodes when the type's root node has no children.
590 TEST_F(SyncApiTest, GetTotalNodeCountEmpty) { 524 TEST_F(SyncApiTest, GetTotalNodeCountEmpty) {
591 int64 type_root = MakeServerNodeForType(user_share(), BOOKMARKS); 525 int64 type_root = MakeServerNodeForType(test_user_share_.user_share(),
526 BOOKMARKS);
592 { 527 {
593 ReadTransaction trans(FROM_HERE, user_share()); 528 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
594 ReadNode type_root_node(&trans); 529 ReadNode type_root_node(&trans);
595 EXPECT_EQ(BaseNode::INIT_OK, 530 EXPECT_EQ(BaseNode::INIT_OK,
596 type_root_node.InitByIdLookup(type_root)); 531 type_root_node.InitByIdLookup(type_root));
597 EXPECT_EQ(1, type_root_node.GetTotalNodeCount()); 532 EXPECT_EQ(1, type_root_node.GetTotalNodeCount());
598 } 533 }
599 } 534 }
600 535
601 // Test counting nodes when there is one child beneath the type's root. 536 // Test counting nodes when there is one child beneath the type's root.
602 TEST_F(SyncApiTest, GetTotalNodeCountOneChild) { 537 TEST_F(SyncApiTest, GetTotalNodeCountOneChild) {
603 int64 type_root = MakeServerNodeForType(user_share(), BOOKMARKS); 538 int64 type_root = MakeServerNodeForType(test_user_share_.user_share(),
604 int64 parent = MakeFolderWithParent(user_share(), BOOKMARKS, type_root, NULL); 539 BOOKMARKS);
540 int64 parent = MakeFolderWithParent(test_user_share_.user_share(),
541 BOOKMARKS,
542 type_root,
543 NULL);
605 { 544 {
606 ReadTransaction trans(FROM_HERE, user_share()); 545 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
607 ReadNode type_root_node(&trans); 546 ReadNode type_root_node(&trans);
608 EXPECT_EQ(BaseNode::INIT_OK, 547 EXPECT_EQ(BaseNode::INIT_OK,
609 type_root_node.InitByIdLookup(type_root)); 548 type_root_node.InitByIdLookup(type_root));
610 EXPECT_EQ(2, type_root_node.GetTotalNodeCount()); 549 EXPECT_EQ(2, type_root_node.GetTotalNodeCount());
611 ReadNode parent_node(&trans); 550 ReadNode parent_node(&trans);
612 EXPECT_EQ(BaseNode::INIT_OK, 551 EXPECT_EQ(BaseNode::INIT_OK,
613 parent_node.InitByIdLookup(parent)); 552 parent_node.InitByIdLookup(parent));
614 EXPECT_EQ(1, parent_node.GetTotalNodeCount()); 553 EXPECT_EQ(1, parent_node.GetTotalNodeCount());
615 } 554 }
616 } 555 }
617 556
618 // Test counting nodes when there are multiple children beneath the type root, 557 // Test counting nodes when there are multiple children beneath the type root,
619 // and one of those children has children of its own. 558 // and one of those children has children of its own.
620 TEST_F(SyncApiTest, GetTotalNodeCountMultipleChildren) { 559 TEST_F(SyncApiTest, GetTotalNodeCountMultipleChildren) {
621 int64 type_root = MakeServerNodeForType(user_share(), BOOKMARKS); 560 int64 type_root = MakeServerNodeForType(test_user_share_.user_share(),
622 int64 parent = MakeFolderWithParent(user_share(), BOOKMARKS, type_root, NULL); 561 BOOKMARKS);
623 ignore_result(MakeFolderWithParent(user_share(), BOOKMARKS, type_root, NULL)); 562 int64 parent = MakeFolderWithParent(test_user_share_.user_share(),
624 int64 child1 = MakeFolderWithParent(user_share(), BOOKMARKS, parent, NULL); 563 BOOKMARKS,
625 ignore_result(MakeBookmarkWithParent(user_share(), parent, NULL)); 564 type_root,
626 ignore_result(MakeBookmarkWithParent(user_share(), child1, NULL)); 565 NULL);
566 ignore_result(MakeFolderWithParent(test_user_share_.user_share(),
567 BOOKMARKS,
568 type_root,
569 NULL));
570 int64 child1 = MakeFolderWithParent(
571 test_user_share_.user_share(),
572 BOOKMARKS,
573 parent,
574 NULL);
575 ignore_result(MakeBookmarkWithParent(
576 test_user_share_.user_share(),
577 parent,
578 NULL));
579 ignore_result(MakeBookmarkWithParent(
580 test_user_share_.user_share(),
581 child1,
582 NULL));
627 583
628 { 584 {
629 ReadTransaction trans(FROM_HERE, user_share()); 585 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
630 ReadNode type_root_node(&trans); 586 ReadNode type_root_node(&trans);
631 EXPECT_EQ(BaseNode::INIT_OK, 587 EXPECT_EQ(BaseNode::INIT_OK,
632 type_root_node.InitByIdLookup(type_root)); 588 type_root_node.InitByIdLookup(type_root));
633 EXPECT_EQ(6, type_root_node.GetTotalNodeCount()); 589 EXPECT_EQ(6, type_root_node.GetTotalNodeCount());
634 ReadNode node(&trans); 590 ReadNode node(&trans);
635 EXPECT_EQ(BaseNode::INIT_OK, 591 EXPECT_EQ(BaseNode::INIT_OK,
636 node.InitByIdLookup(parent)); 592 node.InitByIdLookup(parent));
637 EXPECT_EQ(4, node.GetTotalNodeCount()); 593 EXPECT_EQ(4, node.GetTotalNodeCount());
638 } 594 }
639 } 595 }
640 596
641 // Verify that Directory keeps track of which attachments are referenced by
642 // which entries.
643 TEST_F(SyncApiTest, AttachmentLinking) {
644 // Add an entry with an attachment.
645 std::string tag1("some tag");
646 syncer::AttachmentId attachment_id(syncer::AttachmentId::Create());
647 sync_pb::AttachmentMetadata attachment_metadata;
648 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record();
649 *record->mutable_id() = attachment_id.GetProto();
650 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id.GetProto()));
651 CreateEntryWithAttachmentMetadata(PREFERENCES, tag1, attachment_metadata);
652
653 // See that the directory knows it's linked.
654 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto()));
655
656 // Add a second entry referencing the same attachment.
657 std::string tag2("some other tag");
658 CreateEntryWithAttachmentMetadata(PREFERENCES, tag2, attachment_metadata);
659
660 // See that the directory knows it's still linked.
661 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto()));
662
663 // Tombstone the first entry.
664 ReplaceWithTombstone(syncer::PREFERENCES, tag1);
665
666 // See that the attachment is still considered linked because the entry hasn't
667 // been purged from the Directory.
668 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto()));
669
670 // Save changes and see that the entry is truly gone.
671 ASSERT_TRUE(dir()->SaveChanges());
672 ASSERT_EQ(LookupEntryByClientTag(PREFERENCES, tag1),
673 syncer::WriteNode::INIT_FAILED_ENTRY_NOT_GOOD);
674
675 // However, the attachment is still linked.
676 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto()));
677
678 // Save, destroy, and recreate the directory. See that it's still linked.
679 ASSERT_TRUE(ReloadDir());
680 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id.GetProto()));
681
682 // Tombstone the second entry, save changes, see that it's truly gone.
683 ReplaceWithTombstone(syncer::PREFERENCES, tag2);
684 ASSERT_TRUE(dir()->SaveChanges());
685 ASSERT_EQ(LookupEntryByClientTag(PREFERENCES, tag2),
686 syncer::WriteNode::INIT_FAILED_ENTRY_NOT_GOOD);
687
688 // Finally, the attachment is no longer linked.
689 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id.GetProto()));
690 }
691
692 namespace { 597 namespace {
693 598
694 class TestHttpPostProviderInterface : public HttpPostProviderInterface { 599 class TestHttpPostProviderInterface : public HttpPostProviderInterface {
695 public: 600 public:
696 virtual ~TestHttpPostProviderInterface() {} 601 virtual ~TestHttpPostProviderInterface() {}
697 602
698 virtual void SetExtraRequestHeaders(const char* headers) OVERRIDE {} 603 virtual void SetExtraRequestHeaders(const char* headers) OVERRIDE {}
699 virtual void SetURL(const char* url, int port) OVERRIDE {} 604 virtual void SetURL(const char* url, int port) OVERRIDE {}
700 virtual void SetPostPayload(const char* content_type, 605 virtual void SetPostPayload(const char* content_type,
701 int content_length, 606 int content_length,
(...skipping 2433 matching lines...) Expand 10 before | Expand all | Expand 10 after
3135 // SyncManagerInitInvalidStorageTest::GetFactory will return 3040 // SyncManagerInitInvalidStorageTest::GetFactory will return
3136 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. 3041 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails.
3137 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's 3042 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's
3138 // task is to ensure that SyncManagerImpl reported initialization failure in 3043 // task is to ensure that SyncManagerImpl reported initialization failure in
3139 // OnInitializationComplete callback. 3044 // OnInitializationComplete callback.
3140 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { 3045 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) {
3141 EXPECT_FALSE(initialization_succeeded_); 3046 EXPECT_FALSE(initialization_succeeded_);
3142 } 3047 }
3143 3048
3144 } // namespace syncer 3049 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/public/write_node.h ('k') | sync/internal_api/write_node.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698