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 <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/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
16 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
23 #include "base/test/values_test_util.h" | 23 #include "base/test/values_test_util.h" |
24 #include "base/values.h" | 24 #include "base/values.h" |
25 #include "google_apis/gaia/gaia_constants.h" | 25 #include "google_apis/gaia/gaia_constants.h" |
26 #include "sync/engine/sync_scheduler.h" | 26 #include "sync/engine/sync_scheduler.h" |
| 27 #include "sync/internal_api/public/base/attachment_id_proto.h" |
27 #include "sync/internal_api/public/base/cancelation_signal.h" | 28 #include "sync/internal_api/public/base/cancelation_signal.h" |
28 #include "sync/internal_api/public/base/model_type_test_util.h" | 29 #include "sync/internal_api/public/base/model_type_test_util.h" |
29 #include "sync/internal_api/public/change_record.h" | 30 #include "sync/internal_api/public/change_record.h" |
30 #include "sync/internal_api/public/engine/model_safe_worker.h" | 31 #include "sync/internal_api/public/engine/model_safe_worker.h" |
31 #include "sync/internal_api/public/engine/polling_constants.h" | 32 #include "sync/internal_api/public/engine/polling_constants.h" |
32 #include "sync/internal_api/public/events/protocol_event.h" | 33 #include "sync/internal_api/public/events/protocol_event.h" |
33 #include "sync/internal_api/public/http_post_provider_factory.h" | 34 #include "sync/internal_api/public/http_post_provider_factory.h" |
34 #include "sync/internal_api/public/http_post_provider_interface.h" | 35 #include "sync/internal_api/public/http_post_provider_interface.h" |
35 #include "sync/internal_api/public/read_node.h" | 36 #include "sync/internal_api/public/read_node.h" |
36 #include "sync/internal_api/public/read_transaction.h" | 37 #include "sync/internal_api/public/read_transaction.h" |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 860 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
860 (*out)[NIGORI] = GROUP_PASSIVE; | 861 (*out)[NIGORI] = GROUP_PASSIVE; |
861 (*out)[DEVICE_INFO] = GROUP_PASSIVE; | 862 (*out)[DEVICE_INFO] = GROUP_PASSIVE; |
862 (*out)[EXPERIMENTS] = GROUP_PASSIVE; | 863 (*out)[EXPERIMENTS] = GROUP_PASSIVE; |
863 (*out)[BOOKMARKS] = GROUP_PASSIVE; | 864 (*out)[BOOKMARKS] = GROUP_PASSIVE; |
864 (*out)[THEMES] = GROUP_PASSIVE; | 865 (*out)[THEMES] = GROUP_PASSIVE; |
865 (*out)[SESSIONS] = GROUP_PASSIVE; | 866 (*out)[SESSIONS] = GROUP_PASSIVE; |
866 (*out)[PASSWORDS] = GROUP_PASSIVE; | 867 (*out)[PASSWORDS] = GROUP_PASSIVE; |
867 (*out)[PREFERENCES] = GROUP_PASSIVE; | 868 (*out)[PREFERENCES] = GROUP_PASSIVE; |
868 (*out)[PRIORITY_PREFERENCES] = GROUP_PASSIVE; | 869 (*out)[PRIORITY_PREFERENCES] = GROUP_PASSIVE; |
| 870 (*out)[ARTICLES] = GROUP_PASSIVE; |
869 } | 871 } |
870 | 872 |
871 ModelTypeSet GetEnabledTypes() { | 873 ModelTypeSet GetEnabledTypes() { |
872 ModelSafeRoutingInfo routing_info; | 874 ModelSafeRoutingInfo routing_info; |
873 GetModelSafeRoutingInfo(&routing_info); | 875 GetModelSafeRoutingInfo(&routing_info); |
874 return GetRoutingInfoTypes(routing_info); | 876 return GetRoutingInfoTypes(routing_info); |
875 } | 877 } |
876 | 878 |
877 virtual void OnChangesApplied( | 879 virtual void OnChangesApplied( |
878 ModelType model_type, | 880 ModelType model_type, |
(...skipping 1986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2865 | 2867 |
2866 // Returns the current size of the change list. | 2868 // Returns the current size of the change list. |
2867 // | 2869 // |
2868 // Note that spurious changes do not necessarily indicate a problem. | 2870 // Note that spurious changes do not necessarily indicate a problem. |
2869 // Assertions on change list size can help detect problems, but it may be | 2871 // Assertions on change list size can help detect problems, but it may be |
2870 // necessary to reduce their strictness if the implementation changes. | 2872 // necessary to reduce their strictness if the implementation changes. |
2871 size_t GetChangeListSize() { | 2873 size_t GetChangeListSize() { |
2872 return last_changes_.Get().size(); | 2874 return last_changes_.Get().size(); |
2873 } | 2875 } |
2874 | 2876 |
| 2877 void ClearChangeList() { last_changes_ = ImmutableChangeRecordList(); } |
| 2878 |
2875 protected: | 2879 protected: |
2876 ImmutableChangeRecordList last_changes_; | 2880 ImmutableChangeRecordList last_changes_; |
2877 TestIdFactory id_factory_; | 2881 TestIdFactory id_factory_; |
2878 }; | 2882 }; |
2879 | 2883 |
2880 // Test creation of a folder and a bookmark. | 2884 // Test creation of a folder and a bookmark. |
2881 TEST_F(SyncManagerChangeProcessingTest, AddBookmarks) { | 2885 TEST_F(SyncManagerChangeProcessingTest, AddBookmarks) { |
2882 int64 type_root = GetIdForDataType(BOOKMARKS); | 2886 int64 type_root = GetIdForDataType(BOOKMARKS); |
2883 int64 folder_id = kInvalidId; | 2887 int64 folder_id = kInvalidId; |
2884 int64 child_id = kInvalidId; | 2888 int64 child_id = kInvalidId; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3100 FindChangeInList(folder_a_id, ChangeRecord::ACTION_UPDATE); | 3104 FindChangeInList(folder_a_id, ChangeRecord::ACTION_UPDATE); |
3101 size_t folder_b_pos = | 3105 size_t folder_b_pos = |
3102 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); | 3106 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); |
3103 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); | 3107 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); |
3104 | 3108 |
3105 // Deletes should appear before updates. | 3109 // Deletes should appear before updates. |
3106 EXPECT_LT(child_pos, folder_a_pos); | 3110 EXPECT_LT(child_pos, folder_a_pos); |
3107 EXPECT_LT(folder_b_pos, folder_a_pos); | 3111 EXPECT_LT(folder_b_pos, folder_a_pos); |
3108 } | 3112 } |
3109 | 3113 |
| 3114 // See that attachment metadata changes are not filtered out by |
| 3115 // SyncManagerImpl::VisiblePropertiesDiffer. |
| 3116 TEST_F(SyncManagerChangeProcessingTest, AttachmentMetadataOnlyChanges) { |
| 3117 // Create an article with no attachments. See that a change is generated. |
| 3118 int64 article_id = kInvalidId; |
| 3119 { |
| 3120 syncable::WriteTransaction trans( |
| 3121 FROM_HERE, syncable::SYNCER, share()->directory.get()); |
| 3122 int64 type_root = GetIdForDataType(ARTICLES); |
| 3123 syncable::Entry root(&trans, syncable::GET_BY_HANDLE, type_root); |
| 3124 ASSERT_TRUE(root.good()); |
| 3125 syncable::MutableEntry article( |
| 3126 &trans, syncable::CREATE, ARTICLES, root.GetId(), "article"); |
| 3127 ASSERT_TRUE(article.good()); |
| 3128 SetNodeProperties(&article); |
| 3129 article_id = article.GetMetahandle(); |
| 3130 } |
| 3131 ASSERT_EQ(1UL, GetChangeListSize()); |
| 3132 FindChangeInList(article_id, ChangeRecord::ACTION_ADD); |
| 3133 ClearChangeList(); |
| 3134 |
| 3135 // Modify the article by adding one attachment. Don't touch anything else. |
| 3136 // See that a change is generated. |
| 3137 { |
| 3138 syncable::WriteTransaction trans( |
| 3139 FROM_HERE, syncable::SYNCER, share()->directory.get()); |
| 3140 syncable::MutableEntry article(&trans, syncable::GET_BY_HANDLE, article_id); |
| 3141 sync_pb::AttachmentMetadata metadata; |
| 3142 *metadata.add_record()->mutable_id() = CreateAttachmentIdProto(); |
| 3143 article.PutAttachmentMetadata(metadata); |
| 3144 } |
| 3145 ASSERT_EQ(1UL, GetChangeListSize()); |
| 3146 FindChangeInList(article_id, ChangeRecord::ACTION_UPDATE); |
| 3147 ClearChangeList(); |
| 3148 |
| 3149 // Modify the article by replacing its attachment with a different one. See |
| 3150 // that a change is generated. |
| 3151 { |
| 3152 syncable::WriteTransaction trans( |
| 3153 FROM_HERE, syncable::SYNCER, share()->directory.get()); |
| 3154 syncable::MutableEntry article(&trans, syncable::GET_BY_HANDLE, article_id); |
| 3155 sync_pb::AttachmentMetadata metadata = article.GetAttachmentMetadata(); |
| 3156 *metadata.add_record()->mutable_id() = CreateAttachmentIdProto(); |
| 3157 article.PutAttachmentMetadata(metadata); |
| 3158 } |
| 3159 ASSERT_EQ(1UL, GetChangeListSize()); |
| 3160 FindChangeInList(article_id, ChangeRecord::ACTION_UPDATE); |
| 3161 ClearChangeList(); |
| 3162 |
| 3163 // Modify the article by replacing its attachment metadata with the same |
| 3164 // attachment metadata. No change should be generated. |
| 3165 { |
| 3166 syncable::WriteTransaction trans( |
| 3167 FROM_HERE, syncable::SYNCER, share()->directory.get()); |
| 3168 syncable::MutableEntry article(&trans, syncable::GET_BY_HANDLE, article_id); |
| 3169 article.PutAttachmentMetadata(article.GetAttachmentMetadata()); |
| 3170 } |
| 3171 ASSERT_EQ(0UL, GetChangeListSize()); |
| 3172 } |
| 3173 |
3110 // During initialization SyncManagerImpl loads sqlite database. If it fails to | 3174 // During initialization SyncManagerImpl loads sqlite database. If it fails to |
3111 // do so it should fail initialization. This test verifies this behavior. | 3175 // do so it should fail initialization. This test verifies this behavior. |
3112 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides | 3176 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides |
3113 // InternalComponentsFactory to return DirectoryBackingStore that always fails | 3177 // InternalComponentsFactory to return DirectoryBackingStore that always fails |
3114 // to load. | 3178 // to load. |
3115 class SyncManagerInitInvalidStorageTest : public SyncManagerTest { | 3179 class SyncManagerInitInvalidStorageTest : public SyncManagerTest { |
3116 public: | 3180 public: |
3117 SyncManagerInitInvalidStorageTest() { | 3181 SyncManagerInitInvalidStorageTest() { |
3118 } | 3182 } |
3119 | 3183 |
3120 virtual InternalComponentsFactory* GetFactory() OVERRIDE { | 3184 virtual InternalComponentsFactory* GetFactory() OVERRIDE { |
3121 return new TestInternalComponentsFactory(GetSwitches(), STORAGE_INVALID); | 3185 return new TestInternalComponentsFactory(GetSwitches(), STORAGE_INVALID); |
3122 } | 3186 } |
3123 }; | 3187 }; |
3124 | 3188 |
3125 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3189 // SyncManagerInitInvalidStorageTest::GetFactory will return |
3126 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3190 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
3127 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3191 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
3128 // task is to ensure that SyncManagerImpl reported initialization failure in | 3192 // task is to ensure that SyncManagerImpl reported initialization failure in |
3129 // OnInitializationComplete callback. | 3193 // OnInitializationComplete callback. |
3130 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3194 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
3131 EXPECT_FALSE(initialization_succeeded_); | 3195 EXPECT_FALSE(initialization_succeeded_); |
3132 } | 3196 } |
3133 | 3197 |
3134 } // namespace syncer | 3198 } // namespace syncer |
OLD | NEW |