| OLD | NEW |
| 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 "sync/internal_api/sync_manager_impl.h" | 9 #include "components/sync/core_impl/sync_manager_impl.h" |
| 10 | 10 |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 | 12 |
| 13 #include <cstddef> | 13 #include <cstddef> |
| 14 #include <map> | 14 #include <map> |
| 15 #include <memory> | 15 #include <memory> |
| 16 #include <utility> | 16 #include <utility> |
| 17 | 17 |
| 18 #include "base/callback.h" | 18 #include "base/callback.h" |
| 19 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 20 #include "base/files/scoped_temp_dir.h" | 20 #include "base/files/scoped_temp_dir.h" |
| 21 #include "base/format_macros.h" | 21 #include "base/format_macros.h" |
| 22 #include "base/location.h" | 22 #include "base/location.h" |
| 23 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
| 24 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/test/values_test_util.h" | 27 #include "base/test/values_test_util.h" |
| 28 #include "base/values.h" | 28 #include "base/values.h" |
| 29 #include "components/sync/base/attachment_id_proto.h" |
| 30 #include "components/sync/base/cancelation_signal.h" |
| 31 #include "components/sync/base/cryptographer.h" |
| 32 #include "components/sync/base/extensions_activity.h" |
| 33 #include "components/sync/base/mock_unrecoverable_error_handler.h" |
| 34 #include "components/sync/base/model_type_test_util.h" |
| 35 #include "components/sync/base/time.h" |
| 36 #include "components/sync/core/change_record.h" |
| 37 #include "components/sync/core/http_post_provider_factory.h" |
| 38 #include "components/sync/core/http_post_provider_interface.h" |
| 39 #include "components/sync/core/read_node.h" |
| 40 #include "components/sync/core/read_transaction.h" |
| 41 #include "components/sync/core/test/test_entry_factory.h" |
| 42 #include "components/sync/core/test/test_internal_components_factory.h" |
| 43 #include "components/sync/core/test/test_user_share.h" |
| 44 #include "components/sync/core/write_node.h" |
| 45 #include "components/sync/core/write_transaction.h" |
| 46 #include "components/sync/core_impl/sync_encryption_handler_impl.h" |
| 47 #include "components/sync/core_impl/syncapi_internal.h" |
| 48 #include "components/sync/engine/events/protocol_event.h" |
| 49 #include "components/sync/engine/model_safe_worker.h" |
| 50 #include "components/sync/engine/polling_constants.h" |
| 51 #include "components/sync/engine_impl/sync_scheduler.h" |
| 52 #include "components/sync/js/js_backend.h" |
| 53 #include "components/sync/js/js_event_handler.h" |
| 54 #include "components/sync/js/js_test_util.h" |
| 55 #include "components/sync/protocol/bookmark_specifics.pb.h" |
| 56 #include "components/sync/protocol/encryption.pb.h" |
| 57 #include "components/sync/protocol/extension_specifics.pb.h" |
| 58 #include "components/sync/protocol/password_specifics.pb.h" |
| 59 #include "components/sync/protocol/preference_specifics.pb.h" |
| 60 #include "components/sync/protocol/proto_value_conversions.h" |
| 61 #include "components/sync/protocol/sync.pb.h" |
| 62 #include "components/sync/sessions_impl/sync_session.h" |
| 63 #include "components/sync/syncable/directory.h" |
| 64 #include "components/sync/syncable/entry.h" |
| 65 #include "components/sync/syncable/mutable_entry.h" |
| 66 #include "components/sync/syncable/nigori_util.h" |
| 67 #include "components/sync/syncable/syncable_id.h" |
| 68 #include "components/sync/syncable/syncable_read_transaction.h" |
| 69 #include "components/sync/syncable/syncable_util.h" |
| 70 #include "components/sync/syncable/syncable_write_transaction.h" |
| 71 #include "components/sync/test/callback_counter.h" |
| 72 #include "components/sync/test/engine/fake_model_worker.h" |
| 73 #include "components/sync/test/engine/fake_sync_scheduler.h" |
| 74 #include "components/sync/test/engine/test_id_factory.h" |
| 75 #include "components/sync/test/fake_encryptor.h" |
| 29 #include "google_apis/gaia/gaia_constants.h" | 76 #include "google_apis/gaia/gaia_constants.h" |
| 30 #include "sync/engine/sync_scheduler.h" | |
| 31 #include "sync/internal_api/public/base/attachment_id_proto.h" | |
| 32 #include "sync/internal_api/public/base/cancelation_signal.h" | |
| 33 #include "sync/internal_api/public/base/model_type_test_util.h" | |
| 34 #include "sync/internal_api/public/change_record.h" | |
| 35 #include "sync/internal_api/public/engine/model_safe_worker.h" | |
| 36 #include "sync/internal_api/public/engine/polling_constants.h" | |
| 37 #include "sync/internal_api/public/events/protocol_event.h" | |
| 38 #include "sync/internal_api/public/http_post_provider_factory.h" | |
| 39 #include "sync/internal_api/public/http_post_provider_interface.h" | |
| 40 #include "sync/internal_api/public/read_node.h" | |
| 41 #include "sync/internal_api/public/read_transaction.h" | |
| 42 #include "sync/internal_api/public/test/test_entry_factory.h" | |
| 43 #include "sync/internal_api/public/test/test_internal_components_factory.h" | |
| 44 #include "sync/internal_api/public/test/test_user_share.h" | |
| 45 #include "sync/internal_api/public/write_node.h" | |
| 46 #include "sync/internal_api/public/write_transaction.h" | |
| 47 #include "sync/internal_api/sync_encryption_handler_impl.h" | |
| 48 #include "sync/internal_api/syncapi_internal.h" | |
| 49 #include "sync/js/js_backend.h" | |
| 50 #include "sync/js/js_event_handler.h" | |
| 51 #include "sync/js/js_test_util.h" | |
| 52 #include "sync/protocol/bookmark_specifics.pb.h" | |
| 53 #include "sync/protocol/encryption.pb.h" | |
| 54 #include "sync/protocol/extension_specifics.pb.h" | |
| 55 #include "sync/protocol/password_specifics.pb.h" | |
| 56 #include "sync/protocol/preference_specifics.pb.h" | |
| 57 #include "sync/protocol/proto_value_conversions.h" | |
| 58 #include "sync/protocol/sync.pb.h" | |
| 59 #include "sync/sessions/sync_session.h" | |
| 60 #include "sync/syncable/directory.h" | |
| 61 #include "sync/syncable/entry.h" | |
| 62 #include "sync/syncable/mutable_entry.h" | |
| 63 #include "sync/syncable/nigori_util.h" | |
| 64 #include "sync/syncable/syncable_id.h" | |
| 65 #include "sync/syncable/syncable_read_transaction.h" | |
| 66 #include "sync/syncable/syncable_util.h" | |
| 67 #include "sync/syncable/syncable_write_transaction.h" | |
| 68 #include "sync/test/callback_counter.h" | |
| 69 #include "sync/test/engine/fake_model_worker.h" | |
| 70 #include "sync/test/engine/fake_sync_scheduler.h" | |
| 71 #include "sync/test/engine/test_id_factory.h" | |
| 72 #include "sync/test/fake_encryptor.h" | |
| 73 #include "sync/util/cryptographer.h" | |
| 74 #include "sync/util/extensions_activity.h" | |
| 75 #include "sync/util/mock_unrecoverable_error_handler.h" | |
| 76 #include "sync/util/time.h" | |
| 77 #include "testing/gmock/include/gmock/gmock.h" | 77 #include "testing/gmock/include/gmock/gmock.h" |
| 78 #include "testing/gtest/include/gtest/gtest.h" | 78 #include "testing/gtest/include/gtest/gtest.h" |
| 79 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" | 79 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" |
| 80 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" | 80 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" |
| 81 #include "url/gurl.h" | 81 #include "url/gurl.h" |
| 82 | 82 |
| 83 using base::ExpectDictStringValue; | 83 using base::ExpectDictStringValue; |
| 84 using testing::_; | 84 using testing::_; |
| 85 using testing::DoAll; | 85 using testing::DoAll; |
| 86 using testing::InSequence; | 86 using testing::InSequence; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 EXPECT_TRUE(node.InitBookmarkByCreation(parent_node, predecessor)); | 155 EXPECT_TRUE(node.InitBookmarkByCreation(parent_node, predecessor)); |
| 156 return node.GetId(); | 156 return node.GetId(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Creates the "synced" root node for a particular datatype. We use the syncable | 159 // Creates the "synced" root node for a particular datatype. We use the syncable |
| 160 // methods here so that the syncer treats these nodes as if they were already | 160 // methods here so that the syncer treats these nodes as if they were already |
| 161 // received from the server. | 161 // received from the server. |
| 162 int64_t MakeTypeRoot(UserShare* share, ModelType model_type) { | 162 int64_t MakeTypeRoot(UserShare* share, ModelType model_type) { |
| 163 sync_pb::EntitySpecifics specifics; | 163 sync_pb::EntitySpecifics specifics; |
| 164 AddDefaultFieldValue(model_type, &specifics); | 164 AddDefaultFieldValue(model_type, &specifics); |
| 165 syncable::WriteTransaction trans( | 165 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, |
| 166 FROM_HERE, syncable::UNITTEST, share->directory.get()); | 166 share->directory.get()); |
| 167 // Attempt to lookup by nigori tag. | 167 // Attempt to lookup by nigori tag. |
| 168 std::string type_tag = ModelTypeToRootTag(model_type); | 168 std::string type_tag = ModelTypeToRootTag(model_type); |
| 169 syncable::Id node_id = syncable::Id::CreateFromServerId(type_tag); | 169 syncable::Id node_id = syncable::Id::CreateFromServerId(type_tag); |
| 170 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 170 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 171 node_id); | 171 node_id); |
| 172 EXPECT_TRUE(entry.good()); | 172 EXPECT_TRUE(entry.good()); |
| 173 entry.PutBaseVersion(1); | 173 entry.PutBaseVersion(1); |
| 174 entry.PutServerVersion(1); | 174 entry.PutServerVersion(1); |
| 175 entry.PutIsUnappliedUpdate(false); | 175 entry.PutIsUnappliedUpdate(false); |
| 176 entry.PutParentId(syncable::Id::GetRoot()); | 176 entry.PutParentId(syncable::Id::GetRoot()); |
| 177 entry.PutServerParentId(syncable::Id::GetRoot()); | 177 entry.PutServerParentId(syncable::Id::GetRoot()); |
| 178 entry.PutServerIsDir(true); | 178 entry.PutServerIsDir(true); |
| 179 entry.PutIsDir(true); | 179 entry.PutIsDir(true); |
| 180 entry.PutServerSpecifics(specifics); | 180 entry.PutServerSpecifics(specifics); |
| 181 entry.PutSpecifics(specifics); | 181 entry.PutSpecifics(specifics); |
| 182 entry.PutUniqueServerTag(type_tag); | 182 entry.PutUniqueServerTag(type_tag); |
| 183 entry.PutNonUniqueName(type_tag); | 183 entry.PutNonUniqueName(type_tag); |
| 184 entry.PutIsDel(false); | 184 entry.PutIsDel(false); |
| 185 return entry.GetMetahandle(); | 185 return entry.GetMetahandle(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 // Simulates creating a "synced" node as a child of the root datatype node. | 188 // Simulates creating a "synced" node as a child of the root datatype node. |
| 189 int64_t MakeServerNode(UserShare* share, | 189 int64_t MakeServerNode(UserShare* share, |
| 190 ModelType model_type, | 190 ModelType model_type, |
| 191 const std::string& client_tag, | 191 const std::string& client_tag, |
| 192 const std::string& hashed_tag, | 192 const std::string& hashed_tag, |
| 193 const sync_pb::EntitySpecifics& specifics) { | 193 const sync_pb::EntitySpecifics& specifics) { |
| 194 syncable::WriteTransaction trans( | 194 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, |
| 195 FROM_HERE, syncable::UNITTEST, share->directory.get()); | 195 share->directory.get()); |
| 196 syncable::Entry root_entry(&trans, syncable::GET_TYPE_ROOT, model_type); | 196 syncable::Entry root_entry(&trans, syncable::GET_TYPE_ROOT, model_type); |
| 197 EXPECT_TRUE(root_entry.good()); | 197 EXPECT_TRUE(root_entry.good()); |
| 198 syncable::Id root_id = root_entry.GetId(); | 198 syncable::Id root_id = root_entry.GetId(); |
| 199 syncable::Id node_id = syncable::Id::CreateFromServerId(client_tag); | 199 syncable::Id node_id = syncable::Id::CreateFromServerId(client_tag); |
| 200 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 200 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 201 node_id); | 201 node_id); |
| 202 EXPECT_TRUE(entry.good()); | 202 EXPECT_TRUE(entry.good()); |
| 203 entry.PutBaseVersion(1); | 203 entry.PutBaseVersion(1); |
| 204 entry.PutServerVersion(1); | 204 entry.PutServerVersion(1); |
| 205 entry.PutIsUnappliedUpdate(false); | 205 entry.PutIsUnappliedUpdate(false); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 383 |
| 384 ignore_result(MakeNodeWithRoot(user_share(), BOOKMARKS, "collideme")); | 384 ignore_result(MakeNodeWithRoot(user_share(), BOOKMARKS, "collideme")); |
| 385 ignore_result(MakeNodeWithRoot(user_share(), PREFERENCES, "collideme")); | 385 ignore_result(MakeNodeWithRoot(user_share(), PREFERENCES, "collideme")); |
| 386 ignore_result(MakeNodeWithRoot(user_share(), AUTOFILL, "collideme")); | 386 ignore_result(MakeNodeWithRoot(user_share(), AUTOFILL, "collideme")); |
| 387 | 387 |
| 388 { | 388 { |
| 389 ReadTransaction trans(FROM_HERE, user_share()); | 389 ReadTransaction trans(FROM_HERE, user_share()); |
| 390 | 390 |
| 391 ReadNode bookmarknode(&trans); | 391 ReadNode bookmarknode(&trans); |
| 392 EXPECT_EQ(BaseNode::INIT_OK, | 392 EXPECT_EQ(BaseNode::INIT_OK, |
| 393 bookmarknode.InitByClientTagLookup(BOOKMARKS, | 393 bookmarknode.InitByClientTagLookup(BOOKMARKS, "collideme")); |
| 394 "collideme")); | |
| 395 | 394 |
| 396 ReadNode prefnode(&trans); | 395 ReadNode prefnode(&trans); |
| 397 EXPECT_EQ(BaseNode::INIT_OK, | 396 EXPECT_EQ(BaseNode::INIT_OK, |
| 398 prefnode.InitByClientTagLookup(PREFERENCES, | 397 prefnode.InitByClientTagLookup(PREFERENCES, "collideme")); |
| 399 "collideme")); | |
| 400 | 398 |
| 401 ReadNode autofillnode(&trans); | 399 ReadNode autofillnode(&trans); |
| 402 EXPECT_EQ(BaseNode::INIT_OK, | 400 EXPECT_EQ(BaseNode::INIT_OK, |
| 403 autofillnode.InitByClientTagLookup(AUTOFILL, | 401 autofillnode.InitByClientTagLookup(AUTOFILL, "collideme")); |
| 404 "collideme")); | |
| 405 | 402 |
| 406 EXPECT_NE(bookmarknode.GetId(), prefnode.GetId()); | 403 EXPECT_NE(bookmarknode.GetId(), prefnode.GetId()); |
| 407 EXPECT_NE(autofillnode.GetId(), prefnode.GetId()); | 404 EXPECT_NE(autofillnode.GetId(), prefnode.GetId()); |
| 408 EXPECT_NE(bookmarknode.GetId(), autofillnode.GetId()); | 405 EXPECT_NE(bookmarknode.GetId(), autofillnode.GetId()); |
| 409 } | 406 } |
| 410 } | 407 } |
| 411 | 408 |
| 412 TEST_F(SyncApiTest, ReadMissingTagsFails) { | 409 TEST_F(SyncApiTest, ReadMissingTagsFails) { |
| 413 { | 410 { |
| 414 ReadTransaction trans(FROM_HERE, user_share()); | 411 ReadTransaction trans(FROM_HERE, user_share()); |
| 415 ReadNode node(&trans); | 412 ReadNode node(&trans); |
| 416 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, | 413 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, |
| 417 node.InitByClientTagLookup(BOOKMARKS, | 414 node.InitByClientTagLookup(BOOKMARKS, "testtag")); |
| 418 "testtag")); | |
| 419 } | 415 } |
| 420 { | 416 { |
| 421 WriteTransaction trans(FROM_HERE, user_share()); | 417 WriteTransaction trans(FROM_HERE, user_share()); |
| 422 WriteNode node(&trans); | 418 WriteNode node(&trans); |
| 423 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, | 419 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, |
| 424 node.InitByClientTagLookup(BOOKMARKS, | 420 node.InitByClientTagLookup(BOOKMARKS, "testtag")); |
| 425 "testtag")); | |
| 426 } | 421 } |
| 427 } | 422 } |
| 428 | 423 |
| 429 // TODO(chron): Hook this all up to the server and write full integration tests | 424 // TODO(chron): Hook this all up to the server and write full integration tests |
| 430 // for update->undelete behavior. | 425 // for update->undelete behavior. |
| 431 TEST_F(SyncApiTest, TestDeleteBehavior) { | 426 TEST_F(SyncApiTest, TestDeleteBehavior) { |
| 432 int64_t node_id; | 427 int64_t node_id; |
| 433 int64_t folder_id; | 428 int64_t folder_id; |
| 434 std::string test_title("test1"); | 429 std::string test_title("test1"); |
| 435 | 430 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 451 wnode.SetTitle(test_title); | 446 wnode.SetTitle(test_title); |
| 452 | 447 |
| 453 node_id = wnode.GetId(); | 448 node_id = wnode.GetId(); |
| 454 } | 449 } |
| 455 | 450 |
| 456 // Ensure we can delete something with a tag. | 451 // Ensure we can delete something with a tag. |
| 457 { | 452 { |
| 458 WriteTransaction trans(FROM_HERE, user_share()); | 453 WriteTransaction trans(FROM_HERE, user_share()); |
| 459 WriteNode wnode(&trans); | 454 WriteNode wnode(&trans); |
| 460 EXPECT_EQ(BaseNode::INIT_OK, | 455 EXPECT_EQ(BaseNode::INIT_OK, |
| 461 wnode.InitByClientTagLookup(BOOKMARKS, | 456 wnode.InitByClientTagLookup(BOOKMARKS, "testtag")); |
| 462 "testtag")); | |
| 463 EXPECT_FALSE(wnode.GetIsFolder()); | 457 EXPECT_FALSE(wnode.GetIsFolder()); |
| 464 EXPECT_EQ(wnode.GetTitle(), test_title); | 458 EXPECT_EQ(wnode.GetTitle(), test_title); |
| 465 | 459 |
| 466 wnode.Tombstone(); | 460 wnode.Tombstone(); |
| 467 } | 461 } |
| 468 | 462 |
| 469 // Lookup of a node which was deleted should return failure, | 463 // Lookup of a node which was deleted should return failure, |
| 470 // but have found some data about the node. | 464 // but have found some data about the node. |
| 471 { | 465 { |
| 472 ReadTransaction trans(FROM_HERE, user_share()); | 466 ReadTransaction trans(FROM_HERE, user_share()); |
| 473 ReadNode node(&trans); | 467 ReadNode node(&trans); |
| 474 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, | 468 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, |
| 475 node.InitByClientTagLookup(BOOKMARKS, | 469 node.InitByClientTagLookup(BOOKMARKS, "testtag")); |
| 476 "testtag")); | |
| 477 // Note that for proper function of this API this doesn't need to be | 470 // Note that for proper function of this API this doesn't need to be |
| 478 // filled, we're checking just to make sure the DB worked in this test. | 471 // filled, we're checking just to make sure the DB worked in this test. |
| 479 EXPECT_EQ(node.GetTitle(), test_title); | 472 EXPECT_EQ(node.GetTitle(), test_title); |
| 480 } | 473 } |
| 481 | 474 |
| 482 { | 475 { |
| 483 WriteTransaction trans(FROM_HERE, user_share()); | 476 WriteTransaction trans(FROM_HERE, user_share()); |
| 484 ReadNode folder_node(&trans); | 477 ReadNode folder_node(&trans); |
| 485 EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id)); | 478 EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id)); |
| 486 | 479 |
| 487 WriteNode wnode(&trans); | 480 WriteNode wnode(&trans); |
| 488 // This will undelete the tag. | 481 // This will undelete the tag. |
| 489 WriteNode::InitUniqueByCreationResult result = | 482 WriteNode::InitUniqueByCreationResult result = |
| 490 wnode.InitUniqueByCreation(BOOKMARKS, folder_node, "testtag"); | 483 wnode.InitUniqueByCreation(BOOKMARKS, folder_node, "testtag"); |
| 491 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 484 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 492 EXPECT_EQ(wnode.GetIsFolder(), false); | 485 EXPECT_EQ(wnode.GetIsFolder(), false); |
| 493 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); | 486 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); |
| 494 EXPECT_EQ(wnode.GetId(), node_id); | 487 EXPECT_EQ(wnode.GetId(), node_id); |
| 495 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared | 488 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared |
| 496 wnode.SetTitle(test_title); | 489 wnode.SetTitle(test_title); |
| 497 } | 490 } |
| 498 | 491 |
| 499 // Now look up should work. | 492 // Now look up should work. |
| 500 { | 493 { |
| 501 ReadTransaction trans(FROM_HERE, user_share()); | 494 ReadTransaction trans(FROM_HERE, user_share()); |
| 502 ReadNode node(&trans); | 495 ReadNode node(&trans); |
| 503 EXPECT_EQ(BaseNode::INIT_OK, | 496 EXPECT_EQ(BaseNode::INIT_OK, |
| 504 node.InitByClientTagLookup(BOOKMARKS, | 497 node.InitByClientTagLookup(BOOKMARKS, "testtag")); |
| 505 "testtag")); | |
| 506 EXPECT_EQ(node.GetTitle(), test_title); | 498 EXPECT_EQ(node.GetTitle(), test_title); |
| 507 EXPECT_EQ(node.GetModelType(), BOOKMARKS); | 499 EXPECT_EQ(node.GetModelType(), BOOKMARKS); |
| 508 } | 500 } |
| 509 } | 501 } |
| 510 | 502 |
| 511 TEST_F(SyncApiTest, WriteAndReadPassword) { | 503 TEST_F(SyncApiTest, WriteAndReadPassword) { |
| 512 KeyParams params = {"localhost", "username", "passphrase"}; | 504 KeyParams params = {"localhost", "username", "passphrase"}; |
| 513 { | 505 { |
| 514 ReadTransaction trans(FROM_HERE, user_share()); | 506 ReadTransaction trans(FROM_HERE, user_share()); |
| 515 trans.GetCryptographer()->AddKey(params); | 507 trans.GetCryptographer()->AddKey(params); |
| 516 } | 508 } |
| 517 { | 509 { |
| 518 WriteTransaction trans(FROM_HERE, user_share()); | 510 WriteTransaction trans(FROM_HERE, user_share()); |
| 519 ReadNode root_node(&trans); | 511 ReadNode root_node(&trans); |
| 520 root_node.InitByRootLookup(); | 512 root_node.InitByRootLookup(); |
| 521 | 513 |
| 522 WriteNode password_node(&trans); | 514 WriteNode password_node(&trans); |
| 523 WriteNode::InitUniqueByCreationResult result = | 515 WriteNode::InitUniqueByCreationResult result = |
| 524 password_node.InitUniqueByCreation(PASSWORDS, | 516 password_node.InitUniqueByCreation(PASSWORDS, root_node, "foo"); |
| 525 root_node, "foo"); | |
| 526 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 517 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 527 sync_pb::PasswordSpecificsData data; | 518 sync_pb::PasswordSpecificsData data; |
| 528 data.set_password_value("secret"); | 519 data.set_password_value("secret"); |
| 529 password_node.SetPasswordSpecifics(data); | 520 password_node.SetPasswordSpecifics(data); |
| 530 } | 521 } |
| 531 { | 522 { |
| 532 ReadTransaction trans(FROM_HERE, user_share()); | 523 ReadTransaction trans(FROM_HERE, user_share()); |
| 533 | 524 |
| 534 ReadNode password_node(&trans); | 525 ReadNode password_node(&trans); |
| 535 EXPECT_EQ(BaseNode::INIT_OK, | 526 EXPECT_EQ(BaseNode::INIT_OK, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 563 pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar"); | 554 pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar"); |
| 564 ASSERT_EQ(WriteNode::INIT_SUCCESS, result); | 555 ASSERT_EQ(WriteNode::INIT_SUCCESS, result); |
| 565 pref_node.SetTitle("bar"); | 556 pref_node.SetTitle("bar"); |
| 566 } | 557 } |
| 567 { | 558 { |
| 568 ReadTransaction trans(FROM_HERE, user_share()); | 559 ReadTransaction trans(FROM_HERE, user_share()); |
| 569 | 560 |
| 570 ReadNode bookmark_node(&trans); | 561 ReadNode bookmark_node(&trans); |
| 571 ASSERT_EQ(BaseNode::INIT_OK, bookmark_node.InitByIdLookup(bookmark_id)); | 562 ASSERT_EQ(BaseNode::INIT_OK, bookmark_node.InitByIdLookup(bookmark_id)); |
| 572 EXPECT_EQ("foo", bookmark_node.GetTitle()); | 563 EXPECT_EQ("foo", bookmark_node.GetTitle()); |
| 573 EXPECT_EQ(kEncryptedString, | 564 EXPECT_EQ(kEncryptedString, bookmark_node.GetEntry()->GetNonUniqueName()); |
| 574 bookmark_node.GetEntry()->GetNonUniqueName()); | |
| 575 | 565 |
| 576 ReadNode pref_node(&trans); | 566 ReadNode pref_node(&trans); |
| 577 ASSERT_EQ(BaseNode::INIT_OK, | 567 ASSERT_EQ(BaseNode::INIT_OK, |
| 578 pref_node.InitByClientTagLookup(PREFERENCES, | 568 pref_node.InitByClientTagLookup(PREFERENCES, "bar")); |
| 579 "bar")); | |
| 580 EXPECT_EQ(kEncryptedString, pref_node.GetTitle()); | 569 EXPECT_EQ(kEncryptedString, pref_node.GetTitle()); |
| 581 } | 570 } |
| 582 } | 571 } |
| 583 | 572 |
| 584 // Non-unique name should not be empty. For bookmarks non-unique name is copied | 573 // Non-unique name should not be empty. For bookmarks non-unique name is copied |
| 585 // from bookmark title. This test verifies that setting bookmark title to "" | 574 // from bookmark title. This test verifies that setting bookmark title to "" |
| 586 // results in single space title and non-unique name in internal representation. | 575 // results in single space title and non-unique name in internal representation. |
| 587 // GetTitle should still return empty string. | 576 // GetTitle should still return empty string. |
| 588 TEST_F(SyncApiTest, WriteEmptyBookmarkTitle) { | 577 TEST_F(SyncApiTest, WriteEmptyBookmarkTitle) { |
| 589 int bookmark_id; | 578 int bookmark_id; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 WriteTransaction trans(FROM_HERE, user_share()); | 618 WriteTransaction trans(FROM_HERE, user_share()); |
| 630 WriteNode node(&trans); | 619 WriteNode node(&trans); |
| 631 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); | 620 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); |
| 632 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); | 621 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); |
| 633 | 622 |
| 634 sync_pb::EntitySpecifics entity_specifics; | 623 sync_pb::EntitySpecifics entity_specifics; |
| 635 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); | 624 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); |
| 636 std::string unknown_fields; | 625 std::string unknown_fields; |
| 637 { | 626 { |
| 638 ::google::protobuf::io::StringOutputStream unknown_fields_stream( | 627 ::google::protobuf::io::StringOutputStream unknown_fields_stream( |
| 639 &unknown_fields); | 628 &unknown_fields); |
| 640 ::google::protobuf::io::CodedOutputStream output(&unknown_fields_stream); | 629 ::google::protobuf::io::CodedOutputStream output(&unknown_fields_stream); |
| 641 const int tag = 5; | 630 const int tag = 5; |
| 642 const int value = 100; | 631 const int value = 100; |
| 643 output.WriteTag(tag); | 632 output.WriteTag(tag); |
| 644 output.WriteLittleEndian32(value); | 633 output.WriteLittleEndian32(value); |
| 645 } | 634 } |
| 646 *entity_specifics.mutable_unknown_fields() = unknown_fields; | 635 *entity_specifics.mutable_unknown_fields() = unknown_fields; |
| 647 node.SetEntitySpecifics(entity_specifics); | 636 node.SetEntitySpecifics(entity_specifics); |
| 648 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); | 637 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); |
| 649 EXPECT_EQ(unknown_fields, node.GetEntitySpecifics().unknown_fields()); | 638 EXPECT_EQ(unknown_fields, node.GetEntitySpecifics().unknown_fields()); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 }; | 893 }; |
| 905 | 894 |
| 906 class SyncManagerObserverMock : public SyncManager::Observer { | 895 class SyncManagerObserverMock : public SyncManager::Observer { |
| 907 public: | 896 public: |
| 908 MOCK_METHOD1(OnSyncCycleCompleted, | 897 MOCK_METHOD1(OnSyncCycleCompleted, |
| 909 void(const SyncSessionSnapshot&)); // NOLINT | 898 void(const SyncSessionSnapshot&)); // NOLINT |
| 910 MOCK_METHOD4(OnInitializationComplete, | 899 MOCK_METHOD4(OnInitializationComplete, |
| 911 void(const WeakHandle<JsBackend>&, | 900 void(const WeakHandle<JsBackend>&, |
| 912 const WeakHandle<DataTypeDebugInfoListener>&, | 901 const WeakHandle<DataTypeDebugInfoListener>&, |
| 913 bool, | 902 bool, |
| 914 syncer::ModelTypeSet)); // NOLINT | 903 syncer::ModelTypeSet)); // NOLINT |
| 915 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT | 904 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT |
| 916 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT | 905 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT |
| 917 MOCK_METHOD1(OnActionableError, void(const SyncProtocolError&)); // NOLINT | 906 MOCK_METHOD1(OnActionableError, void(const SyncProtocolError&)); // NOLINT |
| 918 MOCK_METHOD1(OnMigrationRequested, void(syncer::ModelTypeSet)); // NOLINT | 907 MOCK_METHOD1(OnMigrationRequested, void(syncer::ModelTypeSet)); // NOLINT |
| 919 MOCK_METHOD1(OnProtocolEvent, void(const ProtocolEvent&)); // NOLINT | 908 MOCK_METHOD1(OnProtocolEvent, void(const ProtocolEvent&)); // NOLINT |
| 920 }; | 909 }; |
| 921 | 910 |
| 922 class SyncEncryptionHandlerObserverMock | 911 class SyncEncryptionHandlerObserverMock |
| 923 : public SyncEncryptionHandler::Observer { | 912 : public SyncEncryptionHandler::Observer { |
| 924 public: | 913 public: |
| 925 MOCK_METHOD2(OnPassphraseRequired, | 914 MOCK_METHOD2(OnPassphraseRequired, |
| 926 void(PassphraseRequiredReason, | 915 void(PassphraseRequiredReason, |
| 927 const sync_pb::EncryptedData&)); // NOLINT | 916 const sync_pb::EncryptedData&)); // NOLINT |
| 928 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT | 917 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT |
| 929 MOCK_METHOD2(OnBootstrapTokenUpdated, | 918 MOCK_METHOD2(OnBootstrapTokenUpdated, |
| 930 void(const std::string&, BootstrapTokenType type)); // NOLINT | 919 void(const std::string&, BootstrapTokenType type)); // NOLINT |
| 931 MOCK_METHOD2(OnEncryptedTypesChanged, | 920 MOCK_METHOD2(OnEncryptedTypesChanged, void(ModelTypeSet, bool)); // NOLINT |
| 932 void(ModelTypeSet, bool)); // NOLINT | 921 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT |
| 933 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT | |
| 934 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT | 922 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT |
| 935 MOCK_METHOD2(OnPassphraseTypeChanged, void(PassphraseType, | 923 MOCK_METHOD2(OnPassphraseTypeChanged, |
| 936 base::Time)); // NOLINT | 924 void(PassphraseType, |
| 925 base::Time)); // NOLINT |
| 937 MOCK_METHOD1(OnLocalSetPassphraseEncryption, | 926 MOCK_METHOD1(OnLocalSetPassphraseEncryption, |
| 938 void(const SyncEncryptionHandler::NigoriState&)); // NOLINT | 927 void(const SyncEncryptionHandler::NigoriState&)); // NOLINT |
| 939 }; | 928 }; |
| 940 | 929 |
| 941 } // namespace | 930 } // namespace |
| 942 | 931 |
| 943 class SyncManagerTest : public testing::Test, | 932 class SyncManagerTest : public testing::Test, |
| 944 public SyncManager::ChangeDelegate { | 933 public SyncManager::ChangeDelegate { |
| 945 protected: | 934 protected: |
| 946 enum NigoriStatus { | 935 enum NigoriStatus { DONT_WRITE_NIGORI, WRITE_TO_NIGORI }; |
| 947 DONT_WRITE_NIGORI, | |
| 948 WRITE_TO_NIGORI | |
| 949 }; | |
| 950 | 936 |
| 951 enum EncryptionStatus { | 937 enum EncryptionStatus { UNINITIALIZED, DEFAULT_ENCRYPTION, FULL_ENCRYPTION }; |
| 952 UNINITIALIZED, | |
| 953 DEFAULT_ENCRYPTION, | |
| 954 FULL_ENCRYPTION | |
| 955 }; | |
| 956 | 938 |
| 957 SyncManagerTest() | 939 SyncManagerTest() : sync_manager_("Test sync manager") { |
| 958 : sync_manager_("Test sync manager") { | |
| 959 switches_.encryption_method = | 940 switches_.encryption_method = |
| 960 InternalComponentsFactory::ENCRYPTION_KEYSTORE; | 941 InternalComponentsFactory::ENCRYPTION_KEYSTORE; |
| 961 } | 942 } |
| 962 | 943 |
| 963 virtual ~SyncManagerTest() { | 944 virtual ~SyncManagerTest() {} |
| 964 } | |
| 965 | 945 |
| 966 // Test implementation. | 946 // Test implementation. |
| 967 void SetUp() { | 947 void SetUp() { |
| 968 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 948 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 969 | 949 |
| 970 extensions_activity_ = new ExtensionsActivity(); | 950 extensions_activity_ = new ExtensionsActivity(); |
| 971 | 951 |
| 972 SyncCredentials credentials; | 952 SyncCredentials credentials; |
| 973 credentials.account_id = "foo@bar.com"; | 953 credentials.account_id = "foo@bar.com"; |
| 974 credentials.email = "foo@bar.com"; | 954 credentials.email = "foo@bar.com"; |
| 975 credentials.sync_token = "sometoken"; | 955 credentials.sync_token = "sometoken"; |
| 976 OAuth2TokenService::ScopeSet scope_set; | 956 OAuth2TokenService::ScopeSet scope_set; |
| 977 scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope); | 957 scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope); |
| 978 credentials.scope_set = scope_set; | 958 credentials.scope_set = scope_set; |
| 979 | 959 |
| 980 sync_manager_.AddObserver(&manager_observer_); | 960 sync_manager_.AddObserver(&manager_observer_); |
| 981 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _, _)). | 961 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _, _)) |
| 982 WillOnce(DoAll(SaveArg<0>(&js_backend_), | 962 .WillOnce(DoAll(SaveArg<0>(&js_backend_), |
| 983 SaveArg<2>(&initialization_succeeded_))); | 963 SaveArg<2>(&initialization_succeeded_))); |
| 984 | 964 |
| 985 EXPECT_FALSE(js_backend_.IsInitialized()); | 965 EXPECT_FALSE(js_backend_.IsInitialized()); |
| 986 | 966 |
| 987 std::vector<scoped_refptr<ModelSafeWorker> > workers; | 967 std::vector<scoped_refptr<ModelSafeWorker>> workers; |
| 988 ModelSafeRoutingInfo routing_info; | 968 ModelSafeRoutingInfo routing_info; |
| 989 GetModelSafeRoutingInfo(&routing_info); | 969 GetModelSafeRoutingInfo(&routing_info); |
| 990 | 970 |
| 991 // This works only because all routing info types are GROUP_PASSIVE. | 971 // This works only because all routing info types are GROUP_PASSIVE. |
| 992 // If we had types in other groups, we would need additional workers | 972 // If we had types in other groups, we would need additional workers |
| 993 // to support them. | 973 // to support them. |
| 994 scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(GROUP_PASSIVE); | 974 scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(GROUP_PASSIVE); |
| 995 workers.push_back(worker); | 975 workers.push_back(worker); |
| 996 | 976 |
| 997 SyncManager::InitArgs args; | 977 SyncManager::InitArgs args; |
| 998 args.database_location = temp_dir_.path(); | 978 args.database_location = temp_dir_.path(); |
| 999 args.service_url = GURL("https://example.com/"); | 979 args.service_url = GURL("https://example.com/"); |
| 1000 args.post_factory = std::unique_ptr<HttpPostProviderFactory>( | 980 args.post_factory = std::unique_ptr<HttpPostProviderFactory>( |
| 1001 new TestHttpPostProviderFactory()); | 981 new TestHttpPostProviderFactory()); |
| 1002 args.workers = workers; | 982 args.workers = workers; |
| 1003 args.extensions_activity = extensions_activity_.get(), | 983 args.extensions_activity = extensions_activity_.get(), |
| 1004 args.change_delegate = this; | 984 args.change_delegate = this; |
| 1005 args.credentials = credentials; | 985 args.credentials = credentials; |
| 1006 args.invalidator_client_id = "fake_invalidator_client_id"; | 986 args.invalidator_client_id = "fake_invalidator_client_id"; |
| 1007 args.internal_components_factory.reset(GetFactory()); | 987 args.internal_components_factory.reset(GetFactory()); |
| 1008 args.encryptor = &encryptor_; | 988 args.encryptor = &encryptor_; |
| 1009 args.unrecoverable_error_handler = | 989 args.unrecoverable_error_handler = |
| 1010 MakeWeakHandle(mock_unrecoverable_error_handler_.GetWeakPtr()); | 990 MakeWeakHandle(mock_unrecoverable_error_handler_.GetWeakPtr()); |
| 1011 args.cancelation_signal = &cancelation_signal_; | 991 args.cancelation_signal = &cancelation_signal_; |
| 1012 sync_manager_.Init(&args); | 992 sync_manager_.Init(&args); |
| 1013 | 993 |
| 1014 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); | 994 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); |
| 1015 | 995 |
| 1016 EXPECT_TRUE(js_backend_.IsInitialized()); | 996 EXPECT_TRUE(js_backend_.IsInitialized()); |
| 1017 EXPECT_EQ(InternalComponentsFactory::STORAGE_ON_DISK, | 997 EXPECT_EQ(InternalComponentsFactory::STORAGE_ON_DISK, storage_used_); |
| 1018 storage_used_); | |
| 1019 | 998 |
| 1020 if (initialization_succeeded_) { | 999 if (initialization_succeeded_) { |
| 1021 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 1000 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 1022 i != routing_info.end(); ++i) { | 1001 i != routing_info.end(); ++i) { |
| 1023 type_roots_[i->first] = | 1002 type_roots_[i->first] = |
| 1024 MakeTypeRoot(sync_manager_.GetUserShare(), i->first); | 1003 MakeTypeRoot(sync_manager_.GetUserShare(), i->first); |
| 1025 } | 1004 } |
| 1026 } | 1005 } |
| 1027 | 1006 |
| 1028 PumpLoop(); | 1007 PumpLoop(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 if (encryption_status != UNINITIALIZED) { | 1060 if (encryption_status != UNINITIALIZED) { |
| 1082 KeyParams params = {"localhost", "dummy", "foobar"}; | 1061 KeyParams params = {"localhost", "dummy", "foobar"}; |
| 1083 cryptographer->AddKey(params); | 1062 cryptographer->AddKey(params); |
| 1084 } else { | 1063 } else { |
| 1085 DCHECK_NE(nigori_status, WRITE_TO_NIGORI); | 1064 DCHECK_NE(nigori_status, WRITE_TO_NIGORI); |
| 1086 } | 1065 } |
| 1087 if (nigori_status == WRITE_TO_NIGORI) { | 1066 if (nigori_status == WRITE_TO_NIGORI) { |
| 1088 sync_pb::NigoriSpecifics nigori; | 1067 sync_pb::NigoriSpecifics nigori; |
| 1089 cryptographer->GetKeys(nigori.mutable_encryption_keybag()); | 1068 cryptographer->GetKeys(nigori.mutable_encryption_keybag()); |
| 1090 share->directory->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes( | 1069 share->directory->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes( |
| 1091 &nigori, | 1070 &nigori, trans.GetWrappedTrans()); |
| 1092 trans.GetWrappedTrans()); | |
| 1093 WriteNode node(&trans); | 1071 WriteNode node(&trans); |
| 1094 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(nigori_id)); | 1072 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(nigori_id)); |
| 1095 node.SetNigoriSpecifics(nigori); | 1073 node.SetNigoriSpecifics(nigori); |
| 1096 } | 1074 } |
| 1097 return cryptographer->is_ready(); | 1075 return cryptographer->is_ready(); |
| 1098 } | 1076 } |
| 1099 | 1077 |
| 1100 int64_t GetIdForDataType(ModelType type) { | 1078 int64_t GetIdForDataType(ModelType type) { |
| 1101 if (type_roots_.count(type) == 0) | 1079 if (type_roots_.count(type) == 0) |
| 1102 return 0; | 1080 return 0; |
| 1103 return type_roots_[type]; | 1081 return type_roots_[type]; |
| 1104 } | 1082 } |
| 1105 | 1083 |
| 1106 void PumpLoop() { | 1084 void PumpLoop() { base::RunLoop().RunUntilIdle(); } |
| 1107 base::RunLoop().RunUntilIdle(); | |
| 1108 } | |
| 1109 | 1085 |
| 1110 void SetJsEventHandler(const WeakHandle<JsEventHandler>& event_handler) { | 1086 void SetJsEventHandler(const WeakHandle<JsEventHandler>& event_handler) { |
| 1111 js_backend_.Call(FROM_HERE, &JsBackend::SetJsEventHandler, | 1087 js_backend_.Call(FROM_HERE, &JsBackend::SetJsEventHandler, event_handler); |
| 1112 event_handler); | |
| 1113 PumpLoop(); | 1088 PumpLoop(); |
| 1114 } | 1089 } |
| 1115 | 1090 |
| 1116 // Looks up an entry by client tag and resets IS_UNSYNCED value to false. | 1091 // Looks up an entry by client tag and resets IS_UNSYNCED value to false. |
| 1117 // Returns true if entry was previously unsynced, false if IS_UNSYNCED was | 1092 // Returns true if entry was previously unsynced, false if IS_UNSYNCED was |
| 1118 // already false. | 1093 // already false. |
| 1119 bool ResetUnsyncedEntry(ModelType type, | 1094 bool ResetUnsyncedEntry(ModelType type, const std::string& client_tag) { |
| 1120 const std::string& client_tag) { | |
| 1121 UserShare* share = sync_manager_.GetUserShare(); | 1095 UserShare* share = sync_manager_.GetUserShare(); |
| 1122 syncable::WriteTransaction trans( | 1096 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, |
| 1123 FROM_HERE, syncable::UNITTEST, share->directory.get()); | 1097 share->directory.get()); |
| 1124 const std::string hash = syncable::GenerateSyncableHash(type, client_tag); | 1098 const std::string hash = syncable::GenerateSyncableHash(type, client_tag); |
| 1125 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, | 1099 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, hash); |
| 1126 hash); | |
| 1127 EXPECT_TRUE(entry.good()); | 1100 EXPECT_TRUE(entry.good()); |
| 1128 if (!entry.GetIsUnsynced()) | 1101 if (!entry.GetIsUnsynced()) |
| 1129 return false; | 1102 return false; |
| 1130 entry.PutIsUnsynced(false); | 1103 entry.PutIsUnsynced(false); |
| 1131 return true; | 1104 return true; |
| 1132 } | 1105 } |
| 1133 | 1106 |
| 1134 virtual InternalComponentsFactory* GetFactory() { | 1107 virtual InternalComponentsFactory* GetFactory() { |
| 1135 return new TestInternalComponentsFactory( | 1108 return new TestInternalComponentsFactory( |
| 1136 GetSwitches(), InternalComponentsFactory::STORAGE_IN_MEMORY, | 1109 GetSwitches(), InternalComponentsFactory::STORAGE_IN_MEMORY, |
| 1137 &storage_used_); | 1110 &storage_used_); |
| 1138 } | 1111 } |
| 1139 | 1112 |
| 1140 // Returns true if we are currently encrypting all sync data. May | 1113 // Returns true if we are currently encrypting all sync data. May |
| 1141 // be called on any thread. | 1114 // be called on any thread. |
| 1142 bool IsEncryptEverythingEnabledForTest() { | 1115 bool IsEncryptEverythingEnabledForTest() { |
| 1143 return sync_manager_.GetEncryptionHandler()->IsEncryptEverythingEnabled(); | 1116 return sync_manager_.GetEncryptionHandler()->IsEncryptEverythingEnabled(); |
| 1144 } | 1117 } |
| 1145 | 1118 |
| 1146 // Gets the set of encrypted types from the cryptographer | 1119 // Gets the set of encrypted types from the cryptographer |
| 1147 // Note: opens a transaction. May be called from any thread. | 1120 // Note: opens a transaction. May be called from any thread. |
| 1148 ModelTypeSet GetEncryptedTypes() { | 1121 ModelTypeSet GetEncryptedTypes() { |
| 1149 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1122 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1150 return GetEncryptedTypesWithTrans(&trans); | 1123 return GetEncryptedTypesWithTrans(&trans); |
| 1151 } | 1124 } |
| 1152 | 1125 |
| 1153 ModelTypeSet GetEncryptedTypesWithTrans(BaseTransaction* trans) { | 1126 ModelTypeSet GetEncryptedTypesWithTrans(BaseTransaction* trans) { |
| 1154 return trans->GetDirectory()->GetNigoriHandler()-> | 1127 return trans->GetDirectory()->GetNigoriHandler()->GetEncryptedTypes( |
| 1155 GetEncryptedTypes(trans->GetWrappedTrans()); | 1128 trans->GetWrappedTrans()); |
| 1156 } | 1129 } |
| 1157 | 1130 |
| 1158 void SimulateInvalidatorEnabledForTest(bool is_enabled) { | 1131 void SimulateInvalidatorEnabledForTest(bool is_enabled) { |
| 1159 DCHECK(sync_manager_.thread_checker_.CalledOnValidThread()); | 1132 DCHECK(sync_manager_.thread_checker_.CalledOnValidThread()); |
| 1160 sync_manager_.SetInvalidatorEnabled(is_enabled); | 1133 sync_manager_.SetInvalidatorEnabled(is_enabled); |
| 1161 } | 1134 } |
| 1162 | 1135 |
| 1163 void SetProgressMarkerForType(ModelType type, bool set) { | 1136 void SetProgressMarkerForType(ModelType type, bool set) { |
| 1164 if (set) { | 1137 if (set) { |
| 1165 sync_pb::DataTypeProgressMarker marker; | 1138 sync_pb::DataTypeProgressMarker marker; |
| 1166 marker.set_token("token"); | 1139 marker.set_token("token"); |
| 1167 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); | 1140 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); |
| 1168 sync_manager_.directory()->SetDownloadProgress(type, marker); | 1141 sync_manager_.directory()->SetDownloadProgress(type, marker); |
| 1169 } else { | 1142 } else { |
| 1170 sync_pb::DataTypeProgressMarker marker; | 1143 sync_pb::DataTypeProgressMarker marker; |
| 1171 sync_manager_.directory()->SetDownloadProgress(type, marker); | 1144 sync_manager_.directory()->SetDownloadProgress(type, marker); |
| 1172 } | 1145 } |
| 1173 } | 1146 } |
| 1174 | 1147 |
| 1175 InternalComponentsFactory::Switches GetSwitches() const { | 1148 InternalComponentsFactory::Switches GetSwitches() const { return switches_; } |
| 1176 return switches_; | |
| 1177 } | |
| 1178 | 1149 |
| 1179 void ExpectPassphraseAcceptance() { | 1150 void ExpectPassphraseAcceptance() { |
| 1180 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1151 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1181 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1152 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1182 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1153 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1183 } | 1154 } |
| 1184 | 1155 |
| 1185 void SetImplicitPassphraseAndCheck(const std::string& passphrase) { | 1156 void SetImplicitPassphraseAndCheck(const std::string& passphrase) { |
| 1186 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1157 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, |
| 1187 passphrase, | 1158 false); |
| 1188 false); | |
| 1189 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1159 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1190 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | 1160 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1191 } | 1161 } |
| 1192 | 1162 |
| 1193 void SetCustomPassphraseAndCheck(const std::string& passphrase) { | 1163 void SetCustomPassphraseAndCheck(const std::string& passphrase) { |
| 1194 EXPECT_CALL(encryption_observer_, | 1164 EXPECT_CALL(encryption_observer_, |
| 1195 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _)); | 1165 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _)); |
| 1196 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1166 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, |
| 1197 passphrase, | 1167 true); |
| 1198 true); | |
| 1199 EXPECT_EQ(CUSTOM_PASSPHRASE, | 1168 EXPECT_EQ(CUSTOM_PASSPHRASE, |
| 1200 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | 1169 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1201 } | 1170 } |
| 1202 | 1171 |
| 1203 bool HasUnrecoverableError() { | 1172 bool HasUnrecoverableError() { |
| 1204 return mock_unrecoverable_error_handler_.invocation_count() > 0; | 1173 return mock_unrecoverable_error_handler_.invocation_count() > 0; |
| 1205 } | 1174 } |
| 1206 | 1175 |
| 1207 private: | 1176 private: |
| 1208 // Needed by |sync_manager_|. | 1177 // Needed by |sync_manager_|. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 sync_manager_.GetEncryptionHandler()->Init(); | 1221 sync_manager_.GetEncryptionHandler()->Init(); |
| 1253 PumpLoop(); | 1222 PumpLoop(); |
| 1254 | 1223 |
| 1255 const ModelTypeSet encrypted_types = GetEncryptedTypes(); | 1224 const ModelTypeSet encrypted_types = GetEncryptedTypes(); |
| 1256 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); | 1225 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); |
| 1257 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); | 1226 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); |
| 1258 | 1227 |
| 1259 { | 1228 { |
| 1260 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1229 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1261 ReadNode node(&trans); | 1230 ReadNode node(&trans); |
| 1262 EXPECT_EQ(BaseNode::INIT_OK, | 1231 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(GetIdForDataType(NIGORI))); |
| 1263 node.InitByIdLookup(GetIdForDataType(NIGORI))); | |
| 1264 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); | 1232 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
| 1265 EXPECT_TRUE(nigori.has_encryption_keybag()); | 1233 EXPECT_TRUE(nigori.has_encryption_keybag()); |
| 1266 Cryptographer* cryptographer = trans.GetCryptographer(); | 1234 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1267 EXPECT_TRUE(cryptographer->is_ready()); | 1235 EXPECT_TRUE(cryptographer->is_ready()); |
| 1268 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag())); | 1236 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag())); |
| 1269 } | 1237 } |
| 1270 } | 1238 } |
| 1271 | 1239 |
| 1272 // Attempt to refresh encryption when nigori not downloaded. | 1240 // Attempt to refresh encryption when nigori not downloaded. |
| 1273 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { | 1241 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1297 sync_manager_.GetEncryptionHandler()->Init(); | 1265 sync_manager_.GetEncryptionHandler()->Init(); |
| 1298 PumpLoop(); | 1266 PumpLoop(); |
| 1299 | 1267 |
| 1300 const ModelTypeSet encrypted_types = GetEncryptedTypes(); | 1268 const ModelTypeSet encrypted_types = GetEncryptedTypes(); |
| 1301 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. | 1269 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. |
| 1302 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); | 1270 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); |
| 1303 | 1271 |
| 1304 { | 1272 { |
| 1305 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1273 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1306 ReadNode node(&trans); | 1274 ReadNode node(&trans); |
| 1307 EXPECT_EQ(BaseNode::INIT_OK, | 1275 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(GetIdForDataType(NIGORI))); |
| 1308 node.InitByIdLookup(GetIdForDataType(NIGORI))); | |
| 1309 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); | 1276 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
| 1310 EXPECT_TRUE(nigori.has_encryption_keybag()); | 1277 EXPECT_TRUE(nigori.has_encryption_keybag()); |
| 1311 Cryptographer* cryptographer = trans.GetCryptographer(); | 1278 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1312 EXPECT_TRUE(cryptographer->is_ready()); | 1279 EXPECT_TRUE(cryptographer->is_ready()); |
| 1313 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag())); | 1280 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag())); |
| 1314 } | 1281 } |
| 1315 } | 1282 } |
| 1316 | 1283 |
| 1317 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { | 1284 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { |
| 1318 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1285 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1319 EXPECT_CALL(encryption_observer_, | 1286 EXPECT_CALL( |
| 1320 OnEncryptedTypesChanged( | 1287 encryption_observer_, |
| 1321 HasModelTypes(EncryptableUserTypes()), true)); | 1288 OnEncryptedTypesChanged(HasModelTypes(EncryptableUserTypes()), true)); |
| 1322 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1289 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1323 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); | 1290 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| 1324 EXPECT_TRUE(IsEncryptEverythingEnabledForTest()); | 1291 EXPECT_TRUE(IsEncryptEverythingEnabledForTest()); |
| 1325 } | 1292 } |
| 1326 | 1293 |
| 1327 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { | 1294 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { |
| 1328 size_t batch_size = 5; | 1295 size_t batch_size = 5; |
| 1329 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1296 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1330 | 1297 |
| 1331 // Create some unencrypted unsynced data. | 1298 // Create some unencrypted unsynced data. |
| 1332 int64_t folder = MakeFolderWithParent(sync_manager_.GetUserShare(), BOOKMARKS, | 1299 int64_t folder = MakeFolderWithParent(sync_manager_.GetUserShare(), BOOKMARKS, |
| 1333 GetIdForDataType(BOOKMARKS), NULL); | 1300 GetIdForDataType(BOOKMARKS), NULL); |
| 1334 // First batch_size nodes are children of folder. | 1301 // First batch_size nodes are children of folder. |
| 1335 size_t i; | 1302 size_t i; |
| 1336 for (i = 0; i < batch_size; ++i) { | 1303 for (i = 0; i < batch_size; ++i) { |
| 1337 MakeBookmarkWithParent(sync_manager_.GetUserShare(), folder, NULL); | 1304 MakeBookmarkWithParent(sync_manager_.GetUserShare(), folder, NULL); |
| 1338 } | 1305 } |
| 1339 // Next batch_size nodes are a different type and on their own. | 1306 // Next batch_size nodes are a different type and on their own. |
| 1340 for (; i < 2*batch_size; ++i) { | 1307 for (; i < 2 * batch_size; ++i) { |
| 1341 MakeNodeWithRoot(sync_manager_.GetUserShare(), SESSIONS, | 1308 MakeNodeWithRoot(sync_manager_.GetUserShare(), SESSIONS, |
| 1342 base::StringPrintf("%" PRIuS "", i)); | 1309 base::StringPrintf("%" PRIuS "", i)); |
| 1343 } | 1310 } |
| 1344 // Last batch_size nodes are a third type that will not need encryption. | 1311 // Last batch_size nodes are a third type that will not need encryption. |
| 1345 for (; i < 3*batch_size; ++i) { | 1312 for (; i < 3 * batch_size; ++i) { |
| 1346 MakeNodeWithRoot(sync_manager_.GetUserShare(), THEMES, | 1313 MakeNodeWithRoot(sync_manager_.GetUserShare(), THEMES, |
| 1347 base::StringPrintf("%" PRIuS "", i)); | 1314 base::StringPrintf("%" PRIuS "", i)); |
| 1348 } | 1315 } |
| 1349 | 1316 |
| 1350 { | 1317 { |
| 1351 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1318 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1352 EXPECT_EQ(SyncEncryptionHandler::SensitiveTypes(), | 1319 EXPECT_EQ(SyncEncryptionHandler::SensitiveTypes(), |
| 1353 GetEncryptedTypesWithTrans(&trans)); | 1320 GetEncryptedTypesWithTrans(&trans)); |
| 1354 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1321 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1355 trans.GetWrappedTrans(), | 1322 trans.GetWrappedTrans(), BOOKMARKS, false /* not encrypted */)); |
| 1356 BOOKMARKS, | |
| 1357 false /* not encrypted */)); | |
| 1358 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1323 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1359 trans.GetWrappedTrans(), | 1324 trans.GetWrappedTrans(), SESSIONS, false /* not encrypted */)); |
| 1360 SESSIONS, | |
| 1361 false /* not encrypted */)); | |
| 1362 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1325 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1363 trans.GetWrappedTrans(), | 1326 trans.GetWrappedTrans(), THEMES, false /* not encrypted */)); |
| 1364 THEMES, | |
| 1365 false /* not encrypted */)); | |
| 1366 } | 1327 } |
| 1367 | 1328 |
| 1368 EXPECT_CALL(encryption_observer_, | 1329 EXPECT_CALL( |
| 1369 OnEncryptedTypesChanged( | 1330 encryption_observer_, |
| 1370 HasModelTypes(EncryptableUserTypes()), true)); | 1331 OnEncryptedTypesChanged(HasModelTypes(EncryptableUserTypes()), true)); |
| 1371 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1332 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1372 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); | 1333 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| 1373 EXPECT_TRUE(IsEncryptEverythingEnabledForTest()); | 1334 EXPECT_TRUE(IsEncryptEverythingEnabledForTest()); |
| 1374 { | 1335 { |
| 1375 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1336 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1376 EXPECT_EQ(EncryptableUserTypes(), GetEncryptedTypesWithTrans(&trans)); | 1337 EXPECT_EQ(EncryptableUserTypes(), GetEncryptedTypesWithTrans(&trans)); |
| 1377 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1338 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1378 trans.GetWrappedTrans(), | 1339 trans.GetWrappedTrans(), BOOKMARKS, true /* is encrypted */)); |
| 1379 BOOKMARKS, | |
| 1380 true /* is encrypted */)); | |
| 1381 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1340 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1382 trans.GetWrappedTrans(), | 1341 trans.GetWrappedTrans(), SESSIONS, true /* is encrypted */)); |
| 1383 SESSIONS, | |
| 1384 true /* is encrypted */)); | |
| 1385 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1342 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1386 trans.GetWrappedTrans(), | 1343 trans.GetWrappedTrans(), THEMES, true /* is encrypted */)); |
| 1387 THEMES, | |
| 1388 true /* is encrypted */)); | |
| 1389 } | 1344 } |
| 1390 | 1345 |
| 1391 // Trigger's a ReEncryptEverything with new passphrase. | 1346 // Trigger's a ReEncryptEverything with new passphrase. |
| 1392 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 1347 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1393 EXPECT_CALL(encryption_observer_, | 1348 EXPECT_CALL(encryption_observer_, |
| 1394 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1349 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1395 ExpectPassphraseAcceptance(); | 1350 ExpectPassphraseAcceptance(); |
| 1396 SetCustomPassphraseAndCheck("new_passphrase"); | 1351 SetCustomPassphraseAndCheck("new_passphrase"); |
| 1397 EXPECT_TRUE(IsEncryptEverythingEnabledForTest()); | 1352 EXPECT_TRUE(IsEncryptEverythingEnabledForTest()); |
| 1398 { | 1353 { |
| 1399 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1354 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1400 EXPECT_EQ(EncryptableUserTypes(), GetEncryptedTypesWithTrans(&trans)); | 1355 EXPECT_EQ(EncryptableUserTypes(), GetEncryptedTypesWithTrans(&trans)); |
| 1401 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1356 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1402 trans.GetWrappedTrans(), | 1357 trans.GetWrappedTrans(), BOOKMARKS, true /* is encrypted */)); |
| 1403 BOOKMARKS, | |
| 1404 true /* is encrypted */)); | |
| 1405 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1358 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1406 trans.GetWrappedTrans(), | 1359 trans.GetWrappedTrans(), SESSIONS, true /* is encrypted */)); |
| 1407 SESSIONS, | |
| 1408 true /* is encrypted */)); | |
| 1409 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1360 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1410 trans.GetWrappedTrans(), | 1361 trans.GetWrappedTrans(), THEMES, true /* is encrypted */)); |
| 1411 THEMES, | |
| 1412 true /* is encrypted */)); | |
| 1413 } | 1362 } |
| 1414 // Calling EncryptDataTypes with an empty encrypted types should not trigger | 1363 // Calling EncryptDataTypes with an empty encrypted types should not trigger |
| 1415 // a reencryption and should just notify immediately. | 1364 // a reencryption and should just notify immediately. |
| 1416 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 1365 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1417 EXPECT_CALL(encryption_observer_, | 1366 EXPECT_CALL(encryption_observer_, |
| 1418 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)).Times(0); | 1367 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)) |
| 1368 .Times(0); |
| 1419 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()).Times(0); | 1369 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()).Times(0); |
| 1420 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()).Times(0); | 1370 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()).Times(0); |
| 1421 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); | 1371 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| 1422 } | 1372 } |
| 1423 | 1373 |
| 1424 // Test that when there are no pending keys and the cryptographer is not | 1374 // Test that when there are no pending keys and the cryptographer is not |
| 1425 // initialized, we add a key based on the current GAIA password. | 1375 // initialized, we add a key based on the current GAIA password. |
| 1426 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) | 1376 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) |
| 1427 TEST_F(SyncManagerTest, SetInitialGaiaPass) { | 1377 TEST_F(SyncManagerTest, SetInitialGaiaPass) { |
| 1428 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); | 1378 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 Cryptographer* cryptographer = trans.GetCryptographer(); | 1433 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1484 std::string bootstrap_token; | 1434 std::string bootstrap_token; |
| 1485 cryptographer->GetBootstrapToken(&bootstrap_token); | 1435 cryptographer->GetBootstrapToken(&bootstrap_token); |
| 1486 verifier.Bootstrap(bootstrap_token); | 1436 verifier.Bootstrap(bootstrap_token); |
| 1487 | 1437 |
| 1488 ReadNode root_node(&trans); | 1438 ReadNode root_node(&trans); |
| 1489 root_node.InitByRootLookup(); | 1439 root_node.InitByRootLookup(); |
| 1490 | 1440 |
| 1491 WriteNode password_node(&trans); | 1441 WriteNode password_node(&trans); |
| 1492 WriteNode::InitUniqueByCreationResult result = | 1442 WriteNode::InitUniqueByCreationResult result = |
| 1493 password_node.InitUniqueByCreation(PASSWORDS, | 1443 password_node.InitUniqueByCreation(PASSWORDS, root_node, "foo"); |
| 1494 root_node, "foo"); | |
| 1495 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 1444 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 1496 sync_pb::PasswordSpecificsData data; | 1445 sync_pb::PasswordSpecificsData data; |
| 1497 data.set_password_value("secret"); | 1446 data.set_password_value("secret"); |
| 1498 password_node.SetPasswordSpecifics(data); | 1447 password_node.SetPasswordSpecifics(data); |
| 1499 } | 1448 } |
| 1500 EXPECT_CALL(encryption_observer_, | 1449 EXPECT_CALL(encryption_observer_, |
| 1501 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1450 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1502 ExpectPassphraseAcceptance(); | 1451 ExpectPassphraseAcceptance(); |
| 1503 SetCustomPassphraseAndCheck("new_passphrase"); | 1452 SetCustomPassphraseAndCheck("new_passphrase"); |
| 1504 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); | 1453 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); |
| 1505 { | 1454 { |
| 1506 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1455 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1507 Cryptographer* cryptographer = trans.GetCryptographer(); | 1456 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1508 EXPECT_TRUE(cryptographer->is_ready()); | 1457 EXPECT_TRUE(cryptographer->is_ready()); |
| 1509 // Verify the default key has changed. | 1458 // Verify the default key has changed. |
| 1510 sync_pb::EncryptedData encrypted; | 1459 sync_pb::EncryptedData encrypted; |
| 1511 cryptographer->GetKeys(&encrypted); | 1460 cryptographer->GetKeys(&encrypted); |
| 1512 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); | 1461 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); |
| 1513 | 1462 |
| 1514 ReadNode password_node(&trans); | 1463 ReadNode password_node(&trans); |
| 1515 EXPECT_EQ(BaseNode::INIT_OK, | 1464 EXPECT_EQ(BaseNode::INIT_OK, |
| 1516 password_node.InitByClientTagLookup(PASSWORDS, | 1465 password_node.InitByClientTagLookup(PASSWORDS, "foo")); |
| 1517 "foo")); | |
| 1518 const sync_pb::PasswordSpecificsData& data = | 1466 const sync_pb::PasswordSpecificsData& data = |
| 1519 password_node.GetPasswordSpecifics(); | 1467 password_node.GetPasswordSpecifics(); |
| 1520 EXPECT_EQ("secret", data.password_value()); | 1468 EXPECT_EQ("secret", data.password_value()); |
| 1521 } | 1469 } |
| 1522 } | 1470 } |
| 1523 | 1471 |
| 1524 // Manually set the pending keys in the cryptographer/nigori to reflect the data | 1472 // Manually set the pending keys in the cryptographer/nigori to reflect the data |
| 1525 // being encrypted with a new (unprovided) GAIA password, then supply the | 1473 // being encrypted with a new (unprovided) GAIA password, then supply the |
| 1526 // password. | 1474 // password. |
| 1527 // (case 7 in SyncManager::SyncInternal::SetDecryptionPassphrase) | 1475 // (case 7 in SyncManager::SyncInternal::SetDecryptionPassphrase) |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1742 } | 1690 } |
| 1743 EXPECT_CALL(encryption_observer_, | 1691 EXPECT_CALL(encryption_observer_, |
| 1744 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1692 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1745 ExpectPassphraseAcceptance(); | 1693 ExpectPassphraseAcceptance(); |
| 1746 SetCustomPassphraseAndCheck("new_passphrase"); | 1694 SetCustomPassphraseAndCheck("new_passphrase"); |
| 1747 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); | 1695 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); |
| 1748 { | 1696 { |
| 1749 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1697 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1750 ReadNode password_node(&trans); | 1698 ReadNode password_node(&trans); |
| 1751 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, | 1699 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, |
| 1752 password_node.InitByClientTagLookup(PASSWORDS, | 1700 password_node.InitByClientTagLookup(PASSWORDS, tag)); |
| 1753 tag)); | |
| 1754 } | 1701 } |
| 1755 { | 1702 { |
| 1756 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1703 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1757 ReadNode password_node(&trans); | 1704 ReadNode password_node(&trans); |
| 1758 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, | 1705 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, |
| 1759 password_node.InitByIdLookup(node_id)); | 1706 password_node.InitByIdLookup(node_id)); |
| 1760 } | 1707 } |
| 1761 } | 1708 } |
| 1762 | 1709 |
| 1763 // Friended by WriteNode, so can't be in an anonymouse namespace. | 1710 // Friended by WriteNode, so can't be in an anonymouse namespace. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 // We should de-canonicalize the title in GetTitle(), but the title in the | 1763 // We should de-canonicalize the title in GetTitle(), but the title in the |
| 1817 // specifics should be stored in the server legal form. | 1764 // specifics should be stored in the server legal form. |
| 1818 EXPECT_EQ(raw_title2, node2.GetTitle()); | 1765 EXPECT_EQ(raw_title2, node2.GetTitle()); |
| 1819 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); | 1766 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); |
| 1820 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); | 1767 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); |
| 1821 } | 1768 } |
| 1822 | 1769 |
| 1823 { | 1770 { |
| 1824 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1771 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1825 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1772 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1826 trans.GetWrappedTrans(), | 1773 trans.GetWrappedTrans(), BOOKMARKS, false /* not encrypted */)); |
| 1827 BOOKMARKS, | |
| 1828 false /* not encrypted */)); | |
| 1829 } | 1774 } |
| 1830 | 1775 |
| 1831 EXPECT_CALL(encryption_observer_, | 1776 EXPECT_CALL( |
| 1832 OnEncryptedTypesChanged( | 1777 encryption_observer_, |
| 1833 HasModelTypes(EncryptableUserTypes()), true)); | 1778 OnEncryptedTypesChanged(HasModelTypes(EncryptableUserTypes()), true)); |
| 1834 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1779 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1835 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); | 1780 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| 1836 EXPECT_TRUE(IsEncryptEverythingEnabledForTest()); | 1781 EXPECT_TRUE(IsEncryptEverythingEnabledForTest()); |
| 1837 | 1782 |
| 1838 { | 1783 { |
| 1839 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1784 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1840 EXPECT_EQ(EncryptableUserTypes(), GetEncryptedTypesWithTrans(&trans)); | 1785 EXPECT_EQ(EncryptableUserTypes(), GetEncryptedTypesWithTrans(&trans)); |
| 1841 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1786 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1842 trans.GetWrappedTrans(), | 1787 trans.GetWrappedTrans(), BOOKMARKS, true /* is encrypted */)); |
| 1843 BOOKMARKS, | |
| 1844 true /* is encrypted */)); | |
| 1845 | 1788 |
| 1846 ReadNode node(&trans); | 1789 ReadNode node(&trans); |
| 1847 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); | 1790 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); |
| 1848 EXPECT_EQ(BOOKMARKS, node.GetModelType()); | 1791 EXPECT_EQ(BOOKMARKS, node.GetModelType()); |
| 1849 EXPECT_EQ(title, node.GetTitle()); | 1792 EXPECT_EQ(title, node.GetTitle()); |
| 1850 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); | 1793 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); |
| 1851 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); | 1794 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); |
| 1852 | 1795 |
| 1853 ReadNode node2(&trans); | 1796 ReadNode node2(&trans); |
| 1854 EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2)); | 1797 EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1895 } | 1838 } |
| 1896 | 1839 |
| 1897 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary | 1840 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary |
| 1898 // changes. | 1841 // changes. |
| 1899 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { | 1842 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { |
| 1900 std::string client_tag = "title"; | 1843 std::string client_tag = "title"; |
| 1901 sync_pb::EntitySpecifics entity_specifics; | 1844 sync_pb::EntitySpecifics entity_specifics; |
| 1902 entity_specifics.mutable_bookmark()->set_url("url"); | 1845 entity_specifics.mutable_bookmark()->set_url("url"); |
| 1903 entity_specifics.mutable_bookmark()->set_title("title"); | 1846 entity_specifics.mutable_bookmark()->set_title("title"); |
| 1904 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, | 1847 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 1905 syncable::GenerateSyncableHash(BOOKMARKS, | 1848 syncable::GenerateSyncableHash(BOOKMARKS, client_tag), |
| 1906 client_tag), | |
| 1907 entity_specifics); | 1849 entity_specifics); |
| 1908 // New node shouldn't start off unsynced. | 1850 // New node shouldn't start off unsynced. |
| 1909 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 1851 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 1910 // Manually change to the same data. Should not set is_unsynced. | 1852 // Manually change to the same data. Should not set is_unsynced. |
| 1911 { | 1853 { |
| 1912 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1854 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1913 WriteNode node(&trans); | 1855 WriteNode node(&trans); |
| 1914 EXPECT_EQ(BaseNode::INIT_OK, | 1856 EXPECT_EQ(BaseNode::INIT_OK, |
| 1915 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 1857 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 1916 node.SetEntitySpecifics(entity_specifics); | 1858 node.SetEntitySpecifics(entity_specifics); |
| 1917 } | 1859 } |
| 1918 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 1860 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 1919 | 1861 |
| 1920 // Encrypt the datatatype, should set is_unsynced. | 1862 // Encrypt the datatatype, should set is_unsynced. |
| 1921 EXPECT_CALL(encryption_observer_, | 1863 EXPECT_CALL( |
| 1922 OnEncryptedTypesChanged( | 1864 encryption_observer_, |
| 1923 HasModelTypes(EncryptableUserTypes()), true)); | 1865 OnEncryptedTypesChanged(HasModelTypes(EncryptableUserTypes()), true)); |
| 1924 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1866 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1925 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 1867 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
| 1926 | 1868 |
| 1927 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1869 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1928 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); | 1870 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); |
| 1929 sync_manager_.GetEncryptionHandler()->Init(); | 1871 sync_manager_.GetEncryptionHandler()->Init(); |
| 1930 PumpLoop(); | 1872 PumpLoop(); |
| 1931 { | 1873 { |
| 1932 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1874 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1933 ReadNode node(&trans); | 1875 ReadNode node(&trans); |
| 1934 EXPECT_EQ(BaseNode::INIT_OK, | 1876 EXPECT_EQ(BaseNode::INIT_OK, |
| 1935 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 1877 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 1936 const syncable::Entry* node_entry = node.GetEntry(); | 1878 const syncable::Entry* node_entry = node.GetEntry(); |
| 1937 const sync_pb::EntitySpecifics& specifics = node_entry->GetSpecifics(); | 1879 const sync_pb::EntitySpecifics& specifics = node_entry->GetSpecifics(); |
| 1938 EXPECT_TRUE(specifics.has_encrypted()); | 1880 EXPECT_TRUE(specifics.has_encrypted()); |
| 1939 EXPECT_EQ(kEncryptedString, node_entry->GetNonUniqueName()); | 1881 EXPECT_EQ(kEncryptedString, node_entry->GetNonUniqueName()); |
| 1940 Cryptographer* cryptographer = trans.GetCryptographer(); | 1882 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1941 EXPECT_TRUE(cryptographer->is_ready()); | 1883 EXPECT_TRUE(cryptographer->is_ready()); |
| 1942 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 1884 EXPECT_TRUE( |
| 1943 specifics.encrypted())); | 1885 cryptographer->CanDecryptUsingDefaultKey(specifics.encrypted())); |
| 1944 } | 1886 } |
| 1945 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 1887 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 1946 | 1888 |
| 1947 // Set a new passphrase. Should set is_unsynced. | 1889 // Set a new passphrase. Should set is_unsynced. |
| 1948 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 1890 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1949 EXPECT_CALL(encryption_observer_, | 1891 EXPECT_CALL(encryption_observer_, |
| 1950 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1892 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1951 ExpectPassphraseAcceptance(); | 1893 ExpectPassphraseAcceptance(); |
| 1952 SetCustomPassphraseAndCheck("new_passphrase"); | 1894 SetCustomPassphraseAndCheck("new_passphrase"); |
| 1953 { | 1895 { |
| 1954 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1896 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1955 ReadNode node(&trans); | 1897 ReadNode node(&trans); |
| 1956 EXPECT_EQ(BaseNode::INIT_OK, | 1898 EXPECT_EQ(BaseNode::INIT_OK, |
| 1957 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 1899 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 1958 const syncable::Entry* node_entry = node.GetEntry(); | 1900 const syncable::Entry* node_entry = node.GetEntry(); |
| 1959 const sync_pb::EntitySpecifics& specifics = node_entry->GetSpecifics(); | 1901 const sync_pb::EntitySpecifics& specifics = node_entry->GetSpecifics(); |
| 1960 EXPECT_TRUE(specifics.has_encrypted()); | 1902 EXPECT_TRUE(specifics.has_encrypted()); |
| 1961 EXPECT_EQ(kEncryptedString, node_entry->GetNonUniqueName()); | 1903 EXPECT_EQ(kEncryptedString, node_entry->GetNonUniqueName()); |
| 1962 Cryptographer* cryptographer = trans.GetCryptographer(); | 1904 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1963 EXPECT_TRUE(cryptographer->is_ready()); | 1905 EXPECT_TRUE(cryptographer->is_ready()); |
| 1964 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 1906 EXPECT_TRUE( |
| 1965 specifics.encrypted())); | 1907 cryptographer->CanDecryptUsingDefaultKey(specifics.encrypted())); |
| 1966 } | 1908 } |
| 1967 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 1909 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 1968 | 1910 |
| 1969 // Force a re-encrypt everything. Should not set is_unsynced. | 1911 // Force a re-encrypt everything. Should not set is_unsynced. |
| 1970 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 1912 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1971 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1913 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1972 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1914 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1973 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); | 1915 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); |
| 1974 | 1916 |
| 1975 sync_manager_.GetEncryptionHandler()->Init(); | 1917 sync_manager_.GetEncryptionHandler()->Init(); |
| 1976 PumpLoop(); | 1918 PumpLoop(); |
| 1977 | 1919 |
| 1978 { | 1920 { |
| 1979 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1921 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1980 ReadNode node(&trans); | 1922 ReadNode node(&trans); |
| 1981 EXPECT_EQ(BaseNode::INIT_OK, | 1923 EXPECT_EQ(BaseNode::INIT_OK, |
| 1982 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 1924 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 1983 const syncable::Entry* node_entry = node.GetEntry(); | 1925 const syncable::Entry* node_entry = node.GetEntry(); |
| 1984 const sync_pb::EntitySpecifics& specifics = node_entry->GetSpecifics(); | 1926 const sync_pb::EntitySpecifics& specifics = node_entry->GetSpecifics(); |
| 1985 EXPECT_TRUE(specifics.has_encrypted()); | 1927 EXPECT_TRUE(specifics.has_encrypted()); |
| 1986 EXPECT_EQ(kEncryptedString, node_entry->GetNonUniqueName()); | 1928 EXPECT_EQ(kEncryptedString, node_entry->GetNonUniqueName()); |
| 1987 Cryptographer* cryptographer = trans.GetCryptographer(); | 1929 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1988 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 1930 EXPECT_TRUE( |
| 1989 specifics.encrypted())); | 1931 cryptographer->CanDecryptUsingDefaultKey(specifics.encrypted())); |
| 1990 } | 1932 } |
| 1991 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 1933 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 1992 | 1934 |
| 1993 // Manually change to the same data. Should not set is_unsynced. | 1935 // Manually change to the same data. Should not set is_unsynced. |
| 1994 { | 1936 { |
| 1995 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1937 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1996 WriteNode node(&trans); | 1938 WriteNode node(&trans); |
| 1997 EXPECT_EQ(BaseNode::INIT_OK, | 1939 EXPECT_EQ(BaseNode::INIT_OK, |
| 1998 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 1940 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 1999 node.SetEntitySpecifics(entity_specifics); | 1941 node.SetEntitySpecifics(entity_specifics); |
| 2000 const syncable::Entry* node_entry = node.GetEntry(); | 1942 const syncable::Entry* node_entry = node.GetEntry(); |
| 2001 const sync_pb::EntitySpecifics& specifics = node_entry->GetSpecifics(); | 1943 const sync_pb::EntitySpecifics& specifics = node_entry->GetSpecifics(); |
| 2002 EXPECT_TRUE(specifics.has_encrypted()); | 1944 EXPECT_TRUE(specifics.has_encrypted()); |
| 2003 EXPECT_FALSE(node_entry->GetIsUnsynced()); | 1945 EXPECT_FALSE(node_entry->GetIsUnsynced()); |
| 2004 EXPECT_EQ(kEncryptedString, node_entry->GetNonUniqueName()); | 1946 EXPECT_EQ(kEncryptedString, node_entry->GetNonUniqueName()); |
| 2005 Cryptographer* cryptographer = trans.GetCryptographer(); | 1947 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2006 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 1948 EXPECT_TRUE( |
| 2007 specifics.encrypted())); | 1949 cryptographer->CanDecryptUsingDefaultKey(specifics.encrypted())); |
| 2008 } | 1950 } |
| 2009 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 1951 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2010 | 1952 |
| 2011 // Manually change to different data. Should set is_unsynced. | 1953 // Manually change to different data. Should set is_unsynced. |
| 2012 { | 1954 { |
| 2013 entity_specifics.mutable_bookmark()->set_url("url2"); | 1955 entity_specifics.mutable_bookmark()->set_url("url2"); |
| 2014 entity_specifics.mutable_bookmark()->set_title("title2"); | 1956 entity_specifics.mutable_bookmark()->set_title("title2"); |
| 2015 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1957 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2016 WriteNode node(&trans); | 1958 WriteNode node(&trans); |
| 2017 EXPECT_EQ(BaseNode::INIT_OK, | 1959 EXPECT_EQ(BaseNode::INIT_OK, |
| 2018 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 1960 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2019 node.SetEntitySpecifics(entity_specifics); | 1961 node.SetEntitySpecifics(entity_specifics); |
| 2020 const syncable::Entry* node_entry = node.GetEntry(); | 1962 const syncable::Entry* node_entry = node.GetEntry(); |
| 2021 const sync_pb::EntitySpecifics& specifics = node_entry->GetSpecifics(); | 1963 const sync_pb::EntitySpecifics& specifics = node_entry->GetSpecifics(); |
| 2022 EXPECT_TRUE(specifics.has_encrypted()); | 1964 EXPECT_TRUE(specifics.has_encrypted()); |
| 2023 EXPECT_TRUE(node_entry->GetIsUnsynced()); | 1965 EXPECT_TRUE(node_entry->GetIsUnsynced()); |
| 2024 EXPECT_EQ(kEncryptedString, node_entry->GetNonUniqueName()); | 1966 EXPECT_EQ(kEncryptedString, node_entry->GetNonUniqueName()); |
| 2025 Cryptographer* cryptographer = trans.GetCryptographer(); | 1967 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2026 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 1968 EXPECT_TRUE( |
| 2027 specifics.encrypted())); | 1969 cryptographer->CanDecryptUsingDefaultKey(specifics.encrypted())); |
| 2028 } | 1970 } |
| 2029 } | 1971 } |
| 2030 | 1972 |
| 2031 // Passwords have their own handling for encryption. Verify it does not result | 1973 // Passwords have their own handling for encryption. Verify it does not result |
| 2032 // in unnecessary writes via SetEntitySpecifics. | 1974 // in unnecessary writes via SetEntitySpecifics. |
| 2033 TEST_F(SyncManagerTest, UpdatePasswordSetEntitySpecificsNoChange) { | 1975 TEST_F(SyncManagerTest, UpdatePasswordSetEntitySpecificsNoChange) { |
| 2034 std::string client_tag = "title"; | 1976 std::string client_tag = "title"; |
| 2035 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1977 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2036 sync_pb::EntitySpecifics entity_specifics; | 1978 sync_pb::EntitySpecifics entity_specifics; |
| 2037 { | 1979 { |
| 2038 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1980 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2039 Cryptographer* cryptographer = trans.GetCryptographer(); | 1981 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2040 sync_pb::PasswordSpecificsData data; | 1982 sync_pb::PasswordSpecificsData data; |
| 2041 data.set_password_value("secret"); | 1983 data.set_password_value("secret"); |
| 2042 cryptographer->Encrypt( | 1984 cryptographer->Encrypt( |
| 2043 data, | 1985 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| 2044 entity_specifics.mutable_password()-> | |
| 2045 mutable_encrypted()); | |
| 2046 } | 1986 } |
| 2047 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 1987 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2048 syncable::GenerateSyncableHash(PASSWORDS, | 1988 syncable::GenerateSyncableHash(PASSWORDS, client_tag), |
| 2049 client_tag), | |
| 2050 entity_specifics); | 1989 entity_specifics); |
| 2051 // New node shouldn't start off unsynced. | 1990 // New node shouldn't start off unsynced. |
| 2052 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 1991 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2053 | 1992 |
| 2054 // Manually change to the same data via SetEntitySpecifics. Should not set | 1993 // Manually change to the same data via SetEntitySpecifics. Should not set |
| 2055 // is_unsynced. | 1994 // is_unsynced. |
| 2056 { | 1995 { |
| 2057 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1996 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2058 WriteNode node(&trans); | 1997 WriteNode node(&trans); |
| 2059 EXPECT_EQ(BaseNode::INIT_OK, | 1998 EXPECT_EQ(BaseNode::INIT_OK, |
| 2060 node.InitByClientTagLookup(PASSWORDS, client_tag)); | 1999 node.InitByClientTagLookup(PASSWORDS, client_tag)); |
| 2061 node.SetEntitySpecifics(entity_specifics); | 2000 node.SetEntitySpecifics(entity_specifics); |
| 2062 } | 2001 } |
| 2063 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2002 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2064 } | 2003 } |
| 2065 | 2004 |
| 2066 // Passwords have their own handling for encryption. Verify it does not result | 2005 // Passwords have their own handling for encryption. Verify it does not result |
| 2067 // in unnecessary writes via SetPasswordSpecifics. | 2006 // in unnecessary writes via SetPasswordSpecifics. |
| 2068 TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) { | 2007 TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) { |
| 2069 std::string client_tag = "title"; | 2008 std::string client_tag = "title"; |
| 2070 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2009 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2071 sync_pb::EntitySpecifics entity_specifics; | 2010 sync_pb::EntitySpecifics entity_specifics; |
| 2072 { | 2011 { |
| 2073 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2012 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2074 Cryptographer* cryptographer = trans.GetCryptographer(); | 2013 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2075 sync_pb::PasswordSpecificsData data; | 2014 sync_pb::PasswordSpecificsData data; |
| 2076 data.set_password_value("secret"); | 2015 data.set_password_value("secret"); |
| 2077 cryptographer->Encrypt( | 2016 cryptographer->Encrypt( |
| 2078 data, | 2017 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| 2079 entity_specifics.mutable_password()-> | |
| 2080 mutable_encrypted()); | |
| 2081 } | 2018 } |
| 2082 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2019 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2083 syncable::GenerateSyncableHash(PASSWORDS, | 2020 syncable::GenerateSyncableHash(PASSWORDS, client_tag), |
| 2084 client_tag), | |
| 2085 entity_specifics); | 2021 entity_specifics); |
| 2086 // New node shouldn't start off unsynced. | 2022 // New node shouldn't start off unsynced. |
| 2087 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2023 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2088 | 2024 |
| 2089 // Manually change to the same data via SetPasswordSpecifics. Should not set | 2025 // Manually change to the same data via SetPasswordSpecifics. Should not set |
| 2090 // is_unsynced. | 2026 // is_unsynced. |
| 2091 { | 2027 { |
| 2092 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2028 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2093 WriteNode node(&trans); | 2029 WriteNode node(&trans); |
| 2094 EXPECT_EQ(BaseNode::INIT_OK, | 2030 EXPECT_EQ(BaseNode::INIT_OK, |
| 2095 node.InitByClientTagLookup(PASSWORDS, client_tag)); | 2031 node.InitByClientTagLookup(PASSWORDS, client_tag)); |
| 2096 node.SetPasswordSpecifics(node.GetPasswordSpecifics()); | 2032 node.SetPasswordSpecifics(node.GetPasswordSpecifics()); |
| 2097 } | 2033 } |
| 2098 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2034 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2099 | 2035 |
| 2100 // Manually change to different data. Should set is_unsynced. | 2036 // Manually change to different data. Should set is_unsynced. |
| 2101 { | 2037 { |
| 2102 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2038 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2103 WriteNode node(&trans); | 2039 WriteNode node(&trans); |
| 2104 EXPECT_EQ(BaseNode::INIT_OK, | 2040 EXPECT_EQ(BaseNode::INIT_OK, |
| 2105 node.InitByClientTagLookup(PASSWORDS, client_tag)); | 2041 node.InitByClientTagLookup(PASSWORDS, client_tag)); |
| 2106 Cryptographer* cryptographer = trans.GetCryptographer(); | 2042 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2107 sync_pb::PasswordSpecificsData data; | 2043 sync_pb::PasswordSpecificsData data; |
| 2108 data.set_password_value("secret2"); | 2044 data.set_password_value("secret2"); |
| 2109 cryptographer->Encrypt( | 2045 cryptographer->Encrypt( |
| 2110 data, | 2046 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| 2111 entity_specifics.mutable_password()->mutable_encrypted()); | |
| 2112 node.SetPasswordSpecifics(data); | 2047 node.SetPasswordSpecifics(data); |
| 2113 const syncable::Entry* node_entry = node.GetEntry(); | 2048 const syncable::Entry* node_entry = node.GetEntry(); |
| 2114 EXPECT_TRUE(node_entry->GetIsUnsynced()); | 2049 EXPECT_TRUE(node_entry->GetIsUnsynced()); |
| 2115 } | 2050 } |
| 2116 } | 2051 } |
| 2117 | 2052 |
| 2118 // Passwords have their own handling for encryption. Verify setting a new | 2053 // Passwords have their own handling for encryption. Verify setting a new |
| 2119 // passphrase updates the data. | 2054 // passphrase updates the data. |
| 2120 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { | 2055 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { |
| 2121 std::string client_tag = "title"; | 2056 std::string client_tag = "title"; |
| 2122 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2057 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2123 sync_pb::EntitySpecifics entity_specifics; | 2058 sync_pb::EntitySpecifics entity_specifics; |
| 2124 { | 2059 { |
| 2125 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2060 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2126 Cryptographer* cryptographer = trans.GetCryptographer(); | 2061 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2127 sync_pb::PasswordSpecificsData data; | 2062 sync_pb::PasswordSpecificsData data; |
| 2128 data.set_password_value("secret"); | 2063 data.set_password_value("secret"); |
| 2129 cryptographer->Encrypt( | 2064 cryptographer->Encrypt( |
| 2130 data, | 2065 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| 2131 entity_specifics.mutable_password()->mutable_encrypted()); | |
| 2132 } | 2066 } |
| 2133 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2067 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2134 syncable::GenerateSyncableHash(PASSWORDS, | 2068 syncable::GenerateSyncableHash(PASSWORDS, client_tag), |
| 2135 client_tag), | |
| 2136 entity_specifics); | 2069 entity_specifics); |
| 2137 // New node shouldn't start off unsynced. | 2070 // New node shouldn't start off unsynced. |
| 2138 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2071 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2139 | 2072 |
| 2140 // Set a new passphrase. Should set is_unsynced. | 2073 // Set a new passphrase. Should set is_unsynced. |
| 2141 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2074 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2142 EXPECT_CALL(encryption_observer_, | 2075 EXPECT_CALL(encryption_observer_, |
| 2143 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 2076 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 2144 ExpectPassphraseAcceptance(); | 2077 ExpectPassphraseAcceptance(); |
| 2145 SetCustomPassphraseAndCheck("new_passphrase"); | 2078 SetCustomPassphraseAndCheck("new_passphrase"); |
| 2146 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2079 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2147 } | 2080 } |
| 2148 | 2081 |
| 2149 // Passwords have their own handling for encryption. Verify it does not result | 2082 // Passwords have their own handling for encryption. Verify it does not result |
| 2150 // in unnecessary writes via ReencryptEverything. | 2083 // in unnecessary writes via ReencryptEverything. |
| 2151 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { | 2084 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { |
| 2152 std::string client_tag = "title"; | 2085 std::string client_tag = "title"; |
| 2153 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2086 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2154 sync_pb::EntitySpecifics entity_specifics; | 2087 sync_pb::EntitySpecifics entity_specifics; |
| 2155 { | 2088 { |
| 2156 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2089 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2157 Cryptographer* cryptographer = trans.GetCryptographer(); | 2090 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2158 sync_pb::PasswordSpecificsData data; | 2091 sync_pb::PasswordSpecificsData data; |
| 2159 data.set_password_value("secret"); | 2092 data.set_password_value("secret"); |
| 2160 cryptographer->Encrypt( | 2093 cryptographer->Encrypt( |
| 2161 data, | 2094 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| 2162 entity_specifics.mutable_password()->mutable_encrypted()); | |
| 2163 } | 2095 } |
| 2164 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2096 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2165 syncable::GenerateSyncableHash(PASSWORDS, | 2097 syncable::GenerateSyncableHash(PASSWORDS, client_tag), |
| 2166 client_tag), | |
| 2167 entity_specifics); | 2098 entity_specifics); |
| 2168 // New node shouldn't start off unsynced. | 2099 // New node shouldn't start off unsynced. |
| 2169 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2100 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2170 | 2101 |
| 2171 // Force a re-encrypt everything. Should not set is_unsynced. | 2102 // Force a re-encrypt everything. Should not set is_unsynced. |
| 2172 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2103 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2173 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2104 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2174 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 2105 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2175 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); | 2106 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 2176 sync_manager_.GetEncryptionHandler()->Init(); | 2107 sync_manager_.GetEncryptionHandler()->Init(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2188 { | 2119 { |
| 2189 // Create a synced bookmark with undecryptable data. | 2120 // Create a synced bookmark with undecryptable data. |
| 2190 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2121 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2191 | 2122 |
| 2192 Cryptographer other_cryptographer(&encryptor_); | 2123 Cryptographer other_cryptographer(&encryptor_); |
| 2193 KeyParams fake_params = {"localhost", "dummy", "fake_key"}; | 2124 KeyParams fake_params = {"localhost", "dummy", "fake_key"}; |
| 2194 other_cryptographer.AddKey(fake_params); | 2125 other_cryptographer.AddKey(fake_params); |
| 2195 sync_pb::PasswordSpecificsData data; | 2126 sync_pb::PasswordSpecificsData data; |
| 2196 data.set_password_value("secret"); | 2127 data.set_password_value("secret"); |
| 2197 other_cryptographer.Encrypt( | 2128 other_cryptographer.Encrypt( |
| 2198 data, | 2129 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| 2199 entity_specifics.mutable_password()->mutable_encrypted()); | |
| 2200 | 2130 |
| 2201 // Set up the real cryptographer with a different key. | 2131 // Set up the real cryptographer with a different key. |
| 2202 KeyParams real_params = {"localhost", "username", "real_key"}; | 2132 KeyParams real_params = {"localhost", "username", "real_key"}; |
| 2203 trans.GetCryptographer()->AddKey(real_params); | 2133 trans.GetCryptographer()->AddKey(real_params); |
| 2204 } | 2134 } |
| 2205 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, kClientTag, | 2135 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, kClientTag, |
| 2206 syncable::GenerateSyncableHash(PASSWORDS, | 2136 syncable::GenerateSyncableHash(PASSWORDS, kClientTag), |
| 2207 kClientTag), | |
| 2208 entity_specifics); | 2137 entity_specifics); |
| 2209 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); | 2138 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); |
| 2210 | 2139 |
| 2211 // Force a re-encrypt everything. Should trigger an unrecoverable error due | 2140 // Force a re-encrypt everything. Should trigger an unrecoverable error due |
| 2212 // to being unable to decrypt the data that was previously applied. | 2141 // to being unable to decrypt the data that was previously applied. |
| 2213 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2142 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2214 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2143 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2215 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 2144 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2216 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); | 2145 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 2217 EXPECT_FALSE(HasUnrecoverableError()); | 2146 EXPECT_FALSE(HasUnrecoverableError()); |
| 2218 sync_manager_.GetEncryptionHandler()->Init(); | 2147 sync_manager_.GetEncryptionHandler()->Init(); |
| 2219 PumpLoop(); | 2148 PumpLoop(); |
| 2220 EXPECT_TRUE(HasUnrecoverableError()); | 2149 EXPECT_TRUE(HasUnrecoverableError()); |
| 2221 } | 2150 } |
| 2222 | 2151 |
| 2223 // Test that attempting to start up with corrupted bookmark data triggers | 2152 // Test that attempting to start up with corrupted bookmark data triggers |
| 2224 // an unrecoverable error (rather than crashing). | 2153 // an unrecoverable error (rather than crashing). |
| 2225 TEST_F(SyncManagerTest, ReencryptEverythingWithUnrecoverableErrorBookmarks) { | 2154 TEST_F(SyncManagerTest, ReencryptEverythingWithUnrecoverableErrorBookmarks) { |
| 2226 const char kClientTag[] = "client_tag"; | 2155 const char kClientTag[] = "client_tag"; |
| 2227 EXPECT_CALL(encryption_observer_, | 2156 EXPECT_CALL( |
| 2228 OnEncryptedTypesChanged( | 2157 encryption_observer_, |
| 2229 HasModelTypes(EncryptableUserTypes()), true)); | 2158 OnEncryptedTypesChanged(HasModelTypes(EncryptableUserTypes()), true)); |
| 2230 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 2159 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
| 2231 sync_pb::EntitySpecifics entity_specifics; | 2160 sync_pb::EntitySpecifics entity_specifics; |
| 2232 { | 2161 { |
| 2233 // Create a synced bookmark with undecryptable data. | 2162 // Create a synced bookmark with undecryptable data. |
| 2234 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2163 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2235 | 2164 |
| 2236 Cryptographer other_cryptographer(&encryptor_); | 2165 Cryptographer other_cryptographer(&encryptor_); |
| 2237 KeyParams fake_params = {"localhost", "dummy", "fake_key"}; | 2166 KeyParams fake_params = {"localhost", "dummy", "fake_key"}; |
| 2238 other_cryptographer.AddKey(fake_params); | 2167 other_cryptographer.AddKey(fake_params); |
| 2239 sync_pb::EntitySpecifics bm_specifics; | 2168 sync_pb::EntitySpecifics bm_specifics; |
| 2240 bm_specifics.mutable_bookmark()->set_title("title"); | 2169 bm_specifics.mutable_bookmark()->set_title("title"); |
| 2241 bm_specifics.mutable_bookmark()->set_url("url"); | 2170 bm_specifics.mutable_bookmark()->set_url("url"); |
| 2242 sync_pb::EncryptedData encrypted; | 2171 sync_pb::EncryptedData encrypted; |
| 2243 other_cryptographer.Encrypt(bm_specifics, &encrypted); | 2172 other_cryptographer.Encrypt(bm_specifics, &encrypted); |
| 2244 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); | 2173 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); |
| 2245 | 2174 |
| 2246 // Set up the real cryptographer with a different key. | 2175 // Set up the real cryptographer with a different key. |
| 2247 KeyParams real_params = {"localhost", "username", "real_key"}; | 2176 KeyParams real_params = {"localhost", "username", "real_key"}; |
| 2248 trans.GetCryptographer()->AddKey(real_params); | 2177 trans.GetCryptographer()->AddKey(real_params); |
| 2249 } | 2178 } |
| 2250 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, kClientTag, | 2179 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, kClientTag, |
| 2251 syncable::GenerateSyncableHash(BOOKMARKS, | 2180 syncable::GenerateSyncableHash(BOOKMARKS, kClientTag), |
| 2252 kClientTag), | |
| 2253 entity_specifics); | 2181 entity_specifics); |
| 2254 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, kClientTag)); | 2182 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, kClientTag)); |
| 2255 | 2183 |
| 2256 // Force a re-encrypt everything. Should trigger an unrecoverable error due | 2184 // Force a re-encrypt everything. Should trigger an unrecoverable error due |
| 2257 // to being unable to decrypt the data that was previously applied. | 2185 // to being unable to decrypt the data that was previously applied. |
| 2258 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2186 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2259 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2187 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2260 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 2188 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2261 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); | 2189 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); |
| 2262 EXPECT_FALSE(HasUnrecoverableError()); | 2190 EXPECT_FALSE(HasUnrecoverableError()); |
| 2263 sync_manager_.GetEncryptionHandler()->Init(); | 2191 sync_manager_.GetEncryptionHandler()->Init(); |
| 2264 PumpLoop(); | 2192 PumpLoop(); |
| 2265 EXPECT_TRUE(HasUnrecoverableError()); | 2193 EXPECT_TRUE(HasUnrecoverableError()); |
| 2266 } | 2194 } |
| 2267 | 2195 |
| 2268 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks | 2196 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks |
| 2269 // when we write the same data, but does set it when we write new data. | 2197 // when we write the same data, but does set it when we write new data. |
| 2270 TEST_F(SyncManagerTest, SetBookmarkTitle) { | 2198 TEST_F(SyncManagerTest, SetBookmarkTitle) { |
| 2271 std::string client_tag = "title"; | 2199 std::string client_tag = "title"; |
| 2272 sync_pb::EntitySpecifics entity_specifics; | 2200 sync_pb::EntitySpecifics entity_specifics; |
| 2273 entity_specifics.mutable_bookmark()->set_url("url"); | 2201 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2274 entity_specifics.mutable_bookmark()->set_title("title"); | 2202 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2275 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, | 2203 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2276 syncable::GenerateSyncableHash(BOOKMARKS, | 2204 syncable::GenerateSyncableHash(BOOKMARKS, client_tag), |
| 2277 client_tag), | |
| 2278 entity_specifics); | 2205 entity_specifics); |
| 2279 // New node shouldn't start off unsynced. | 2206 // New node shouldn't start off unsynced. |
| 2280 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2207 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2281 | 2208 |
| 2282 // Manually change to the same title. Should not set is_unsynced. | 2209 // Manually change to the same title. Should not set is_unsynced. |
| 2283 { | 2210 { |
| 2284 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2211 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2285 WriteNode node(&trans); | 2212 WriteNode node(&trans); |
| 2286 EXPECT_EQ(BaseNode::INIT_OK, | 2213 EXPECT_EQ(BaseNode::INIT_OK, |
| 2287 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 2214 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2302 | 2229 |
| 2303 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted | 2230 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted |
| 2304 // bookmarks when we write the same data, but does set it when we write new | 2231 // bookmarks when we write the same data, but does set it when we write new |
| 2305 // data. | 2232 // data. |
| 2306 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { | 2233 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { |
| 2307 std::string client_tag = "title"; | 2234 std::string client_tag = "title"; |
| 2308 sync_pb::EntitySpecifics entity_specifics; | 2235 sync_pb::EntitySpecifics entity_specifics; |
| 2309 entity_specifics.mutable_bookmark()->set_url("url"); | 2236 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2310 entity_specifics.mutable_bookmark()->set_title("title"); | 2237 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2311 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, | 2238 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2312 syncable::GenerateSyncableHash(BOOKMARKS, | 2239 syncable::GenerateSyncableHash(BOOKMARKS, client_tag), |
| 2313 client_tag), | |
| 2314 entity_specifics); | 2240 entity_specifics); |
| 2315 // New node shouldn't start off unsynced. | 2241 // New node shouldn't start off unsynced. |
| 2316 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2242 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2317 | 2243 |
| 2318 // Encrypt the datatatype, should set is_unsynced. | 2244 // Encrypt the datatatype, should set is_unsynced. |
| 2319 EXPECT_CALL(encryption_observer_, | 2245 EXPECT_CALL( |
| 2320 OnEncryptedTypesChanged( | 2246 encryption_observer_, |
| 2321 HasModelTypes(EncryptableUserTypes()), true)); | 2247 OnEncryptedTypesChanged(HasModelTypes(EncryptableUserTypes()), true)); |
| 2322 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2248 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2323 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 2249 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
| 2324 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 2250 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2325 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); | 2251 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); |
| 2326 sync_manager_.GetEncryptionHandler()->Init(); | 2252 sync_manager_.GetEncryptionHandler()->Init(); |
| 2327 PumpLoop(); | 2253 PumpLoop(); |
| 2328 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2254 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2329 | 2255 |
| 2330 // Manually change to the same title. Should not set is_unsynced. | 2256 // Manually change to the same title. Should not set is_unsynced. |
| 2331 // NON_UNIQUE_NAME should be kEncryptedString. | 2257 // NON_UNIQUE_NAME should be kEncryptedString. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2358 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2284 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2359 } | 2285 } |
| 2360 | 2286 |
| 2361 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks | 2287 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks |
| 2362 // when we write the same data, but does set it when we write new data. | 2288 // when we write the same data, but does set it when we write new data. |
| 2363 TEST_F(SyncManagerTest, SetNonBookmarkTitle) { | 2289 TEST_F(SyncManagerTest, SetNonBookmarkTitle) { |
| 2364 std::string client_tag = "title"; | 2290 std::string client_tag = "title"; |
| 2365 sync_pb::EntitySpecifics entity_specifics; | 2291 sync_pb::EntitySpecifics entity_specifics; |
| 2366 entity_specifics.mutable_preference()->set_name("name"); | 2292 entity_specifics.mutable_preference()->set_name("name"); |
| 2367 entity_specifics.mutable_preference()->set_value("value"); | 2293 entity_specifics.mutable_preference()->set_value("value"); |
| 2368 MakeServerNode(sync_manager_.GetUserShare(), | 2294 MakeServerNode(sync_manager_.GetUserShare(), PREFERENCES, client_tag, |
| 2369 PREFERENCES, | 2295 syncable::GenerateSyncableHash(PREFERENCES, client_tag), |
| 2370 client_tag, | |
| 2371 syncable::GenerateSyncableHash(PREFERENCES, | |
| 2372 client_tag), | |
| 2373 entity_specifics); | 2296 entity_specifics); |
| 2374 // New node shouldn't start off unsynced. | 2297 // New node shouldn't start off unsynced. |
| 2375 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); | 2298 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2376 | 2299 |
| 2377 // Manually change to the same title. Should not set is_unsynced. | 2300 // Manually change to the same title. Should not set is_unsynced. |
| 2378 { | 2301 { |
| 2379 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2302 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2380 WriteNode node(&trans); | 2303 WriteNode node(&trans); |
| 2381 EXPECT_EQ(BaseNode::INIT_OK, | 2304 EXPECT_EQ(BaseNode::INIT_OK, |
| 2382 node.InitByClientTagLookup(PREFERENCES, client_tag)); | 2305 node.InitByClientTagLookup(PREFERENCES, client_tag)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2396 } | 2319 } |
| 2397 | 2320 |
| 2398 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted | 2321 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted |
| 2399 // non-bookmarks when we write the same data or when we write new data | 2322 // non-bookmarks when we write the same data or when we write new data |
| 2400 // data (should remained kEncryptedString). | 2323 // data (should remained kEncryptedString). |
| 2401 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { | 2324 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { |
| 2402 std::string client_tag = "title"; | 2325 std::string client_tag = "title"; |
| 2403 sync_pb::EntitySpecifics entity_specifics; | 2326 sync_pb::EntitySpecifics entity_specifics; |
| 2404 entity_specifics.mutable_preference()->set_name("name"); | 2327 entity_specifics.mutable_preference()->set_name("name"); |
| 2405 entity_specifics.mutable_preference()->set_value("value"); | 2328 entity_specifics.mutable_preference()->set_value("value"); |
| 2406 MakeServerNode(sync_manager_.GetUserShare(), | 2329 MakeServerNode(sync_manager_.GetUserShare(), PREFERENCES, client_tag, |
| 2407 PREFERENCES, | 2330 syncable::GenerateSyncableHash(PREFERENCES, client_tag), |
| 2408 client_tag, | |
| 2409 syncable::GenerateSyncableHash(PREFERENCES, | |
| 2410 client_tag), | |
| 2411 entity_specifics); | 2331 entity_specifics); |
| 2412 // New node shouldn't start off unsynced. | 2332 // New node shouldn't start off unsynced. |
| 2413 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); | 2333 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2414 | 2334 |
| 2415 // Encrypt the datatatype, should set is_unsynced. | 2335 // Encrypt the datatatype, should set is_unsynced. |
| 2416 EXPECT_CALL(encryption_observer_, | 2336 EXPECT_CALL( |
| 2417 OnEncryptedTypesChanged( | 2337 encryption_observer_, |
| 2418 HasModelTypes(EncryptableUserTypes()), true)); | 2338 OnEncryptedTypesChanged(HasModelTypes(EncryptableUserTypes()), true)); |
| 2419 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2339 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2420 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 2340 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
| 2421 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 2341 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2422 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); | 2342 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); |
| 2423 sync_manager_.GetEncryptionHandler()->Init(); | 2343 sync_manager_.GetEncryptionHandler()->Init(); |
| 2424 PumpLoop(); | 2344 PumpLoop(); |
| 2425 EXPECT_TRUE(ResetUnsyncedEntry(PREFERENCES, client_tag)); | 2345 EXPECT_TRUE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2426 | 2346 |
| 2427 // Manually change to the same title. Should not set is_unsynced. | 2347 // Manually change to the same title. Should not set is_unsynced. |
| 2428 // NON_UNIQUE_NAME should be kEncryptedString. | 2348 // NON_UNIQUE_NAME should be kEncryptedString. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2457 | 2377 |
| 2458 // Ensure that titles are truncated to 255 bytes, and attempting to reset | 2378 // Ensure that titles are truncated to 255 bytes, and attempting to reset |
| 2459 // them to their longer version does not set IS_UNSYNCED. | 2379 // them to their longer version does not set IS_UNSYNCED. |
| 2460 TEST_F(SyncManagerTest, SetLongTitle) { | 2380 TEST_F(SyncManagerTest, SetLongTitle) { |
| 2461 const int kNumChars = 512; | 2381 const int kNumChars = 512; |
| 2462 const std::string kClientTag = "tag"; | 2382 const std::string kClientTag = "tag"; |
| 2463 std::string title(kNumChars, '0'); | 2383 std::string title(kNumChars, '0'); |
| 2464 sync_pb::EntitySpecifics entity_specifics; | 2384 sync_pb::EntitySpecifics entity_specifics; |
| 2465 entity_specifics.mutable_preference()->set_name("name"); | 2385 entity_specifics.mutable_preference()->set_name("name"); |
| 2466 entity_specifics.mutable_preference()->set_value("value"); | 2386 entity_specifics.mutable_preference()->set_value("value"); |
| 2467 MakeServerNode(sync_manager_.GetUserShare(), | 2387 MakeServerNode(sync_manager_.GetUserShare(), PREFERENCES, "short_title", |
| 2468 PREFERENCES, | 2388 syncable::GenerateSyncableHash(PREFERENCES, kClientTag), |
| 2469 "short_title", | |
| 2470 syncable::GenerateSyncableHash(PREFERENCES, | |
| 2471 kClientTag), | |
| 2472 entity_specifics); | 2389 entity_specifics); |
| 2473 // New node shouldn't start off unsynced. | 2390 // New node shouldn't start off unsynced. |
| 2474 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, kClientTag)); | 2391 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, kClientTag)); |
| 2475 | 2392 |
| 2476 // Manually change to the long title. Should set is_unsynced. | 2393 // Manually change to the long title. Should set is_unsynced. |
| 2477 { | 2394 { |
| 2478 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2395 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2479 WriteNode node(&trans); | 2396 WriteNode node(&trans); |
| 2480 EXPECT_EQ(BaseNode::INIT_OK, | 2397 EXPECT_EQ(BaseNode::INIT_OK, |
| 2481 node.InitByClientTagLookup(PREFERENCES, kClientTag)); | 2398 node.InitByClientTagLookup(PREFERENCES, kClientTag)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2521 Cryptographer* crypto = trans.GetCryptographer(); | 2438 Cryptographer* crypto = trans.GetCryptographer(); |
| 2522 sync_pb::EntitySpecifics bm_specifics; | 2439 sync_pb::EntitySpecifics bm_specifics; |
| 2523 bm_specifics.mutable_bookmark()->set_title("title"); | 2440 bm_specifics.mutable_bookmark()->set_title("title"); |
| 2524 bm_specifics.mutable_bookmark()->set_url("url"); | 2441 bm_specifics.mutable_bookmark()->set_url("url"); |
| 2525 sync_pb::EncryptedData encrypted; | 2442 sync_pb::EncryptedData encrypted; |
| 2526 crypto->Encrypt(bm_specifics, &encrypted); | 2443 crypto->Encrypt(bm_specifics, &encrypted); |
| 2527 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); | 2444 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); |
| 2528 AddDefaultFieldValue(BOOKMARKS, &entity_specifics); | 2445 AddDefaultFieldValue(BOOKMARKS, &entity_specifics); |
| 2529 } | 2446 } |
| 2530 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, | 2447 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2531 syncable::GenerateSyncableHash(BOOKMARKS, | 2448 syncable::GenerateSyncableHash(BOOKMARKS, client_tag), |
| 2532 client_tag), | |
| 2533 entity_specifics); | 2449 entity_specifics); |
| 2534 | 2450 |
| 2535 { | 2451 { |
| 2536 // Verify the data. | 2452 // Verify the data. |
| 2537 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2453 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2538 ReadNode node(&trans); | 2454 ReadNode node(&trans); |
| 2539 EXPECT_EQ(BaseNode::INIT_OK, | 2455 EXPECT_EQ(BaseNode::INIT_OK, |
| 2540 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 2456 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2541 EXPECT_EQ(title, node.GetTitle()); | 2457 EXPECT_EQ(title, node.GetTitle()); |
| 2542 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); | 2458 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2575 ModelSafeRoutingInfo routing_info; | 2491 ModelSafeRoutingInfo routing_info; |
| 2576 GetModelSafeRoutingInfo(&routing_info); | 2492 GetModelSafeRoutingInfo(&routing_info); |
| 2577 | 2493 |
| 2578 { | 2494 { |
| 2579 ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare()); | 2495 ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2580 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 2496 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 2581 i != routing_info.end(); ++i) { | 2497 i != routing_info.end(); ++i) { |
| 2582 // Transaction version is incremented when SyncManagerTest::SetUp() | 2498 // Transaction version is incremented when SyncManagerTest::SetUp() |
| 2583 // creates a node of each type. | 2499 // creates a node of each type. |
| 2584 EXPECT_EQ(1, | 2500 EXPECT_EQ(1, |
| 2585 sync_manager_.GetUserShare()->directory-> | 2501 sync_manager_.GetUserShare()->directory->GetTransactionVersion( |
| 2586 GetTransactionVersion(i->first)); | 2502 i->first)); |
| 2587 } | 2503 } |
| 2588 } | 2504 } |
| 2589 | 2505 |
| 2590 // Create bookmark node to increment transaction version of bookmark model. | 2506 // Create bookmark node to increment transaction version of bookmark model. |
| 2591 std::string client_tag = "title"; | 2507 std::string client_tag = "title"; |
| 2592 sync_pb::EntitySpecifics entity_specifics; | 2508 sync_pb::EntitySpecifics entity_specifics; |
| 2593 entity_specifics.mutable_bookmark()->set_url("url"); | 2509 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2594 entity_specifics.mutable_bookmark()->set_title("title"); | 2510 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2595 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, | 2511 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2596 syncable::GenerateSyncableHash(BOOKMARKS, | 2512 syncable::GenerateSyncableHash(BOOKMARKS, client_tag), |
| 2597 client_tag), | |
| 2598 entity_specifics); | 2513 entity_specifics); |
| 2599 | 2514 |
| 2600 { | 2515 { |
| 2601 ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare()); | 2516 ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2602 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 2517 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 2603 i != routing_info.end(); ++i) { | 2518 i != routing_info.end(); ++i) { |
| 2604 EXPECT_EQ(i->first == BOOKMARKS ? 2 : 1, | 2519 EXPECT_EQ(i->first == BOOKMARKS ? 2 : 1, |
| 2605 sync_manager_.GetUserShare()->directory-> | 2520 sync_manager_.GetUserShare()->directory->GetTransactionVersion( |
| 2606 GetTransactionVersion(i->first)); | 2521 i->first)); |
| 2607 } | 2522 } |
| 2608 } | 2523 } |
| 2609 } | 2524 } |
| 2610 | 2525 |
| 2611 class MockSyncScheduler : public FakeSyncScheduler { | 2526 class MockSyncScheduler : public FakeSyncScheduler { |
| 2612 public: | 2527 public: |
| 2613 MockSyncScheduler() : FakeSyncScheduler() {} | 2528 MockSyncScheduler() : FakeSyncScheduler() {} |
| 2614 virtual ~MockSyncScheduler() {} | 2529 virtual ~MockSyncScheduler() {} |
| 2615 | 2530 |
| 2616 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time)); | 2531 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time)); |
| 2617 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); | 2532 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); |
| 2618 }; | 2533 }; |
| 2619 | 2534 |
| 2620 class ComponentsFactory : public TestInternalComponentsFactory { | 2535 class ComponentsFactory : public TestInternalComponentsFactory { |
| 2621 public: | 2536 public: |
| 2622 ComponentsFactory(const Switches& switches, | 2537 ComponentsFactory(const Switches& switches, |
| 2623 SyncScheduler* scheduler_to_use, | 2538 SyncScheduler* scheduler_to_use, |
| 2624 sessions::SyncSessionContext** session_context, | 2539 sessions::SyncSessionContext** session_context, |
| 2625 InternalComponentsFactory::StorageOption* storage_used) | 2540 InternalComponentsFactory::StorageOption* storage_used) |
| 2626 : TestInternalComponentsFactory( | 2541 : TestInternalComponentsFactory( |
| 2627 switches, InternalComponentsFactory::STORAGE_IN_MEMORY, storage_used), | 2542 switches, |
| 2543 InternalComponentsFactory::STORAGE_IN_MEMORY, |
| 2544 storage_used), |
| 2628 scheduler_to_use_(scheduler_to_use), | 2545 scheduler_to_use_(scheduler_to_use), |
| 2629 session_context_(session_context) {} | 2546 session_context_(session_context) {} |
| 2630 ~ComponentsFactory() override {} | 2547 ~ComponentsFactory() override {} |
| 2631 | 2548 |
| 2632 std::unique_ptr<SyncScheduler> BuildScheduler( | 2549 std::unique_ptr<SyncScheduler> BuildScheduler( |
| 2633 const std::string& name, | 2550 const std::string& name, |
| 2634 sessions::SyncSessionContext* context, | 2551 sessions::SyncSessionContext* context, |
| 2635 CancelationSignal* stop_handle) override { | 2552 CancelationSignal* stop_handle) override { |
| 2636 *session_context_ = context; | 2553 *session_context_ = context; |
| 2637 return std::move(scheduler_to_use_); | 2554 return std::move(scheduler_to_use_); |
| 2638 } | 2555 } |
| 2639 | 2556 |
| 2640 private: | 2557 private: |
| 2641 std::unique_ptr<SyncScheduler> scheduler_to_use_; | 2558 std::unique_ptr<SyncScheduler> scheduler_to_use_; |
| 2642 sessions::SyncSessionContext** session_context_; | 2559 sessions::SyncSessionContext** session_context_; |
| 2643 }; | 2560 }; |
| 2644 | 2561 |
| 2645 class SyncManagerTestWithMockScheduler : public SyncManagerTest { | 2562 class SyncManagerTestWithMockScheduler : public SyncManagerTest { |
| 2646 public: | 2563 public: |
| 2647 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} | 2564 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} |
| 2648 InternalComponentsFactory* GetFactory() override { | 2565 InternalComponentsFactory* GetFactory() override { |
| 2649 scheduler_ = new MockSyncScheduler(); | 2566 scheduler_ = new MockSyncScheduler(); |
| 2650 return new ComponentsFactory(GetSwitches(), scheduler_, &session_context_, | 2567 return new ComponentsFactory(GetSwitches(), scheduler_, &session_context_, |
| 2651 &storage_used_); | 2568 &storage_used_); |
| 2652 } | 2569 } |
| 2653 | 2570 |
| 2654 MockSyncScheduler* scheduler() { return scheduler_; } | 2571 MockSyncScheduler* scheduler() { return scheduler_; } |
| 2655 sessions::SyncSessionContext* session_context() { | 2572 sessions::SyncSessionContext* session_context() { return session_context_; } |
| 2656 return session_context_; | |
| 2657 } | |
| 2658 | 2573 |
| 2659 private: | 2574 private: |
| 2660 MockSyncScheduler* scheduler_; | 2575 MockSyncScheduler* scheduler_; |
| 2661 sessions::SyncSessionContext* session_context_; | 2576 sessions::SyncSessionContext* session_context_; |
| 2662 }; | 2577 }; |
| 2663 | 2578 |
| 2664 // Test that the configuration params are properly created and sent to | 2579 // Test that the configuration params are properly created and sent to |
| 2665 // ScheduleConfigure. No callback should be invoked. Any disabled datatypes | 2580 // ScheduleConfigure. No callback should be invoked. Any disabled datatypes |
| 2666 // should be purged. | 2581 // should be purged. |
| 2667 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) { | 2582 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) { |
| 2668 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; | 2583 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; |
| 2669 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); | 2584 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); |
| 2670 ModelSafeRoutingInfo new_routing_info; | 2585 ModelSafeRoutingInfo new_routing_info; |
| 2671 GetModelSafeRoutingInfo(&new_routing_info); | 2586 GetModelSafeRoutingInfo(&new_routing_info); |
| 2672 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); | 2587 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); |
| 2673 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types); | 2588 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), enabled_types); |
| 2674 | 2589 |
| 2675 ConfigurationParams params; | 2590 ConfigurationParams params; |
| 2676 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE, _)); | 2591 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE, _)); |
| 2677 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). | 2592 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)) |
| 2678 WillOnce(SaveArg<0>(¶ms)); | 2593 .WillOnce(SaveArg<0>(¶ms)); |
| 2679 | 2594 |
| 2680 // Set data for all types. | 2595 // Set data for all types. |
| 2681 ModelTypeSet protocol_types = ProtocolTypes(); | 2596 ModelTypeSet protocol_types = ProtocolTypes(); |
| 2682 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | 2597 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); |
| 2683 iter.Inc()) { | 2598 iter.Inc()) { |
| 2684 SetProgressMarkerForType(iter.Get(), true); | 2599 SetProgressMarkerForType(iter.Get(), true); |
| 2685 } | 2600 } |
| 2686 | 2601 |
| 2687 CallbackCounter ready_task_counter, retry_task_counter; | 2602 CallbackCounter ready_task_counter, retry_task_counter; |
| 2688 sync_manager_.ConfigureSyncer( | 2603 sync_manager_.ConfigureSyncer( |
| 2689 reason, | 2604 reason, types_to_download, disabled_types, ModelTypeSet(), ModelTypeSet(), |
| 2690 types_to_download, | 2605 new_routing_info, base::Bind(&CallbackCounter::Callback, |
| 2691 disabled_types, | 2606 base::Unretained(&ready_task_counter)), |
| 2692 ModelTypeSet(), | |
| 2693 ModelTypeSet(), | |
| 2694 new_routing_info, | |
| 2695 base::Bind(&CallbackCounter::Callback, | |
| 2696 base::Unretained(&ready_task_counter)), | |
| 2697 base::Bind(&CallbackCounter::Callback, | 2607 base::Bind(&CallbackCounter::Callback, |
| 2698 base::Unretained(&retry_task_counter))); | 2608 base::Unretained(&retry_task_counter))); |
| 2699 EXPECT_EQ(0, ready_task_counter.times_called()); | 2609 EXPECT_EQ(0, ready_task_counter.times_called()); |
| 2700 EXPECT_EQ(0, retry_task_counter.times_called()); | 2610 EXPECT_EQ(0, retry_task_counter.times_called()); |
| 2701 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | 2611 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, params.source); |
| 2702 params.source); | |
| 2703 EXPECT_EQ(types_to_download, params.types_to_download); | 2612 EXPECT_EQ(types_to_download, params.types_to_download); |
| 2704 EXPECT_EQ(new_routing_info, params.routing_info); | 2613 EXPECT_EQ(new_routing_info, params.routing_info); |
| 2705 | 2614 |
| 2706 // Verify all the disabled types were purged. | 2615 // Verify all the disabled types were purged. |
| 2707 EXPECT_EQ(enabled_types, | 2616 EXPECT_EQ(enabled_types, |
| 2708 sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes()); | 2617 sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes()); |
| 2709 EXPECT_EQ(disabled_types, sync_manager_.GetTypesWithEmptyProgressMarkerToken( | 2618 EXPECT_EQ(disabled_types, sync_manager_.GetTypesWithEmptyProgressMarkerToken( |
| 2710 ModelTypeSet::All())); | 2619 ModelTypeSet::All())); |
| 2711 } | 2620 } |
| 2712 | 2621 |
| 2713 // Test that on a reconfiguration (configuration where the session context | 2622 // Test that on a reconfiguration (configuration where the session context |
| 2714 // already has routing info), only those recently disabled types are purged. | 2623 // already has routing info), only those recently disabled types are purged. |
| 2715 TEST_F(SyncManagerTestWithMockScheduler, ReConfiguration) { | 2624 TEST_F(SyncManagerTestWithMockScheduler, ReConfiguration) { |
| 2716 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; | 2625 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; |
| 2717 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); | 2626 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); |
| 2718 ModelTypeSet disabled_types = ModelTypeSet(THEMES, SESSIONS); | 2627 ModelTypeSet disabled_types = ModelTypeSet(THEMES, SESSIONS); |
| 2719 ModelSafeRoutingInfo old_routing_info; | 2628 ModelSafeRoutingInfo old_routing_info; |
| 2720 ModelSafeRoutingInfo new_routing_info; | 2629 ModelSafeRoutingInfo new_routing_info; |
| 2721 GetModelSafeRoutingInfo(&old_routing_info); | 2630 GetModelSafeRoutingInfo(&old_routing_info); |
| 2722 new_routing_info = old_routing_info; | 2631 new_routing_info = old_routing_info; |
| 2723 new_routing_info.erase(THEMES); | 2632 new_routing_info.erase(THEMES); |
| 2724 new_routing_info.erase(SESSIONS); | 2633 new_routing_info.erase(SESSIONS); |
| 2725 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); | 2634 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); |
| 2726 | 2635 |
| 2727 ConfigurationParams params; | 2636 ConfigurationParams params; |
| 2728 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE, _)); | 2637 EXPECT_CALL(*scheduler(), Start(SyncScheduler::CONFIGURATION_MODE, _)); |
| 2729 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)). | 2638 EXPECT_CALL(*scheduler(), ScheduleConfiguration(_)) |
| 2730 WillOnce(SaveArg<0>(¶ms)); | 2639 .WillOnce(SaveArg<0>(¶ms)); |
| 2731 | 2640 |
| 2732 // Set data for all types except those recently disabled (so we can verify | 2641 // Set data for all types except those recently disabled (so we can verify |
| 2733 // only those recently disabled are purged) . | 2642 // only those recently disabled are purged) . |
| 2734 ModelTypeSet protocol_types = ProtocolTypes(); | 2643 ModelTypeSet protocol_types = ProtocolTypes(); |
| 2735 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | 2644 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); |
| 2736 iter.Inc()) { | 2645 iter.Inc()) { |
| 2737 if (!disabled_types.Has(iter.Get())) { | 2646 if (!disabled_types.Has(iter.Get())) { |
| 2738 SetProgressMarkerForType(iter.Get(), true); | 2647 SetProgressMarkerForType(iter.Get(), true); |
| 2739 } else { | 2648 } else { |
| 2740 SetProgressMarkerForType(iter.Get(), false); | 2649 SetProgressMarkerForType(iter.Get(), false); |
| 2741 } | 2650 } |
| 2742 } | 2651 } |
| 2743 | 2652 |
| 2744 // Set the context to have the old routing info. | 2653 // Set the context to have the old routing info. |
| 2745 session_context()->SetRoutingInfo(old_routing_info); | 2654 session_context()->SetRoutingInfo(old_routing_info); |
| 2746 | 2655 |
| 2747 CallbackCounter ready_task_counter, retry_task_counter; | 2656 CallbackCounter ready_task_counter, retry_task_counter; |
| 2748 sync_manager_.ConfigureSyncer( | 2657 sync_manager_.ConfigureSyncer( |
| 2749 reason, | 2658 reason, types_to_download, ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), |
| 2750 types_to_download, | 2659 new_routing_info, base::Bind(&CallbackCounter::Callback, |
| 2751 ModelTypeSet(), | 2660 base::Unretained(&ready_task_counter)), |
| 2752 ModelTypeSet(), | |
| 2753 ModelTypeSet(), | |
| 2754 new_routing_info, | |
| 2755 base::Bind(&CallbackCounter::Callback, | |
| 2756 base::Unretained(&ready_task_counter)), | |
| 2757 base::Bind(&CallbackCounter::Callback, | 2661 base::Bind(&CallbackCounter::Callback, |
| 2758 base::Unretained(&retry_task_counter))); | 2662 base::Unretained(&retry_task_counter))); |
| 2759 EXPECT_EQ(0, ready_task_counter.times_called()); | 2663 EXPECT_EQ(0, ready_task_counter.times_called()); |
| 2760 EXPECT_EQ(0, retry_task_counter.times_called()); | 2664 EXPECT_EQ(0, retry_task_counter.times_called()); |
| 2761 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | 2665 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, params.source); |
| 2762 params.source); | |
| 2763 EXPECT_EQ(types_to_download, params.types_to_download); | 2666 EXPECT_EQ(types_to_download, params.types_to_download); |
| 2764 EXPECT_EQ(new_routing_info, params.routing_info); | 2667 EXPECT_EQ(new_routing_info, params.routing_info); |
| 2765 | 2668 |
| 2766 // Verify only the recently disabled types were purged. | 2669 // Verify only the recently disabled types were purged. |
| 2767 EXPECT_EQ(disabled_types, sync_manager_.GetTypesWithEmptyProgressMarkerToken( | 2670 EXPECT_EQ(disabled_types, sync_manager_.GetTypesWithEmptyProgressMarkerToken( |
| 2768 ProtocolTypes())); | 2671 ProtocolTypes())); |
| 2769 } | 2672 } |
| 2770 | 2673 |
| 2771 // Test that SyncManager::ClearServerData invokes the scheduler. | 2674 // Test that SyncManager::ClearServerData invokes the scheduler. |
| 2772 TEST_F(SyncManagerTestWithMockScheduler, ClearServerData) { | 2675 TEST_F(SyncManagerTestWithMockScheduler, ClearServerData) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2787 | 2690 |
| 2788 UserShare* share = sync_manager_.GetUserShare(); | 2691 UserShare* share = sync_manager_.GetUserShare(); |
| 2789 | 2692 |
| 2790 // The test harness automatically initializes all types in the routing info. | 2693 // The test harness automatically initializes all types in the routing info. |
| 2791 // Check that autofill is not among them. | 2694 // Check that autofill is not among them. |
| 2792 ASSERT_FALSE(enabled_types.Has(AUTOFILL)); | 2695 ASSERT_FALSE(enabled_types.Has(AUTOFILL)); |
| 2793 | 2696 |
| 2794 // Further ensure that the test harness did not create its root node. | 2697 // Further ensure that the test harness did not create its root node. |
| 2795 { | 2698 { |
| 2796 syncable::ReadTransaction trans(FROM_HERE, share->directory.get()); | 2699 syncable::ReadTransaction trans(FROM_HERE, share->directory.get()); |
| 2797 syncable::Entry autofill_root_node(&trans, | 2700 syncable::Entry autofill_root_node(&trans, syncable::GET_TYPE_ROOT, |
| 2798 syncable::GET_TYPE_ROOT, | |
| 2799 AUTOFILL); | 2701 AUTOFILL); |
| 2800 ASSERT_FALSE(autofill_root_node.good()); | 2702 ASSERT_FALSE(autofill_root_node.good()); |
| 2801 } | 2703 } |
| 2802 | 2704 |
| 2803 // One more redundant check. | 2705 // One more redundant check. |
| 2804 ASSERT_FALSE( | 2706 ASSERT_FALSE( |
| 2805 sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes().Has( | 2707 sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes().Has( |
| 2806 AUTOFILL)); | 2708 AUTOFILL)); |
| 2807 | 2709 |
| 2808 // Give autofill a progress marker. | 2710 // Give autofill a progress marker. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2827 prefs_marker.set_data_type_id( | 2729 prefs_marker.set_data_type_id( |
| 2828 GetSpecificsFieldNumberFromModelType(PREFERENCES)); | 2730 GetSpecificsFieldNumberFromModelType(PREFERENCES)); |
| 2829 prefs_marker.set_token("token"); | 2731 prefs_marker.set_token("token"); |
| 2830 share->directory->SetDownloadProgress(PREFERENCES, prefs_marker); | 2732 share->directory->SetDownloadProgress(PREFERENCES, prefs_marker); |
| 2831 | 2733 |
| 2832 // Add a fully synced preferences node under the root. | 2734 // Add a fully synced preferences node under the root. |
| 2833 std::string pref_client_tag = "prefABC"; | 2735 std::string pref_client_tag = "prefABC"; |
| 2834 std::string pref_hashed_tag = "hashXYZ"; | 2736 std::string pref_hashed_tag = "hashXYZ"; |
| 2835 sync_pb::EntitySpecifics pref_specifics; | 2737 sync_pb::EntitySpecifics pref_specifics; |
| 2836 AddDefaultFieldValue(PREFERENCES, &pref_specifics); | 2738 AddDefaultFieldValue(PREFERENCES, &pref_specifics); |
| 2837 int pref_meta = MakeServerNode( | 2739 int pref_meta = MakeServerNode(share, PREFERENCES, pref_client_tag, |
| 2838 share, PREFERENCES, pref_client_tag, pref_hashed_tag, pref_specifics); | 2740 pref_hashed_tag, pref_specifics); |
| 2839 | 2741 |
| 2840 // And now, the purge. | 2742 // And now, the purge. |
| 2841 EXPECT_TRUE(sync_manager_.PurgePartiallySyncedTypes()); | 2743 EXPECT_TRUE(sync_manager_.PurgePartiallySyncedTypes()); |
| 2842 | 2744 |
| 2843 // Ensure that autofill lost its progress marker, but preferences did not. | 2745 // Ensure that autofill lost its progress marker, but preferences did not. |
| 2844 ModelTypeSet empty_tokens = | 2746 ModelTypeSet empty_tokens = |
| 2845 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); | 2747 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); |
| 2846 EXPECT_TRUE(empty_tokens.Has(AUTOFILL)); | 2748 EXPECT_TRUE(empty_tokens.Has(AUTOFILL)); |
| 2847 EXPECT_FALSE(empty_tokens.Has(PREFERENCES)); | 2749 EXPECT_FALSE(empty_tokens.Has(PREFERENCES)); |
| 2848 | 2750 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2870 | 2772 |
| 2871 // Set progress markers for all types. | 2773 // Set progress markers for all types. |
| 2872 ModelTypeSet protocol_types = ProtocolTypes(); | 2774 ModelTypeSet protocol_types = ProtocolTypes(); |
| 2873 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | 2775 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); |
| 2874 iter.Inc()) { | 2776 iter.Inc()) { |
| 2875 SetProgressMarkerForType(iter.Get(), true); | 2777 SetProgressMarkerForType(iter.Get(), true); |
| 2876 } | 2778 } |
| 2877 | 2779 |
| 2878 // Verify all the enabled types remain after cleanup, and all the disabled | 2780 // Verify all the enabled types remain after cleanup, and all the disabled |
| 2879 // types were purged. | 2781 // types were purged. |
| 2880 sync_manager_.PurgeDisabledTypes(disabled_types, | 2782 sync_manager_.PurgeDisabledTypes(disabled_types, ModelTypeSet(), |
| 2881 ModelTypeSet(), | |
| 2882 ModelTypeSet()); | 2783 ModelTypeSet()); |
| 2883 EXPECT_EQ(enabled_types, | 2784 EXPECT_EQ(enabled_types, |
| 2884 sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes()); | 2785 sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes()); |
| 2885 EXPECT_EQ(disabled_types, sync_manager_.GetTypesWithEmptyProgressMarkerToken( | 2786 EXPECT_EQ(disabled_types, sync_manager_.GetTypesWithEmptyProgressMarkerToken( |
| 2886 ModelTypeSet::All())); | 2787 ModelTypeSet::All())); |
| 2887 | 2788 |
| 2888 // Disable some more types. | 2789 // Disable some more types. |
| 2889 disabled_types.Put(BOOKMARKS); | 2790 disabled_types.Put(BOOKMARKS); |
| 2890 disabled_types.Put(PREFERENCES); | 2791 disabled_types.Put(PREFERENCES); |
| 2891 ModelTypeSet new_enabled_types = | 2792 ModelTypeSet new_enabled_types = |
| 2892 Difference(ModelTypeSet::All(), disabled_types); | 2793 Difference(ModelTypeSet::All(), disabled_types); |
| 2893 | 2794 |
| 2894 // Verify only the non-disabled types remain after cleanup. | 2795 // Verify only the non-disabled types remain after cleanup. |
| 2895 sync_manager_.PurgeDisabledTypes(disabled_types, | 2796 sync_manager_.PurgeDisabledTypes(disabled_types, ModelTypeSet(), |
| 2896 ModelTypeSet(), | |
| 2897 ModelTypeSet()); | 2797 ModelTypeSet()); |
| 2898 EXPECT_EQ(new_enabled_types, | 2798 EXPECT_EQ(new_enabled_types, |
| 2899 sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes()); | 2799 sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes()); |
| 2900 EXPECT_EQ(disabled_types, sync_manager_.GetTypesWithEmptyProgressMarkerToken( | 2800 EXPECT_EQ(disabled_types, sync_manager_.GetTypesWithEmptyProgressMarkerToken( |
| 2901 ModelTypeSet::All())); | 2801 ModelTypeSet::All())); |
| 2902 } | 2802 } |
| 2903 | 2803 |
| 2904 // Test PurgeDisabledTypes properly unapplies types by deleting their local data | 2804 // Test PurgeDisabledTypes properly unapplies types by deleting their local data |
| 2905 // and preserving their server data and progress marker. | 2805 // and preserving their server data and progress marker. |
| 2906 TEST_F(SyncManagerTest, PurgeUnappliedTypes) { | 2806 TEST_F(SyncManagerTest, PurgeUnappliedTypes) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2926 // 2. Locally created preference, server unknown, unsynced | 2826 // 2. Locally created preference, server unknown, unsynced |
| 2927 // 3. Locally deleted preference, server known, unsynced | 2827 // 3. Locally deleted preference, server known, unsynced |
| 2928 // 4. Server deleted preference, locally known. | 2828 // 4. Server deleted preference, locally known. |
| 2929 // 5. Server created preference, locally unknown, unapplied. | 2829 // 5. Server created preference, locally unknown, unapplied. |
| 2930 // 6. A fully synced bookmark (no unique_client_tag). | 2830 // 6. A fully synced bookmark (no unique_client_tag). |
| 2931 UserShare* share = sync_manager_.GetUserShare(); | 2831 UserShare* share = sync_manager_.GetUserShare(); |
| 2932 sync_pb::EntitySpecifics pref_specifics; | 2832 sync_pb::EntitySpecifics pref_specifics; |
| 2933 AddDefaultFieldValue(PREFERENCES, &pref_specifics); | 2833 AddDefaultFieldValue(PREFERENCES, &pref_specifics); |
| 2934 sync_pb::EntitySpecifics bm_specifics; | 2834 sync_pb::EntitySpecifics bm_specifics; |
| 2935 AddDefaultFieldValue(BOOKMARKS, &bm_specifics); | 2835 AddDefaultFieldValue(BOOKMARKS, &bm_specifics); |
| 2936 int pref1_meta = MakeServerNode( | 2836 int pref1_meta = |
| 2937 share, PREFERENCES, "pref1", "hash1", pref_specifics); | 2837 MakeServerNode(share, PREFERENCES, "pref1", "hash1", pref_specifics); |
| 2938 int64_t pref2_meta = MakeNodeWithRoot(share, PREFERENCES, "pref2"); | 2838 int64_t pref2_meta = MakeNodeWithRoot(share, PREFERENCES, "pref2"); |
| 2939 int pref3_meta = MakeServerNode( | 2839 int pref3_meta = |
| 2940 share, PREFERENCES, "pref3", "hash3", pref_specifics); | 2840 MakeServerNode(share, PREFERENCES, "pref3", "hash3", pref_specifics); |
| 2941 int pref4_meta = MakeServerNode( | 2841 int pref4_meta = |
| 2942 share, PREFERENCES, "pref4", "hash4", pref_specifics); | 2842 MakeServerNode(share, PREFERENCES, "pref4", "hash4", pref_specifics); |
| 2943 int pref5_meta = MakeServerNode( | 2843 int pref5_meta = |
| 2944 share, PREFERENCES, "pref5", "hash5", pref_specifics); | 2844 MakeServerNode(share, PREFERENCES, "pref5", "hash5", pref_specifics); |
| 2945 int bookmark_meta = MakeServerNode( | 2845 int bookmark_meta = |
| 2946 share, BOOKMARKS, "bookmark", "", bm_specifics); | 2846 MakeServerNode(share, BOOKMARKS, "bookmark", "", bm_specifics); |
| 2947 | 2847 |
| 2948 { | 2848 { |
| 2949 syncable::WriteTransaction trans(FROM_HERE, | 2849 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 2950 syncable::SYNCER, | |
| 2951 share->directory.get()); | 2850 share->directory.get()); |
| 2952 // Pref's 1 and 2 are already set up properly. | 2851 // Pref's 1 and 2 are already set up properly. |
| 2953 // Locally delete pref 3. | 2852 // Locally delete pref 3. |
| 2954 syncable::MutableEntry pref3(&trans, GET_BY_HANDLE, pref3_meta); | 2853 syncable::MutableEntry pref3(&trans, GET_BY_HANDLE, pref3_meta); |
| 2955 pref3.PutIsDel(true); | 2854 pref3.PutIsDel(true); |
| 2956 pref3.PutIsUnsynced(true); | 2855 pref3.PutIsUnsynced(true); |
| 2957 // Delete pref 4 at the server. | 2856 // Delete pref 4 at the server. |
| 2958 syncable::MutableEntry pref4(&trans, GET_BY_HANDLE, pref4_meta); | 2857 syncable::MutableEntry pref4(&trans, GET_BY_HANDLE, pref4_meta); |
| 2959 pref4.PutServerIsDel(true); | 2858 pref4.PutServerIsDel(true); |
| 2960 pref4.PutIsUnappliedUpdate(true); | 2859 pref4.PutIsUnappliedUpdate(true); |
| 2961 pref4.PutServerVersion(2); | 2860 pref4.PutServerVersion(2); |
| 2962 // Pref 5 is an new unapplied update. | 2861 // Pref 5 is an new unapplied update. |
| 2963 syncable::MutableEntry pref5(&trans, GET_BY_HANDLE, pref5_meta); | 2862 syncable::MutableEntry pref5(&trans, GET_BY_HANDLE, pref5_meta); |
| 2964 pref5.PutIsUnappliedUpdate(true); | 2863 pref5.PutIsUnappliedUpdate(true); |
| 2965 pref5.PutIsDel(true); | 2864 pref5.PutIsDel(true); |
| 2966 pref5.PutBaseVersion(-1); | 2865 pref5.PutBaseVersion(-1); |
| 2967 // Bookmark is already set up properly | 2866 // Bookmark is already set up properly |
| 2968 } | 2867 } |
| 2969 | 2868 |
| 2970 // Take a snapshot to clear all the dirty bits. | 2869 // Take a snapshot to clear all the dirty bits. |
| 2971 share->directory.get()->SaveChanges(); | 2870 share->directory.get()->SaveChanges(); |
| 2972 | 2871 |
| 2973 // Now request a purge for the unapplied types. | 2872 // Now request a purge for the unapplied types. |
| 2974 disabled_types.PutAll(unapplied_types); | 2873 disabled_types.PutAll(unapplied_types); |
| 2975 sync_manager_.PurgeDisabledTypes(disabled_types, | 2874 sync_manager_.PurgeDisabledTypes(disabled_types, ModelTypeSet(), |
| 2976 ModelTypeSet(), | |
| 2977 unapplied_types); | 2875 unapplied_types); |
| 2978 | 2876 |
| 2979 // Verify the unapplied types still have progress markers and initial sync | 2877 // Verify the unapplied types still have progress markers and initial sync |
| 2980 // ended after cleanup. | 2878 // ended after cleanup. |
| 2981 EXPECT_TRUE( | 2879 EXPECT_TRUE( |
| 2982 sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes().HasAll( | 2880 sync_manager_.GetUserShare()->directory->InitialSyncEndedTypes().HasAll( |
| 2983 unapplied_types)); | 2881 unapplied_types)); |
| 2984 EXPECT_TRUE( | 2882 EXPECT_TRUE( |
| 2985 sync_manager_.GetTypesWithEmptyProgressMarkerToken(unapplied_types). | 2883 sync_manager_.GetTypesWithEmptyProgressMarkerToken(unapplied_types) |
| 2986 Empty()); | 2884 .Empty()); |
| 2987 | 2885 |
| 2988 // Ensure the items were unapplied as necessary. | 2886 // Ensure the items were unapplied as necessary. |
| 2989 { | 2887 { |
| 2990 syncable::ReadTransaction trans(FROM_HERE, share->directory.get()); | 2888 syncable::ReadTransaction trans(FROM_HERE, share->directory.get()); |
| 2991 syncable::Entry pref_node(&trans, GET_BY_HANDLE, pref1_meta); | 2889 syncable::Entry pref_node(&trans, GET_BY_HANDLE, pref1_meta); |
| 2992 ASSERT_TRUE(pref_node.good()); | 2890 ASSERT_TRUE(pref_node.good()); |
| 2993 EXPECT_TRUE(pref_node.GetKernelCopy().is_dirty()); | 2891 EXPECT_TRUE(pref_node.GetKernelCopy().is_dirty()); |
| 2994 EXPECT_FALSE(pref_node.GetIsUnsynced()); | 2892 EXPECT_FALSE(pref_node.GetIsUnsynced()); |
| 2995 EXPECT_TRUE(pref_node.GetIsUnappliedUpdate()); | 2893 EXPECT_TRUE(pref_node.GetIsUnappliedUpdate()); |
| 2996 EXPECT_TRUE(pref_node.GetIsDel()); | 2894 EXPECT_TRUE(pref_node.GetIsDel()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3058 const ImmutableChangeRecordList& changes) override { | 2956 const ImmutableChangeRecordList& changes) override { |
| 3059 last_changes_ = changes; | 2957 last_changes_ = changes; |
| 3060 } | 2958 } |
| 3061 | 2959 |
| 3062 void OnChangesComplete(ModelType model_type) override {} | 2960 void OnChangesComplete(ModelType model_type) override {} |
| 3063 | 2961 |
| 3064 const ImmutableChangeRecordList& GetRecentChangeList() { | 2962 const ImmutableChangeRecordList& GetRecentChangeList() { |
| 3065 return last_changes_; | 2963 return last_changes_; |
| 3066 } | 2964 } |
| 3067 | 2965 |
| 3068 UserShare* share() { | 2966 UserShare* share() { return sync_manager_.GetUserShare(); } |
| 3069 return sync_manager_.GetUserShare(); | |
| 3070 } | |
| 3071 | 2967 |
| 3072 // Set some flags so our nodes reasonably approximate the real world scenario | 2968 // Set some flags so our nodes reasonably approximate the real world scenario |
| 3073 // and can get past CheckTreeInvariants. | 2969 // and can get past CheckTreeInvariants. |
| 3074 // | 2970 // |
| 3075 // It's never going to be truly accurate, since we're squashing update | 2971 // It's never going to be truly accurate, since we're squashing update |
| 3076 // receipt, processing and application into a single transaction. | 2972 // receipt, processing and application into a single transaction. |
| 3077 void SetNodeProperties(syncable::MutableEntry *entry) { | 2973 void SetNodeProperties(syncable::MutableEntry* entry) { |
| 3078 entry->PutId(id_factory_.NewServerId()); | 2974 entry->PutId(id_factory_.NewServerId()); |
| 3079 entry->PutBaseVersion(10); | 2975 entry->PutBaseVersion(10); |
| 3080 entry->PutServerVersion(10); | 2976 entry->PutServerVersion(10); |
| 3081 } | 2977 } |
| 3082 | 2978 |
| 3083 // Looks for the given change in the list. Returns the index at which it was | 2979 // Looks for the given change in the list. Returns the index at which it was |
| 3084 // found. Returns -1 on lookup failure. | 2980 // found. Returns -1 on lookup failure. |
| 3085 size_t FindChangeInList(int64_t id, ChangeRecord::Action action) { | 2981 size_t FindChangeInList(int64_t id, ChangeRecord::Action action) { |
| 3086 SCOPED_TRACE(id); | 2982 SCOPED_TRACE(id); |
| 3087 for (size_t i = 0; i < last_changes_.Get().size(); ++i) { | 2983 for (size_t i = 0; i < last_changes_.Get().size(); ++i) { |
| 3088 if (last_changes_.Get()[i].id == id | 2984 if (last_changes_.Get()[i].id == id && |
| 3089 && last_changes_.Get()[i].action == action) { | 2985 last_changes_.Get()[i].action == action) { |
| 3090 return i; | 2986 return i; |
| 3091 } | 2987 } |
| 3092 } | 2988 } |
| 3093 ADD_FAILURE() << "Failed to find specified change"; | 2989 ADD_FAILURE() << "Failed to find specified change"; |
| 3094 return static_cast<size_t>(-1); | 2990 return static_cast<size_t>(-1); |
| 3095 } | 2991 } |
| 3096 | 2992 |
| 3097 // Returns the current size of the change list. | 2993 // Returns the current size of the change list. |
| 3098 // | 2994 // |
| 3099 // Note that spurious changes do not necessarily indicate a problem. | 2995 // Note that spurious changes do not necessarily indicate a problem. |
| 3100 // Assertions on change list size can help detect problems, but it may be | 2996 // Assertions on change list size can help detect problems, but it may be |
| 3101 // necessary to reduce their strictness if the implementation changes. | 2997 // necessary to reduce their strictness if the implementation changes. |
| 3102 size_t GetChangeListSize() { | 2998 size_t GetChangeListSize() { return last_changes_.Get().size(); } |
| 3103 return last_changes_.Get().size(); | |
| 3104 } | |
| 3105 | 2999 |
| 3106 void ClearChangeList() { last_changes_ = ImmutableChangeRecordList(); } | 3000 void ClearChangeList() { last_changes_ = ImmutableChangeRecordList(); } |
| 3107 | 3001 |
| 3108 protected: | 3002 protected: |
| 3109 ImmutableChangeRecordList last_changes_; | 3003 ImmutableChangeRecordList last_changes_; |
| 3110 TestIdFactory id_factory_; | 3004 TestIdFactory id_factory_; |
| 3111 }; | 3005 }; |
| 3112 | 3006 |
| 3113 // Test creation of a folder and a bookmark. | 3007 // Test creation of a folder and a bookmark. |
| 3114 TEST_F(SyncManagerChangeProcessingTest, AddBookmarks) { | 3008 TEST_F(SyncManagerChangeProcessingTest, AddBookmarks) { |
| 3115 int64_t type_root = GetIdForDataType(BOOKMARKS); | 3009 int64_t type_root = GetIdForDataType(BOOKMARKS); |
| 3116 int64_t folder_id = kInvalidId; | 3010 int64_t folder_id = kInvalidId; |
| 3117 int64_t child_id = kInvalidId; | 3011 int64_t child_id = kInvalidId; |
| 3118 | 3012 |
| 3119 // Create a folder and a bookmark under it. | 3013 // Create a folder and a bookmark under it. |
| 3120 { | 3014 { |
| 3121 syncable::WriteTransaction trans( | 3015 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 3122 FROM_HERE, syncable::SYNCER, share()->directory.get()); | 3016 share()->directory.get()); |
| 3123 syncable::Entry root(&trans, syncable::GET_BY_HANDLE, type_root); | 3017 syncable::Entry root(&trans, syncable::GET_BY_HANDLE, type_root); |
| 3124 ASSERT_TRUE(root.good()); | 3018 ASSERT_TRUE(root.good()); |
| 3125 | 3019 |
| 3126 syncable::MutableEntry folder(&trans, syncable::CREATE, | 3020 syncable::MutableEntry folder(&trans, syncable::CREATE, BOOKMARKS, |
| 3127 BOOKMARKS, root.GetId(), "folder"); | 3021 root.GetId(), "folder"); |
| 3128 ASSERT_TRUE(folder.good()); | 3022 ASSERT_TRUE(folder.good()); |
| 3129 SetNodeProperties(&folder); | 3023 SetNodeProperties(&folder); |
| 3130 folder.PutIsDir(true); | 3024 folder.PutIsDir(true); |
| 3131 folder_id = folder.GetMetahandle(); | 3025 folder_id = folder.GetMetahandle(); |
| 3132 | 3026 |
| 3133 syncable::MutableEntry child(&trans, syncable::CREATE, | 3027 syncable::MutableEntry child(&trans, syncable::CREATE, BOOKMARKS, |
| 3134 BOOKMARKS, folder.GetId(), "child"); | 3028 folder.GetId(), "child"); |
| 3135 ASSERT_TRUE(child.good()); | 3029 ASSERT_TRUE(child.good()); |
| 3136 SetNodeProperties(&child); | 3030 SetNodeProperties(&child); |
| 3137 child_id = child.GetMetahandle(); | 3031 child_id = child.GetMetahandle(); |
| 3138 } | 3032 } |
| 3139 | 3033 |
| 3140 // The closing of the above scope will delete the transaction. Its processed | 3034 // The closing of the above scope will delete the transaction. Its processed |
| 3141 // changes should be waiting for us in a member of the test harness. | 3035 // changes should be waiting for us in a member of the test harness. |
| 3142 EXPECT_EQ(2UL, GetChangeListSize()); | 3036 EXPECT_EQ(2UL, GetChangeListSize()); |
| 3143 | 3037 |
| 3144 // We don't need to check these return values here. The function will add a | 3038 // We don't need to check these return values here. The function will add a |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3186 } | 3080 } |
| 3187 | 3081 |
| 3188 // Test moving a bookmark into an empty folder. | 3082 // Test moving a bookmark into an empty folder. |
| 3189 TEST_F(SyncManagerChangeProcessingTest, MoveBookmarkIntoEmptyFolder) { | 3083 TEST_F(SyncManagerChangeProcessingTest, MoveBookmarkIntoEmptyFolder) { |
| 3190 int64_t type_root = GetIdForDataType(BOOKMARKS); | 3084 int64_t type_root = GetIdForDataType(BOOKMARKS); |
| 3191 int64_t folder_b_id = kInvalidId; | 3085 int64_t folder_b_id = kInvalidId; |
| 3192 int64_t child_id = kInvalidId; | 3086 int64_t child_id = kInvalidId; |
| 3193 | 3087 |
| 3194 // Create two folders. Place a child under folder A. | 3088 // Create two folders. Place a child under folder A. |
| 3195 { | 3089 { |
| 3196 syncable::WriteTransaction trans( | 3090 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 3197 FROM_HERE, syncable::SYNCER, share()->directory.get()); | 3091 share()->directory.get()); |
| 3198 syncable::Entry root(&trans, syncable::GET_BY_HANDLE, type_root); | 3092 syncable::Entry root(&trans, syncable::GET_BY_HANDLE, type_root); |
| 3199 ASSERT_TRUE(root.good()); | 3093 ASSERT_TRUE(root.good()); |
| 3200 | 3094 |
| 3201 syncable::MutableEntry folder_a(&trans, syncable::CREATE, | 3095 syncable::MutableEntry folder_a(&trans, syncable::CREATE, BOOKMARKS, |
| 3202 BOOKMARKS, root.GetId(), "folderA"); | 3096 root.GetId(), "folderA"); |
| 3203 ASSERT_TRUE(folder_a.good()); | 3097 ASSERT_TRUE(folder_a.good()); |
| 3204 SetNodeProperties(&folder_a); | 3098 SetNodeProperties(&folder_a); |
| 3205 folder_a.PutIsDir(true); | 3099 folder_a.PutIsDir(true); |
| 3206 | 3100 |
| 3207 syncable::MutableEntry folder_b(&trans, syncable::CREATE, | 3101 syncable::MutableEntry folder_b(&trans, syncable::CREATE, BOOKMARKS, |
| 3208 BOOKMARKS, root.GetId(), "folderB"); | 3102 root.GetId(), "folderB"); |
| 3209 ASSERT_TRUE(folder_b.good()); | 3103 ASSERT_TRUE(folder_b.good()); |
| 3210 SetNodeProperties(&folder_b); | 3104 SetNodeProperties(&folder_b); |
| 3211 folder_b.PutIsDir(true); | 3105 folder_b.PutIsDir(true); |
| 3212 folder_b_id = folder_b.GetMetahandle(); | 3106 folder_b_id = folder_b.GetMetahandle(); |
| 3213 | 3107 |
| 3214 syncable::MutableEntry child(&trans, syncable::CREATE, | 3108 syncable::MutableEntry child(&trans, syncable::CREATE, BOOKMARKS, |
| 3215 BOOKMARKS, folder_a.GetId(), | 3109 folder_a.GetId(), "child"); |
| 3216 "child"); | |
| 3217 ASSERT_TRUE(child.good()); | 3110 ASSERT_TRUE(child.good()); |
| 3218 SetNodeProperties(&child); | 3111 SetNodeProperties(&child); |
| 3219 child_id = child.GetMetahandle(); | 3112 child_id = child.GetMetahandle(); |
| 3220 } | 3113 } |
| 3221 | 3114 |
| 3222 // Close that transaction. The above was to setup the initial scenario. The | 3115 // Close that transaction. The above was to setup the initial scenario. The |
| 3223 // real test starts now. | 3116 // real test starts now. |
| 3224 | 3117 |
| 3225 // Move the child from folder A to folder B. | 3118 // Move the child from folder A to folder B. |
| 3226 { | 3119 { |
| 3227 syncable::WriteTransaction trans( | 3120 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 3228 FROM_HERE, syncable::SYNCER, share()->directory.get()); | 3121 share()->directory.get()); |
| 3229 | 3122 |
| 3230 syncable::Entry folder_b(&trans, syncable::GET_BY_HANDLE, folder_b_id); | 3123 syncable::Entry folder_b(&trans, syncable::GET_BY_HANDLE, folder_b_id); |
| 3231 syncable::MutableEntry child(&trans, syncable::GET_BY_HANDLE, child_id); | 3124 syncable::MutableEntry child(&trans, syncable::GET_BY_HANDLE, child_id); |
| 3232 | 3125 |
| 3233 child.PutParentId(folder_b.GetId()); | 3126 child.PutParentId(folder_b.GetId()); |
| 3234 } | 3127 } |
| 3235 | 3128 |
| 3236 EXPECT_EQ(1UL, GetChangeListSize()); | 3129 EXPECT_EQ(1UL, GetChangeListSize()); |
| 3237 | 3130 |
| 3238 // Verify that this was detected as a real change. An early version of the | 3131 // Verify that this was detected as a real change. An early version of the |
| 3239 // UniquePosition code had a bug where moves from one folder to another were | 3132 // UniquePosition code had a bug where moves from one folder to another were |
| 3240 // ignored unless the moved node's UniquePosition value was also changed in | 3133 // ignored unless the moved node's UniquePosition value was also changed in |
| 3241 // some way. | 3134 // some way. |
| 3242 FindChangeInList(child_id, ChangeRecord::ACTION_UPDATE); | 3135 FindChangeInList(child_id, ChangeRecord::ACTION_UPDATE); |
| 3243 } | 3136 } |
| 3244 | 3137 |
| 3245 // Test moving a bookmark into a non-empty folder. | 3138 // Test moving a bookmark into a non-empty folder. |
| 3246 TEST_F(SyncManagerChangeProcessingTest, MoveIntoPopulatedFolder) { | 3139 TEST_F(SyncManagerChangeProcessingTest, MoveIntoPopulatedFolder) { |
| 3247 int64_t type_root = GetIdForDataType(BOOKMARKS); | 3140 int64_t type_root = GetIdForDataType(BOOKMARKS); |
| 3248 int64_t child_a_id = kInvalidId; | 3141 int64_t child_a_id = kInvalidId; |
| 3249 int64_t child_b_id = kInvalidId; | 3142 int64_t child_b_id = kInvalidId; |
| 3250 | 3143 |
| 3251 // Create two folders. Place one child each under folder A and folder B. | 3144 // Create two folders. Place one child each under folder A and folder B. |
| 3252 { | 3145 { |
| 3253 syncable::WriteTransaction trans( | 3146 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 3254 FROM_HERE, syncable::SYNCER, share()->directory.get()); | 3147 share()->directory.get()); |
| 3255 syncable::Entry root(&trans, syncable::GET_BY_HANDLE, type_root); | 3148 syncable::Entry root(&trans, syncable::GET_BY_HANDLE, type_root); |
| 3256 ASSERT_TRUE(root.good()); | 3149 ASSERT_TRUE(root.good()); |
| 3257 | 3150 |
| 3258 syncable::MutableEntry folder_a(&trans, syncable::CREATE, | 3151 syncable::MutableEntry folder_a(&trans, syncable::CREATE, BOOKMARKS, |
| 3259 BOOKMARKS, root.GetId(), "folderA"); | 3152 root.GetId(), "folderA"); |
| 3260 ASSERT_TRUE(folder_a.good()); | 3153 ASSERT_TRUE(folder_a.good()); |
| 3261 SetNodeProperties(&folder_a); | 3154 SetNodeProperties(&folder_a); |
| 3262 folder_a.PutIsDir(true); | 3155 folder_a.PutIsDir(true); |
| 3263 | 3156 |
| 3264 syncable::MutableEntry folder_b(&trans, syncable::CREATE, | 3157 syncable::MutableEntry folder_b(&trans, syncable::CREATE, BOOKMARKS, |
| 3265 BOOKMARKS, root.GetId(), "folderB"); | 3158 root.GetId(), "folderB"); |
| 3266 ASSERT_TRUE(folder_b.good()); | 3159 ASSERT_TRUE(folder_b.good()); |
| 3267 SetNodeProperties(&folder_b); | 3160 SetNodeProperties(&folder_b); |
| 3268 folder_b.PutIsDir(true); | 3161 folder_b.PutIsDir(true); |
| 3269 | 3162 |
| 3270 syncable::MutableEntry child_a(&trans, syncable::CREATE, | 3163 syncable::MutableEntry child_a(&trans, syncable::CREATE, BOOKMARKS, |
| 3271 BOOKMARKS, folder_a.GetId(), | 3164 folder_a.GetId(), "childA"); |
| 3272 "childA"); | |
| 3273 ASSERT_TRUE(child_a.good()); | 3165 ASSERT_TRUE(child_a.good()); |
| 3274 SetNodeProperties(&child_a); | 3166 SetNodeProperties(&child_a); |
| 3275 child_a_id = child_a.GetMetahandle(); | 3167 child_a_id = child_a.GetMetahandle(); |
| 3276 | 3168 |
| 3277 syncable::MutableEntry child_b(&trans, syncable::CREATE, | 3169 syncable::MutableEntry child_b(&trans, syncable::CREATE, BOOKMARKS, |
| 3278 BOOKMARKS, folder_b.GetId(), | 3170 folder_b.GetId(), "childB"); |
| 3279 "childB"); | |
| 3280 SetNodeProperties(&child_b); | 3171 SetNodeProperties(&child_b); |
| 3281 child_b_id = child_b.GetMetahandle(); | 3172 child_b_id = child_b.GetMetahandle(); |
| 3282 } | 3173 } |
| 3283 | 3174 |
| 3284 // Close that transaction. The above was to setup the initial scenario. The | 3175 // Close that transaction. The above was to setup the initial scenario. The |
| 3285 // real test starts now. | 3176 // real test starts now. |
| 3286 | 3177 |
| 3287 { | 3178 { |
| 3288 syncable::WriteTransaction trans( | 3179 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 3289 FROM_HERE, syncable::SYNCER, share()->directory.get()); | 3180 share()->directory.get()); |
| 3290 | 3181 |
| 3291 syncable::MutableEntry child_a(&trans, syncable::GET_BY_HANDLE, child_a_id); | 3182 syncable::MutableEntry child_a(&trans, syncable::GET_BY_HANDLE, child_a_id); |
| 3292 syncable::MutableEntry child_b(&trans, syncable::GET_BY_HANDLE, child_b_id); | 3183 syncable::MutableEntry child_b(&trans, syncable::GET_BY_HANDLE, child_b_id); |
| 3293 | 3184 |
| 3294 // Move child A from folder A to folder B and update its position. | 3185 // Move child A from folder A to folder B and update its position. |
| 3295 child_a.PutParentId(child_b.GetParentId()); | 3186 child_a.PutParentId(child_b.GetParentId()); |
| 3296 child_a.PutPredecessor(child_b.GetId()); | 3187 child_a.PutPredecessor(child_b.GetId()); |
| 3297 } | 3188 } |
| 3298 | 3189 |
| 3299 EXPECT_EQ(1UL, GetChangeListSize()); | 3190 EXPECT_EQ(1UL, GetChangeListSize()); |
| 3300 | 3191 |
| 3301 // Verify that only child a is in the change list. | 3192 // Verify that only child a is in the change list. |
| 3302 // (This function will add a failure if the lookup fails.) | 3193 // (This function will add a failure if the lookup fails.) |
| 3303 FindChangeInList(child_a_id, ChangeRecord::ACTION_UPDATE); | 3194 FindChangeInList(child_a_id, ChangeRecord::ACTION_UPDATE); |
| 3304 } | 3195 } |
| 3305 | 3196 |
| 3306 // Tests the ordering of deletion changes. | 3197 // Tests the ordering of deletion changes. |
| 3307 TEST_F(SyncManagerChangeProcessingTest, DeletionsAndChanges) { | 3198 TEST_F(SyncManagerChangeProcessingTest, DeletionsAndChanges) { |
| 3308 int64_t type_root = GetIdForDataType(BOOKMARKS); | 3199 int64_t type_root = GetIdForDataType(BOOKMARKS); |
| 3309 int64_t folder_a_id = kInvalidId; | 3200 int64_t folder_a_id = kInvalidId; |
| 3310 int64_t folder_b_id = kInvalidId; | 3201 int64_t folder_b_id = kInvalidId; |
| 3311 int64_t child_id = kInvalidId; | 3202 int64_t child_id = kInvalidId; |
| 3312 | 3203 |
| 3313 // Create two folders. Place a child under folder A. | 3204 // Create two folders. Place a child under folder A. |
| 3314 { | 3205 { |
| 3315 syncable::WriteTransaction trans( | 3206 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 3316 FROM_HERE, syncable::SYNCER, share()->directory.get()); | 3207 share()->directory.get()); |
| 3317 syncable::Entry root(&trans, syncable::GET_BY_HANDLE, type_root); | 3208 syncable::Entry root(&trans, syncable::GET_BY_HANDLE, type_root); |
| 3318 ASSERT_TRUE(root.good()); | 3209 ASSERT_TRUE(root.good()); |
| 3319 | 3210 |
| 3320 syncable::MutableEntry folder_a(&trans, syncable::CREATE, | 3211 syncable::MutableEntry folder_a(&trans, syncable::CREATE, BOOKMARKS, |
| 3321 BOOKMARKS, root.GetId(), "folderA"); | 3212 root.GetId(), "folderA"); |
| 3322 ASSERT_TRUE(folder_a.good()); | 3213 ASSERT_TRUE(folder_a.good()); |
| 3323 SetNodeProperties(&folder_a); | 3214 SetNodeProperties(&folder_a); |
| 3324 folder_a.PutIsDir(true); | 3215 folder_a.PutIsDir(true); |
| 3325 folder_a_id = folder_a.GetMetahandle(); | 3216 folder_a_id = folder_a.GetMetahandle(); |
| 3326 | 3217 |
| 3327 syncable::MutableEntry folder_b(&trans, syncable::CREATE, | 3218 syncable::MutableEntry folder_b(&trans, syncable::CREATE, BOOKMARKS, |
| 3328 BOOKMARKS, root.GetId(), "folderB"); | 3219 root.GetId(), "folderB"); |
| 3329 ASSERT_TRUE(folder_b.good()); | 3220 ASSERT_TRUE(folder_b.good()); |
| 3330 SetNodeProperties(&folder_b); | 3221 SetNodeProperties(&folder_b); |
| 3331 folder_b.PutIsDir(true); | 3222 folder_b.PutIsDir(true); |
| 3332 folder_b_id = folder_b.GetMetahandle(); | 3223 folder_b_id = folder_b.GetMetahandle(); |
| 3333 | 3224 |
| 3334 syncable::MutableEntry child(&trans, syncable::CREATE, | 3225 syncable::MutableEntry child(&trans, syncable::CREATE, BOOKMARKS, |
| 3335 BOOKMARKS, folder_a.GetId(), | 3226 folder_a.GetId(), "child"); |
| 3336 "child"); | |
| 3337 ASSERT_TRUE(child.good()); | 3227 ASSERT_TRUE(child.good()); |
| 3338 SetNodeProperties(&child); | 3228 SetNodeProperties(&child); |
| 3339 child_id = child.GetMetahandle(); | 3229 child_id = child.GetMetahandle(); |
| 3340 } | 3230 } |
| 3341 | 3231 |
| 3342 // Close that transaction. The above was to setup the initial scenario. The | 3232 // Close that transaction. The above was to setup the initial scenario. The |
| 3343 // real test starts now. | 3233 // real test starts now. |
| 3344 | 3234 |
| 3345 { | 3235 { |
| 3346 syncable::WriteTransaction trans( | 3236 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 3347 FROM_HERE, syncable::SYNCER, share()->directory.get()); | 3237 share()->directory.get()); |
| 3348 | 3238 |
| 3349 syncable::MutableEntry folder_a( | 3239 syncable::MutableEntry folder_a(&trans, syncable::GET_BY_HANDLE, |
| 3350 &trans, syncable::GET_BY_HANDLE, folder_a_id); | 3240 folder_a_id); |
| 3351 syncable::MutableEntry folder_b( | 3241 syncable::MutableEntry folder_b(&trans, syncable::GET_BY_HANDLE, |
| 3352 &trans, syncable::GET_BY_HANDLE, folder_b_id); | 3242 folder_b_id); |
| 3353 syncable::MutableEntry child(&trans, syncable::GET_BY_HANDLE, child_id); | 3243 syncable::MutableEntry child(&trans, syncable::GET_BY_HANDLE, child_id); |
| 3354 | 3244 |
| 3355 // Delete folder B and its child. | 3245 // Delete folder B and its child. |
| 3356 child.PutIsDel(true); | 3246 child.PutIsDel(true); |
| 3357 folder_b.PutIsDel(true); | 3247 folder_b.PutIsDel(true); |
| 3358 | 3248 |
| 3359 // Make an unrelated change to folder A. | 3249 // Make an unrelated change to folder A. |
| 3360 folder_a.PutNonUniqueName("NewNameA"); | 3250 folder_a.PutNonUniqueName("NewNameA"); |
| 3361 } | 3251 } |
| 3362 | 3252 |
| 3363 EXPECT_EQ(3UL, GetChangeListSize()); | 3253 EXPECT_EQ(3UL, GetChangeListSize()); |
| 3364 | 3254 |
| 3365 size_t folder_a_pos = | 3255 size_t folder_a_pos = |
| 3366 FindChangeInList(folder_a_id, ChangeRecord::ACTION_UPDATE); | 3256 FindChangeInList(folder_a_id, ChangeRecord::ACTION_UPDATE); |
| 3367 size_t folder_b_pos = | 3257 size_t folder_b_pos = |
| 3368 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); | 3258 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); |
| 3369 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); | 3259 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); |
| 3370 | 3260 |
| 3371 // Deletes should appear before updates. | 3261 // Deletes should appear before updates. |
| 3372 EXPECT_LT(child_pos, folder_a_pos); | 3262 EXPECT_LT(child_pos, folder_a_pos); |
| 3373 EXPECT_LT(folder_b_pos, folder_a_pos); | 3263 EXPECT_LT(folder_b_pos, folder_a_pos); |
| 3374 } | 3264 } |
| 3375 | 3265 |
| 3376 // See that attachment metadata changes are not filtered out by | 3266 // See that attachment metadata changes are not filtered out by |
| 3377 // SyncManagerImpl::VisiblePropertiesDiffer. | 3267 // SyncManagerImpl::VisiblePropertiesDiffer. |
| 3378 TEST_F(SyncManagerChangeProcessingTest, AttachmentMetadataOnlyChanges) { | 3268 TEST_F(SyncManagerChangeProcessingTest, AttachmentMetadataOnlyChanges) { |
| 3379 // Create an article with no attachments. See that a change is generated. | 3269 // Create an article with no attachments. See that a change is generated. |
| 3380 int64_t article_id = kInvalidId; | 3270 int64_t article_id = kInvalidId; |
| 3381 { | 3271 { |
| 3382 syncable::WriteTransaction trans( | 3272 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 3383 FROM_HERE, syncable::SYNCER, share()->directory.get()); | 3273 share()->directory.get()); |
| 3384 int64_t type_root = GetIdForDataType(ARTICLES); | 3274 int64_t type_root = GetIdForDataType(ARTICLES); |
| 3385 syncable::Entry root(&trans, syncable::GET_BY_HANDLE, type_root); | 3275 syncable::Entry root(&trans, syncable::GET_BY_HANDLE, type_root); |
| 3386 ASSERT_TRUE(root.good()); | 3276 ASSERT_TRUE(root.good()); |
| 3387 syncable::MutableEntry article( | 3277 syncable::MutableEntry article(&trans, syncable::CREATE, ARTICLES, |
| 3388 &trans, syncable::CREATE, ARTICLES, root.GetId(), "article"); | 3278 root.GetId(), "article"); |
| 3389 ASSERT_TRUE(article.good()); | 3279 ASSERT_TRUE(article.good()); |
| 3390 SetNodeProperties(&article); | 3280 SetNodeProperties(&article); |
| 3391 article_id = article.GetMetahandle(); | 3281 article_id = article.GetMetahandle(); |
| 3392 } | 3282 } |
| 3393 ASSERT_EQ(1UL, GetChangeListSize()); | 3283 ASSERT_EQ(1UL, GetChangeListSize()); |
| 3394 FindChangeInList(article_id, ChangeRecord::ACTION_ADD); | 3284 FindChangeInList(article_id, ChangeRecord::ACTION_ADD); |
| 3395 ClearChangeList(); | 3285 ClearChangeList(); |
| 3396 | 3286 |
| 3397 // Modify the article by adding one attachment. Don't touch anything else. | 3287 // Modify the article by adding one attachment. Don't touch anything else. |
| 3398 // See that a change is generated. | 3288 // See that a change is generated. |
| 3399 { | 3289 { |
| 3400 syncable::WriteTransaction trans( | 3290 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 3401 FROM_HERE, syncable::SYNCER, share()->directory.get()); | 3291 share()->directory.get()); |
| 3402 syncable::MutableEntry article(&trans, syncable::GET_BY_HANDLE, article_id); | 3292 syncable::MutableEntry article(&trans, syncable::GET_BY_HANDLE, article_id); |
| 3403 sync_pb::AttachmentMetadata metadata; | 3293 sync_pb::AttachmentMetadata metadata; |
| 3404 *metadata.add_record()->mutable_id() = CreateAttachmentIdProto(0, 0); | 3294 *metadata.add_record()->mutable_id() = CreateAttachmentIdProto(0, 0); |
| 3405 article.PutAttachmentMetadata(metadata); | 3295 article.PutAttachmentMetadata(metadata); |
| 3406 } | 3296 } |
| 3407 ASSERT_EQ(1UL, GetChangeListSize()); | 3297 ASSERT_EQ(1UL, GetChangeListSize()); |
| 3408 FindChangeInList(article_id, ChangeRecord::ACTION_UPDATE); | 3298 FindChangeInList(article_id, ChangeRecord::ACTION_UPDATE); |
| 3409 ClearChangeList(); | 3299 ClearChangeList(); |
| 3410 | 3300 |
| 3411 // Modify the article by replacing its attachment with a different one. See | 3301 // Modify the article by replacing its attachment with a different one. See |
| 3412 // that a change is generated. | 3302 // that a change is generated. |
| 3413 { | 3303 { |
| 3414 syncable::WriteTransaction trans( | 3304 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 3415 FROM_HERE, syncable::SYNCER, share()->directory.get()); | 3305 share()->directory.get()); |
| 3416 syncable::MutableEntry article(&trans, syncable::GET_BY_HANDLE, article_id); | 3306 syncable::MutableEntry article(&trans, syncable::GET_BY_HANDLE, article_id); |
| 3417 sync_pb::AttachmentMetadata metadata = article.GetAttachmentMetadata(); | 3307 sync_pb::AttachmentMetadata metadata = article.GetAttachmentMetadata(); |
| 3418 *metadata.add_record()->mutable_id() = CreateAttachmentIdProto(0, 0); | 3308 *metadata.add_record()->mutable_id() = CreateAttachmentIdProto(0, 0); |
| 3419 article.PutAttachmentMetadata(metadata); | 3309 article.PutAttachmentMetadata(metadata); |
| 3420 } | 3310 } |
| 3421 ASSERT_EQ(1UL, GetChangeListSize()); | 3311 ASSERT_EQ(1UL, GetChangeListSize()); |
| 3422 FindChangeInList(article_id, ChangeRecord::ACTION_UPDATE); | 3312 FindChangeInList(article_id, ChangeRecord::ACTION_UPDATE); |
| 3423 ClearChangeList(); | 3313 ClearChangeList(); |
| 3424 | 3314 |
| 3425 // Modify the article by replacing its attachment metadata with the same | 3315 // Modify the article by replacing its attachment metadata with the same |
| 3426 // attachment metadata. No change should be generated. | 3316 // attachment metadata. No change should be generated. |
| 3427 { | 3317 { |
| 3428 syncable::WriteTransaction trans( | 3318 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, |
| 3429 FROM_HERE, syncable::SYNCER, share()->directory.get()); | 3319 share()->directory.get()); |
| 3430 syncable::MutableEntry article(&trans, syncable::GET_BY_HANDLE, article_id); | 3320 syncable::MutableEntry article(&trans, syncable::GET_BY_HANDLE, article_id); |
| 3431 article.PutAttachmentMetadata(article.GetAttachmentMetadata()); | 3321 article.PutAttachmentMetadata(article.GetAttachmentMetadata()); |
| 3432 } | 3322 } |
| 3433 ASSERT_EQ(0UL, GetChangeListSize()); | 3323 ASSERT_EQ(0UL, GetChangeListSize()); |
| 3434 } | 3324 } |
| 3435 | 3325 |
| 3436 // During initialization SyncManagerImpl loads sqlite database. If it fails to | 3326 // During initialization SyncManagerImpl loads sqlite database. If it fails to |
| 3437 // do so it should fail initialization. This test verifies this behavior. | 3327 // do so it should fail initialization. This test verifies this behavior. |
| 3438 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides | 3328 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides |
| 3439 // InternalComponentsFactory to return DirectoryBackingStore that always fails | 3329 // InternalComponentsFactory to return DirectoryBackingStore that always fails |
| 3440 // to load. | 3330 // to load. |
| 3441 class SyncManagerInitInvalidStorageTest : public SyncManagerTest { | 3331 class SyncManagerInitInvalidStorageTest : public SyncManagerTest { |
| 3442 public: | 3332 public: |
| 3443 SyncManagerInitInvalidStorageTest() { | 3333 SyncManagerInitInvalidStorageTest() {} |
| 3444 } | |
| 3445 | 3334 |
| 3446 InternalComponentsFactory* GetFactory() override { | 3335 InternalComponentsFactory* GetFactory() override { |
| 3447 return new TestInternalComponentsFactory( | 3336 return new TestInternalComponentsFactory( |
| 3448 GetSwitches(), InternalComponentsFactory::STORAGE_INVALID, | 3337 GetSwitches(), InternalComponentsFactory::STORAGE_INVALID, |
| 3449 &storage_used_); | 3338 &storage_used_); |
| 3450 } | 3339 } |
| 3451 }; | 3340 }; |
| 3452 | 3341 |
| 3453 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3342 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3454 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3343 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3455 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3344 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3456 // task is to ensure that SyncManagerImpl reported initialization failure in | 3345 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3457 // OnInitializationComplete callback. | 3346 // OnInitializationComplete callback. |
| 3458 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3347 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3459 EXPECT_FALSE(initialization_succeeded_); | 3348 EXPECT_FALSE(initialization_succeeded_); |
| 3460 } | 3349 } |
| 3461 | 3350 |
| 3462 } // namespace syncer | 3351 } // namespace syncer |
| OLD | NEW |