OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "base/message_loop_proxy.h" |
19 #include "base/scoped_temp_dir.h" | 20 #include "base/scoped_temp_dir.h" |
20 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
21 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
22 #include "base/test/thread_test_helper.h" | |
23 #include "base/test/values_test_util.h" | 23 #include "base/test/values_test_util.h" |
24 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
25 #include "base/values.h" | 25 #include "base/values.h" |
26 #include "chrome/browser/sync/engine/model_safe_worker.h" | 26 #include "chrome/browser/sync/engine/model_safe_worker.h" |
27 #include "chrome/browser/sync/engine/nigori_util.h" | 27 #include "chrome/browser/sync/engine/nigori_util.h" |
28 #include "chrome/browser/sync/engine/polling_constants.h" | 28 #include "chrome/browser/sync/engine/polling_constants.h" |
29 #include "chrome/browser/sync/engine/syncapi_internal.h" | 29 #include "chrome/browser/sync/engine/syncapi_internal.h" |
30 #include "chrome/browser/sync/internal_api/change_record.h" | 30 #include "chrome/browser/sync/internal_api/change_record.h" |
31 #include "chrome/browser/sync/internal_api/http_post_provider_factory.h" | 31 #include "chrome/browser/sync/internal_api/http_post_provider_factory.h" |
32 #include "chrome/browser/sync/internal_api/http_post_provider_interface.h" | 32 #include "chrome/browser/sync/internal_api/http_post_provider_interface.h" |
(...skipping 20 matching lines...) Expand all Loading... |
53 #include "chrome/browser/sync/sessions/sync_session.h" | 53 #include "chrome/browser/sync/sessions/sync_session.h" |
54 #include "chrome/browser/sync/syncable/model_type_test_util.h" | 54 #include "chrome/browser/sync/syncable/model_type_test_util.h" |
55 #include "chrome/browser/sync/syncable/syncable.h" | 55 #include "chrome/browser/sync/syncable/syncable.h" |
56 #include "chrome/browser/sync/syncable/syncable_id.h" | 56 #include "chrome/browser/sync/syncable/syncable_id.h" |
57 #include "chrome/browser/sync/test/engine/test_user_share.h" | 57 #include "chrome/browser/sync/test/engine/test_user_share.h" |
58 #include "chrome/browser/sync/test/fake_encryptor.h" | 58 #include "chrome/browser/sync/test/fake_encryptor.h" |
59 #include "chrome/browser/sync/test/fake_extensions_activity_monitor.h" | 59 #include "chrome/browser/sync/test/fake_extensions_activity_monitor.h" |
60 #include "chrome/browser/sync/util/cryptographer.h" | 60 #include "chrome/browser/sync/util/cryptographer.h" |
61 #include "chrome/browser/sync/util/extensions_activity_monitor.h" | 61 #include "chrome/browser/sync/util/extensions_activity_monitor.h" |
62 #include "chrome/browser/sync/util/time.h" | 62 #include "chrome/browser/sync/util/time.h" |
63 #include "content/test/test_browser_thread.h" | |
64 #include "testing/gmock/include/gmock/gmock.h" | 63 #include "testing/gmock/include/gmock/gmock.h" |
65 #include "testing/gtest/include/gtest/gtest.h" | 64 #include "testing/gtest/include/gtest/gtest.h" |
66 | 65 |
67 using base::ExpectDictStringValue; | 66 using base::ExpectDictStringValue; |
68 using browser_sync::Cryptographer; | 67 using browser_sync::Cryptographer; |
69 using browser_sync::FakeEncryptor; | 68 using browser_sync::FakeEncryptor; |
70 using browser_sync::FakeExtensionsActivityMonitor; | 69 using browser_sync::FakeExtensionsActivityMonitor; |
71 using browser_sync::HasArgsAsList; | 70 using browser_sync::HasArgsAsList; |
72 using browser_sync::HasDetailsAsDictionary; | 71 using browser_sync::HasDetailsAsDictionary; |
73 using browser_sync::KeyParams; | 72 using browser_sync::KeyParams; |
74 using browser_sync::kNigoriTag; | 73 using browser_sync::kNigoriTag; |
75 using browser_sync::JsArgList; | 74 using browser_sync::JsArgList; |
76 using browser_sync::JsBackend; | 75 using browser_sync::JsBackend; |
77 using browser_sync::JsEventHandler; | 76 using browser_sync::JsEventHandler; |
78 using browser_sync::JsReplyHandler; | 77 using browser_sync::JsReplyHandler; |
79 using browser_sync::MockJsEventHandler; | 78 using browser_sync::MockJsEventHandler; |
80 using browser_sync::MockJsReplyHandler; | 79 using browser_sync::MockJsReplyHandler; |
81 using browser_sync::ModelSafeRoutingInfo; | 80 using browser_sync::ModelSafeRoutingInfo; |
82 using browser_sync::ModelSafeWorker; | 81 using browser_sync::ModelSafeWorker; |
83 using browser_sync::ModelSafeWorkerRegistrar; | 82 using browser_sync::ModelSafeWorkerRegistrar; |
84 using browser_sync::sessions::SyncSessionSnapshot; | 83 using browser_sync::sessions::SyncSessionSnapshot; |
85 using browser_sync::TestUnrecoverableErrorHandler; | 84 using browser_sync::TestUnrecoverableErrorHandler; |
86 using browser_sync::WeakHandle; | 85 using browser_sync::WeakHandle; |
87 using content::BrowserThread; | |
88 using syncable::IS_DEL; | 86 using syncable::IS_DEL; |
89 using syncable::IS_UNSYNCED; | 87 using syncable::IS_UNSYNCED; |
90 using syncable::kEncryptedString; | 88 using syncable::kEncryptedString; |
91 using syncable::ModelTypeSet; | 89 using syncable::ModelTypeSet; |
92 using syncable::ModelType; | 90 using syncable::ModelType; |
93 using syncable::NON_UNIQUE_NAME; | 91 using syncable::NON_UNIQUE_NAME; |
94 using syncable::SPECIFICS; | 92 using syncable::SPECIFICS; |
95 using testing::_; | 93 using testing::_; |
96 using testing::AnyNumber; | 94 using testing::AnyNumber; |
97 using testing::AtLeast; | 95 using testing::AtLeast; |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 WRITE_TO_NIGORI | 709 WRITE_TO_NIGORI |
712 }; | 710 }; |
713 | 711 |
714 enum EncryptionStatus { | 712 enum EncryptionStatus { |
715 UNINITIALIZED, | 713 UNINITIALIZED, |
716 DEFAULT_ENCRYPTION, | 714 DEFAULT_ENCRYPTION, |
717 FULL_ENCRYPTION | 715 FULL_ENCRYPTION |
718 }; | 716 }; |
719 | 717 |
720 SyncManagerTest() | 718 SyncManagerTest() |
721 : ui_thread_(BrowserThread::UI, &ui_loop_), | 719 : sync_notifier_mock_(NULL), |
722 file_thread_(BrowserThread::FILE), | |
723 sync_notifier_mock_(NULL), | |
724 sync_manager_("Test sync manager"), | 720 sync_manager_("Test sync manager"), |
725 sync_notifier_observer_(NULL), | 721 sync_notifier_observer_(NULL), |
726 update_enabled_types_call_count_(0) {} | 722 update_enabled_types_call_count_(0) {} |
727 | 723 |
728 virtual ~SyncManagerTest() { | 724 virtual ~SyncManagerTest() { |
729 EXPECT_FALSE(sync_notifier_mock_); | 725 EXPECT_FALSE(sync_notifier_mock_); |
730 } | 726 } |
731 | 727 |
732 // Test implementation. | 728 // Test implementation. |
733 void SetUp() { | 729 void SetUp() { |
734 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 730 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
735 | 731 |
736 file_thread_.Start(); | |
737 | |
738 SyncCredentials credentials; | 732 SyncCredentials credentials; |
739 credentials.email = "foo@bar.com"; | 733 credentials.email = "foo@bar.com"; |
740 credentials.sync_token = "sometoken"; | 734 credentials.sync_token = "sometoken"; |
741 | 735 |
742 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); | 736 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); |
743 EXPECT_CALL(*sync_notifier_mock_, AddObserver(_)). | 737 EXPECT_CALL(*sync_notifier_mock_, AddObserver(_)). |
744 WillOnce(Invoke(this, &SyncManagerTest::SyncNotifierAddObserver)); | 738 WillOnce(Invoke(this, &SyncManagerTest::SyncNotifierAddObserver)); |
745 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); | 739 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); |
746 EXPECT_CALL(*sync_notifier_mock_, SetState("")); | 740 EXPECT_CALL(*sync_notifier_mock_, SetState("")); |
747 EXPECT_CALL(*sync_notifier_mock_, | 741 EXPECT_CALL(*sync_notifier_mock_, |
748 UpdateCredentials(credentials.email, credentials.sync_token)); | 742 UpdateCredentials(credentials.email, credentials.sync_token)); |
749 EXPECT_CALL(*sync_notifier_mock_, UpdateEnabledTypes(_)). | 743 EXPECT_CALL(*sync_notifier_mock_, UpdateEnabledTypes(_)). |
750 Times(AtLeast(1)). | 744 Times(AtLeast(1)). |
751 WillRepeatedly( | 745 WillRepeatedly( |
752 Invoke(this, &SyncManagerTest::SyncNotifierUpdateEnabledTypes)); | 746 Invoke(this, &SyncManagerTest::SyncNotifierUpdateEnabledTypes)); |
753 EXPECT_CALL(*sync_notifier_mock_, RemoveObserver(_)). | 747 EXPECT_CALL(*sync_notifier_mock_, RemoveObserver(_)). |
754 WillOnce(Invoke(this, &SyncManagerTest::SyncNotifierRemoveObserver)); | 748 WillOnce(Invoke(this, &SyncManagerTest::SyncNotifierRemoveObserver)); |
755 | 749 |
756 sync_manager_.AddObserver(&observer_); | 750 sync_manager_.AddObserver(&observer_); |
757 EXPECT_CALL(observer_, OnInitializationComplete(_, _)). | 751 EXPECT_CALL(observer_, OnInitializationComplete(_, _)). |
758 WillOnce(SaveArg<0>(&js_backend_)); | 752 WillOnce(SaveArg<0>(&js_backend_)); |
759 | 753 |
760 EXPECT_FALSE(sync_notifier_observer_); | 754 EXPECT_FALSE(sync_notifier_observer_); |
761 EXPECT_FALSE(js_backend_.IsInitialized()); | 755 EXPECT_FALSE(js_backend_.IsInitialized()); |
762 | 756 |
763 // Takes ownership of |sync_notifier_mock_|. | 757 // Takes ownership of |sync_notifier_mock_|. |
764 sync_manager_.Init(temp_dir_.path(), | 758 sync_manager_.Init(temp_dir_.path(), |
765 WeakHandle<JsEventHandler>(), | 759 WeakHandle<JsEventHandler>(), |
766 "bogus", 0, false, | 760 "bogus", 0, false, |
| 761 base::MessageLoopProxy::current(), |
767 new TestHttpPostProviderFactory(), this, | 762 new TestHttpPostProviderFactory(), this, |
768 &extensions_activity_monitor_, this, "bogus", | 763 &extensions_activity_monitor_, this, "bogus", |
769 credentials, sync_notifier_mock_, "", | 764 credentials, sync_notifier_mock_, "", |
770 true /* setup_for_test_mode */, | 765 true /* setup_for_test_mode */, |
771 &encryptor_, | 766 &encryptor_, |
772 &handler_, | 767 &handler_, |
773 NULL); | 768 NULL); |
774 | 769 |
775 EXPECT_TRUE(sync_notifier_observer_); | 770 EXPECT_TRUE(sync_notifier_observer_); |
776 EXPECT_TRUE(js_backend_.IsInitialized()); | 771 EXPECT_TRUE(js_backend_.IsInitialized()); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 void SyncNotifierUpdateEnabledTypes(syncable::ModelTypeSet types) { | 867 void SyncNotifierUpdateEnabledTypes(syncable::ModelTypeSet types) { |
873 ModelSafeRoutingInfo routes; | 868 ModelSafeRoutingInfo routes; |
874 GetModelSafeRoutingInfo(&routes); | 869 GetModelSafeRoutingInfo(&routes); |
875 const syncable::ModelTypeSet expected_types = | 870 const syncable::ModelTypeSet expected_types = |
876 GetRoutingInfoTypes(routes); | 871 GetRoutingInfoTypes(routes); |
877 EXPECT_TRUE(types.Equals(expected_types)); | 872 EXPECT_TRUE(types.Equals(expected_types)); |
878 ++update_enabled_types_call_count_; | 873 ++update_enabled_types_call_count_; |
879 } | 874 } |
880 | 875 |
881 void PumpLoop() { | 876 void PumpLoop() { |
882 ui_loop_.RunAllPending(); | 877 message_loop_.RunAllPending(); |
883 } | 878 } |
884 | 879 |
885 void SendJsMessage(const std::string& name, const JsArgList& args, | 880 void SendJsMessage(const std::string& name, const JsArgList& args, |
886 const WeakHandle<JsReplyHandler>& reply_handler) { | 881 const WeakHandle<JsReplyHandler>& reply_handler) { |
887 js_backend_.Call(FROM_HERE, &JsBackend::ProcessJsMessage, | 882 js_backend_.Call(FROM_HERE, &JsBackend::ProcessJsMessage, |
888 name, args, reply_handler); | 883 name, args, reply_handler); |
889 PumpLoop(); | 884 PumpLoop(); |
890 } | 885 } |
891 | 886 |
892 void SetJsEventHandler(const WeakHandle<JsEventHandler>& event_handler) { | 887 void SetJsEventHandler(const WeakHandle<JsEventHandler>& event_handler) { |
(...skipping 14 matching lines...) Expand all Loading... |
907 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, | 902 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, |
908 hash); | 903 hash); |
909 EXPECT_TRUE(entry.good()); | 904 EXPECT_TRUE(entry.good()); |
910 if (!entry.Get(IS_UNSYNCED)) | 905 if (!entry.Get(IS_UNSYNCED)) |
911 return false; | 906 return false; |
912 entry.Put(IS_UNSYNCED, false); | 907 entry.Put(IS_UNSYNCED, false); |
913 return true; | 908 return true; |
914 } | 909 } |
915 | 910 |
916 private: | 911 private: |
917 // Needed by |ui_thread_|. | |
918 MessageLoopForUI ui_loop_; | |
919 // Needed by |sync_manager_|. | 912 // Needed by |sync_manager_|. |
920 content::TestBrowserThread ui_thread_; | 913 MessageLoop message_loop_; |
921 // Needed by |sync_manager_|. | |
922 content::TestBrowserThread file_thread_; | |
923 // Needed by |sync_manager_|. | 914 // Needed by |sync_manager_|. |
924 ScopedTempDir temp_dir_; | 915 ScopedTempDir temp_dir_; |
925 // Sync Id's for the roots of the enabled datatypes. | 916 // Sync Id's for the roots of the enabled datatypes. |
926 std::map<ModelType, int64> type_roots_; | 917 std::map<ModelType, int64> type_roots_; |
927 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 918 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
928 StrictMock<SyncNotifierMock>* sync_notifier_mock_; | 919 StrictMock<SyncNotifierMock>* sync_notifier_mock_; |
929 | 920 |
930 protected: | 921 protected: |
931 FakeEncryptor encryptor_; | 922 FakeEncryptor encryptor_; |
932 TestUnrecoverableErrorHandler handler_; | 923 TestUnrecoverableErrorHandler handler_; |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 // Should trigger the replies. | 1276 // Should trigger the replies. |
1286 PumpLoop(); | 1277 PumpLoop(); |
1287 } | 1278 } |
1288 | 1279 |
1289 TEST_F(SyncManagerTest, RefreshEncryptionReady) { | 1280 TEST_F(SyncManagerTest, RefreshEncryptionReady) { |
1290 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1281 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
1291 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1282 EXPECT_CALL(observer_, OnEncryptionComplete()); |
1292 | 1283 |
1293 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, | 1284 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, |
1294 base::Unretained(this))); | 1285 base::Unretained(this))); |
1295 scoped_refptr<base::ThreadTestHelper> helper( | |
1296 new base::ThreadTestHelper( | |
1297 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | |
1298 ASSERT_TRUE(helper->Run()); | |
1299 PumpLoop(); | 1286 PumpLoop(); |
1300 | 1287 |
1301 const syncable::ModelTypeSet encrypted_types = | 1288 const syncable::ModelTypeSet encrypted_types = |
1302 sync_manager_.GetEncryptedDataTypesForTest(); | 1289 sync_manager_.GetEncryptedDataTypesForTest(); |
1303 EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS)); | 1290 EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS)); |
1304 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); | 1291 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); |
1305 { | 1292 { |
1306 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1293 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
1307 ReadNode node(&trans); | 1294 ReadNode node(&trans); |
1308 EXPECT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); | 1295 EXPECT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); |
1309 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); | 1296 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
1310 EXPECT_TRUE(nigori.has_encrypted()); | 1297 EXPECT_TRUE(nigori.has_encrypted()); |
1311 EXPECT_GT(nigori.device_information_size(), 0); | 1298 EXPECT_GT(nigori.device_information_size(), 0); |
1312 Cryptographer* cryptographer = trans.GetCryptographer(); | 1299 Cryptographer* cryptographer = trans.GetCryptographer(); |
1313 EXPECT_TRUE(cryptographer->is_ready()); | 1300 EXPECT_TRUE(cryptographer->is_ready()); |
1314 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); | 1301 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); |
1315 } | 1302 } |
1316 } | 1303 } |
1317 | 1304 |
1318 // Attempt to refresh encryption when nigori not downloaded. | 1305 // Attempt to refresh encryption when nigori not downloaded. |
1319 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { | 1306 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { |
1320 // Don't set up encryption (no nigori node created). | 1307 // Don't set up encryption (no nigori node created). |
1321 | 1308 |
1322 // Should fail. | 1309 // Should fail. |
1323 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, | 1310 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, |
1324 base::Unretained(this))); | 1311 base::Unretained(this))); |
1325 scoped_refptr<base::ThreadTestHelper> helper( | |
1326 new base::ThreadTestHelper( | |
1327 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | |
1328 ASSERT_TRUE(helper->Run()); | |
1329 PumpLoop(); | 1312 PumpLoop(); |
1330 | 1313 |
1331 const syncable::ModelTypeSet encrypted_types = | 1314 const syncable::ModelTypeSet encrypted_types = |
1332 sync_manager_.GetEncryptedDataTypesForTest(); | 1315 sync_manager_.GetEncryptedDataTypesForTest(); |
1333 EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS)); // Hardcoded. | 1316 EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS)); // Hardcoded. |
1334 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); | 1317 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); |
1335 } | 1318 } |
1336 | 1319 |
1337 // Attempt to refresh encryption when nigori is empty. | 1320 // Attempt to refresh encryption when nigori is empty. |
1338 TEST_F(SyncManagerTest, RefreshEncryptionEmptyNigori) { | 1321 TEST_F(SyncManagerTest, RefreshEncryptionEmptyNigori) { |
1339 EXPECT_TRUE(SetUpEncryption(DONT_WRITE_NIGORI, DEFAULT_ENCRYPTION)); | 1322 EXPECT_TRUE(SetUpEncryption(DONT_WRITE_NIGORI, DEFAULT_ENCRYPTION)); |
1340 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1323 EXPECT_CALL(observer_, OnEncryptionComplete()); |
1341 | 1324 |
1342 // Should write to nigori. | 1325 // Should write to nigori. |
1343 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, | 1326 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, |
1344 base::Unretained(this))); | 1327 base::Unretained(this))); |
1345 scoped_refptr<base::ThreadTestHelper> helper( | |
1346 new base::ThreadTestHelper( | |
1347 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | |
1348 ASSERT_TRUE(helper->Run()); | |
1349 PumpLoop(); | 1328 PumpLoop(); |
1350 | 1329 |
1351 const syncable::ModelTypeSet encrypted_types = | 1330 const syncable::ModelTypeSet encrypted_types = |
1352 sync_manager_.GetEncryptedDataTypesForTest(); | 1331 sync_manager_.GetEncryptedDataTypesForTest(); |
1353 EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS)); // Hardcoded. | 1332 EXPECT_TRUE(encrypted_types.Has(syncable::PASSWORDS)); // Hardcoded. |
1354 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); | 1333 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); |
1355 { | 1334 { |
1356 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1335 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
1357 ReadNode node(&trans); | 1336 ReadNode node(&trans); |
1358 EXPECT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); | 1337 EXPECT_TRUE(node.InitByIdLookup(GetIdForDataType(syncable::NIGORI))); |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1948 | 1927 |
1949 // Encrypt the datatatype, should set is_unsynced. | 1928 // Encrypt the datatatype, should set is_unsynced. |
1950 EXPECT_CALL(observer_, | 1929 EXPECT_CALL(observer_, |
1951 OnEncryptedTypesChanged( | 1930 OnEncryptedTypesChanged( |
1952 HasModelTypes(syncable::ModelTypeSet::All()), true)); | 1931 HasModelTypes(syncable::ModelTypeSet::All()), true)); |
1953 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1932 EXPECT_CALL(observer_, OnEncryptionComplete()); |
1954 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 1933 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
1955 | 1934 |
1956 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, | 1935 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, |
1957 base::Unretained(this))); | 1936 base::Unretained(this))); |
1958 scoped_refptr<base::ThreadTestHelper> helper( | |
1959 new base::ThreadTestHelper( | |
1960 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | |
1961 ASSERT_TRUE(helper->Run()); | |
1962 PumpLoop(); | 1937 PumpLoop(); |
1963 { | 1938 { |
1964 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1939 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
1965 ReadNode node(&trans); | 1940 ReadNode node(&trans); |
1966 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); | 1941 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); |
1967 const syncable::Entry* node_entry = node.GetEntry(); | 1942 const syncable::Entry* node_entry = node.GetEntry(); |
1968 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 1943 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
1969 EXPECT_TRUE(specifics.has_encrypted()); | 1944 EXPECT_TRUE(specifics.has_encrypted()); |
1970 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 1945 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
1971 Cryptographer* cryptographer = trans.GetCryptographer(); | 1946 Cryptographer* cryptographer = trans.GetCryptographer(); |
(...skipping 23 matching lines...) Expand all Loading... |
1995 specifics.encrypted())); | 1970 specifics.encrypted())); |
1996 } | 1971 } |
1997 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 1972 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
1998 | 1973 |
1999 // Force a re-encrypt everything. Should not set is_unsynced. | 1974 // Force a re-encrypt everything. Should not set is_unsynced. |
2000 testing::Mock::VerifyAndClearExpectations(&observer_); | 1975 testing::Mock::VerifyAndClearExpectations(&observer_); |
2001 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1976 EXPECT_CALL(observer_, OnEncryptionComplete()); |
2002 | 1977 |
2003 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, | 1978 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, |
2004 base::Unretained(this))); | 1979 base::Unretained(this))); |
2005 ASSERT_TRUE(helper->Run()); | |
2006 PumpLoop(); | 1980 PumpLoop(); |
2007 | 1981 |
2008 { | 1982 { |
2009 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1983 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2010 ReadNode node(&trans); | 1984 ReadNode node(&trans); |
2011 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); | 1985 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); |
2012 const syncable::Entry* node_entry = node.GetEntry(); | 1986 const syncable::Entry* node_entry = node.GetEntry(); |
2013 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 1987 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
2014 EXPECT_TRUE(specifics.has_encrypted()); | 1988 EXPECT_TRUE(specifics.has_encrypted()); |
2015 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 1989 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2193 client_tag), | 2167 client_tag), |
2194 entity_specifics); | 2168 entity_specifics); |
2195 // New node shouldn't start off unsynced. | 2169 // New node shouldn't start off unsynced. |
2196 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2170 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
2197 | 2171 |
2198 // Force a re-encrypt everything. Should not set is_unsynced. | 2172 // Force a re-encrypt everything. Should not set is_unsynced. |
2199 testing::Mock::VerifyAndClearExpectations(&observer_); | 2173 testing::Mock::VerifyAndClearExpectations(&observer_); |
2200 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2174 EXPECT_CALL(observer_, OnEncryptionComplete()); |
2201 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, | 2175 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, |
2202 base::Unretained(this))); | 2176 base::Unretained(this))); |
2203 scoped_refptr<base::ThreadTestHelper> helper( | |
2204 new base::ThreadTestHelper( | |
2205 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | |
2206 ASSERT_TRUE(helper->Run()); | |
2207 PumpLoop(); | 2177 PumpLoop(); |
2208 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2178 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
2209 } | 2179 } |
2210 | 2180 |
2211 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks | 2181 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks |
2212 // when we write the same data, but does set it when we write new data. | 2182 // when we write the same data, but does set it when we write new data. |
2213 TEST_F(SyncManagerTest, SetBookmarkTitle) { | 2183 TEST_F(SyncManagerTest, SetBookmarkTitle) { |
2214 std::string client_tag = "title"; | 2184 std::string client_tag = "title"; |
2215 sync_pb::EntitySpecifics entity_specifics; | 2185 sync_pb::EntitySpecifics entity_specifics; |
2216 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url("url"); | 2186 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url("url"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2257 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2227 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
2258 | 2228 |
2259 // Encrypt the datatatype, should set is_unsynced. | 2229 // Encrypt the datatatype, should set is_unsynced. |
2260 EXPECT_CALL(observer_, | 2230 EXPECT_CALL(observer_, |
2261 OnEncryptedTypesChanged( | 2231 OnEncryptedTypesChanged( |
2262 HasModelTypes(syncable::ModelTypeSet::All()), true)); | 2232 HasModelTypes(syncable::ModelTypeSet::All()), true)); |
2263 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2233 EXPECT_CALL(observer_, OnEncryptionComplete()); |
2264 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 2234 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
2265 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, | 2235 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, |
2266 base::Unretained(this))); | 2236 base::Unretained(this))); |
2267 scoped_refptr<base::ThreadTestHelper> helper( | |
2268 new base::ThreadTestHelper( | |
2269 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | |
2270 ASSERT_TRUE(helper->Run()); | |
2271 PumpLoop(); | 2237 PumpLoop(); |
2272 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2238 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
2273 | 2239 |
2274 // Manually change to the same title. Should not set is_unsynced. | 2240 // Manually change to the same title. Should not set is_unsynced. |
2275 // NON_UNIQUE_NAME should be kEncryptedString. | 2241 // NON_UNIQUE_NAME should be kEncryptedString. |
2276 { | 2242 { |
2277 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2243 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2278 WriteNode node(&trans); | 2244 WriteNode node(&trans); |
2279 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); | 2245 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); |
2280 node.SetTitle(UTF8ToWide(client_tag)); | 2246 node.SetTitle(UTF8ToWide(client_tag)); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2353 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); | 2319 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); |
2354 | 2320 |
2355 // Encrypt the datatatype, should set is_unsynced. | 2321 // Encrypt the datatatype, should set is_unsynced. |
2356 EXPECT_CALL(observer_, | 2322 EXPECT_CALL(observer_, |
2357 OnEncryptedTypesChanged( | 2323 OnEncryptedTypesChanged( |
2358 HasModelTypes(syncable::ModelTypeSet::All()), true)); | 2324 HasModelTypes(syncable::ModelTypeSet::All()), true)); |
2359 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2325 EXPECT_CALL(observer_, OnEncryptionComplete()); |
2360 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 2326 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
2361 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, | 2327 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, |
2362 base::Unretained(this))); | 2328 base::Unretained(this))); |
2363 scoped_refptr<base::ThreadTestHelper> helper( | |
2364 new base::ThreadTestHelper( | |
2365 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | |
2366 ASSERT_TRUE(helper->Run()); | |
2367 PumpLoop(); | 2329 PumpLoop(); |
2368 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); | 2330 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); |
2369 | 2331 |
2370 // Manually change to the same title. Should not set is_unsynced. | 2332 // Manually change to the same title. Should not set is_unsynced. |
2371 // NON_UNIQUE_NAME should be kEncryptedString. | 2333 // NON_UNIQUE_NAME should be kEncryptedString. |
2372 { | 2334 { |
2373 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2335 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2374 WriteNode node(&trans); | 2336 WriteNode node(&trans); |
2375 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); | 2337 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PREFERENCES, client_tag)); |
2376 node.SetTitle(UTF8ToWide(client_tag)); | 2338 node.SetTitle(UTF8ToWide(client_tag)); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2447 EXPECT_EQ(title, node.GetTitle()); | 2409 EXPECT_EQ(title, node.GetTitle()); |
2448 EXPECT_EQ(GURL(url2), node.GetURL()); | 2410 EXPECT_EQ(GURL(url2), node.GetURL()); |
2449 const syncable::Entry* node_entry = node.GetEntry(); | 2411 const syncable::Entry* node_entry = node.GetEntry(); |
2450 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2412 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
2451 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2413 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
2452 EXPECT_TRUE(specifics.has_encrypted()); | 2414 EXPECT_TRUE(specifics.has_encrypted()); |
2453 } | 2415 } |
2454 } | 2416 } |
2455 | 2417 |
2456 } // namespace browser_sync | 2418 } // namespace browser_sync |
OLD | NEW |