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

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

Issue 10152003: sync: Make BaseNode lookup-related Init functions return specific failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 8 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
OLDNEW
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 // 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 138
139 // Makes a non-folder child of a non-root node. Returns the id of the 139 // Makes a non-folder child of a non-root node. Returns the id of the
140 // newly-created node. 140 // newly-created node.
141 int64 MakeNodeWithParent(UserShare* share, 141 int64 MakeNodeWithParent(UserShare* share,
142 ModelType model_type, 142 ModelType model_type,
143 const std::string& client_tag, 143 const std::string& client_tag,
144 int64 parent_id) { 144 int64 parent_id) {
145 WriteTransaction trans(FROM_HERE, share); 145 WriteTransaction trans(FROM_HERE, share);
146 ReadNode parent_node(&trans); 146 ReadNode parent_node(&trans);
147 EXPECT_TRUE(parent_node.InitByIdLookup(parent_id)); 147 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id));
148 WriteNode node(&trans); 148 WriteNode node(&trans);
149 EXPECT_TRUE(node.InitUniqueByCreation(model_type, parent_node, client_tag)); 149 EXPECT_TRUE(node.InitUniqueByCreation(model_type, parent_node, client_tag));
150 node.SetIsFolder(false); 150 node.SetIsFolder(false);
151 return node.GetId(); 151 return node.GetId();
152 } 152 }
153 153
154 // Makes a folder child of a non-root node. Returns the id of the 154 // Makes a folder child of a non-root node. Returns the id of the
155 // newly-created node. 155 // newly-created node.
156 int64 MakeFolderWithParent(UserShare* share, 156 int64 MakeFolderWithParent(UserShare* share,
157 ModelType model_type, 157 ModelType model_type,
158 int64 parent_id, 158 int64 parent_id,
159 BaseNode* predecessor) { 159 BaseNode* predecessor) {
160 WriteTransaction trans(FROM_HERE, share); 160 WriteTransaction trans(FROM_HERE, share);
161 ReadNode parent_node(&trans); 161 ReadNode parent_node(&trans);
162 EXPECT_TRUE(parent_node.InitByIdLookup(parent_id)); 162 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id));
163 WriteNode node(&trans); 163 WriteNode node(&trans);
164 EXPECT_TRUE(node.InitByCreation(model_type, parent_node, predecessor)); 164 EXPECT_TRUE(node.InitByCreation(model_type, parent_node, predecessor));
165 node.SetIsFolder(true); 165 node.SetIsFolder(true);
166 return node.GetId(); 166 return node.GetId();
167 } 167 }
168 168
169 // Creates the "synced" root node for a particular datatype. We use the syncable 169 // Creates the "synced" root node for a particular datatype. We use the syncable
170 // methods here so that the syncer treats these nodes as if they were already 170 // methods here so that the syncer treats these nodes as if they were already
171 // received from the server. 171 // received from the server.
172 int64 MakeServerNodeForType(UserShare* share, 172 int64 MakeServerNodeForType(UserShare* share,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 249 }
250 { 250 {
251 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 251 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
252 EXPECT_TRUE(trans.GetWrappedTrans() != NULL); 252 EXPECT_TRUE(trans.GetWrappedTrans() != NULL);
253 } 253 }
254 { 254 {
255 // No entries but root should exist 255 // No entries but root should exist
256 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 256 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
257 ReadNode node(&trans); 257 ReadNode node(&trans);
258 // Metahandle 1 can be root, sanity check 2 258 // Metahandle 1 can be root, sanity check 2
259 EXPECT_FALSE(node.InitByIdLookup(2)); 259 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, node.InitByIdLookup(2));
260 } 260 }
261 } 261 }
262 262
263 TEST_F(SyncApiTest, BasicTagWrite) { 263 TEST_F(SyncApiTest, BasicTagWrite) {
264 { 264 {
265 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 265 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
266 ReadNode root_node(&trans); 266 ReadNode root_node(&trans);
267 root_node.InitByRootLookup(); 267 root_node.InitByRootLookup();
268 EXPECT_EQ(root_node.GetFirstChildId(), 0); 268 EXPECT_EQ(root_node.GetFirstChildId(), 0);
269 } 269 }
270 270
271 ignore_result(MakeNode(test_user_share_.user_share(), 271 ignore_result(MakeNode(test_user_share_.user_share(),
272 syncable::BOOKMARKS, "testtag")); 272 syncable::BOOKMARKS, "testtag"));
273 273
274 { 274 {
275 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 275 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
276 ReadNode node(&trans); 276 ReadNode node(&trans);
277 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, 277 EXPECT_EQ(BaseNode::INIT_OK,
278 "testtag")); 278 node.InitByClientTagLookup(syncable::BOOKMARKS, "testtag"));
279 279
280 ReadNode root_node(&trans); 280 ReadNode root_node(&trans);
281 root_node.InitByRootLookup(); 281 root_node.InitByRootLookup();
282 EXPECT_NE(node.GetId(), 0); 282 EXPECT_NE(node.GetId(), 0);
283 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId()); 283 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId());
284 } 284 }
285 } 285 }
286 286
287 TEST_F(SyncApiTest, GenerateSyncableHash) { 287 TEST_F(SyncApiTest, GenerateSyncableHash) {
288 EXPECT_EQ("OyaXV5mEzrPS4wbogmtKvRfekAI=", 288 EXPECT_EQ("OyaXV5mEzrPS4wbogmtKvRfekAI=",
(...skipping 23 matching lines...) Expand all
312 syncable::BOOKMARKS, "collideme")); 312 syncable::BOOKMARKS, "collideme"));
313 ignore_result(MakeNode(test_user_share_.user_share(), 313 ignore_result(MakeNode(test_user_share_.user_share(),
314 syncable::PREFERENCES, "collideme")); 314 syncable::PREFERENCES, "collideme"));
315 ignore_result(MakeNode(test_user_share_.user_share(), 315 ignore_result(MakeNode(test_user_share_.user_share(),
316 syncable::AUTOFILL, "collideme")); 316 syncable::AUTOFILL, "collideme"));
317 317
318 { 318 {
319 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 319 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
320 320
321 ReadNode bookmarknode(&trans); 321 ReadNode bookmarknode(&trans);
322 EXPECT_TRUE(bookmarknode.InitByClientTagLookup(syncable::BOOKMARKS, 322 EXPECT_EQ(BaseNode::INIT_OK,
323 "collideme")); 323 bookmarknode.InitByClientTagLookup(syncable::BOOKMARKS,
324 "collideme"));
324 325
325 ReadNode prefnode(&trans); 326 ReadNode prefnode(&trans);
326 EXPECT_TRUE(prefnode.InitByClientTagLookup(syncable::PREFERENCES, 327 EXPECT_EQ(BaseNode::INIT_OK,
327 "collideme")); 328 prefnode.InitByClientTagLookup(syncable::PREFERENCES,
329 "collideme"));
328 330
329 ReadNode autofillnode(&trans); 331 ReadNode autofillnode(&trans);
330 EXPECT_TRUE(autofillnode.InitByClientTagLookup(syncable::AUTOFILL, 332 EXPECT_EQ(BaseNode::INIT_OK,
331 "collideme")); 333 autofillnode.InitByClientTagLookup(syncable::AUTOFILL,
334 "collideme"));
332 335
333 EXPECT_NE(bookmarknode.GetId(), prefnode.GetId()); 336 EXPECT_NE(bookmarknode.GetId(), prefnode.GetId());
334 EXPECT_NE(autofillnode.GetId(), prefnode.GetId()); 337 EXPECT_NE(autofillnode.GetId(), prefnode.GetId());
335 EXPECT_NE(bookmarknode.GetId(), autofillnode.GetId()); 338 EXPECT_NE(bookmarknode.GetId(), autofillnode.GetId());
336 } 339 }
337 } 340 }
338 341
339 TEST_F(SyncApiTest, ReadMissingTagsFails) { 342 TEST_F(SyncApiTest, ReadMissingTagsFails) {
340 { 343 {
341 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 344 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
342 ReadNode node(&trans); 345 ReadNode node(&trans);
343 EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS, 346 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD,
344 "testtag")); 347 node.InitByClientTagLookup(syncable::BOOKMARKS,
348 "testtag"));
345 } 349 }
346 { 350 {
347 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 351 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
348 WriteNode node(&trans); 352 WriteNode node(&trans);
349 EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS, 353 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD,
350 "testtag")); 354 node.InitByClientTagLookup(syncable::BOOKMARKS,
355 "testtag"));
351 } 356 }
352 } 357 }
353 358
354 // TODO(chron): Hook this all up to the server and write full integration tests 359 // TODO(chron): Hook this all up to the server and write full integration tests
355 // for update->undelete behavior. 360 // for update->undelete behavior.
356 TEST_F(SyncApiTest, TestDeleteBehavior) { 361 TEST_F(SyncApiTest, TestDeleteBehavior) {
357 int64 node_id; 362 int64 node_id;
358 int64 folder_id; 363 int64 folder_id;
359 std::string test_title("test1"); 364 std::string test_title("test1");
360 365
(...skipping 14 matching lines...) Expand all
375 wnode.SetIsFolder(false); 380 wnode.SetIsFolder(false);
376 wnode.SetTitle(UTF8ToWide(test_title)); 381 wnode.SetTitle(UTF8ToWide(test_title));
377 382
378 node_id = wnode.GetId(); 383 node_id = wnode.GetId();
379 } 384 }
380 385
381 // Ensure we can delete something with a tag. 386 // Ensure we can delete something with a tag.
382 { 387 {
383 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 388 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
384 WriteNode wnode(&trans); 389 WriteNode wnode(&trans);
385 EXPECT_TRUE(wnode.InitByClientTagLookup(syncable::BOOKMARKS, 390 EXPECT_EQ(BaseNode::INIT_OK,
386 "testtag")); 391 wnode.InitByClientTagLookup(syncable::BOOKMARKS,
392 "testtag"));
387 EXPECT_FALSE(wnode.GetIsFolder()); 393 EXPECT_FALSE(wnode.GetIsFolder());
388 EXPECT_EQ(wnode.GetTitle(), test_title); 394 EXPECT_EQ(wnode.GetTitle(), test_title);
389 395
390 wnode.Remove(); 396 wnode.Remove();
391 } 397 }
392 398
393 // Lookup of a node which was deleted should return failure, 399 // Lookup of a node which was deleted should return failure,
394 // but have found some data about the node. 400 // but have found some data about the node.
395 { 401 {
396 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 402 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
397 ReadNode node(&trans); 403 ReadNode node(&trans);
398 EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS, 404 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL,
399 "testtag")); 405 node.InitByClientTagLookup(syncable::BOOKMARKS,
406 "testtag"));
400 // Note that for proper function of this API this doesn't need to be 407 // Note that for proper function of this API this doesn't need to be
401 // filled, we're checking just to make sure the DB worked in this test. 408 // filled, we're checking just to make sure the DB worked in this test.
402 EXPECT_EQ(node.GetTitle(), test_title); 409 EXPECT_EQ(node.GetTitle(), test_title);
403 } 410 }
404 411
405 { 412 {
406 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 413 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
407 ReadNode folder_node(&trans); 414 ReadNode folder_node(&trans);
408 EXPECT_TRUE(folder_node.InitByIdLookup(folder_id)); 415 EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id));
409 416
410 WriteNode wnode(&trans); 417 WriteNode wnode(&trans);
411 // This will undelete the tag. 418 // This will undelete the tag.
412 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS, 419 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS,
413 folder_node, "testtag")); 420 folder_node, "testtag"));
414 EXPECT_EQ(wnode.GetIsFolder(), false); 421 EXPECT_EQ(wnode.GetIsFolder(), false);
415 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); 422 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId());
416 EXPECT_EQ(wnode.GetId(), node_id); 423 EXPECT_EQ(wnode.GetId(), node_id);
417 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared 424 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared
418 wnode.SetTitle(UTF8ToWide(test_title)); 425 wnode.SetTitle(UTF8ToWide(test_title));
419 } 426 }
420 427
421 // Now look up should work. 428 // Now look up should work.
422 { 429 {
423 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 430 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
424 ReadNode node(&trans); 431 ReadNode node(&trans);
425 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, 432 EXPECT_EQ(BaseNode::INIT_OK,
426 "testtag")); 433 node.InitByClientTagLookup(syncable::BOOKMARKS,
434 "testtag"));
427 EXPECT_EQ(node.GetTitle(), test_title); 435 EXPECT_EQ(node.GetTitle(), test_title);
428 EXPECT_EQ(node.GetModelType(), syncable::BOOKMARKS); 436 EXPECT_EQ(node.GetModelType(), syncable::BOOKMARKS);
429 } 437 }
430 } 438 }
431 439
432 TEST_F(SyncApiTest, WriteAndReadPassword) { 440 TEST_F(SyncApiTest, WriteAndReadPassword) {
433 KeyParams params = {"localhost", "username", "passphrase"}; 441 KeyParams params = {"localhost", "username", "passphrase"};
434 { 442 {
435 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 443 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
436 trans.GetCryptographer()->AddKey(params); 444 trans.GetCryptographer()->AddKey(params);
437 } 445 }
438 { 446 {
439 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 447 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
440 ReadNode root_node(&trans); 448 ReadNode root_node(&trans);
441 root_node.InitByRootLookup(); 449 root_node.InitByRootLookup();
442 450
443 WriteNode password_node(&trans); 451 WriteNode password_node(&trans);
444 EXPECT_TRUE(password_node.InitUniqueByCreation(syncable::PASSWORDS, 452 EXPECT_TRUE(password_node.InitUniqueByCreation(syncable::PASSWORDS,
445 root_node, "foo")); 453 root_node, "foo"));
446 sync_pb::PasswordSpecificsData data; 454 sync_pb::PasswordSpecificsData data;
447 data.set_password_value("secret"); 455 data.set_password_value("secret");
448 password_node.SetPasswordSpecifics(data); 456 password_node.SetPasswordSpecifics(data);
449 } 457 }
450 { 458 {
451 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 459 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
452 ReadNode root_node(&trans); 460 ReadNode root_node(&trans);
453 root_node.InitByRootLookup(); 461 root_node.InitByRootLookup();
454 462
455 ReadNode password_node(&trans); 463 ReadNode password_node(&trans);
456 EXPECT_TRUE(password_node.InitByClientTagLookup(syncable::PASSWORDS, 464 EXPECT_EQ(BaseNode::INIT_OK,
457 "foo")); 465 password_node.InitByClientTagLookup(syncable::PASSWORDS,
466 "foo"));
458 const sync_pb::PasswordSpecificsData& data = 467 const sync_pb::PasswordSpecificsData& data =
459 password_node.GetPasswordSpecifics(); 468 password_node.GetPasswordSpecifics();
460 EXPECT_EQ("secret", data.password_value()); 469 EXPECT_EQ("secret", data.password_value());
461 } 470 }
462 } 471 }
463 472
464 TEST_F(SyncApiTest, WriteEncryptedTitle) { 473 TEST_F(SyncApiTest, WriteEncryptedTitle) {
465 KeyParams params = {"localhost", "username", "passphrase"}; 474 KeyParams params = {"localhost", "username", "passphrase"};
466 { 475 {
467 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 476 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
(...skipping 14 matching lines...) Expand all
482 EXPECT_TRUE(pref_node.InitUniqueByCreation(syncable::PREFERENCES, 491 EXPECT_TRUE(pref_node.InitUniqueByCreation(syncable::PREFERENCES,
483 root_node, "bar")); 492 root_node, "bar"));
484 pref_node.SetTitle(UTF8ToWide("bar")); 493 pref_node.SetTitle(UTF8ToWide("bar"));
485 } 494 }
486 { 495 {
487 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 496 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
488 ReadNode root_node(&trans); 497 ReadNode root_node(&trans);
489 root_node.InitByRootLookup(); 498 root_node.InitByRootLookup();
490 499
491 ReadNode bookmark_node(&trans); 500 ReadNode bookmark_node(&trans);
492 EXPECT_TRUE(bookmark_node.InitByClientTagLookup(syncable::BOOKMARKS, 501 EXPECT_EQ(BaseNode::INIT_OK,
493 "foo")); 502 bookmark_node.InitByClientTagLookup(syncable::BOOKMARKS,
503 "foo"));
494 EXPECT_EQ("foo", bookmark_node.GetTitle()); 504 EXPECT_EQ("foo", bookmark_node.GetTitle());
495 EXPECT_EQ(kEncryptedString, 505 EXPECT_EQ(kEncryptedString,
496 bookmark_node.GetEntry()->Get(syncable::NON_UNIQUE_NAME)); 506 bookmark_node.GetEntry()->Get(syncable::NON_UNIQUE_NAME));
497 507
498 ReadNode pref_node(&trans); 508 ReadNode pref_node(&trans);
499 EXPECT_TRUE(pref_node.InitByClientTagLookup(syncable::PREFERENCES, 509 EXPECT_EQ(BaseNode::INIT_OK,
500 "bar")); 510 pref_node.InitByClientTagLookup(syncable::PREFERENCES,
511 "bar"));
501 EXPECT_EQ(kEncryptedString, pref_node.GetTitle()); 512 EXPECT_EQ(kEncryptedString, pref_node.GetTitle());
502 } 513 }
503 } 514 }
504 515
505 TEST_F(SyncApiTest, BaseNodeSetSpecifics) { 516 TEST_F(SyncApiTest, BaseNodeSetSpecifics) {
506 int64 child_id = MakeNode(test_user_share_.user_share(), 517 int64 child_id = MakeNode(test_user_share_.user_share(),
507 syncable::BOOKMARKS, "testtag"); 518 syncable::BOOKMARKS, "testtag");
508 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 519 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
509 WriteNode node(&trans); 520 WriteNode node(&trans);
510 EXPECT_TRUE(node.InitByIdLookup(child_id)); 521 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id));
511 522
512 sync_pb::EntitySpecifics entity_specifics; 523 sync_pb::EntitySpecifics entity_specifics;
513 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); 524 entity_specifics.mutable_bookmark()->set_url("http://www.google.com");
514 525
515 EXPECT_NE(entity_specifics.SerializeAsString(), 526 EXPECT_NE(entity_specifics.SerializeAsString(),
516 node.GetEntitySpecifics().SerializeAsString()); 527 node.GetEntitySpecifics().SerializeAsString());
517 node.SetEntitySpecifics(entity_specifics); 528 node.SetEntitySpecifics(entity_specifics);
518 EXPECT_EQ(entity_specifics.SerializeAsString(), 529 EXPECT_EQ(entity_specifics.SerializeAsString(),
519 node.GetEntitySpecifics().SerializeAsString()); 530 node.GetEntitySpecifics().SerializeAsString());
520 } 531 }
521 532
522 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) { 533 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) {
523 int64 child_id = MakeNode(test_user_share_.user_share(), 534 int64 child_id = MakeNode(test_user_share_.user_share(),
524 syncable::BOOKMARKS, "testtag"); 535 syncable::BOOKMARKS, "testtag");
525 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 536 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
526 WriteNode node(&trans); 537 WriteNode node(&trans);
527 EXPECT_TRUE(node.InitByIdLookup(child_id)); 538 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id));
528 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); 539 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty());
529 540
530 sync_pb::EntitySpecifics entity_specifics; 541 sync_pb::EntitySpecifics entity_specifics;
531 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); 542 entity_specifics.mutable_bookmark()->set_url("http://www.google.com");
532 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100); 543 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100);
533 node.SetEntitySpecifics(entity_specifics); 544 node.SetEntitySpecifics(entity_specifics);
534 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); 545 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty());
535 546
536 entity_specifics.mutable_unknown_fields()->Clear(); 547 entity_specifics.mutable_unknown_fields()->Clear();
537 node.SetEntitySpecifics(entity_specifics); 548 node.SetEntitySpecifics(entity_specifics);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 } 622 }
612 623
613 TEST_F(SyncApiTest, EmptyTags) { 624 TEST_F(SyncApiTest, EmptyTags) {
614 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 625 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
615 ReadNode root_node(&trans); 626 ReadNode root_node(&trans);
616 root_node.InitByRootLookup(); 627 root_node.InitByRootLookup();
617 WriteNode node(&trans); 628 WriteNode node(&trans);
618 std::string empty_tag; 629 std::string empty_tag;
619 EXPECT_FALSE(node.InitUniqueByCreation( 630 EXPECT_FALSE(node.InitUniqueByCreation(
620 syncable::TYPED_URLS, root_node, empty_tag)); 631 syncable::TYPED_URLS, root_node, empty_tag));
621 EXPECT_FALSE(node.InitByTagLookup(empty_tag)); 632 EXPECT_EQ(BaseNode::INIT_FAILED_PRECONDITION,
633 node.InitByTagLookup(empty_tag));
622 } 634 }
623 635
624 namespace { 636 namespace {
625 637
626 class TestHttpPostProviderInterface : public HttpPostProviderInterface { 638 class TestHttpPostProviderInterface : public HttpPostProviderInterface {
627 public: 639 public:
628 virtual ~TestHttpPostProviderInterface() {} 640 virtual ~TestHttpPostProviderInterface() {}
629 641
630 virtual void SetUserAgent(const char* user_agent) OVERRIDE {} 642 virtual void SetUserAgent(const char* user_agent) OVERRIDE {}
631 virtual void SetExtraRequestHeaders(const char* headers) OVERRIDE {} 643 virtual void SetExtraRequestHeaders(const char* headers) OVERRIDE {}
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 } else { 846 } else {
835 DCHECK_NE(nigori_status, WRITE_TO_NIGORI); 847 DCHECK_NE(nigori_status, WRITE_TO_NIGORI);
836 } 848 }
837 if (encryption_status == FULL_ENCRYPTION) 849 if (encryption_status == FULL_ENCRYPTION)
838 cryptographer->set_encrypt_everything(); 850 cryptographer->set_encrypt_everything();
839 if (nigori_status == WRITE_TO_NIGORI) { 851 if (nigori_status == WRITE_TO_NIGORI) {
840 sync_pb::NigoriSpecifics nigori; 852 sync_pb::NigoriSpecifics nigori;
841 cryptographer->GetKeys(nigori.mutable_encrypted()); 853 cryptographer->GetKeys(nigori.mutable_encrypted());
842 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); 854 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori);
843 WriteNode node(&trans); 855 WriteNode node(&trans);
844 EXPECT_TRUE(node.InitByIdLookup(nigori_id)); 856 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(nigori_id));
845 node.SetNigoriSpecifics(nigori); 857 node.SetNigoriSpecifics(nigori);
846 } 858 }
847 return cryptographer->is_ready(); 859 return cryptographer->is_ready();
848 } 860 }
849 861
850 int64 GetIdForDataType(ModelType type) { 862 int64 GetIdForDataType(ModelType type) {
851 if (type_roots_.count(type) == 0) 863 if (type_roots_.count(type) == 0)
852 return 0; 864 return 0;
853 return type_roots_[type]; 865 return type_roots_[type];
854 } 866 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 sync_manager_.UpdateEnabledTypes(); 947 sync_manager_.UpdateEnabledTypes();
936 EXPECT_EQ(2, update_enabled_types_call_count_); 948 EXPECT_EQ(2, update_enabled_types_call_count_);
937 } 949 }
938 950
939 TEST_F(SyncManagerTest, DoNotSyncTabsInNigoriNode) { 951 TEST_F(SyncManagerTest, DoNotSyncTabsInNigoriNode) {
940 const syncable::ModelTypeSet encrypted_types(syncable::TYPED_URLS); 952 const syncable::ModelTypeSet encrypted_types(syncable::TYPED_URLS);
941 sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types); 953 sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types);
942 954
943 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 955 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
944 ReadNode node(&trans); 956 ReadNode node(&trans);
945 ASSERT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); 957 ASSERT_EQ(BaseNode::INIT_OK,
958 node.InitByIdLookup(GetIdForDataType(syncable::NIGORI)));
946 EXPECT_FALSE(node.GetNigoriSpecifics().sync_tabs()); 959 EXPECT_FALSE(node.GetNigoriSpecifics().sync_tabs());
947 } 960 }
948 961
949 TEST_F(SyncManagerTest, SyncTabsInNigoriNode) { 962 TEST_F(SyncManagerTest, SyncTabsInNigoriNode) {
950 const syncable::ModelTypeSet encrypted_types(syncable::SESSIONS); 963 const syncable::ModelTypeSet encrypted_types(syncable::SESSIONS);
951 sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types); 964 sync_manager_.MaybeSetSyncTabsInNigoriNode(encrypted_types);
952 965
953 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 966 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
954 ReadNode node(&trans); 967 ReadNode node(&trans);
955 ASSERT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); 968 ASSERT_EQ(BaseNode::INIT_OK,
969 node.InitByIdLookup(GetIdForDataType(syncable::NIGORI)));
956 EXPECT_TRUE(node.GetNigoriSpecifics().sync_tabs()); 970 EXPECT_TRUE(node.GetNigoriSpecifics().sync_tabs());
957 } 971 }
958 972
959 TEST_F(SyncManagerTest, ProcessJsMessage) { 973 TEST_F(SyncManagerTest, ProcessJsMessage) {
960 const JsArgList kNoArgs; 974 const JsArgList kNoArgs;
961 975
962 StrictMock<MockJsReplyHandler> reply_handler; 976 StrictMock<MockJsReplyHandler> reply_handler;
963 977
964 ListValue false_args; 978 ListValue false_args;
965 false_args.Append(Value::CreateBooleanValue(false)); 979 false_args.Append(Value::CreateBooleanValue(false));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 EXPECT_EQ(1u, return_args.Get().GetSize()); 1021 EXPECT_EQ(1u, return_args.Get().GetSize());
1008 ListValue* nodes = NULL; 1022 ListValue* nodes = NULL;
1009 ASSERT_TRUE(return_args.Get().GetList(0, &nodes)); 1023 ASSERT_TRUE(return_args.Get().GetList(0, &nodes));
1010 ASSERT_TRUE(nodes); 1024 ASSERT_TRUE(nodes);
1011 EXPECT_EQ(1u, nodes->GetSize()); 1025 EXPECT_EQ(1u, nodes->GetSize());
1012 DictionaryValue* node_info = NULL; 1026 DictionaryValue* node_info = NULL;
1013 EXPECT_TRUE(nodes->GetDictionary(0, &node_info)); 1027 EXPECT_TRUE(nodes->GetDictionary(0, &node_info));
1014 ASSERT_TRUE(node_info); 1028 ASSERT_TRUE(node_info);
1015 ReadTransaction trans(FROM_HERE, sync_manager.GetUserShare()); 1029 ReadTransaction trans(FROM_HERE, sync_manager.GetUserShare());
1016 ReadNode node(&trans); 1030 ReadNode node(&trans);
1017 EXPECT_TRUE(node.InitByIdLookup(id)); 1031 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
1018 CheckNodeValue(node, *node_info, is_detailed); 1032 CheckNodeValue(node, *node_info, is_detailed);
1019 } 1033 }
1020 1034
1021 class SyncManagerGetNodesByIdTest : public SyncManagerTest { 1035 class SyncManagerGetNodesByIdTest : public SyncManagerTest {
1022 protected: 1036 protected:
1023 virtual ~SyncManagerGetNodesByIdTest() {} 1037 virtual ~SyncManagerGetNodesByIdTest() {}
1024 1038
1025 void RunGetNodesByIdTest(const char* message_name, bool is_detailed) { 1039 void RunGetNodesByIdTest(const char* message_name, bool is_detailed) {
1026 int64 root_id = kInvalidId; 1040 int64 root_id = kInvalidId;
1027 { 1041 {
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 1338 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing));
1325 PumpLoop(); 1339 PumpLoop();
1326 1340
1327 const syncable::ModelTypeSet encrypted_types = 1341 const syncable::ModelTypeSet encrypted_types =
1328 sync_manager_.GetEncryptedDataTypesForTest(); 1342 sync_manager_.GetEncryptedDataTypesForTest();
1329 EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS)); 1343 EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS));
1330 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); 1344 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest());
1331 { 1345 {
1332 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1346 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1333 ReadNode node(&trans); 1347 ReadNode node(&trans);
1334 EXPECT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); 1348 EXPECT_EQ(BaseNode::INIT_OK,
1349 node.InitByIdLookup(GetIdForDataType(syncable::NIGORI)));
1335 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); 1350 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
1336 EXPECT_TRUE(nigori.has_encrypted()); 1351 EXPECT_TRUE(nigori.has_encrypted());
1337 Cryptographer* cryptographer = trans.GetCryptographer(); 1352 Cryptographer* cryptographer = trans.GetCryptographer();
1338 EXPECT_TRUE(cryptographer->is_ready()); 1353 EXPECT_TRUE(cryptographer->is_ready());
1339 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1354 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted()));
1340 } 1355 }
1341 } 1356 }
1342 1357
1343 // Attempt to refresh encryption when nigori not downloaded. 1358 // Attempt to refresh encryption when nigori not downloaded.
1344 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { 1359 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) {
(...skipping 18 matching lines...) Expand all
1363 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 1378 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing));
1364 PumpLoop(); 1379 PumpLoop();
1365 1380
1366 const syncable::ModelTypeSet encrypted_types = 1381 const syncable::ModelTypeSet encrypted_types =
1367 sync_manager_.GetEncryptedDataTypesForTest(); 1382 sync_manager_.GetEncryptedDataTypesForTest();
1368 EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS)); // Hardcoded. 1383 EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS)); // Hardcoded.
1369 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); 1384 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest());
1370 { 1385 {
1371 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1386 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1372 ReadNode node(&trans); 1387 ReadNode node(&trans);
1373 EXPECT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); 1388 EXPECT_EQ(BaseNode::INIT_OK,
1389 node.InitByIdLookup(GetIdForDataType(syncable::NIGORI)));
1374 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); 1390 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
1375 EXPECT_TRUE(nigori.has_encrypted()); 1391 EXPECT_TRUE(nigori.has_encrypted());
1376 Cryptographer* cryptographer = trans.GetCryptographer(); 1392 Cryptographer* cryptographer = trans.GetCryptographer();
1377 EXPECT_TRUE(cryptographer->is_ready()); 1393 EXPECT_TRUE(cryptographer->is_ready());
1378 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1394 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted()));
1379 } 1395 }
1380 } 1396 }
1381 1397
1382 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { 1398 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) {
1383 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1399 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 TEST_F(SyncManagerTest, SetInitialGaiaPass) { 1524 TEST_F(SyncManagerTest, SetInitialGaiaPass) {
1509 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); 1525 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED));
1510 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1526 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_));
1511 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1527 EXPECT_CALL(observer_, OnPassphraseAccepted());
1512 EXPECT_CALL(observer_, OnEncryptionComplete()); 1528 EXPECT_CALL(observer_, OnEncryptionComplete());
1513 sync_manager_.SetEncryptionPassphrase("new_passphrase", false); 1529 sync_manager_.SetEncryptionPassphrase("new_passphrase", false);
1514 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); 1530 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest());
1515 { 1531 {
1516 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1532 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1517 ReadNode node(&trans); 1533 ReadNode node(&trans);
1518 EXPECT_TRUE(node.InitByTagLookup(kNigoriTag)); 1534 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1519 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); 1535 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
1520 Cryptographer* cryptographer = trans.GetCryptographer(); 1536 Cryptographer* cryptographer = trans.GetCryptographer();
1521 EXPECT_TRUE(cryptographer->is_ready()); 1537 EXPECT_TRUE(cryptographer->is_ready());
1522 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1538 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted()));
1523 } 1539 }
1524 } 1540 }
1525 1541
1526 // Test that when there are no pending keys and we have on the old GAIA 1542 // Test that when there are no pending keys and we have on the old GAIA
1527 // password, we update and re-encrypt everything with the new GAIA password. 1543 // password, we update and re-encrypt everything with the new GAIA password.
1528 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) 1544 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 { 1600 {
1585 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1601 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1586 Cryptographer* cryptographer = trans.GetCryptographer(); 1602 Cryptographer* cryptographer = trans.GetCryptographer();
1587 EXPECT_TRUE(cryptographer->is_ready()); 1603 EXPECT_TRUE(cryptographer->is_ready());
1588 // Verify the default key has changed. 1604 // Verify the default key has changed.
1589 sync_pb::EncryptedData encrypted; 1605 sync_pb::EncryptedData encrypted;
1590 cryptographer->GetKeys(&encrypted); 1606 cryptographer->GetKeys(&encrypted);
1591 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); 1607 EXPECT_FALSE(verifier.CanDecrypt(encrypted));
1592 1608
1593 ReadNode password_node(&trans); 1609 ReadNode password_node(&trans);
1594 EXPECT_TRUE(password_node.InitByClientTagLookup(syncable::PASSWORDS, 1610 EXPECT_EQ(BaseNode::INIT_OK,
1595 "foo")); 1611 password_node.InitByClientTagLookup(syncable::PASSWORDS,
1612 "foo"));
1596 const sync_pb::PasswordSpecificsData& data = 1613 const sync_pb::PasswordSpecificsData& data =
1597 password_node.GetPasswordSpecifics(); 1614 password_node.GetPasswordSpecifics();
1598 EXPECT_EQ("secret", data.password_value()); 1615 EXPECT_EQ("secret", data.password_value());
1599 } 1616 }
1600 } 1617 }
1601 1618
1602 // Manually set the pending keys in the cryptographer/nigori to reflect the data 1619 // Manually set the pending keys in the cryptographer/nigori to reflect the data
1603 // being encrypted with a new (unprovided) GAIA password, then supply the 1620 // being encrypted with a new (unprovided) GAIA password, then supply the
1604 // password. 1621 // password.
1605 // (case 7 in SyncManager::SyncInternal::SetDecryptionPassphrase) 1622 // (case 7 in SyncManager::SyncInternal::SetDecryptionPassphrase)
1606 TEST_F(SyncManagerTest, SupplyPendingGAIAPass) { 1623 TEST_F(SyncManagerTest, SupplyPendingGAIAPass) {
1607 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1624 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1608 Cryptographer other_cryptographer(&encryptor_); 1625 Cryptographer other_cryptographer(&encryptor_);
1609 { 1626 {
1610 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1627 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1611 Cryptographer* cryptographer = trans.GetCryptographer(); 1628 Cryptographer* cryptographer = trans.GetCryptographer();
1612 std::string bootstrap_token; 1629 std::string bootstrap_token;
1613 cryptographer->GetBootstrapToken(&bootstrap_token); 1630 cryptographer->GetBootstrapToken(&bootstrap_token);
1614 other_cryptographer.Bootstrap(bootstrap_token); 1631 other_cryptographer.Bootstrap(bootstrap_token);
1615 1632
1616 // Now update the nigori to reflect the new keys, and update the 1633 // Now update the nigori to reflect the new keys, and update the
1617 // cryptographer to have pending keys. 1634 // cryptographer to have pending keys.
1618 KeyParams params = {"localhost", "dummy", "passphrase2"}; 1635 KeyParams params = {"localhost", "dummy", "passphrase2"};
1619 other_cryptographer.AddKey(params); 1636 other_cryptographer.AddKey(params);
1620 WriteNode node(&trans); 1637 WriteNode node(&trans);
1621 EXPECT_TRUE(node.InitByTagLookup(kNigoriTag)); 1638 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1622 sync_pb::NigoriSpecifics nigori; 1639 sync_pb::NigoriSpecifics nigori;
1623 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1640 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1624 cryptographer->Update(nigori); 1641 cryptographer->Update(nigori);
1625 EXPECT_TRUE(cryptographer->has_pending_keys()); 1642 EXPECT_TRUE(cryptographer->has_pending_keys());
1626 node.SetNigoriSpecifics(nigori); 1643 node.SetNigoriSpecifics(nigori);
1627 } 1644 }
1628 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1645 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_));
1629 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1646 EXPECT_CALL(observer_, OnPassphraseAccepted());
1630 EXPECT_CALL(observer_, OnEncryptionComplete()); 1647 EXPECT_CALL(observer_, OnEncryptionComplete());
1631 sync_manager_.SetDecryptionPassphrase("passphrase2"); 1648 sync_manager_.SetDecryptionPassphrase("passphrase2");
(...skipping 23 matching lines...) Expand all
1655 Cryptographer* cryptographer = trans.GetCryptographer(); 1672 Cryptographer* cryptographer = trans.GetCryptographer();
1656 std::string bootstrap_token; 1673 std::string bootstrap_token;
1657 cryptographer->GetBootstrapToken(&bootstrap_token); 1674 cryptographer->GetBootstrapToken(&bootstrap_token);
1658 other_cryptographer.Bootstrap(bootstrap_token); 1675 other_cryptographer.Bootstrap(bootstrap_token);
1659 1676
1660 // Now update the nigori to reflect the new keys, and update the 1677 // Now update the nigori to reflect the new keys, and update the
1661 // cryptographer to have pending keys. 1678 // cryptographer to have pending keys.
1662 KeyParams params = {"localhost", "dummy", "old_gaia"}; 1679 KeyParams params = {"localhost", "dummy", "old_gaia"};
1663 other_cryptographer.AddKey(params); 1680 other_cryptographer.AddKey(params);
1664 WriteNode node(&trans); 1681 WriteNode node(&trans);
1665 EXPECT_TRUE(node.InitByTagLookup(kNigoriTag)); 1682 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1666 sync_pb::NigoriSpecifics nigori; 1683 sync_pb::NigoriSpecifics nigori;
1667 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1684 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1668 node.SetNigoriSpecifics(nigori); 1685 node.SetNigoriSpecifics(nigori);
1669 cryptographer->Update(nigori); 1686 cryptographer->Update(nigori);
1670 1687
1671 // other_cryptographer now contains all encryption keys, and is encrypting 1688 // other_cryptographer now contains all encryption keys, and is encrypting
1672 // with the newest gaia. 1689 // with the newest gaia.
1673 KeyParams new_params = {"localhost", "dummy", "new_gaia"}; 1690 KeyParams new_params = {"localhost", "dummy", "new_gaia"};
1674 other_cryptographer.AddKey(new_params); 1691 other_cryptographer.AddKey(new_params);
1675 } 1692 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 Cryptographer* cryptographer = trans.GetCryptographer(); 1743 Cryptographer* cryptographer = trans.GetCryptographer();
1727 std::string bootstrap_token; 1744 std::string bootstrap_token;
1728 cryptographer->GetBootstrapToken(&bootstrap_token); 1745 cryptographer->GetBootstrapToken(&bootstrap_token);
1729 other_cryptographer.Bootstrap(bootstrap_token); 1746 other_cryptographer.Bootstrap(bootstrap_token);
1730 1747
1731 // Now update the nigori to reflect the new keys, and update the 1748 // Now update the nigori to reflect the new keys, and update the
1732 // cryptographer to have pending keys. 1749 // cryptographer to have pending keys.
1733 KeyParams params = {"localhost", "dummy", "explicit"}; 1750 KeyParams params = {"localhost", "dummy", "explicit"};
1734 other_cryptographer.AddKey(params); 1751 other_cryptographer.AddKey(params);
1735 WriteNode node(&trans); 1752 WriteNode node(&trans);
1736 EXPECT_TRUE(node.InitByTagLookup(kNigoriTag)); 1753 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1737 sync_pb::NigoriSpecifics nigori; 1754 sync_pb::NigoriSpecifics nigori;
1738 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1755 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1739 cryptographer->Update(nigori); 1756 cryptographer->Update(nigori);
1740 EXPECT_TRUE(cryptographer->has_pending_keys()); 1757 EXPECT_TRUE(cryptographer->has_pending_keys());
1741 nigori.set_using_explicit_passphrase(true); 1758 nigori.set_using_explicit_passphrase(true);
1742 node.SetNigoriSpecifics(nigori); 1759 node.SetNigoriSpecifics(nigori);
1743 } 1760 }
1744 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1761 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_));
1745 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1762 EXPECT_CALL(observer_, OnPassphraseAccepted());
1746 EXPECT_CALL(observer_, OnEncryptionComplete()); 1763 EXPECT_CALL(observer_, OnEncryptionComplete());
(...skipping 18 matching lines...) Expand all
1765 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); 1782 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED));
1766 Cryptographer other_cryptographer(&encryptor_); 1783 Cryptographer other_cryptographer(&encryptor_);
1767 { 1784 {
1768 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1785 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1769 Cryptographer* cryptographer = trans.GetCryptographer(); 1786 Cryptographer* cryptographer = trans.GetCryptographer();
1770 // Now update the nigori to reflect the new keys, and update the 1787 // Now update the nigori to reflect the new keys, and update the
1771 // cryptographer to have pending keys. 1788 // cryptographer to have pending keys.
1772 KeyParams params = {"localhost", "dummy", "passphrase"}; 1789 KeyParams params = {"localhost", "dummy", "passphrase"};
1773 other_cryptographer.AddKey(params); 1790 other_cryptographer.AddKey(params);
1774 WriteNode node(&trans); 1791 WriteNode node(&trans);
1775 EXPECT_TRUE(node.InitByTagLookup(kNigoriTag)); 1792 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1776 sync_pb::NigoriSpecifics nigori; 1793 sync_pb::NigoriSpecifics nigori;
1777 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1794 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1778 node.SetNigoriSpecifics(nigori); 1795 node.SetNigoriSpecifics(nigori);
1779 cryptographer->Update(nigori); 1796 cryptographer->Update(nigori);
1780 EXPECT_FALSE(cryptographer->is_ready()); 1797 EXPECT_FALSE(cryptographer->is_ready());
1781 } 1798 }
1782 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1799 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_));
1783 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1800 EXPECT_CALL(observer_, OnPassphraseAccepted());
1784 EXPECT_CALL(observer_, OnEncryptionComplete()); 1801 EXPECT_CALL(observer_, OnEncryptionComplete());
1785 sync_manager_.SetEncryptionPassphrase("passphrase", false); 1802 sync_manager_.SetEncryptionPassphrase("passphrase", false);
(...skipping 20 matching lines...) Expand all
1806 node_id = password_node.GetId(); 1823 node_id = password_node.GetId();
1807 } 1824 }
1808 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1825 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_));
1809 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1826 EXPECT_CALL(observer_, OnPassphraseAccepted());
1810 EXPECT_CALL(observer_, OnEncryptionComplete()); 1827 EXPECT_CALL(observer_, OnEncryptionComplete());
1811 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); 1828 sync_manager_.SetEncryptionPassphrase("new_passphrase", true);
1812 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); 1829 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest());
1813 { 1830 {
1814 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1831 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1815 ReadNode password_node(&trans); 1832 ReadNode password_node(&trans);
1816 EXPECT_FALSE(password_node.InitByClientTagLookup(syncable::PASSWORDS, 1833 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY,
1817 tag)); 1834 password_node.InitByClientTagLookup(syncable::PASSWORDS,
1835 tag));
1818 } 1836 }
1819 { 1837 {
1820 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1838 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1821 ReadNode password_node(&trans); 1839 ReadNode password_node(&trans);
1822 EXPECT_FALSE(password_node.InitByIdLookup(node_id)); 1840 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY,
1841 password_node.InitByIdLookup(node_id));
1823 } 1842 }
1824 } 1843 }
1825 1844
1826 TEST_F(SyncManagerTest, NudgeDelayTest) { 1845 TEST_F(SyncManagerTest, NudgeDelayTest) {
1827 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncable::BOOKMARKS), 1846 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncable::BOOKMARKS),
1828 base::TimeDelta::FromMilliseconds( 1847 base::TimeDelta::FromMilliseconds(
1829 SyncManager::kDefaultNudgeDelayMilliseconds)); 1848 SyncManager::kDefaultNudgeDelayMilliseconds));
1830 1849
1831 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncable::AUTOFILL), 1850 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncable::AUTOFILL),
1832 base::TimeDelta::FromSeconds( 1851 base::TimeDelta::FromSeconds(
(...skipping 18 matching lines...) Expand all
1851 // Create a bookmark using the legacy format. 1870 // Create a bookmark using the legacy format.
1852 int64 node_id1 = MakeNode(sync_manager_.GetUserShare(), 1871 int64 node_id1 = MakeNode(sync_manager_.GetUserShare(),
1853 syncable::BOOKMARKS, 1872 syncable::BOOKMARKS,
1854 "testtag"); 1873 "testtag");
1855 int64 node_id2 = MakeNode(sync_manager_.GetUserShare(), 1874 int64 node_id2 = MakeNode(sync_manager_.GetUserShare(),
1856 syncable::BOOKMARKS, 1875 syncable::BOOKMARKS,
1857 "testtag2"); 1876 "testtag2");
1858 { 1877 {
1859 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1878 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1860 WriteNode node(&trans); 1879 WriteNode node(&trans);
1861 EXPECT_TRUE(node.InitByIdLookup(node_id1)); 1880 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1));
1862 1881
1863 sync_pb::EntitySpecifics entity_specifics; 1882 sync_pb::EntitySpecifics entity_specifics;
1864 entity_specifics.mutable_bookmark()->set_url(url); 1883 entity_specifics.mutable_bookmark()->set_url(url);
1865 node.SetEntitySpecifics(entity_specifics); 1884 node.SetEntitySpecifics(entity_specifics);
1866 1885
1867 // Set the old style title. 1886 // Set the old style title.
1868 syncable::MutableEntry* node_entry = node.entry_; 1887 syncable::MutableEntry* node_entry = node.entry_;
1869 node_entry->Put(syncable::NON_UNIQUE_NAME, title); 1888 node_entry->Put(syncable::NON_UNIQUE_NAME, title);
1870 1889
1871 WriteNode node2(&trans); 1890 WriteNode node2(&trans);
1872 EXPECT_TRUE(node2.InitByIdLookup(node_id2)); 1891 EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2));
1873 1892
1874 sync_pb::EntitySpecifics entity_specifics2; 1893 sync_pb::EntitySpecifics entity_specifics2;
1875 entity_specifics2.mutable_bookmark()->set_url(url2); 1894 entity_specifics2.mutable_bookmark()->set_url(url2);
1876 node2.SetEntitySpecifics(entity_specifics2); 1895 node2.SetEntitySpecifics(entity_specifics2);
1877 1896
1878 // Set the old style title. 1897 // Set the old style title.
1879 syncable::MutableEntry* node_entry2 = node2.entry_; 1898 syncable::MutableEntry* node_entry2 = node2.entry_;
1880 node_entry2->Put(syncable::NON_UNIQUE_NAME, title2); 1899 node_entry2->Put(syncable::NON_UNIQUE_NAME, title2);
1881 } 1900 }
1882 1901
1883 { 1902 {
1884 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1903 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1885 ReadNode node(&trans); 1904 ReadNode node(&trans);
1886 EXPECT_TRUE(node.InitByIdLookup(node_id1)); 1905 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1));
1887 EXPECT_EQ(syncable::BOOKMARKS, node.GetModelType()); 1906 EXPECT_EQ(syncable::BOOKMARKS, node.GetModelType());
1888 EXPECT_EQ(title, node.GetTitle()); 1907 EXPECT_EQ(title, node.GetTitle());
1889 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); 1908 EXPECT_EQ(title, node.GetBookmarkSpecifics().title());
1890 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); 1909 EXPECT_EQ(url, node.GetBookmarkSpecifics().url());
1891 1910
1892 ReadNode node2(&trans); 1911 ReadNode node2(&trans);
1893 EXPECT_TRUE(node2.InitByIdLookup(node_id2)); 1912 EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2));
1894 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); 1913 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType());
1895 // We should de-canonicalize the title in GetTitle(), but the title in the 1914 // We should de-canonicalize the title in GetTitle(), but the title in the
1896 // specifics should be stored in the server legal form. 1915 // specifics should be stored in the server legal form.
1897 EXPECT_EQ(raw_title2, node2.GetTitle()); 1916 EXPECT_EQ(raw_title2, node2.GetTitle());
1898 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); 1917 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title());
1899 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); 1918 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url());
1900 } 1919 }
1901 1920
1902 { 1921 {
1903 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1922 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
(...skipping 15 matching lines...) Expand all
1919 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1938 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1920 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals( 1939 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(
1921 syncable::ModelTypeSet::All())); 1940 syncable::ModelTypeSet::All()));
1922 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1941 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1923 trans.GetWrappedTrans(), 1942 trans.GetWrappedTrans(),
1924 trans.GetCryptographer(), 1943 trans.GetCryptographer(),
1925 syncable::BOOKMARKS, 1944 syncable::BOOKMARKS,
1926 true /* is encrypted */)); 1945 true /* is encrypted */));
1927 1946
1928 ReadNode node(&trans); 1947 ReadNode node(&trans);
1929 EXPECT_TRUE(node.InitByIdLookup(node_id1)); 1948 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1));
1930 EXPECT_EQ(syncable::BOOKMARKS, node.GetModelType()); 1949 EXPECT_EQ(syncable::BOOKMARKS, node.GetModelType());
1931 EXPECT_EQ(title, node.GetTitle()); 1950 EXPECT_EQ(title, node.GetTitle());
1932 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); 1951 EXPECT_EQ(title, node.GetBookmarkSpecifics().title());
1933 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); 1952 EXPECT_EQ(url, node.GetBookmarkSpecifics().url());
1934 1953
1935 ReadNode node2(&trans); 1954 ReadNode node2(&trans);
1936 EXPECT_TRUE(node2.InitByIdLookup(node_id2)); 1955 EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2));
1937 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); 1956 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType());
1938 // We should de-canonicalize the title in GetTitle(), but the title in the 1957 // We should de-canonicalize the title in GetTitle(), but the title in the
1939 // specifics should be stored in the server legal form. 1958 // specifics should be stored in the server legal form.
1940 EXPECT_EQ(raw_title2, node2.GetTitle()); 1959 EXPECT_EQ(raw_title2, node2.GetTitle());
1941 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); 1960 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title());
1942 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); 1961 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url());
1943 } 1962 }
1944 } 1963 }
1945 1964
1946 // Create a bookmark and set the title/url, then verify the data was properly 1965 // Create a bookmark and set the title/url, then verify the data was properly
(...skipping 12 matching lines...) Expand all
1959 node.SetTitle(UTF8ToWide(title)); 1978 node.SetTitle(UTF8ToWide(title));
1960 node.SetURL(url); 1979 node.SetURL(url);
1961 } 1980 }
1962 { 1981 {
1963 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1982 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1964 ReadNode root_node(&trans); 1983 ReadNode root_node(&trans);
1965 root_node.InitByRootLookup(); 1984 root_node.InitByRootLookup();
1966 int64 child_id = root_node.GetFirstChildId(); 1985 int64 child_id = root_node.GetFirstChildId();
1967 1986
1968 ReadNode node(&trans); 1987 ReadNode node(&trans);
1969 ASSERT_TRUE(node.InitByIdLookup(child_id)); 1988 ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id));
1970 EXPECT_FALSE(node.GetIsFolder()); 1989 EXPECT_FALSE(node.GetIsFolder());
1971 EXPECT_EQ(title, node.GetTitle()); 1990 EXPECT_EQ(title, node.GetTitle());
1972 EXPECT_EQ(url, node.GetURL()); 1991 EXPECT_EQ(url, node.GetURL());
1973 } 1992 }
1974 } 1993 }
1975 1994
1976 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary 1995 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary
1977 // changes. 1996 // changes.
1978 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { 1997 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) {
1979 std::string client_tag = "title"; 1998 std::string client_tag = "title";
1980 sync_pb::EntitySpecifics entity_specifics; 1999 sync_pb::EntitySpecifics entity_specifics;
1981 entity_specifics.mutable_bookmark()->set_url("url"); 2000 entity_specifics.mutable_bookmark()->set_url("url");
1982 entity_specifics.mutable_bookmark()->set_title("title"); 2001 entity_specifics.mutable_bookmark()->set_title("title");
1983 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, 2002 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag,
1984 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, 2003 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS,
1985 client_tag), 2004 client_tag),
1986 entity_specifics); 2005 entity_specifics);
1987 // New node shouldn't start off unsynced. 2006 // New node shouldn't start off unsynced.
1988 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2007 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
1989 // Manually change to the same data. Should not set is_unsynced. 2008 // Manually change to the same data. Should not set is_unsynced.
1990 { 2009 {
1991 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2010 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1992 WriteNode node(&trans); 2011 WriteNode node(&trans);
1993 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2012 EXPECT_EQ(BaseNode::INIT_OK,
2013 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
1994 node.SetEntitySpecifics(entity_specifics); 2014 node.SetEntitySpecifics(entity_specifics);
1995 } 2015 }
1996 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2016 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
1997 2017
1998 // Encrypt the datatatype, should set is_unsynced. 2018 // Encrypt the datatatype, should set is_unsynced.
1999 EXPECT_CALL(observer_, 2019 EXPECT_CALL(observer_,
2000 OnEncryptedTypesChanged( 2020 OnEncryptedTypesChanged(
2001 HasModelTypes(syncable::ModelTypeSet::All()), true)); 2021 HasModelTypes(syncable::ModelTypeSet::All()), true));
2002 EXPECT_CALL(observer_, OnEncryptionComplete()); 2022 EXPECT_CALL(observer_, OnEncryptionComplete());
2003 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); 2023 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION));
2004 2024
2005 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 2025 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing));
2006 PumpLoop(); 2026 PumpLoop();
2007 { 2027 {
2008 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2028 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2009 ReadNode node(&trans); 2029 ReadNode node(&trans);
2010 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2030 EXPECT_EQ(BaseNode::INIT_OK,
2031 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2011 const syncable::Entry* node_entry = node.GetEntry(); 2032 const syncable::Entry* node_entry = node.GetEntry();
2012 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2033 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2013 EXPECT_TRUE(specifics.has_encrypted()); 2034 EXPECT_TRUE(specifics.has_encrypted());
2014 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2035 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2015 Cryptographer* cryptographer = trans.GetCryptographer(); 2036 Cryptographer* cryptographer = trans.GetCryptographer();
2016 EXPECT_TRUE(cryptographer->is_ready()); 2037 EXPECT_TRUE(cryptographer->is_ready());
2017 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( 2038 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey(
2018 specifics.encrypted())); 2039 specifics.encrypted()));
2019 } 2040 }
2020 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2041 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
2021 2042
2022 // Set a new passphrase. Should set is_unsynced. 2043 // Set a new passphrase. Should set is_unsynced.
2023 testing::Mock::VerifyAndClearExpectations(&observer_); 2044 testing::Mock::VerifyAndClearExpectations(&observer_);
2024 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 2045 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_));
2025 EXPECT_CALL(observer_, OnPassphraseAccepted()); 2046 EXPECT_CALL(observer_, OnPassphraseAccepted());
2026 EXPECT_CALL(observer_, OnEncryptionComplete()); 2047 EXPECT_CALL(observer_, OnEncryptionComplete());
2027 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); 2048 sync_manager_.SetEncryptionPassphrase("new_passphrase", true);
2028 { 2049 {
2029 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2050 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2030 ReadNode node(&trans); 2051 ReadNode node(&trans);
2031 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2052 EXPECT_EQ(BaseNode::INIT_OK,
2053 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2032 const syncable::Entry* node_entry = node.GetEntry(); 2054 const syncable::Entry* node_entry = node.GetEntry();
2033 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2055 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2034 EXPECT_TRUE(specifics.has_encrypted()); 2056 EXPECT_TRUE(specifics.has_encrypted());
2035 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2057 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2036 Cryptographer* cryptographer = trans.GetCryptographer(); 2058 Cryptographer* cryptographer = trans.GetCryptographer();
2037 EXPECT_TRUE(cryptographer->is_ready()); 2059 EXPECT_TRUE(cryptographer->is_ready());
2038 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( 2060 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey(
2039 specifics.encrypted())); 2061 specifics.encrypted()));
2040 } 2062 }
2041 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2063 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
2042 2064
2043 // Force a re-encrypt everything. Should not set is_unsynced. 2065 // Force a re-encrypt everything. Should not set is_unsynced.
2044 testing::Mock::VerifyAndClearExpectations(&observer_); 2066 testing::Mock::VerifyAndClearExpectations(&observer_);
2045 EXPECT_CALL(observer_, OnEncryptionComplete()); 2067 EXPECT_CALL(observer_, OnEncryptionComplete());
2046 2068
2047 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 2069 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing));
2048 PumpLoop(); 2070 PumpLoop();
2049 2071
2050 { 2072 {
2051 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2073 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2052 ReadNode node(&trans); 2074 ReadNode node(&trans);
2053 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2075 EXPECT_EQ(BaseNode::INIT_OK,
2076 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2054 const syncable::Entry* node_entry = node.GetEntry(); 2077 const syncable::Entry* node_entry = node.GetEntry();
2055 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2078 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2056 EXPECT_TRUE(specifics.has_encrypted()); 2079 EXPECT_TRUE(specifics.has_encrypted());
2057 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2080 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2058 Cryptographer* cryptographer = trans.GetCryptographer(); 2081 Cryptographer* cryptographer = trans.GetCryptographer();
2059 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( 2082 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey(
2060 specifics.encrypted())); 2083 specifics.encrypted()));
2061 } 2084 }
2062 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2085 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
2063 2086
2064 // Manually change to the same data. Should not set is_unsynced. 2087 // Manually change to the same data. Should not set is_unsynced.
2065 { 2088 {
2066 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2089 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2067 WriteNode node(&trans); 2090 WriteNode node(&trans);
2068 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2091 EXPECT_EQ(BaseNode::INIT_OK,
2092 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2069 node.SetEntitySpecifics(entity_specifics); 2093 node.SetEntitySpecifics(entity_specifics);
2070 const syncable::Entry* node_entry = node.GetEntry(); 2094 const syncable::Entry* node_entry = node.GetEntry();
2071 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2095 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2072 EXPECT_TRUE(specifics.has_encrypted()); 2096 EXPECT_TRUE(specifics.has_encrypted());
2073 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED)); 2097 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED));
2074 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2098 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2075 Cryptographer* cryptographer = trans.GetCryptographer(); 2099 Cryptographer* cryptographer = trans.GetCryptographer();
2076 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( 2100 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey(
2077 specifics.encrypted())); 2101 specifics.encrypted()));
2078 } 2102 }
2079 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2103 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
2080 2104
2081 // Manually change to different data. Should set is_unsynced. 2105 // Manually change to different data. Should set is_unsynced.
2082 { 2106 {
2083 entity_specifics.mutable_bookmark()->set_url("url2"); 2107 entity_specifics.mutable_bookmark()->set_url("url2");
2084 entity_specifics.mutable_bookmark()->set_title("title2"); 2108 entity_specifics.mutable_bookmark()->set_title("title2");
2085 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2109 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2086 WriteNode node(&trans); 2110 WriteNode node(&trans);
2087 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2111 EXPECT_EQ(BaseNode::INIT_OK,
2112 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2088 node.SetEntitySpecifics(entity_specifics); 2113 node.SetEntitySpecifics(entity_specifics);
2089 const syncable::Entry* node_entry = node.GetEntry(); 2114 const syncable::Entry* node_entry = node.GetEntry();
2090 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2115 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2091 EXPECT_TRUE(specifics.has_encrypted()); 2116 EXPECT_TRUE(specifics.has_encrypted());
2092 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); 2117 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED));
2093 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2118 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2094 Cryptographer* cryptographer = trans.GetCryptographer(); 2119 Cryptographer* cryptographer = trans.GetCryptographer();
2095 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( 2120 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey(
2096 specifics.encrypted())); 2121 specifics.encrypted()));
2097 } 2122 }
(...skipping 20 matching lines...) Expand all
2118 client_tag), 2143 client_tag),
2119 entity_specifics); 2144 entity_specifics);
2120 // New node shouldn't start off unsynced. 2145 // New node shouldn't start off unsynced.
2121 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); 2146 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2122 2147
2123 // Manually change to the same data via SetEntitySpecifics. Should not set 2148 // Manually change to the same data via SetEntitySpecifics. Should not set
2124 // is_unsynced. 2149 // is_unsynced.
2125 { 2150 {
2126 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2151 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2127 WriteNode node(&trans); 2152 WriteNode node(&trans);
2128 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); 2153 EXPECT_EQ(BaseNode::INIT_OK,
2154 node.InitByClientTagLookup(syncable::PASSWORDS, client_tag));
2129 node.SetEntitySpecifics(entity_specifics); 2155 node.SetEntitySpecifics(entity_specifics);
2130 } 2156 }
2131 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); 2157 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2132 } 2158 }
2133 2159
2134 // Passwords have their own handling for encryption. Verify it does not result 2160 // Passwords have their own handling for encryption. Verify it does not result
2135 // in unnecessary writes via SetPasswordSpecifics. 2161 // in unnecessary writes via SetPasswordSpecifics.
2136 TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) { 2162 TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) {
2137 std::string client_tag = "title"; 2163 std::string client_tag = "title";
2138 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 2164 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
(...skipping 13 matching lines...) Expand all
2152 client_tag), 2178 client_tag),
2153 entity_specifics); 2179 entity_specifics);
2154 // New node shouldn't start off unsynced. 2180 // New node shouldn't start off unsynced.
2155 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); 2181 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2156 2182
2157 // Manually change to the same data via SetPasswordSpecifics. Should not set 2183 // Manually change to the same data via SetPasswordSpecifics. Should not set
2158 // is_unsynced. 2184 // is_unsynced.
2159 { 2185 {
2160 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2186 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2161 WriteNode node(&trans); 2187 WriteNode node(&trans);
2162 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); 2188 EXPECT_EQ(BaseNode::INIT_OK,
2189 node.InitByClientTagLookup(syncable::PASSWORDS, client_tag));
2163 node.SetPasswordSpecifics(node.GetPasswordSpecifics()); 2190 node.SetPasswordSpecifics(node.GetPasswordSpecifics());
2164 } 2191 }
2165 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); 2192 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2166 2193
2167 // Manually change to different data. Should set is_unsynced. 2194 // Manually change to different data. Should set is_unsynced.
2168 { 2195 {
2169 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2196 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2170 WriteNode node(&trans); 2197 WriteNode node(&trans);
2171 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); 2198 EXPECT_EQ(BaseNode::INIT_OK,
2199 node.InitByClientTagLookup(syncable::PASSWORDS, client_tag));
2172 Cryptographer* cryptographer = trans.GetCryptographer(); 2200 Cryptographer* cryptographer = trans.GetCryptographer();
2173 sync_pb::PasswordSpecificsData data; 2201 sync_pb::PasswordSpecificsData data;
2174 data.set_password_value("secret2"); 2202 data.set_password_value("secret2");
2175 cryptographer->Encrypt( 2203 cryptographer->Encrypt(
2176 data, 2204 data,
2177 entity_specifics.mutable_password()->mutable_encrypted()); 2205 entity_specifics.mutable_password()->mutable_encrypted());
2178 node.SetPasswordSpecifics(data); 2206 node.SetPasswordSpecifics(data);
2179 const syncable::Entry* node_entry = node.GetEntry(); 2207 const syncable::Entry* node_entry = node.GetEntry();
2180 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); 2208 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED));
2181 } 2209 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2253 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, 2281 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS,
2254 client_tag), 2282 client_tag),
2255 entity_specifics); 2283 entity_specifics);
2256 // New node shouldn't start off unsynced. 2284 // New node shouldn't start off unsynced.
2257 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2285 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
2258 2286
2259 // Manually change to the same title. Should not set is_unsynced. 2287 // Manually change to the same title. Should not set is_unsynced.
2260 { 2288 {
2261 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2289 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2262 WriteNode node(&trans); 2290 WriteNode node(&trans);
2263 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2291 EXPECT_EQ(BaseNode::INIT_OK,
2292 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2264 node.SetTitle(UTF8ToWide(client_tag)); 2293 node.SetTitle(UTF8ToWide(client_tag));
2265 } 2294 }
2266 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2295 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
2267 2296
2268 // Manually change to new title. Should set is_unsynced. 2297 // Manually change to new title. Should set is_unsynced.
2269 { 2298 {
2270 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2299 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2271 WriteNode node(&trans); 2300 WriteNode node(&trans);
2272 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2301 EXPECT_EQ(BaseNode::INIT_OK,
2302 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2273 node.SetTitle(UTF8ToWide("title2")); 2303 node.SetTitle(UTF8ToWide("title2"));
2274 } 2304 }
2275 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2305 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
2276 } 2306 }
2277 2307
2278 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted 2308 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted
2279 // bookmarks when we write the same data, but does set it when we write new 2309 // bookmarks when we write the same data, but does set it when we write new
2280 // data. 2310 // data.
2281 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { 2311 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) {
2282 std::string client_tag = "title"; 2312 std::string client_tag = "title";
(...skipping 15 matching lines...) Expand all
2298 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); 2328 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION));
2299 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 2329 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing));
2300 PumpLoop(); 2330 PumpLoop();
2301 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2331 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
2302 2332
2303 // Manually change to the same title. Should not set is_unsynced. 2333 // Manually change to the same title. Should not set is_unsynced.
2304 // NON_UNIQUE_NAME should be kEncryptedString. 2334 // NON_UNIQUE_NAME should be kEncryptedString.
2305 { 2335 {
2306 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2336 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2307 WriteNode node(&trans); 2337 WriteNode node(&trans);
2308 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2338 EXPECT_EQ(BaseNode::INIT_OK,
2339 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2309 node.SetTitle(UTF8ToWide(client_tag)); 2340 node.SetTitle(UTF8ToWide(client_tag));
2310 const syncable::Entry* node_entry = node.GetEntry(); 2341 const syncable::Entry* node_entry = node.GetEntry();
2311 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2342 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2312 EXPECT_TRUE(specifics.has_encrypted()); 2343 EXPECT_TRUE(specifics.has_encrypted());
2313 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2344 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2314 } 2345 }
2315 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2346 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
2316 2347
2317 // Manually change to new title. Should set is_unsynced. NON_UNIQUE_NAME 2348 // Manually change to new title. Should set is_unsynced. NON_UNIQUE_NAME
2318 // should still be kEncryptedString. 2349 // should still be kEncryptedString.
2319 { 2350 {
2320 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2351 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2321 WriteNode node(&trans); 2352 WriteNode node(&trans);
2322 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2353 EXPECT_EQ(BaseNode::INIT_OK,
2354 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2323 node.SetTitle(UTF8ToWide("title2")); 2355 node.SetTitle(UTF8ToWide("title2"));
2324 const syncable::Entry* node_entry = node.GetEntry(); 2356 const syncable::Entry* node_entry = node.GetEntry();
2325 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2357 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2326 EXPECT_TRUE(specifics.has_encrypted()); 2358 EXPECT_TRUE(specifics.has_encrypted());
2327 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2359 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2328 } 2360 }
2329 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); 2361 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag));
2330 } 2362 }
2331 2363
2332 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks 2364 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks
2333 // when we write the same data, but does set it when we write new data. 2365 // when we write the same data, but does set it when we write new data.
2334 TEST_F(SyncManagerTest, SetNonBookmarkTitle) { 2366 TEST_F(SyncManagerTest, SetNonBookmarkTitle) {
2335 std::string client_tag = "title"; 2367 std::string client_tag = "title";
2336 sync_pb::EntitySpecifics entity_specifics; 2368 sync_pb::EntitySpecifics entity_specifics;
2337 entity_specifics.mutable_preference()->set_name("name"); 2369 entity_specifics.mutable_preference()->set_name("name");
2338 entity_specifics.mutable_preference()->set_value("value"); 2370 entity_specifics.mutable_preference()->set_value("value");
2339 MakeServerNode(sync_manager_.GetUserShare(), 2371 MakeServerNode(sync_manager_.GetUserShare(),
2340 syncable::PREFERENCES, 2372 syncable::PREFERENCES,
2341 client_tag, 2373 client_tag,
2342 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, 2374 BaseNode::GenerateSyncableHash(syncable::PREFERENCES,
2343 client_tag), 2375 client_tag),
2344 entity_specifics); 2376 entity_specifics);
2345 // New node shouldn't start off unsynced. 2377 // New node shouldn't start off unsynced.
2346 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); 2378 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag));
2347 2379
2348 // Manually change to the same title. Should not set is_unsynced. 2380 // Manually change to the same title. Should not set is_unsynced.
2349 { 2381 {
2350 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2382 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2351 WriteNode node(&trans); 2383 WriteNode node(&trans);
2352 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); 2384 EXPECT_EQ(BaseNode::INIT_OK,
2385 node.InitByClientTagLookup(syncable::PREFERENCES, client_tag));
2353 node.SetTitle(UTF8ToWide(client_tag)); 2386 node.SetTitle(UTF8ToWide(client_tag));
2354 } 2387 }
2355 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); 2388 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag));
2356 2389
2357 // Manually change to new title. Should set is_unsynced. 2390 // Manually change to new title. Should set is_unsynced.
2358 { 2391 {
2359 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2392 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2360 WriteNode node(&trans); 2393 WriteNode node(&trans);
2361 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); 2394 EXPECT_EQ(BaseNode::INIT_OK,
2395 node.InitByClientTagLookup(syncable::PREFERENCES, client_tag));
2362 node.SetTitle(UTF8ToWide("title2")); 2396 node.SetTitle(UTF8ToWide("title2"));
2363 } 2397 }
2364 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); 2398 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag));
2365 } 2399 }
2366 2400
2367 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted 2401 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted
2368 // non-bookmarks when we write the same data or when we write new data 2402 // non-bookmarks when we write the same data or when we write new data
2369 // data (should remained kEncryptedString). 2403 // data (should remained kEncryptedString).
2370 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { 2404 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) {
2371 std::string client_tag = "title"; 2405 std::string client_tag = "title";
(...skipping 17 matching lines...) Expand all
2389 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); 2423 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION));
2390 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 2424 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing));
2391 PumpLoop(); 2425 PumpLoop();
2392 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); 2426 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag));
2393 2427
2394 // Manually change to the same title. Should not set is_unsynced. 2428 // Manually change to the same title. Should not set is_unsynced.
2395 // NON_UNIQUE_NAME should be kEncryptedString. 2429 // NON_UNIQUE_NAME should be kEncryptedString.
2396 { 2430 {
2397 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2431 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2398 WriteNode node(&trans); 2432 WriteNode node(&trans);
2399 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); 2433 EXPECT_EQ(BaseNode::INIT_OK,
2434 node.InitByClientTagLookup(syncable::PREFERENCES, client_tag));
2400 node.SetTitle(UTF8ToWide(client_tag)); 2435 node.SetTitle(UTF8ToWide(client_tag));
2401 const syncable::Entry* node_entry = node.GetEntry(); 2436 const syncable::Entry* node_entry = node.GetEntry();
2402 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2437 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2403 EXPECT_TRUE(specifics.has_encrypted()); 2438 EXPECT_TRUE(specifics.has_encrypted());
2404 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2439 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2405 } 2440 }
2406 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); 2441 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag));
2407 2442
2408 // Manually change to new title. Should not set is_unsynced because the 2443 // Manually change to new title. Should not set is_unsynced because the
2409 // NON_UNIQUE_NAME should still be kEncryptedString. 2444 // NON_UNIQUE_NAME should still be kEncryptedString.
2410 { 2445 {
2411 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2446 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2412 WriteNode node(&trans); 2447 WriteNode node(&trans);
2413 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); 2448 EXPECT_EQ(BaseNode::INIT_OK,
2449 node.InitByClientTagLookup(syncable::PREFERENCES, client_tag));
2414 node.SetTitle(UTF8ToWide("title2")); 2450 node.SetTitle(UTF8ToWide("title2"));
2415 const syncable::Entry* node_entry = node.GetEntry(); 2451 const syncable::Entry* node_entry = node.GetEntry();
2416 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2452 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2417 EXPECT_TRUE(specifics.has_encrypted()); 2453 EXPECT_TRUE(specifics.has_encrypted());
2418 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2454 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2419 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED)); 2455 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED));
2420 } 2456 }
2421 } 2457 }
2422 2458
2423 // Create an encrypted entry when the cryptographer doesn't think the type is 2459 // Create an encrypted entry when the cryptographer doesn't think the type is
(...skipping 19 matching lines...) Expand all
2443 } 2479 }
2444 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, 2480 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag,
2445 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, 2481 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS,
2446 client_tag), 2482 client_tag),
2447 entity_specifics); 2483 entity_specifics);
2448 2484
2449 { 2485 {
2450 // Verify the data. 2486 // Verify the data.
2451 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2487 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2452 ReadNode node(&trans); 2488 ReadNode node(&trans);
2453 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2489 EXPECT_EQ(BaseNode::INIT_OK,
2490 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2454 EXPECT_EQ(title, node.GetTitle()); 2491 EXPECT_EQ(title, node.GetTitle());
2455 EXPECT_EQ(GURL(url), node.GetURL()); 2492 EXPECT_EQ(GURL(url), node.GetURL());
2456 } 2493 }
2457 2494
2458 { 2495 {
2459 // Overwrite the url (which overwrites the specifics). 2496 // Overwrite the url (which overwrites the specifics).
2460 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2497 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2461 WriteNode node(&trans); 2498 WriteNode node(&trans);
2462 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2499 EXPECT_EQ(BaseNode::INIT_OK,
2500 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2463 node.SetURL(GURL(url2)); 2501 node.SetURL(GURL(url2));
2464 } 2502 }
2465 2503
2466 { 2504 {
2467 // Verify it's still encrypted and it has the most recent url. 2505 // Verify it's still encrypted and it has the most recent url.
2468 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2506 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2469 ReadNode node(&trans); 2507 ReadNode node(&trans);
2470 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); 2508 EXPECT_EQ(BaseNode::INIT_OK,
2509 node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag));
2471 EXPECT_EQ(title, node.GetTitle()); 2510 EXPECT_EQ(title, node.GetTitle());
2472 EXPECT_EQ(GURL(url2), node.GetURL()); 2511 EXPECT_EQ(GURL(url2), node.GetURL());
2473 const syncable::Entry* node_entry = node.GetEntry(); 2512 const syncable::Entry* node_entry = node.GetEntry();
2474 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2513 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2475 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2514 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2476 EXPECT_TRUE(specifics.has_encrypted()); 2515 EXPECT_TRUE(specifics.has_encrypted());
2477 } 2516 }
2478 } 2517 }
2479 2518
2480 } // namespace browser_sync 2519 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/sync_manager.cc ('k') | chrome/browser/sync/internal_api/write_node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698