OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
8 | 8 |
9 #include <map> | |
10 | |
11 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
12 #include "base/format_macros.h" | |
13 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
14 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
15 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
16 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
17 #include "base/string_util.h" | |
18 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
19 #include "base/values.h" | 15 #include "base/values.h" |
20 #include "chrome/browser/browser_thread.h" | 16 #include "chrome/browser/browser_thread.h" |
21 #include "chrome/browser/sync/engine/model_safe_worker.h" | |
22 #include "chrome/browser/sync/engine/syncapi.h" | 17 #include "chrome/browser/sync/engine/syncapi.h" |
23 #include "chrome/browser/sync/js_arg_list.h" | 18 #include "chrome/browser/sync/js_arg_list.h" |
24 #include "chrome/browser/sync/js_backend.h" | 19 #include "chrome/browser/sync/js_backend.h" |
25 #include "chrome/browser/sync/js_event_handler.h" | 20 #include "chrome/browser/sync/js_event_handler.h" |
26 #include "chrome/browser/sync/js_event_router.h" | 21 #include "chrome/browser/sync/js_event_router.h" |
27 #include "chrome/browser/sync/js_test_util.h" | 22 #include "chrome/browser/sync/js_test_util.h" |
28 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 23 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
29 #include "chrome/browser/sync/protocol/proto_value_conversions.h" | 24 #include "chrome/browser/sync/protocol/proto_value_conversions.h" |
30 #include "chrome/browser/sync/sessions/sync_session.h" | |
31 #include "chrome/browser/sync/syncable/directory_manager.h" | 25 #include "chrome/browser/sync/syncable/directory_manager.h" |
32 #include "chrome/browser/sync/syncable/nigori_util.h" | |
33 #include "chrome/browser/sync/syncable/syncable.h" | 26 #include "chrome/browser/sync/syncable/syncable.h" |
34 #include "chrome/browser/sync/syncable/syncable_id.h" | |
35 #include "chrome/browser/sync/util/cryptographer.h" | |
36 #include "chrome/test/sync/engine/test_directory_setter_upper.h" | 27 #include "chrome/test/sync/engine/test_directory_setter_upper.h" |
37 #include "chrome/test/values_test_util.h" | 28 #include "chrome/test/values_test_util.h" |
38 #include "jingle/notifier/base/notifier_options.h" | 29 #include "jingle/notifier/base/notifier_options.h" |
39 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
41 | 32 |
42 using browser_sync::Cryptographer; | |
43 using browser_sync::HasArgsAsList; | 33 using browser_sync::HasArgsAsList; |
44 using browser_sync::KeyParams; | 34 using browser_sync::KeyParams; |
45 using browser_sync::JsArgList; | 35 using browser_sync::JsArgList; |
46 using browser_sync::MockJsEventHandler; | 36 using browser_sync::MockJsEventHandler; |
47 using browser_sync::MockJsEventRouter; | 37 using browser_sync::MockJsEventRouter; |
48 using browser_sync::ModelSafeRoutingInfo; | |
49 using browser_sync::ModelSafeWorker; | |
50 using browser_sync::ModelSafeWorkerRegistrar; | |
51 using browser_sync::sessions::SyncSessionSnapshot; | |
52 using syncable::ModelType; | |
53 using syncable::ModelTypeSet; | |
54 using test::ExpectDictionaryValue; | 38 using test::ExpectDictionaryValue; |
55 using test::ExpectStringValue; | 39 using test::ExpectStringValue; |
56 using testing::_; | 40 using testing::_; |
57 using testing::Invoke; | 41 using testing::Invoke; |
58 using testing::SaveArg; | 42 using testing::SaveArg; |
59 using testing::StrictMock; | 43 using testing::StrictMock; |
60 | 44 |
61 namespace sync_api { | 45 namespace sync_api { |
62 | 46 |
63 namespace { | 47 namespace { |
64 | 48 |
65 void ExpectInt64Value(int64 expected_value, | 49 void ExpectInt64Value(int64 expected_value, |
66 const DictionaryValue& value, const std::string& key) { | 50 const DictionaryValue& value, const std::string& key) { |
67 std::string int64_str; | 51 std::string int64_str; |
68 EXPECT_TRUE(value.GetString(key, &int64_str)); | 52 EXPECT_TRUE(value.GetString(key, &int64_str)); |
69 int64 val = 0; | 53 int64 val = 0; |
70 EXPECT_TRUE(base::StringToInt64(int64_str, &val)); | 54 EXPECT_TRUE(base::StringToInt64(int64_str, &val)); |
71 EXPECT_EQ(expected_value, val); | 55 EXPECT_EQ(expected_value, val); |
72 } | 56 } |
73 | 57 |
74 // Makes a non-folder child of the root node. Returns the id of the | 58 // Makes a non-folder child of the root node. Returns the id of the |
75 // newly-created node. | 59 // newly-created node. |
76 int64 MakeNode(UserShare* share, | 60 int64 MakeNode(UserShare* share, |
77 ModelType model_type, | 61 syncable::ModelType model_type, |
78 const std::string& client_tag) { | 62 const std::string& client_tag) { |
79 WriteTransaction trans(share); | 63 WriteTransaction trans(share); |
80 ReadNode root_node(&trans); | 64 ReadNode root_node(&trans); |
81 root_node.InitByRootLookup(); | 65 root_node.InitByRootLookup(); |
82 WriteNode node(&trans); | 66 WriteNode node(&trans); |
83 EXPECT_TRUE(node.InitUniqueByCreation(model_type, root_node, client_tag)); | 67 EXPECT_TRUE(node.InitUniqueByCreation(model_type, root_node, client_tag)); |
84 node.SetIsFolder(false); | 68 node.SetIsFolder(false); |
85 return node.GetId(); | 69 return node.GetId(); |
86 } | 70 } |
87 | 71 |
88 // Make a folder as a child of the root node. Returns the id of the | |
89 // newly-created node. | |
90 int64 MakeFolder(UserShare* share, | |
91 syncable::ModelType model_type, | |
92 const std::string& client_tag) { | |
93 WriteTransaction trans(share); | |
94 ReadNode root_node(&trans); | |
95 root_node.InitByRootLookup(); | |
96 WriteNode node(&trans); | |
97 EXPECT_TRUE(node.InitUniqueByCreation(model_type, root_node, client_tag)); | |
98 node.SetIsFolder(true); | |
99 return node.GetId(); | |
100 } | |
101 | |
102 // Makes a non-folder child of a non-root node. Returns the id of the | |
103 // newly-created node. | |
104 int64 MakeNodeWithParent(UserShare* share, | |
105 ModelType model_type, | |
106 const std::string& client_tag, | |
107 int64 parent_id) { | |
108 WriteTransaction trans(share); | |
109 ReadNode parent_node(&trans); | |
110 parent_node.InitByIdLookup(parent_id); | |
111 WriteNode node(&trans); | |
112 EXPECT_TRUE(node.InitUniqueByCreation(model_type, parent_node, client_tag)); | |
113 node.SetIsFolder(false); | |
114 return node.GetId(); | |
115 } | |
116 | |
117 // Makes a folder child of a non-root node. Returns the id of the | |
118 // newly-created node. | |
119 int64 MakeFolderWithParent(UserShare* share, | |
120 ModelType model_type, | |
121 int64 parent_id, | |
122 BaseNode* predecessor) { | |
123 WriteTransaction trans(share); | |
124 ReadNode parent_node(&trans); | |
125 parent_node.InitByIdLookup(parent_id); | |
126 WriteNode node(&trans); | |
127 EXPECT_TRUE(node.InitByCreation(model_type, parent_node, predecessor)); | |
128 node.SetIsFolder(true); | |
129 return node.GetId(); | |
130 } | |
131 | |
132 // Creates the "synced" root node for a particular datatype. We use the syncable | |
133 // methods here so that the syncer treats these nodes as if they were already | |
134 // received from the server. | |
135 int64 MakeServerNodeForType(UserShare* share, | |
136 ModelType model_type) { | |
137 sync_pb::EntitySpecifics specifics; | |
138 syncable::AddDefaultExtensionValue(model_type, &specifics); | |
139 syncable::ScopedDirLookup dir(share->dir_manager.get(), share->name); | |
140 EXPECT_TRUE(dir.good()); | |
141 syncable::WriteTransaction trans(dir, syncable::UNITTEST, __FILE__, __LINE__); | |
142 // Attempt to lookup by nigori tag. | |
143 std::string type_tag = syncable::ModelTypeToRootTag(model_type); | |
144 syncable::Id node_id = syncable::Id::CreateFromServerId(type_tag); | |
145 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | |
146 node_id); | |
147 EXPECT_TRUE(entry.good()); | |
148 entry.Put(syncable::BASE_VERSION, 1); | |
149 entry.Put(syncable::SERVER_VERSION, 1); | |
150 entry.Put(syncable::IS_UNAPPLIED_UPDATE, false); | |
151 entry.Put(syncable::SERVER_PARENT_ID, syncable::kNullId); | |
152 entry.Put(syncable::SERVER_IS_DIR, true); | |
153 entry.Put(syncable::IS_DIR, true); | |
154 entry.Put(syncable::SERVER_SPECIFICS, specifics); | |
155 entry.Put(syncable::UNIQUE_SERVER_TAG, type_tag); | |
156 entry.Put(syncable::NON_UNIQUE_NAME, type_tag); | |
157 entry.Put(syncable::IS_DEL, false); | |
158 entry.Put(syncable::SPECIFICS, specifics); | |
159 return entry.Get(syncable::META_HANDLE); | |
160 } | |
161 | |
162 } // namespace | 72 } // namespace |
163 | 73 |
164 class SyncApiTest : public testing::Test { | 74 class SyncApiTest : public testing::Test { |
165 public: | 75 public: |
166 virtual void SetUp() { | 76 virtual void SetUp() { |
167 setter_upper_.SetUp(); | 77 setter_upper_.SetUp(); |
168 share_.dir_manager.reset(setter_upper_.manager()); | 78 share_.dir_manager.reset(setter_upper_.manager()); |
169 share_.name = setter_upper_.name(); | 79 share_.name = setter_upper_.name(); |
170 } | 80 } |
171 | 81 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 WriteTransaction trans(&share_); | 191 WriteTransaction trans(&share_); |
282 WriteNode node(&trans); | 192 WriteNode node(&trans); |
283 EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS, | 193 EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS, |
284 "testtag")); | 194 "testtag")); |
285 } | 195 } |
286 } | 196 } |
287 | 197 |
288 // TODO(chron): Hook this all up to the server and write full integration tests | 198 // TODO(chron): Hook this all up to the server and write full integration tests |
289 // for update->undelete behavior. | 199 // for update->undelete behavior. |
290 TEST_F(SyncApiTest, TestDeleteBehavior) { | 200 TEST_F(SyncApiTest, TestDeleteBehavior) { |
| 201 |
291 int64 node_id; | 202 int64 node_id; |
292 int64 folder_id; | 203 int64 folder_id; |
293 std::wstring test_title(L"test1"); | 204 std::wstring test_title(L"test1"); |
294 | 205 |
295 { | 206 { |
296 WriteTransaction trans(&share_); | 207 WriteTransaction trans(&share_); |
297 ReadNode root_node(&trans); | 208 ReadNode root_node(&trans); |
298 root_node.InitByRootLookup(); | 209 root_node.InitByRootLookup(); |
299 | 210 |
300 // we'll use this spare folder later | 211 // we'll use this spare folder later |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 ExpectInt64Value(node.GetId(), value, "id"); | 309 ExpectInt64Value(node.GetId(), value, "id"); |
399 ExpectInt64Value(node.GetModificationTime(), value, "modificationTime"); | 310 ExpectInt64Value(node.GetModificationTime(), value, "modificationTime"); |
400 ExpectInt64Value(node.GetParentId(), value, "parentId"); | 311 ExpectInt64Value(node.GetParentId(), value, "parentId"); |
401 { | 312 { |
402 bool is_folder = false; | 313 bool is_folder = false; |
403 EXPECT_TRUE(value.GetBoolean("isFolder", &is_folder)); | 314 EXPECT_TRUE(value.GetBoolean("isFolder", &is_folder)); |
404 EXPECT_EQ(node.GetIsFolder(), is_folder); | 315 EXPECT_EQ(node.GetIsFolder(), is_folder); |
405 } | 316 } |
406 ExpectStringValue(WideToUTF8(node.GetTitle()), value, "title"); | 317 ExpectStringValue(WideToUTF8(node.GetTitle()), value, "title"); |
407 { | 318 { |
408 ModelType expected_model_type = node.GetModelType(); | 319 syncable::ModelType expected_model_type = node.GetModelType(); |
409 std::string type_str; | 320 std::string type_str; |
410 EXPECT_TRUE(value.GetString("type", &type_str)); | 321 EXPECT_TRUE(value.GetString("type", &type_str)); |
411 if (expected_model_type >= syncable::FIRST_REAL_MODEL_TYPE) { | 322 if (expected_model_type >= syncable::FIRST_REAL_MODEL_TYPE) { |
412 ModelType model_type = | 323 syncable::ModelType model_type = |
413 syncable::ModelTypeFromString(type_str); | 324 syncable::ModelTypeFromString(type_str); |
414 EXPECT_EQ(expected_model_type, model_type); | 325 EXPECT_EQ(expected_model_type, model_type); |
415 } else if (expected_model_type == syncable::TOP_LEVEL_FOLDER) { | 326 } else if (expected_model_type == syncable::TOP_LEVEL_FOLDER) { |
416 EXPECT_EQ("Top-level folder", type_str); | 327 EXPECT_EQ("Top-level folder", type_str); |
417 } else if (expected_model_type == syncable::UNSPECIFIED) { | 328 } else if (expected_model_type == syncable::UNSPECIFIED) { |
418 EXPECT_EQ("Unspecified", type_str); | 329 EXPECT_EQ("Unspecified", type_str); |
419 } else { | 330 } else { |
420 ADD_FAILURE(); | 331 ADD_FAILURE(); |
421 } | 332 } |
422 } | 333 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 if (record.extra.get()) { | 413 if (record.extra.get()) { |
503 expected_extra_value.reset(record.extra->ToValue()); | 414 expected_extra_value.reset(record.extra->ToValue()); |
504 } | 415 } |
505 Value* extra_value = NULL; | 416 Value* extra_value = NULL; |
506 EXPECT_EQ(record.extra.get() != NULL, | 417 EXPECT_EQ(record.extra.get() != NULL, |
507 node_value->Get("extra", &extra_value)); | 418 node_value->Get("extra", &extra_value)); |
508 EXPECT_TRUE(Value::Equals(extra_value, expected_extra_value.get())); | 419 EXPECT_TRUE(Value::Equals(extra_value, expected_extra_value.get())); |
509 } | 420 } |
510 } | 421 } |
511 | 422 |
512 class MockExtraChangeRecordData | 423 class MockExtraChangeRecordData : public SyncManager::ExtraChangeRecordData { |
513 : public SyncManager::ExtraPasswordChangeRecordData { | |
514 public: | 424 public: |
515 MOCK_CONST_METHOD0(ToValue, DictionaryValue*()); | 425 MOCK_CONST_METHOD0(ToValue, DictionaryValue*()); |
516 }; | 426 }; |
517 | 427 |
518 } // namespace | 428 } // namespace |
519 | 429 |
520 TEST_F(SyncApiTest, ChangeRecordToValue) { | 430 TEST_F(SyncApiTest, ChangeRecordToValue) { |
521 int64 child_id = MakeNode(&share_, syncable::BOOKMARKS, "testtag"); | 431 int64 child_id = MakeNode(&share_, syncable::BOOKMARKS, "testtag"); |
522 sync_pb::EntitySpecifics child_specifics; | 432 sync_pb::EntitySpecifics child_specifics; |
523 { | 433 { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 virtual ~TestHttpPostProviderFactory() {} | 500 virtual ~TestHttpPostProviderFactory() {} |
591 virtual HttpPostProviderInterface* Create() { | 501 virtual HttpPostProviderInterface* Create() { |
592 NOTREACHED(); | 502 NOTREACHED(); |
593 return NULL; | 503 return NULL; |
594 } | 504 } |
595 virtual void Destroy(HttpPostProviderInterface* http) { | 505 virtual void Destroy(HttpPostProviderInterface* http) { |
596 NOTREACHED(); | 506 NOTREACHED(); |
597 } | 507 } |
598 }; | 508 }; |
599 | 509 |
600 class SyncManagerObserverMock : public SyncManager::Observer { | 510 class SyncManagerTest : public testing::Test { |
601 public: | |
602 MOCK_METHOD4(OnChangesApplied, | |
603 void(ModelType, | |
604 const BaseTransaction*, | |
605 const SyncManager::ChangeRecord*, | |
606 int)); // NOLINT | |
607 MOCK_METHOD1(OnChangesComplete, void(ModelType)); // NOLINT | |
608 MOCK_METHOD1(OnSyncCycleCompleted, | |
609 void(const SyncSessionSnapshot*)); // NOLINT | |
610 MOCK_METHOD0(OnInitializationComplete, void()); // NOLINT | |
611 MOCK_METHOD1(OnAuthError, void(const GoogleServiceAuthError&)); // NOLINT | |
612 MOCK_METHOD1(OnPassphraseRequired, void(bool)); // NOLINT | |
613 MOCK_METHOD1(OnPassphraseAccepted, void(const std::string&)); // NOLINT | |
614 MOCK_METHOD0(OnPaused, void()); // NOLINT | |
615 MOCK_METHOD0(OnResumed, void()); // NOLINT | |
616 MOCK_METHOD0(OnStopSyncingPermanently, void()); // NOLINT | |
617 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT | |
618 MOCK_METHOD0(OnClearServerDataFailed, void()); // NOLINT | |
619 MOCK_METHOD0(OnClearServerDataSucceeded, void()); // NOLINT | |
620 MOCK_METHOD1(OnEncryptionComplete, void(const ModelTypeSet&)); // NOLINT | |
621 }; | |
622 | |
623 class SyncManagerTest : public testing::Test, | |
624 public ModelSafeWorkerRegistrar { | |
625 protected: | 511 protected: |
626 SyncManagerTest() : ui_thread_(BrowserThread::UI, &ui_loop_) {} | 512 SyncManagerTest() : ui_thread_(BrowserThread::UI, &ui_loop_) {} |
627 | 513 |
628 // Test implementation. | |
629 void SetUp() { | 514 void SetUp() { |
630 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 515 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
631 sync_manager_.Init(temp_dir_.path(), "bogus", 0, false, | 516 sync_manager_.Init(temp_dir_.path(), "bogus", 0, false, |
632 new TestHttpPostProviderFactory(), this, "bogus", | 517 new TestHttpPostProviderFactory(), NULL, "bogus", |
633 SyncCredentials(), notifier::NotifierOptions(), | 518 SyncCredentials(), notifier::NotifierOptions(), |
634 "", true /* setup_for_test_mode */); | 519 "", true /* setup_for_test_mode */); |
635 sync_manager_.AddObserver(&observer_); | |
636 ModelSafeRoutingInfo routes; | |
637 GetModelSafeRoutingInfo(&routes); | |
638 for (ModelSafeRoutingInfo::iterator i = routes.begin(); i != routes.end(); | |
639 ++i) { | |
640 EXPECT_CALL(observer_, OnChangesApplied(i->first, _, _, 1)) | |
641 .RetiresOnSaturation(); | |
642 EXPECT_CALL(observer_, OnChangesComplete(i->first)) | |
643 .RetiresOnSaturation(); | |
644 type_roots_[i->first] = MakeServerNodeForType( | |
645 sync_manager_.GetUserShare(), i->first); | |
646 } | |
647 } | 520 } |
648 | 521 |
649 void TearDown() { | 522 void TearDown() { |
650 sync_manager_.RemoveObserver(&observer_); | |
651 sync_manager_.Shutdown(); | 523 sync_manager_.Shutdown(); |
652 } | 524 } |
653 | 525 |
654 // ModelSafeWorkerRegistrar implementation. | |
655 virtual void GetWorkers(std::vector<ModelSafeWorker*>* out) { | |
656 NOTIMPLEMENTED(); | |
657 out->clear(); | |
658 } | |
659 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | |
660 (*out)[syncable::NIGORI] = browser_sync::GROUP_PASSIVE; | |
661 (*out)[syncable::BOOKMARKS] = browser_sync::GROUP_PASSIVE; | |
662 (*out)[syncable::THEMES] = browser_sync::GROUP_PASSIVE; | |
663 (*out)[syncable::SESSIONS] = browser_sync::GROUP_PASSIVE; | |
664 (*out)[syncable::PASSWORDS] = browser_sync::GROUP_PASSIVE; | |
665 } | |
666 | |
667 // Helper methods. | |
668 bool SetUpEncryption() { | |
669 // We need to create the nigori node as if it were an applied server update. | |
670 UserShare* share = sync_manager_.GetUserShare(); | |
671 int64 nigori_id = GetIdForDataType(syncable::NIGORI); | |
672 if (nigori_id == kInvalidId) | |
673 return false; | |
674 | |
675 // Set the nigori cryptographer information. | |
676 Cryptographer* cryptographer = share->dir_manager->cryptographer(); | |
677 if (!cryptographer) | |
678 return false; | |
679 KeyParams params = {"localhost", "dummy", "foobar"}; | |
680 cryptographer->AddKey(params); | |
681 sync_pb::NigoriSpecifics nigori; | |
682 cryptographer->GetKeys(nigori.mutable_encrypted()); | |
683 WriteTransaction trans(share); | |
684 WriteNode node(&trans); | |
685 node.InitByIdLookup(nigori_id); | |
686 node.SetNigoriSpecifics(nigori); | |
687 return cryptographer->is_ready(); | |
688 } | |
689 | |
690 int64 GetIdForDataType(ModelType type) { | |
691 if (type_roots_.count(type) == 0) | |
692 return 0; | |
693 return type_roots_[type]; | |
694 } | |
695 | |
696 private: | 526 private: |
697 // Needed by |ui_thread_|. | 527 // Needed by |ui_thread_|. |
698 MessageLoopForUI ui_loop_; | 528 MessageLoopForUI ui_loop_; |
699 // Needed by |sync_manager_|. | 529 // Needed by |sync_manager_|. |
700 BrowserThread ui_thread_; | 530 BrowserThread ui_thread_; |
701 // Needed by |sync_manager_|. | 531 // Needed by |sync_manager_|. |
702 ScopedTempDir temp_dir_; | 532 ScopedTempDir temp_dir_; |
703 // Sync Id's for the roots of the enabled datatypes. | |
704 std::map<ModelType, int64> type_roots_; | |
705 | 533 |
706 protected: | 534 protected: |
707 SyncManager sync_manager_; | 535 SyncManager sync_manager_; |
708 StrictMock<SyncManagerObserverMock> observer_; | |
709 }; | 536 }; |
710 | 537 |
711 TEST_F(SyncManagerTest, ParentJsEventRouter) { | 538 TEST_F(SyncManagerTest, ParentJsEventRouter) { |
712 StrictMock<MockJsEventRouter> event_router; | 539 StrictMock<MockJsEventRouter> event_router; |
713 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); | 540 browser_sync::JsBackend* js_backend = sync_manager_.GetJsBackend(); |
714 EXPECT_EQ(NULL, js_backend->GetParentJsEventRouter()); | 541 EXPECT_EQ(NULL, js_backend->GetParentJsEventRouter()); |
715 js_backend->SetParentJsEventRouter(&event_router); | 542 js_backend->SetParentJsEventRouter(&event_router); |
716 EXPECT_EQ(&event_router, js_backend->GetParentJsEventRouter()); | 543 EXPECT_EQ(&event_router, js_backend->GetParentJsEventRouter()); |
717 js_backend->RemoveParentJsEventRouter(); | 544 js_backend->RemoveParentJsEventRouter(); |
718 EXPECT_EQ(NULL, js_backend->GetParentJsEventRouter()); | 545 EXPECT_EQ(NULL, js_backend->GetParentJsEventRouter()); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); | 796 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); |
970 | 797 |
971 js_backend->SetParentJsEventRouter(&event_router); | 798 js_backend->SetParentJsEventRouter(&event_router); |
972 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); | 799 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); |
973 js_backend->RemoveParentJsEventRouter(); | 800 js_backend->RemoveParentJsEventRouter(); |
974 | 801 |
975 sync_manager_.TriggerOnIncomingNotificationForTest(empty_model_types); | 802 sync_manager_.TriggerOnIncomingNotificationForTest(empty_model_types); |
976 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); | 803 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); |
977 } | 804 } |
978 | 805 |
979 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { | |
980 EXPECT_TRUE(SetUpEncryption()); | |
981 ModelTypeSet encrypted_types; | |
982 encrypted_types.insert(syncable::BOOKMARKS); | |
983 // Even though Passwords isn't marked for encryption, it's enabled, so it | |
984 // should automatically be added to the response of OnEncryptionComplete. | |
985 ModelTypeSet expected_types = encrypted_types; | |
986 expected_types.insert(syncable::PASSWORDS); | |
987 EXPECT_CALL(observer_, OnEncryptionComplete(expected_types)); | |
988 sync_manager_.EncryptDataTypes(encrypted_types); | |
989 { | |
990 ReadTransaction trans(sync_manager_.GetUserShare()); | |
991 EXPECT_EQ(encrypted_types, | |
992 GetEncryptedDataTypes(trans.GetWrappedTrans())); | |
993 } | |
994 } | |
995 | |
996 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { | |
997 size_t batch_size = 5; | |
998 EXPECT_TRUE(SetUpEncryption()); | |
999 | |
1000 // Create some unencrypted unsynced data. | |
1001 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(), | |
1002 syncable::BOOKMARKS, | |
1003 GetIdForDataType(syncable::BOOKMARKS), | |
1004 NULL); | |
1005 // First batch_size nodes are children of folder. | |
1006 size_t i; | |
1007 for (i = 0; i < batch_size; ++i) { | |
1008 MakeNodeWithParent(sync_manager_.GetUserShare(), syncable::BOOKMARKS, | |
1009 StringPrintf("%"PRIuS"", i), folder); | |
1010 } | |
1011 // Next batch_size nodes are a different type and on their own. | |
1012 for (; i < 2*batch_size; ++i) { | |
1013 MakeNodeWithParent(sync_manager_.GetUserShare(), syncable::SESSIONS, | |
1014 StringPrintf("%"PRIuS"", i), | |
1015 GetIdForDataType(syncable::SESSIONS)); | |
1016 } | |
1017 // Last batch_size nodes are a third type that will not need encryption. | |
1018 for (; i < 3*batch_size; ++i) { | |
1019 MakeNodeWithParent(sync_manager_.GetUserShare(), syncable::THEMES, | |
1020 StringPrintf("%"PRIuS"", i), | |
1021 GetIdForDataType(syncable::THEMES)); | |
1022 } | |
1023 | |
1024 { | |
1025 ReadTransaction trans(sync_manager_.GetUserShare()); | |
1026 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | |
1027 syncable::BOOKMARKS, | |
1028 false /* not encrypted */)); | |
1029 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | |
1030 syncable::SESSIONS, | |
1031 false /* not encrypted */)); | |
1032 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | |
1033 syncable::THEMES, | |
1034 false /* not encrypted */)); | |
1035 } | |
1036 | |
1037 ModelTypeSet encrypted_types; | |
1038 encrypted_types.insert(syncable::BOOKMARKS); | |
1039 encrypted_types.insert(syncable::SESSIONS); | |
1040 encrypted_types.insert(syncable::PASSWORDS); | |
1041 EXPECT_CALL(observer_, OnEncryptionComplete(encrypted_types)); | |
1042 sync_manager_.EncryptDataTypes(encrypted_types); | |
1043 | |
1044 { | |
1045 ReadTransaction trans(sync_manager_.GetUserShare()); | |
1046 encrypted_types.erase(syncable::PASSWORDS); // Not stored in nigori node. | |
1047 EXPECT_EQ(encrypted_types, | |
1048 GetEncryptedDataTypes(trans.GetWrappedTrans())); | |
1049 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | |
1050 syncable::BOOKMARKS, | |
1051 true /* is encrypted */)); | |
1052 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | |
1053 syncable::SESSIONS, | |
1054 true /* is encrypted */)); | |
1055 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | |
1056 syncable::THEMES, | |
1057 false /* not encrypted */)); | |
1058 } | |
1059 } | |
1060 | |
1061 } // namespace | 806 } // namespace |
1062 | 807 |
1063 } // namespace browser_sync | 808 } // namespace browser_sync |
OLD | NEW |