| 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 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/search_engines/search_terms_data.h" | 10 #include "chrome/browser/search_engines/search_terms_data.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "sync/api/sync_error_factory.h" | 23 #include "sync/api/sync_error_factory.h" |
| 24 #include "sync/api/sync_error_factory_mock.h" | 24 #include "sync/api/sync_error_factory_mock.h" |
| 25 #include "sync/protocol/search_engine_specifics.pb.h" | 25 #include "sync/protocol/search_engine_specifics.pb.h" |
| 26 #include "sync/protocol/sync.pb.h" | 26 #include "sync/protocol/sync.pb.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 using base::Time; | 29 using base::Time; |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Extract the GUID from a search engine csync::SyncData. | 33 // Extract the GUID from a search engine syncer::SyncData. |
| 34 std::string GetGUID(const csync::SyncData& sync_data) { | 34 std::string GetGUID(const syncer::SyncData& sync_data) { |
| 35 return sync_data.GetSpecifics().search_engine().sync_guid(); | 35 return sync_data.GetSpecifics().search_engine().sync_guid(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Extract the URL from a search engine csync::SyncData. | 38 // Extract the URL from a search engine syncer::SyncData. |
| 39 std::string GetURL(const csync::SyncData& sync_data) { | 39 std::string GetURL(const syncer::SyncData& sync_data) { |
| 40 return sync_data.GetSpecifics().search_engine().url(); | 40 return sync_data.GetSpecifics().search_engine().url(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Extract the keyword from a search engine csync::SyncData. | 43 // Extract the keyword from a search engine syncer::SyncData. |
| 44 std::string GetKeyword(const csync::SyncData& sync_data) { | 44 std::string GetKeyword(const syncer::SyncData& sync_data) { |
| 45 return sync_data.GetSpecifics().search_engine().keyword(); | 45 return sync_data.GetSpecifics().search_engine().keyword(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Much like TemplateURLService::CreateSyncDataFromTemplateURL(), but allows the | 48 // Much like TemplateURLService::CreateSyncDataFromTemplateURL(), but allows the |
| 49 // caller to override the keyword, URL, or GUID fields with empty strings, in | 49 // caller to override the keyword, URL, or GUID fields with empty strings, in |
| 50 // order to create custom data that should be handled specially when synced to a | 50 // order to create custom data that should be handled specially when synced to a |
| 51 // client. | 51 // client. |
| 52 csync::SyncData CreateCustomSyncData(const TemplateURL& turl, | 52 syncer::SyncData CreateCustomSyncData(const TemplateURL& turl, |
| 53 bool autogenerate_keyword, | 53 bool autogenerate_keyword, |
| 54 const std::string& url, | 54 const std::string& url, |
| 55 const std::string& sync_guid) { | 55 const std::string& sync_guid) { |
| 56 sync_pb::EntitySpecifics specifics; | 56 sync_pb::EntitySpecifics specifics; |
| 57 sync_pb::SearchEngineSpecifics* se_specifics = | 57 sync_pb::SearchEngineSpecifics* se_specifics = |
| 58 specifics.mutable_search_engine(); | 58 specifics.mutable_search_engine(); |
| 59 se_specifics->set_short_name(UTF16ToUTF8(turl.short_name())); | 59 se_specifics->set_short_name(UTF16ToUTF8(turl.short_name())); |
| 60 se_specifics->set_keyword( | 60 se_specifics->set_keyword( |
| 61 autogenerate_keyword ? std::string() : UTF16ToUTF8(turl.keyword())); | 61 autogenerate_keyword ? std::string() : UTF16ToUTF8(turl.keyword())); |
| 62 se_specifics->set_favicon_url(turl.favicon_url().spec()); | 62 se_specifics->set_favicon_url(turl.favicon_url().spec()); |
| 63 se_specifics->set_url(url); | 63 se_specifics->set_url(url); |
| 64 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); | 64 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); |
| 65 se_specifics->set_originating_url(turl.originating_url().spec()); | 65 se_specifics->set_originating_url(turl.originating_url().spec()); |
| 66 se_specifics->set_date_created(turl.date_created().ToInternalValue()); | 66 se_specifics->set_date_created(turl.date_created().ToInternalValue()); |
| 67 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); | 67 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); |
| 68 se_specifics->set_show_in_default_list(turl.show_in_default_list()); | 68 se_specifics->set_show_in_default_list(turl.show_in_default_list()); |
| 69 se_specifics->set_suggestions_url(turl.suggestions_url()); | 69 se_specifics->set_suggestions_url(turl.suggestions_url()); |
| 70 se_specifics->set_prepopulate_id(turl.prepopulate_id()); | 70 se_specifics->set_prepopulate_id(turl.prepopulate_id()); |
| 71 se_specifics->set_autogenerate_keyword(autogenerate_keyword); | 71 se_specifics->set_autogenerate_keyword(autogenerate_keyword); |
| 72 se_specifics->set_instant_url(turl.instant_url()); | 72 se_specifics->set_instant_url(turl.instant_url()); |
| 73 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); | 73 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); |
| 74 se_specifics->set_sync_guid(sync_guid); | 74 se_specifics->set_sync_guid(sync_guid); |
| 75 return csync::SyncData::CreateLocalData(turl.sync_guid(), // Must be valid! | 75 return syncer::SyncData::CreateLocalData(turl.sync_guid(), // Must be valid! |
| 76 se_specifics->keyword(), specifics); | 76 se_specifics->keyword(), specifics); |
| 77 } | 77 } |
| 78 | 78 |
| 79 | 79 |
| 80 // TestChangeProcessor -------------------------------------------------------- | 80 // TestChangeProcessor -------------------------------------------------------- |
| 81 | 81 |
| 82 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed | 82 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed |
| 83 // back up to Sync. | 83 // back up to Sync. |
| 84 class TestChangeProcessor : public csync::SyncChangeProcessor { | 84 class TestChangeProcessor : public syncer::SyncChangeProcessor { |
| 85 public: | 85 public: |
| 86 TestChangeProcessor(); | 86 TestChangeProcessor(); |
| 87 virtual ~TestChangeProcessor(); | 87 virtual ~TestChangeProcessor(); |
| 88 | 88 |
| 89 // Store a copy of all the changes passed in so we can examine them later. | 89 // Store a copy of all the changes passed in so we can examine them later. |
| 90 virtual csync::SyncError ProcessSyncChanges( | 90 virtual syncer::SyncError ProcessSyncChanges( |
| 91 const tracked_objects::Location& from_here, | 91 const tracked_objects::Location& from_here, |
| 92 const csync::SyncChangeList& change_list) OVERRIDE; | 92 const syncer::SyncChangeList& change_list) OVERRIDE; |
| 93 | 93 |
| 94 bool contains_guid(const std::string& guid) const { | 94 bool contains_guid(const std::string& guid) const { |
| 95 return change_map_.count(guid) != 0; | 95 return change_map_.count(guid) != 0; |
| 96 } | 96 } |
| 97 | 97 |
| 98 csync::SyncChange change_for_guid(const std::string& guid) const { | 98 syncer::SyncChange change_for_guid(const std::string& guid) const { |
| 99 DCHECK(contains_guid(guid)); | 99 DCHECK(contains_guid(guid)); |
| 100 return change_map_.find(guid)->second; | 100 return change_map_.find(guid)->second; |
| 101 } | 101 } |
| 102 | 102 |
| 103 size_t change_list_size() { return change_map_.size(); } | 103 size_t change_list_size() { return change_map_.size(); } |
| 104 | 104 |
| 105 void set_erroneous(bool erroneous) { erroneous_ = erroneous; } | 105 void set_erroneous(bool erroneous) { erroneous_ = erroneous; } |
| 106 | 106 |
| 107 private: | 107 private: |
| 108 // Track the changes received in ProcessSyncChanges. | 108 // Track the changes received in ProcessSyncChanges. |
| 109 std::map<std::string, csync::SyncChange> change_map_; | 109 std::map<std::string, syncer::SyncChange> change_map_; |
| 110 bool erroneous_; | 110 bool erroneous_; |
| 111 | 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); | 112 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 TestChangeProcessor::TestChangeProcessor() : erroneous_(false) { | 115 TestChangeProcessor::TestChangeProcessor() : erroneous_(false) { |
| 116 } | 116 } |
| 117 | 117 |
| 118 TestChangeProcessor::~TestChangeProcessor() { | 118 TestChangeProcessor::~TestChangeProcessor() { |
| 119 } | 119 } |
| 120 | 120 |
| 121 csync::SyncError TestChangeProcessor::ProcessSyncChanges( | 121 syncer::SyncError TestChangeProcessor::ProcessSyncChanges( |
| 122 const tracked_objects::Location& from_here, | 122 const tracked_objects::Location& from_here, |
| 123 const csync::SyncChangeList& change_list) { | 123 const syncer::SyncChangeList& change_list) { |
| 124 if (erroneous_) | 124 if (erroneous_) |
| 125 return csync::SyncError(FROM_HERE, "Some error.", syncable::SEARCH_ENGINES); | 125 return syncer::SyncError( |
| 126 FROM_HERE, "Some error.", syncable::SEARCH_ENGINES); |
| 126 | 127 |
| 127 change_map_.erase(change_map_.begin(), change_map_.end()); | 128 change_map_.erase(change_map_.begin(), change_map_.end()); |
| 128 for (csync::SyncChangeList::const_iterator iter = change_list.begin(); | 129 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); |
| 129 iter != change_list.end(); ++iter) | 130 iter != change_list.end(); ++iter) |
| 130 change_map_[GetGUID(iter->sync_data())] = *iter; | 131 change_map_[GetGUID(iter->sync_data())] = *iter; |
| 131 return csync::SyncError(); | 132 return syncer::SyncError(); |
| 132 } | 133 } |
| 133 | 134 |
| 134 | 135 |
| 135 // SyncChangeProcessorDelegate ------------------------------------------------ | 136 // SyncChangeProcessorDelegate ------------------------------------------------ |
| 136 | 137 |
| 137 class SyncChangeProcessorDelegate : public csync::SyncChangeProcessor { | 138 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor { |
| 138 public: | 139 public: |
| 139 explicit SyncChangeProcessorDelegate(csync::SyncChangeProcessor* recipient); | 140 explicit SyncChangeProcessorDelegate(syncer::SyncChangeProcessor* recipient); |
| 140 virtual ~SyncChangeProcessorDelegate(); | 141 virtual ~SyncChangeProcessorDelegate(); |
| 141 | 142 |
| 142 // csync::SyncChangeProcessor implementation. | 143 // syncer::SyncChangeProcessor implementation. |
| 143 virtual csync::SyncError ProcessSyncChanges( | 144 virtual syncer::SyncError ProcessSyncChanges( |
| 144 const tracked_objects::Location& from_here, | 145 const tracked_objects::Location& from_here, |
| 145 const csync::SyncChangeList& change_list) OVERRIDE; | 146 const syncer::SyncChangeList& change_list) OVERRIDE; |
| 146 | 147 |
| 147 private: | 148 private: |
| 148 // The recipient of all sync changes. | 149 // The recipient of all sync changes. |
| 149 csync::SyncChangeProcessor* recipient_; | 150 syncer::SyncChangeProcessor* recipient_; |
| 150 | 151 |
| 151 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); | 152 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); |
| 152 }; | 153 }; |
| 153 | 154 |
| 154 SyncChangeProcessorDelegate::SyncChangeProcessorDelegate( | 155 SyncChangeProcessorDelegate::SyncChangeProcessorDelegate( |
| 155 csync::SyncChangeProcessor* recipient) | 156 syncer::SyncChangeProcessor* recipient) |
| 156 : recipient_(recipient) { | 157 : recipient_(recipient) { |
| 157 DCHECK(recipient_); | 158 DCHECK(recipient_); |
| 158 } | 159 } |
| 159 | 160 |
| 160 SyncChangeProcessorDelegate::~SyncChangeProcessorDelegate() { | 161 SyncChangeProcessorDelegate::~SyncChangeProcessorDelegate() { |
| 161 } | 162 } |
| 162 | 163 |
| 163 csync::SyncError SyncChangeProcessorDelegate::ProcessSyncChanges( | 164 syncer::SyncError SyncChangeProcessorDelegate::ProcessSyncChanges( |
| 164 const tracked_objects::Location& from_here, | 165 const tracked_objects::Location& from_here, |
| 165 const csync::SyncChangeList& change_list) { | 166 const syncer::SyncChangeList& change_list) { |
| 166 return recipient_->ProcessSyncChanges(from_here, change_list); | 167 return recipient_->ProcessSyncChanges(from_here, change_list); |
| 167 } | 168 } |
| 168 | 169 |
| 169 } // namespace | 170 } // namespace |
| 170 | 171 |
| 171 | 172 |
| 172 // TemplateURLServiceSyncTest ------------------------------------------------- | 173 // TemplateURLServiceSyncTest ------------------------------------------------- |
| 173 | 174 |
| 174 class TemplateURLServiceSyncTest : public testing::Test { | 175 class TemplateURLServiceSyncTest : public testing::Test { |
| 175 public: | 176 public: |
| 176 typedef TemplateURLService::SyncDataMap SyncDataMap; | 177 typedef TemplateURLService::SyncDataMap SyncDataMap; |
| 177 | 178 |
| 178 TemplateURLServiceSyncTest(); | 179 TemplateURLServiceSyncTest(); |
| 179 | 180 |
| 180 virtual void SetUp() OVERRIDE; | 181 virtual void SetUp() OVERRIDE; |
| 181 virtual void TearDown() OVERRIDE; | 182 virtual void TearDown() OVERRIDE; |
| 182 | 183 |
| 183 TemplateURLService* model() { return test_util_a_.model(); } | 184 TemplateURLService* model() { return test_util_a_.model(); } |
| 184 // For readability, we redefine an accessor for Model A for use in tests that | 185 // For readability, we redefine an accessor for Model A for use in tests that |
| 185 // involve syncing two models. | 186 // involve syncing two models. |
| 186 TemplateURLService* model_a() { return test_util_a_.model(); } | 187 TemplateURLService* model_a() { return test_util_a_.model(); } |
| 187 TemplateURLService* model_b() { return model_b_.get(); } | 188 TemplateURLService* model_b() { return model_b_.get(); } |
| 188 TestingProfile* profile_a() { return test_util_a_.profile(); } | 189 TestingProfile* profile_a() { return test_util_a_.profile(); } |
| 189 TestChangeProcessor* processor() { return sync_processor_.get(); } | 190 TestChangeProcessor* processor() { return sync_processor_.get(); } |
| 190 scoped_ptr<csync::SyncChangeProcessor> PassProcessor(); | 191 scoped_ptr<syncer::SyncChangeProcessor> PassProcessor(); |
| 191 scoped_ptr<csync::SyncErrorFactory> CreateAndPassSyncErrorFactory(); | 192 scoped_ptr<syncer::SyncErrorFactory> CreateAndPassSyncErrorFactory(); |
| 192 | 193 |
| 193 // Create a TemplateURL with some test values. The caller owns the returned | 194 // Create a TemplateURL with some test values. The caller owns the returned |
| 194 // TemplateURL*. | 195 // TemplateURL*. |
| 195 TemplateURL* CreateTestTemplateURL(const string16& keyword, | 196 TemplateURL* CreateTestTemplateURL(const string16& keyword, |
| 196 const std::string& url, | 197 const std::string& url, |
| 197 const std::string& guid = std::string(), | 198 const std::string& guid = std::string(), |
| 198 time_t last_mod = 100, | 199 time_t last_mod = 100, |
| 199 bool safe_for_autoreplace = false, | 200 bool safe_for_autoreplace = false, |
| 200 bool created_by_policy = false) const; | 201 bool created_by_policy = false) const; |
| 201 | 202 |
| 202 // Verifies the two TemplateURLs are equal. | 203 // Verifies the two TemplateURLs are equal. |
| 203 // TODO(stevet): Share this with TemplateURLServiceTest. | 204 // TODO(stevet): Share this with TemplateURLServiceTest. |
| 204 void AssertEquals(const TemplateURL& expected, | 205 void AssertEquals(const TemplateURL& expected, |
| 205 const TemplateURL& actual) const; | 206 const TemplateURL& actual) const; |
| 206 | 207 |
| 207 // Expect that two csync::SyncDataLists have equal contents, in terms of the | 208 // Expect that two syncer::SyncDataLists have equal contents, in terms of the |
| 208 // sync_guid, keyword, and url fields. | 209 // sync_guid, keyword, and url fields. |
| 209 void AssertEquals(const csync::SyncDataList& data1, | 210 void AssertEquals(const syncer::SyncDataList& data1, |
| 210 const csync::SyncDataList& data2) const; | 211 const syncer::SyncDataList& data2) const; |
| 211 | 212 |
| 212 // Convenience helper for creating SyncChanges. Takes ownership of |turl|. | 213 // Convenience helper for creating SyncChanges. Takes ownership of |turl|. |
| 213 csync::SyncChange CreateTestSyncChange(csync::SyncChange::SyncChangeType type, | 214 syncer::SyncChange CreateTestSyncChange( |
| 214 TemplateURL* turl) const; | 215 syncer::SyncChange::SyncChangeType type, |
| 216 TemplateURL* turl) const; |
| 215 | 217 |
| 216 // Helper that creates some initial sync data. We cheat a little by specifying | 218 // Helper that creates some initial sync data. We cheat a little by specifying |
| 217 // GUIDs for easy identification later. We also make the last_modified times | 219 // GUIDs for easy identification later. We also make the last_modified times |
| 218 // slightly older than CreateTestTemplateURL's default, to test conflict | 220 // slightly older than CreateTestTemplateURL's default, to test conflict |
| 219 // resolution. | 221 // resolution. |
| 220 csync::SyncDataList CreateInitialSyncData() const; | 222 syncer::SyncDataList CreateInitialSyncData() const; |
| 221 | 223 |
| 222 // Syntactic sugar. | 224 // Syntactic sugar. |
| 223 TemplateURL* Deserialize(const csync::SyncData& sync_data); | 225 TemplateURL* Deserialize(const syncer::SyncData& sync_data); |
| 224 | 226 |
| 225 protected: | 227 protected: |
| 226 // We keep two TemplateURLServices to test syncing between them. | 228 // We keep two TemplateURLServices to test syncing between them. |
| 227 TemplateURLServiceTestUtil test_util_a_; | 229 TemplateURLServiceTestUtil test_util_a_; |
| 228 scoped_ptr<TestingProfile> profile_b_; | 230 scoped_ptr<TestingProfile> profile_b_; |
| 229 scoped_ptr<TemplateURLService> model_b_; | 231 scoped_ptr<TemplateURLService> model_b_; |
| 230 | 232 |
| 231 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. | 233 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. |
| 232 scoped_ptr<TestChangeProcessor> sync_processor_; | 234 scoped_ptr<TestChangeProcessor> sync_processor_; |
| 233 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; | 235 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 251 TemplateURLServiceFactory::GetInstance()->RegisterUserPrefsOnProfile( | 253 TemplateURLServiceFactory::GetInstance()->RegisterUserPrefsOnProfile( |
| 252 profile_b_.get()); | 254 profile_b_.get()); |
| 253 model_b_.reset(new TemplateURLService(profile_b_.get())); | 255 model_b_.reset(new TemplateURLService(profile_b_.get())); |
| 254 model_b_->Load(); | 256 model_b_->Load(); |
| 255 } | 257 } |
| 256 | 258 |
| 257 void TemplateURLServiceSyncTest::TearDown() { | 259 void TemplateURLServiceSyncTest::TearDown() { |
| 258 test_util_a_.TearDown(); | 260 test_util_a_.TearDown(); |
| 259 } | 261 } |
| 260 | 262 |
| 261 scoped_ptr<csync::SyncChangeProcessor> | 263 scoped_ptr<syncer::SyncChangeProcessor> |
| 262 TemplateURLServiceSyncTest::PassProcessor() { | 264 TemplateURLServiceSyncTest::PassProcessor() { |
| 263 return sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(); | 265 return sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(); |
| 264 } | 266 } |
| 265 | 267 |
| 266 scoped_ptr<csync::SyncErrorFactory> TemplateURLServiceSyncTest:: | 268 scoped_ptr<syncer::SyncErrorFactory> TemplateURLServiceSyncTest:: |
| 267 CreateAndPassSyncErrorFactory() { | 269 CreateAndPassSyncErrorFactory() { |
| 268 return scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock()); | 270 return scoped_ptr<syncer::SyncErrorFactory>( |
| 271 new syncer::SyncErrorFactoryMock()); |
| 269 } | 272 } |
| 270 | 273 |
| 271 TemplateURL* TemplateURLServiceSyncTest::CreateTestTemplateURL( | 274 TemplateURL* TemplateURLServiceSyncTest::CreateTestTemplateURL( |
| 272 const string16& keyword, | 275 const string16& keyword, |
| 273 const std::string& url, | 276 const std::string& url, |
| 274 const std::string& guid, | 277 const std::string& guid, |
| 275 time_t last_mod, | 278 time_t last_mod, |
| 276 bool safe_for_autoreplace, | 279 bool safe_for_autoreplace, |
| 277 bool created_by_policy) const { | 280 bool created_by_policy) const { |
| 278 TemplateURLData data; | 281 TemplateURLData data; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 298 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); | 301 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); |
| 299 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); | 302 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); |
| 300 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); | 303 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); |
| 301 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); | 304 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); |
| 302 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); | 305 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); |
| 303 ASSERT_EQ(expected.date_created(), actual.date_created()); | 306 ASSERT_EQ(expected.date_created(), actual.date_created()); |
| 304 ASSERT_EQ(expected.last_modified(), actual.last_modified()); | 307 ASSERT_EQ(expected.last_modified(), actual.last_modified()); |
| 305 } | 308 } |
| 306 | 309 |
| 307 void TemplateURLServiceSyncTest::AssertEquals( | 310 void TemplateURLServiceSyncTest::AssertEquals( |
| 308 const csync::SyncDataList& data1, | 311 const syncer::SyncDataList& data1, |
| 309 const csync::SyncDataList& data2) const { | 312 const syncer::SyncDataList& data2) const { |
| 310 SyncDataMap map1 = TemplateURLService::CreateGUIDToSyncDataMap(data1); | 313 SyncDataMap map1 = TemplateURLService::CreateGUIDToSyncDataMap(data1); |
| 311 SyncDataMap map2 = TemplateURLService::CreateGUIDToSyncDataMap(data2); | 314 SyncDataMap map2 = TemplateURLService::CreateGUIDToSyncDataMap(data2); |
| 312 | 315 |
| 313 for (SyncDataMap::const_iterator iter1 = map1.begin(); | 316 for (SyncDataMap::const_iterator iter1 = map1.begin(); |
| 314 iter1 != map1.end(); iter1++) { | 317 iter1 != map1.end(); iter1++) { |
| 315 SyncDataMap::iterator iter2 = map2.find(iter1->first); | 318 SyncDataMap::iterator iter2 = map2.find(iter1->first); |
| 316 if (iter2 != map2.end()) { | 319 if (iter2 != map2.end()) { |
| 317 ASSERT_EQ(GetKeyword(iter1->second), GetKeyword(iter2->second)); | 320 ASSERT_EQ(GetKeyword(iter1->second), GetKeyword(iter2->second)); |
| 318 ASSERT_EQ(GetURL(iter1->second), GetURL(iter2->second)); | 321 ASSERT_EQ(GetURL(iter1->second), GetURL(iter2->second)); |
| 319 map2.erase(iter2); | 322 map2.erase(iter2); |
| 320 } | 323 } |
| 321 } | 324 } |
| 322 EXPECT_EQ(0U, map2.size()); | 325 EXPECT_EQ(0U, map2.size()); |
| 323 } | 326 } |
| 324 | 327 |
| 325 csync::SyncChange TemplateURLServiceSyncTest::CreateTestSyncChange( | 328 syncer::SyncChange TemplateURLServiceSyncTest::CreateTestSyncChange( |
| 326 csync::SyncChange::SyncChangeType type, | 329 syncer::SyncChange::SyncChangeType type, |
| 327 TemplateURL* turl) const { | 330 TemplateURL* turl) const { |
| 328 // We take control of the TemplateURL so make sure it's cleaned up after | 331 // We take control of the TemplateURL so make sure it's cleaned up after |
| 329 // we create data out of it. | 332 // we create data out of it. |
| 330 scoped_ptr<TemplateURL> scoped_turl(turl); | 333 scoped_ptr<TemplateURL> scoped_turl(turl); |
| 331 return csync::SyncChange(type, | 334 return syncer::SyncChange(type, |
| 332 TemplateURLService::CreateSyncDataFromTemplateURL(*scoped_turl)); | 335 TemplateURLService::CreateSyncDataFromTemplateURL(*scoped_turl)); |
| 333 } | 336 } |
| 334 | 337 |
| 335 csync::SyncDataList TemplateURLServiceSyncTest::CreateInitialSyncData() const { | 338 syncer::SyncDataList TemplateURLServiceSyncTest::CreateInitialSyncData() const { |
| 336 csync::SyncDataList list; | 339 syncer::SyncDataList list; |
| 337 | 340 |
| 338 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 341 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 339 "http://key1.com", "key1", 90)); | 342 "http://key1.com", "key1", 90)); |
| 340 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 343 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 341 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", | 344 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", |
| 342 "key2", 90)); | 345 "key2", 90)); |
| 343 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 346 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 344 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", | 347 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", |
| 345 "key3", 90)); | 348 "key3", 90)); |
| 346 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 349 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 347 | 350 |
| 348 return list; | 351 return list; |
| 349 } | 352 } |
| 350 | 353 |
| 351 TemplateURL* TemplateURLServiceSyncTest::Deserialize( | 354 TemplateURL* TemplateURLServiceSyncTest::Deserialize( |
| 352 const csync::SyncData& sync_data) { | 355 const syncer::SyncData& sync_data) { |
| 353 csync::SyncChangeList dummy; | 356 syncer::SyncChangeList dummy; |
| 354 return TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(NULL, | 357 return TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(NULL, |
| 355 NULL, sync_data, &dummy); | 358 NULL, sync_data, &dummy); |
| 356 } | 359 } |
| 357 | 360 |
| 358 | 361 |
| 359 // Actual tests --------------------------------------------------------------- | 362 // Actual tests --------------------------------------------------------------- |
| 360 | 363 |
| 361 TEST_F(TemplateURLServiceSyncTest, SerializeDeserialize) { | 364 TEST_F(TemplateURLServiceSyncTest, SerializeDeserialize) { |
| 362 // Create a TemplateURL and convert it into a sync specific type. | 365 // Create a TemplateURL and convert it into a sync specific type. |
| 363 scoped_ptr<TemplateURL> turl( | 366 scoped_ptr<TemplateURL> turl( |
| 364 CreateTestTemplateURL( | 367 CreateTestTemplateURL( |
| 365 ASCIIToUTF16("unittest"), "http://www.unittest.com/")); | 368 ASCIIToUTF16("unittest"), "http://www.unittest.com/")); |
| 366 csync::SyncData sync_data = | 369 syncer::SyncData sync_data = |
| 367 TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 370 TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
| 368 // Convert the specifics back to a TemplateURL. | 371 // Convert the specifics back to a TemplateURL. |
| 369 scoped_ptr<TemplateURL> deserialized(Deserialize(sync_data)); | 372 scoped_ptr<TemplateURL> deserialized(Deserialize(sync_data)); |
| 370 EXPECT_TRUE(deserialized.get()); | 373 EXPECT_TRUE(deserialized.get()); |
| 371 // Ensure that the original and the deserialized TURLs are equal in values. | 374 // Ensure that the original and the deserialized TURLs are equal in values. |
| 372 AssertEquals(*turl, *deserialized); | 375 AssertEquals(*turl, *deserialized); |
| 373 } | 376 } |
| 374 | 377 |
| 375 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataBasic) { | 378 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataBasic) { |
| 376 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); | 379 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); |
| 377 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 380 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
| 378 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com")); | 381 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com")); |
| 379 csync::SyncDataList all_sync_data = | 382 syncer::SyncDataList all_sync_data = |
| 380 model()->GetAllSyncData(syncable::SEARCH_ENGINES); | 383 model()->GetAllSyncData(syncable::SEARCH_ENGINES); |
| 381 | 384 |
| 382 EXPECT_EQ(3U, all_sync_data.size()); | 385 EXPECT_EQ(3U, all_sync_data.size()); |
| 383 | 386 |
| 384 for (csync::SyncDataList::const_iterator iter = all_sync_data.begin(); | 387 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 385 iter != all_sync_data.end(); ++iter) { | 388 iter != all_sync_data.end(); ++iter) { |
| 386 std::string guid = GetGUID(*iter); | 389 std::string guid = GetGUID(*iter); |
| 387 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); | 390 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); |
| 388 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); | 391 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); |
| 389 AssertEquals(*service_turl, *deserialized); | 392 AssertEquals(*service_turl, *deserialized); |
| 390 } | 393 } |
| 391 } | 394 } |
| 392 | 395 |
| 393 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoExtensions) { | 396 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoExtensions) { |
| 394 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); | 397 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); |
| 395 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 398 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
| 396 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), | 399 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), |
| 397 std::string(chrome::kExtensionScheme) + "://blahblahblah")); | 400 std::string(chrome::kExtensionScheme) + "://blahblahblah")); |
| 398 csync::SyncDataList all_sync_data = | 401 syncer::SyncDataList all_sync_data = |
| 399 model()->GetAllSyncData(syncable::SEARCH_ENGINES); | 402 model()->GetAllSyncData(syncable::SEARCH_ENGINES); |
| 400 | 403 |
| 401 EXPECT_EQ(2U, all_sync_data.size()); | 404 EXPECT_EQ(2U, all_sync_data.size()); |
| 402 | 405 |
| 403 for (csync::SyncDataList::const_iterator iter = all_sync_data.begin(); | 406 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 404 iter != all_sync_data.end(); ++iter) { | 407 iter != all_sync_data.end(); ++iter) { |
| 405 std::string guid = GetGUID(*iter); | 408 std::string guid = GetGUID(*iter); |
| 406 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); | 409 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); |
| 407 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); | 410 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); |
| 408 AssertEquals(*service_turl, *deserialized); | 411 AssertEquals(*service_turl, *deserialized); |
| 409 } | 412 } |
| 410 } | 413 } |
| 411 | 414 |
| 412 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoManagedEngines) { | 415 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoManagedEngines) { |
| 413 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); | 416 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); |
| 414 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 417 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
| 415 TemplateURL* managed_turl = CreateTestTemplateURL(ASCIIToUTF16("key3"), | 418 TemplateURL* managed_turl = CreateTestTemplateURL(ASCIIToUTF16("key3"), |
| 416 "http://key3.com", std::string(), 100, false, true); | 419 "http://key3.com", std::string(), 100, false, true); |
| 417 model()->Add(managed_turl); | 420 model()->Add(managed_turl); |
| 418 csync::SyncDataList all_sync_data = | 421 syncer::SyncDataList all_sync_data = |
| 419 model()->GetAllSyncData(syncable::SEARCH_ENGINES); | 422 model()->GetAllSyncData(syncable::SEARCH_ENGINES); |
| 420 | 423 |
| 421 EXPECT_EQ(2U, all_sync_data.size()); | 424 EXPECT_EQ(2U, all_sync_data.size()); |
| 422 | 425 |
| 423 for (csync::SyncDataList::const_iterator iter = all_sync_data.begin(); | 426 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 424 iter != all_sync_data.end(); ++iter) { | 427 iter != all_sync_data.end(); ++iter) { |
| 425 std::string guid = GetGUID(*iter); | 428 std::string guid = GetGUID(*iter); |
| 426 TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); | 429 TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); |
| 427 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); | 430 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); |
| 428 ASSERT_FALSE(service_turl->created_by_policy()); | 431 ASSERT_FALSE(service_turl->created_by_policy()); |
| 429 AssertEquals(*service_turl, *deserialized); | 432 AssertEquals(*service_turl, *deserialized); |
| 430 } | 433 } |
| 431 } | 434 } |
| 432 | 435 |
| 433 TEST_F(TemplateURLServiceSyncTest, UniquifyKeyword) { | 436 TEST_F(TemplateURLServiceSyncTest, UniquifyKeyword) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 456 new_keyword = model()->UniquifyKeyword(*turl); | 459 new_keyword = model()->UniquifyKeyword(*turl); |
| 457 EXPECT_EQ(ASCIIToUTF16("key1__"), new_keyword); | 460 EXPECT_EQ(ASCIIToUTF16("key1__"), new_keyword); |
| 458 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); | 461 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); |
| 459 } | 462 } |
| 460 | 463 |
| 461 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictNeitherAutoreplace) { | 464 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictNeitherAutoreplace) { |
| 462 // This tests cases where neither the sync nor the local TemplateURL are | 465 // This tests cases where neither the sync nor the local TemplateURL are |
| 463 // marked safe_for_autoreplace. | 466 // marked safe_for_autoreplace. |
| 464 | 467 |
| 465 // Create a keyword that conflicts, and make it older. Sync keyword is | 468 // Create a keyword that conflicts, and make it older. Sync keyword is |
| 466 // uniquified, and a csync::SyncChange is added. | 469 // uniquified, and a syncer::SyncChange is added. |
| 467 string16 original_turl_keyword = ASCIIToUTF16("key1"); | 470 string16 original_turl_keyword = ASCIIToUTF16("key1"); |
| 468 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, | 471 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 469 "http://key1.com", std::string(), 9000); | 472 "http://key1.com", std::string(), 9000); |
| 470 model()->Add(original_turl); | 473 model()->Add(original_turl); |
| 471 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, | 474 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, |
| 472 "http://new.com", "remote", 8999)); | 475 "http://new.com", "remote", 8999)); |
| 473 csync::SyncChangeList changes; | 476 syncer::SyncChangeList changes; |
| 474 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 477 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 475 original_turl, &changes)); | 478 original_turl, &changes)); |
| 476 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); | 479 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); |
| 477 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); | 480 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); |
| 478 ASSERT_EQ(1U, changes.size()); | 481 ASSERT_EQ(1U, changes.size()); |
| 479 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); | 482 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); |
| 480 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 483 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
| 481 changes.clear(); | 484 changes.clear(); |
| 482 model()->Remove(original_turl); | 485 model()->Remove(original_turl); |
| 483 | 486 |
| 484 // Sync is newer. Original TemplateURL keyword is uniquified. A SyncChange | 487 // Sync is newer. Original TemplateURL keyword is uniquified. A SyncChange |
| 485 // is added (which in a normal run would be deleted by PruneSyncChanges() when | 488 // is added (which in a normal run would be deleted by PruneSyncChanges() when |
| 486 // the local GUID doesn't appear in the sync GUID list). Also ensure that | 489 // the local GUID doesn't appear in the sync GUID list). Also ensure that |
| 487 // this does not change the safe_for_autoreplace flag or the TemplateURLID in | 490 // this does not change the safe_for_autoreplace flag or the TemplateURLID in |
| 488 // the original. | 491 // the original. |
| 489 original_turl = CreateTestTemplateURL(original_turl_keyword, | 492 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 490 "http://key1.com", "local", 9000); | 493 "http://key1.com", "local", 9000); |
| 491 model()->Add(original_turl); | 494 model()->Add(original_turl); |
| 492 TemplateURLID original_id = original_turl->id(); | 495 TemplateURLID original_id = original_turl->id(); |
| 493 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 496 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 494 std::string(), 9001)); | 497 std::string(), 9001)); |
| 495 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 498 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 496 original_turl, &changes)); | 499 original_turl, &changes)); |
| 497 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | 500 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
| 498 EXPECT_NE(original_turl_keyword, original_turl->keyword()); | 501 EXPECT_NE(original_turl_keyword, original_turl->keyword()); |
| 499 EXPECT_FALSE(original_turl->safe_for_autoreplace()); | 502 EXPECT_FALSE(original_turl->safe_for_autoreplace()); |
| 500 EXPECT_EQ(original_id, original_turl->id()); | 503 EXPECT_EQ(original_id, original_turl->id()); |
| 501 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); | 504 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 502 ASSERT_EQ(1U, changes.size()); | 505 ASSERT_EQ(1U, changes.size()); |
| 503 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); | 506 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); |
| 504 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 507 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
| 505 changes.clear(); | 508 changes.clear(); |
| 506 model()->Remove(original_turl); | 509 model()->Remove(original_turl); |
| 507 | 510 |
| 508 // Equal times. Same result as above. Sync left alone, original uniquified so | 511 // Equal times. Same result as above. Sync left alone, original uniquified so |
| 509 // sync_turl can fit. | 512 // sync_turl can fit. |
| 510 original_turl = CreateTestTemplateURL(original_turl_keyword, | 513 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 511 "http://key1.com", "local2", 9000); | 514 "http://key1.com", "local2", 9000); |
| 512 model()->Add(original_turl); | 515 model()->Add(original_turl); |
| 513 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 516 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 514 std::string(), 9000)); | 517 std::string(), 9000)); |
| 515 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 518 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 516 original_turl, &changes)); | 519 original_turl, &changes)); |
| 517 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | 520 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
| 518 EXPECT_NE(original_turl_keyword, original_turl->keyword()); | 521 EXPECT_NE(original_turl_keyword, original_turl->keyword()); |
| 519 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); | 522 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 520 ASSERT_EQ(1U, changes.size()); | 523 ASSERT_EQ(1U, changes.size()); |
| 521 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); | 524 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); |
| 522 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 525 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
| 523 changes.clear(); | 526 changes.clear(); |
| 524 model()->Remove(original_turl); | 527 model()->Remove(original_turl); |
| 525 | 528 |
| 526 // Sync is newer, but original TemplateURL is created by policy, so it wins. | 529 // Sync is newer, but original TemplateURL is created by policy, so it wins. |
| 527 // Sync keyword is uniquified, and a csync::SyncChange is added. | 530 // Sync keyword is uniquified, and a syncer::SyncChange is added. |
| 528 original_turl = CreateTestTemplateURL(original_turl_keyword, | 531 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 529 "http://key1.com", std::string(), 9000, false, true); | 532 "http://key1.com", std::string(), 9000, false, true); |
| 530 model()->Add(original_turl); | 533 model()->Add(original_turl); |
| 531 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 534 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 532 "remote2", 9999)); | 535 "remote2", 9999)); |
| 533 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 536 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 534 original_turl, &changes)); | 537 original_turl, &changes)); |
| 535 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); | 538 EXPECT_NE(original_turl_keyword, sync_turl->keyword()); |
| 536 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); | 539 EXPECT_EQ(original_turl_keyword, original_turl->keyword()); |
| 537 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(sync_turl->keyword())); | 540 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(sync_turl->keyword())); |
| 538 ASSERT_EQ(1U, changes.size()); | 541 ASSERT_EQ(1U, changes.size()); |
| 539 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); | 542 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); |
| 540 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 543 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
| 541 changes.clear(); | 544 changes.clear(); |
| 542 model()->Remove(original_turl); | 545 model()->Remove(original_turl); |
| 543 } | 546 } |
| 544 | 547 |
| 545 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictBothAutoreplace) { | 548 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictBothAutoreplace) { |
| 546 // This tests cases where both the sync and the local TemplateURL are marked | 549 // This tests cases where both the sync and the local TemplateURL are marked |
| 547 // safe_for_autoreplace. | 550 // safe_for_autoreplace. |
| 548 | 551 |
| 549 // Create a keyword that conflicts, and make it older. SyncChange is added, | 552 // Create a keyword that conflicts, and make it older. SyncChange is added, |
| 550 // function returns false. | 553 // function returns false. |
| 551 string16 original_turl_keyword = ASCIIToUTF16("key1"); | 554 string16 original_turl_keyword = ASCIIToUTF16("key1"); |
| 552 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, | 555 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 553 "http://key1.com", std::string(), 9000, true); | 556 "http://key1.com", std::string(), 9000, true); |
| 554 model()->Add(original_turl); | 557 model()->Add(original_turl); |
| 555 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, | 558 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, |
| 556 "http://new.com", "remote", 8999, true)); | 559 "http://new.com", "remote", 8999, true)); |
| 557 csync::SyncChangeList changes; | 560 syncer::SyncChangeList changes; |
| 558 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 561 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 559 original_turl, &changes)); | 562 original_turl, &changes)); |
| 560 EXPECT_EQ(original_turl, | 563 EXPECT_EQ(original_turl, |
| 561 model()->GetTemplateURLForKeyword(original_turl_keyword)); | 564 model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 562 ASSERT_EQ(1U, changes.size()); | 565 ASSERT_EQ(1U, changes.size()); |
| 563 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); | 566 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); |
| 564 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, changes[0].change_type()); | 567 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 565 changes.clear(); | 568 changes.clear(); |
| 566 model()->Remove(original_turl); | 569 model()->Remove(original_turl); |
| 567 | 570 |
| 568 // Sync is newer. Original TemplateURL is removed from the model. A | 571 // Sync is newer. Original TemplateURL is removed from the model. A |
| 569 // csync::SyncChange is added (which in a normal run would be deleted by | 572 // syncer::SyncChange is added (which in a normal run would be deleted by |
| 570 // PruneSyncChanges() when the local GUID doesn't appear in the sync GUID | 573 // PruneSyncChanges() when the local GUID doesn't appear in the sync GUID |
| 571 // list). | 574 // list). |
| 572 original_turl = CreateTestTemplateURL(original_turl_keyword, | 575 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 573 "http://key1.com", "local", 9000, true); | 576 "http://key1.com", "local", 9000, true); |
| 574 model()->Add(original_turl); | 577 model()->Add(original_turl); |
| 575 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 578 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 576 std::string(), 9001, true)); | 579 std::string(), 9001, true)); |
| 577 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 580 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 578 original_turl, &changes)); | 581 original_turl, &changes)); |
| 579 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | 582 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
| 580 EXPECT_TRUE(model()->GetTemplateURLs().empty()); | 583 EXPECT_TRUE(model()->GetTemplateURLs().empty()); |
| 581 ASSERT_EQ(1U, changes.size()); | 584 ASSERT_EQ(1U, changes.size()); |
| 582 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); | 585 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); |
| 583 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, changes[0].change_type()); | 586 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 584 changes.clear(); | 587 changes.clear(); |
| 585 | 588 |
| 586 // Equal times. Same result as above. Sync left alone, original removed so | 589 // Equal times. Same result as above. Sync left alone, original removed so |
| 587 // sync_turl can fit. | 590 // sync_turl can fit. |
| 588 original_turl = CreateTestTemplateURL(original_turl_keyword, | 591 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 589 "http://key1.com", "local2", 9000, true); | 592 "http://key1.com", "local2", 9000, true); |
| 590 model()->Add(original_turl); | 593 model()->Add(original_turl); |
| 591 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 594 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 592 std::string(), 9000, true)); | 595 std::string(), 9000, true)); |
| 593 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 596 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 594 original_turl, &changes)); | 597 original_turl, &changes)); |
| 595 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | 598 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
| 596 EXPECT_TRUE(model()->GetTemplateURLs().empty()); | 599 EXPECT_TRUE(model()->GetTemplateURLs().empty()); |
| 597 ASSERT_EQ(1U, changes.size()); | 600 ASSERT_EQ(1U, changes.size()); |
| 598 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); | 601 EXPECT_EQ("local2", GetGUID(changes[0].sync_data())); |
| 599 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, changes[0].change_type()); | 602 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 600 changes.clear(); | 603 changes.clear(); |
| 601 | 604 |
| 602 // Sync is newer, but original TemplateURL is created by policy, so it wins. | 605 // Sync is newer, but original TemplateURL is created by policy, so it wins. |
| 603 // csync::SyncChange is added, function returns false. | 606 // syncer::SyncChange is added, function returns false. |
| 604 original_turl = CreateTestTemplateURL(original_turl_keyword, | 607 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 605 "http://key1.com", std::string(), 9000, true, true); | 608 "http://key1.com", std::string(), 9000, true, true); |
| 606 model()->Add(original_turl); | 609 model()->Add(original_turl); |
| 607 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 610 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 608 "remote2", 9999, true)); | 611 "remote2", 9999, true)); |
| 609 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 612 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 610 original_turl, &changes)); | 613 original_turl, &changes)); |
| 611 EXPECT_EQ(original_turl, | 614 EXPECT_EQ(original_turl, |
| 612 model()->GetTemplateURLForKeyword(original_turl_keyword)); | 615 model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 613 ASSERT_EQ(1U, changes.size()); | 616 ASSERT_EQ(1U, changes.size()); |
| 614 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); | 617 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); |
| 615 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, changes[0].change_type()); | 618 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 616 changes.clear(); | 619 changes.clear(); |
| 617 model()->Remove(original_turl); | 620 model()->Remove(original_turl); |
| 618 } | 621 } |
| 619 | 622 |
| 620 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictOneAutoreplace) { | 623 TEST_F(TemplateURLServiceSyncTest, SyncKeywordConflictOneAutoreplace) { |
| 621 // This tests cases where either the sync or the local TemplateURL is marked | 624 // This tests cases where either the sync or the local TemplateURL is marked |
| 622 // safe_for_autoreplace, but the other is not. Basically, we run the same | 625 // safe_for_autoreplace, but the other is not. Basically, we run the same |
| 623 // tests as in SyncKeywordConflictBothAutoreplace, but mark the keywords so as | 626 // tests as in SyncKeywordConflictBothAutoreplace, but mark the keywords so as |
| 624 // to reverse the outcome of each test. | 627 // to reverse the outcome of each test. |
| 625 | 628 |
| 626 // Create a keyword that conflicts, and make it older. Normally the local | 629 // Create a keyword that conflicts, and make it older. Normally the local |
| 627 // TemplateURL would win this. | 630 // TemplateURL would win this. |
| 628 string16 original_turl_keyword = ASCIIToUTF16("key1"); | 631 string16 original_turl_keyword = ASCIIToUTF16("key1"); |
| 629 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, | 632 TemplateURL* original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 630 "http://key1.com", "local", 9000, true); | 633 "http://key1.com", "local", 9000, true); |
| 631 model()->Add(original_turl); | 634 model()->Add(original_turl); |
| 632 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, | 635 scoped_ptr<TemplateURL> sync_turl(CreateTestTemplateURL(original_turl_keyword, |
| 633 "http://new.com", std::string(), 8999)); | 636 "http://new.com", std::string(), 8999)); |
| 634 csync::SyncChangeList changes; | 637 syncer::SyncChangeList changes; |
| 635 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 638 EXPECT_TRUE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 636 original_turl, &changes)); | 639 original_turl, &changes)); |
| 637 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); | 640 EXPECT_EQ(original_turl_keyword, sync_turl->keyword()); |
| 638 EXPECT_TRUE(model()->GetTemplateURLs().empty()); | 641 EXPECT_TRUE(model()->GetTemplateURLs().empty()); |
| 639 ASSERT_EQ(1U, changes.size()); | 642 ASSERT_EQ(1U, changes.size()); |
| 640 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); | 643 EXPECT_EQ("local", GetGUID(changes[0].sync_data())); |
| 641 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, changes[0].change_type()); | 644 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 642 changes.clear(); | 645 changes.clear(); |
| 643 | 646 |
| 644 // Sync is newer. Normally the sync TemplateURL would win this. | 647 // Sync is newer. Normally the sync TemplateURL would win this. |
| 645 original_turl = CreateTestTemplateURL(original_turl_keyword, | 648 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 646 "http://key1.com", std::string(), 9000); | 649 "http://key1.com", std::string(), 9000); |
| 647 model()->Add(original_turl); | 650 model()->Add(original_turl); |
| 648 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 651 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 649 "remote", 9001, true)); | 652 "remote", 9001, true)); |
| 650 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 653 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 651 original_turl, &changes)); | 654 original_turl, &changes)); |
| 652 EXPECT_EQ(original_turl, | 655 EXPECT_EQ(original_turl, |
| 653 model()->GetTemplateURLForKeyword(original_turl_keyword)); | 656 model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 654 ASSERT_EQ(1U, changes.size()); | 657 ASSERT_EQ(1U, changes.size()); |
| 655 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); | 658 EXPECT_EQ("remote", GetGUID(changes[0].sync_data())); |
| 656 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, changes[0].change_type()); | 659 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 657 changes.clear(); | 660 changes.clear(); |
| 658 model()->Remove(original_turl); | 661 model()->Remove(original_turl); |
| 659 | 662 |
| 660 // Equal times. Same result as above. | 663 // Equal times. Same result as above. |
| 661 original_turl = CreateTestTemplateURL(original_turl_keyword, | 664 original_turl = CreateTestTemplateURL(original_turl_keyword, |
| 662 "http://key1.com", std::string(), 9000); | 665 "http://key1.com", std::string(), 9000); |
| 663 model()->Add(original_turl); | 666 model()->Add(original_turl); |
| 664 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", | 667 sync_turl.reset(CreateTestTemplateURL(original_turl_keyword, "http://new.com", |
| 665 "remote2", 9000, true)); | 668 "remote2", 9000, true)); |
| 666 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), | 669 EXPECT_FALSE(model()->ResolveSyncKeywordConflict(sync_turl.get(), |
| 667 original_turl, &changes)); | 670 original_turl, &changes)); |
| 668 EXPECT_EQ(original_turl, | 671 EXPECT_EQ(original_turl, |
| 669 model()->GetTemplateURLForKeyword(original_turl_keyword)); | 672 model()->GetTemplateURLForKeyword(original_turl_keyword)); |
| 670 ASSERT_EQ(1U, changes.size()); | 673 ASSERT_EQ(1U, changes.size()); |
| 671 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); | 674 EXPECT_EQ("remote2", GetGUID(changes[0].sync_data())); |
| 672 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, changes[0].change_type()); | 675 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[0].change_type()); |
| 673 changes.clear(); | 676 changes.clear(); |
| 674 model()->Remove(original_turl); | 677 model()->Remove(original_turl); |
| 675 | 678 |
| 676 // We don't run the "created by policy" test since URLs created by policy are | 679 // We don't run the "created by policy" test since URLs created by policy are |
| 677 // never safe_for_autoreplace. | 680 // never safe_for_autoreplace. |
| 678 } | 681 } |
| 679 | 682 |
| 680 TEST_F(TemplateURLServiceSyncTest, FindDuplicateOfSyncTemplateURL) { | 683 TEST_F(TemplateURLServiceSyncTest, FindDuplicateOfSyncTemplateURL) { |
| 681 TemplateURL* original_turl = | 684 TemplateURL* original_turl = |
| 682 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com"); | 685 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com"); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 707 EXPECT_EQ(dupe_turl->url(), sync_turl->url()); | 710 EXPECT_EQ(dupe_turl->url(), sync_turl->url()); |
| 708 } | 711 } |
| 709 | 712 |
| 710 TEST_F(TemplateURLServiceSyncTest, MergeSyncAndLocalURLDuplicates) { | 713 TEST_F(TemplateURLServiceSyncTest, MergeSyncAndLocalURLDuplicates) { |
| 711 TemplateURL* original_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), | 714 TemplateURL* original_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 712 "http://key1.com", std::string(), 9000); | 715 "http://key1.com", std::string(), 9000); |
| 713 model()->Add(original_turl); | 716 model()->Add(original_turl); |
| 714 TemplateURL* sync_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), | 717 TemplateURL* sync_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 715 "http://key1.com", std::string(), 9001); | 718 "http://key1.com", std::string(), 9001); |
| 716 std::string original_guid = original_turl->sync_guid(); | 719 std::string original_guid = original_turl->sync_guid(); |
| 717 csync::SyncChangeList changes; | 720 syncer::SyncChangeList changes; |
| 718 | 721 |
| 719 // The sync TemplateURL is newer. It should replace the original TemplateURL | 722 // The sync TemplateURL is newer. It should replace the original TemplateURL |
| 720 // and a csync::SyncChange should be added to the list. | 723 // and a syncer::SyncChange should be added to the list. |
| 721 // Note that MergeSyncAndLocalURLDuplicates takes ownership of sync_turl. | 724 // Note that MergeSyncAndLocalURLDuplicates takes ownership of sync_turl. |
| 722 model()->MergeSyncAndLocalURLDuplicates(sync_turl, original_turl, &changes); | 725 model()->MergeSyncAndLocalURLDuplicates(sync_turl, original_turl, &changes); |
| 723 TemplateURL* result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); | 726 TemplateURL* result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); |
| 724 ASSERT_TRUE(result); | 727 ASSERT_TRUE(result); |
| 725 EXPECT_EQ(9001, result->last_modified().ToTimeT()); | 728 EXPECT_EQ(9001, result->last_modified().ToTimeT()); |
| 726 EXPECT_EQ(1U, changes.size()); | 729 EXPECT_EQ(1U, changes.size()); |
| 727 // We expect a change to delete the local entry. | 730 // We expect a change to delete the local entry. |
| 728 csync::SyncChange change = changes.at(0); | 731 syncer::SyncChange change = changes.at(0); |
| 729 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, change.change_type()); | 732 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); |
| 730 EXPECT_EQ(original_guid, | 733 EXPECT_EQ(original_guid, |
| 731 change.sync_data().GetSpecifics().search_engine().sync_guid()); | 734 change.sync_data().GetSpecifics().search_engine().sync_guid()); |
| 732 changes.clear(); | 735 changes.clear(); |
| 733 | 736 |
| 734 // The sync TemplateURL is older. The existing TemplateURL should win and a | 737 // The sync TemplateURL is older. The existing TemplateURL should win and a |
| 735 // csync::SyncChange should be added to the list. | 738 // syncer::SyncChange should be added to the list. |
| 736 TemplateURL* sync_turl2 = CreateTestTemplateURL(ASCIIToUTF16("key1"), | 739 TemplateURL* sync_turl2 = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 737 "http://key1.com", std::string(), 8999); | 740 "http://key1.com", std::string(), 8999); |
| 738 std::string sync_guid = sync_turl2->sync_guid(); | 741 std::string sync_guid = sync_turl2->sync_guid(); |
| 739 model()->MergeSyncAndLocalURLDuplicates(sync_turl2, sync_turl, &changes); | 742 model()->MergeSyncAndLocalURLDuplicates(sync_turl2, sync_turl, &changes); |
| 740 result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); | 743 result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); |
| 741 ASSERT_TRUE(result); | 744 ASSERT_TRUE(result); |
| 742 EXPECT_EQ(9001, result->last_modified().ToTimeT()); | 745 EXPECT_EQ(9001, result->last_modified().ToTimeT()); |
| 743 EXPECT_EQ(1U, changes.size()); | 746 EXPECT_EQ(1U, changes.size()); |
| 744 // We expect a change to update the sync entry. | 747 // We expect a change to update the sync entry. |
| 745 change = changes.at(0); | 748 change = changes.at(0); |
| 746 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, change.change_type()); | 749 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
| 747 EXPECT_EQ(sync_guid, | 750 EXPECT_EQ(sync_guid, |
| 748 change.sync_data().GetSpecifics().search_engine().sync_guid()); | 751 change.sync_data().GetSpecifics().search_engine().sync_guid()); |
| 749 } | 752 } |
| 750 | 753 |
| 751 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { | 754 TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { |
| 752 model()->MergeDataAndStartSyncing( | 755 model()->MergeDataAndStartSyncing( |
| 753 syncable::SEARCH_ENGINES, csync::SyncDataList(), | 756 syncable::SEARCH_ENGINES, syncer::SyncDataList(), |
| 754 PassProcessor(), CreateAndPassSyncErrorFactory()); | 757 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 755 | 758 |
| 756 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 759 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 757 EXPECT_EQ(0U, processor()->change_list_size()); | 760 EXPECT_EQ(0U, processor()->change_list_size()); |
| 758 } | 761 } |
| 759 | 762 |
| 760 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) { | 763 TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) { |
| 761 csync::SyncDataList initial_data = CreateInitialSyncData(); | 764 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 762 | 765 |
| 763 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 766 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 764 PassProcessor(), CreateAndPassSyncErrorFactory()); | 767 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 765 | 768 |
| 766 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 769 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 767 // We expect the model to have accepted all of the initial sync data. Search | 770 // We expect the model to have accepted all of the initial sync data. Search |
| 768 // through the model using the GUIDs to ensure that they're present. | 771 // through the model using the GUIDs to ensure that they're present. |
| 769 for (csync::SyncDataList::const_iterator iter = initial_data.begin(); | 772 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 770 iter != initial_data.end(); ++iter) { | 773 iter != initial_data.end(); ++iter) { |
| 771 std::string guid = GetGUID(*iter); | 774 std::string guid = GetGUID(*iter); |
| 772 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); | 775 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); |
| 773 } | 776 } |
| 774 | 777 |
| 775 EXPECT_EQ(0U, processor()->change_list_size()); | 778 EXPECT_EQ(0U, processor()->change_list_size()); |
| 776 } | 779 } |
| 777 | 780 |
| 778 TEST_F(TemplateURLServiceSyncTest, MergeInAllNewData) { | 781 TEST_F(TemplateURLServiceSyncTest, MergeInAllNewData) { |
| 779 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("abc.com"), "http://abc.com", | 782 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("abc.com"), "http://abc.com", |
| 780 "abc")); | 783 "abc")); |
| 781 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("def.com"), "http://def.com", | 784 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("def.com"), "http://def.com", |
| 782 "def")); | 785 "def")); |
| 783 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("xyz.com"), "http://xyz.com", | 786 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("xyz.com"), "http://xyz.com", |
| 784 "xyz")); | 787 "xyz")); |
| 785 csync::SyncDataList initial_data = CreateInitialSyncData(); | 788 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 786 | 789 |
| 787 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 790 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 788 PassProcessor(), CreateAndPassSyncErrorFactory()); | 791 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 789 | 792 |
| 790 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 793 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 791 // We expect the model to have accepted all of the initial sync data. Search | 794 // We expect the model to have accepted all of the initial sync data. Search |
| 792 // through the model using the GUIDs to ensure that they're present. | 795 // through the model using the GUIDs to ensure that they're present. |
| 793 for (csync::SyncDataList::const_iterator iter = initial_data.begin(); | 796 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 794 iter != initial_data.end(); ++iter) { | 797 iter != initial_data.end(); ++iter) { |
| 795 std::string guid = GetGUID(*iter); | 798 std::string guid = GetGUID(*iter); |
| 796 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); | 799 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); |
| 797 } | 800 } |
| 798 // All the original TemplateURLs should also remain in the model. | 801 // All the original TemplateURLs should also remain in the model. |
| 799 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("abc.com"))); | 802 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("abc.com"))); |
| 800 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("def.com"))); | 803 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("def.com"))); |
| 801 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("xyz.com"))); | 804 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("xyz.com"))); |
| 802 // Ensure that Sync received the expected changes. | 805 // Ensure that Sync received the expected changes. |
| 803 EXPECT_EQ(3U, processor()->change_list_size()); | 806 EXPECT_EQ(3U, processor()->change_list_size()); |
| 804 EXPECT_TRUE(processor()->contains_guid("abc")); | 807 EXPECT_TRUE(processor()->contains_guid("abc")); |
| 805 EXPECT_TRUE(processor()->contains_guid("def")); | 808 EXPECT_TRUE(processor()->contains_guid("def")); |
| 806 EXPECT_TRUE(processor()->contains_guid("xyz")); | 809 EXPECT_TRUE(processor()->contains_guid("xyz")); |
| 807 } | 810 } |
| 808 | 811 |
| 809 TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) { | 812 TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) { |
| 810 // The local data is the same as the sync data merged in. i.e. - There have | 813 // The local data is the same as the sync data merged in. i.e. - There have |
| 811 // been no changes since the last time we synced. Even the last_modified | 814 // been no changes since the last time we synced. Even the last_modified |
| 812 // timestamps are the same. | 815 // timestamps are the same. |
| 813 csync::SyncDataList initial_data = CreateInitialSyncData(); | 816 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 814 for (csync::SyncDataList::const_iterator iter = initial_data.begin(); | 817 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 815 iter != initial_data.end(); ++iter) { | 818 iter != initial_data.end(); ++iter) { |
| 816 TemplateURL* converted = Deserialize(*iter); | 819 TemplateURL* converted = Deserialize(*iter); |
| 817 model()->Add(converted); | 820 model()->Add(converted); |
| 818 } | 821 } |
| 819 | 822 |
| 820 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 823 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 821 PassProcessor(), CreateAndPassSyncErrorFactory()); | 824 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 822 | 825 |
| 823 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 826 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 824 for (csync::SyncDataList::const_iterator iter = initial_data.begin(); | 827 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 825 iter != initial_data.end(); ++iter) { | 828 iter != initial_data.end(); ++iter) { |
| 826 std::string guid = GetGUID(*iter); | 829 std::string guid = GetGUID(*iter); |
| 827 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); | 830 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); |
| 828 } | 831 } |
| 829 EXPECT_EQ(0U, processor()->change_list_size()); | 832 EXPECT_EQ(0U, processor()->change_list_size()); |
| 830 } | 833 } |
| 831 | 834 |
| 832 TEST_F(TemplateURLServiceSyncTest, MergeUpdateFromSync) { | 835 TEST_F(TemplateURLServiceSyncTest, MergeUpdateFromSync) { |
| 833 // The local data is the same as the sync data merged in, but timestamps have | 836 // The local data is the same as the sync data merged in, but timestamps have |
| 834 // changed. Ensure the right fields are merged in. | 837 // changed. Ensure the right fields are merged in. |
| 835 csync::SyncDataList initial_data; | 838 syncer::SyncDataList initial_data; |
| 836 TemplateURL* turl1 = CreateTestTemplateURL(ASCIIToUTF16("abc.com"), | 839 TemplateURL* turl1 = CreateTestTemplateURL(ASCIIToUTF16("abc.com"), |
| 837 "http://abc.com", "abc", 9000); | 840 "http://abc.com", "abc", 9000); |
| 838 model()->Add(turl1); | 841 model()->Add(turl1); |
| 839 TemplateURL* turl2 = CreateTestTemplateURL(ASCIIToUTF16("xyz.com"), | 842 TemplateURL* turl2 = CreateTestTemplateURL(ASCIIToUTF16("xyz.com"), |
| 840 "http://xyz.com", "xyz", 9000); | 843 "http://xyz.com", "xyz", 9000); |
| 841 model()->Add(turl2); | 844 model()->Add(turl2); |
| 842 | 845 |
| 843 scoped_ptr<TemplateURL> turl1_newer(CreateTestTemplateURL( | 846 scoped_ptr<TemplateURL> turl1_newer(CreateTestTemplateURL( |
| 844 ASCIIToUTF16("abc.com"), "http://abc.ca", "abc", 9999)); | 847 ASCIIToUTF16("abc.com"), "http://abc.ca", "abc", 9999)); |
| 845 initial_data.push_back( | 848 initial_data.push_back( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 856 // Both were local updates, so we expect the same count. | 859 // Both were local updates, so we expect the same count. |
| 857 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 860 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 858 | 861 |
| 859 // Check that the first replaced the initial abc TemplateURL. | 862 // Check that the first replaced the initial abc TemplateURL. |
| 860 EXPECT_EQ(turl1, model()->GetTemplateURLForGUID("abc")); | 863 EXPECT_EQ(turl1, model()->GetTemplateURLForGUID("abc")); |
| 861 EXPECT_EQ("http://abc.ca", turl1->url()); | 864 EXPECT_EQ("http://abc.ca", turl1->url()); |
| 862 | 865 |
| 863 // Check that the second produced an upstream update to the xyz TemplateURL. | 866 // Check that the second produced an upstream update to the xyz TemplateURL. |
| 864 EXPECT_EQ(1U, processor()->change_list_size()); | 867 EXPECT_EQ(1U, processor()->change_list_size()); |
| 865 ASSERT_TRUE(processor()->contains_guid("xyz")); | 868 ASSERT_TRUE(processor()->contains_guid("xyz")); |
| 866 csync::SyncChange change = processor()->change_for_guid("xyz"); | 869 syncer::SyncChange change = processor()->change_for_guid("xyz"); |
| 867 EXPECT_TRUE(change.change_type() == csync::SyncChange::ACTION_UPDATE); | 870 EXPECT_TRUE(change.change_type() == syncer::SyncChange::ACTION_UPDATE); |
| 868 EXPECT_EQ("http://xyz.com", GetURL(change.sync_data())); | 871 EXPECT_EQ("http://xyz.com", GetURL(change.sync_data())); |
| 869 } | 872 } |
| 870 | 873 |
| 871 TEST_F(TemplateURLServiceSyncTest, MergeAddFromOlderSyncData) { | 874 TEST_F(TemplateURLServiceSyncTest, MergeAddFromOlderSyncData) { |
| 872 // GUIDs all differ, so this is data to be added from Sync, but the timestamps | 875 // GUIDs all differ, so this is data to be added from Sync, but the timestamps |
| 873 // from Sync are older. Set up the local data so that one is a dupe, one has a | 876 // from Sync are older. Set up the local data so that one is a dupe, one has a |
| 874 // conflicting keyword, and the last has no conflicts (a clean ADD). | 877 // conflicting keyword, and the last has no conflicts (a clean ADD). |
| 875 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", | 878 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", |
| 876 "aaa", 100)); // dupe | 879 "aaa", 100)); // dupe |
| 877 | 880 |
| 878 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 881 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 879 "http://expected.com", "bbb", 100)); // keyword conflict | 882 "http://expected.com", "bbb", 100)); // keyword conflict |
| 880 | 883 |
| 881 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), | 884 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), |
| 882 "http://unique.com", "ccc")); // add | 885 "http://unique.com", "ccc")); // add |
| 883 | 886 |
| 884 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 887 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 885 CreateInitialSyncData(), PassProcessor(), | 888 CreateInitialSyncData(), PassProcessor(), |
| 886 CreateAndPassSyncErrorFactory()); | 889 CreateAndPassSyncErrorFactory()); |
| 887 | 890 |
| 888 // The dupe results in a merge. The other two should be added to the model. | 891 // The dupe results in a merge. The other two should be added to the model. |
| 889 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 892 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 890 | 893 |
| 891 // The key1 duplicate results in the local copy winning. Ensure that Sync's | 894 // The key1 duplicate results in the local copy winning. Ensure that Sync's |
| 892 // copy was not added, and the local copy is pushed upstream to Sync as an | 895 // copy was not added, and the local copy is pushed upstream to Sync as an |
| 893 // update. The local copy should have received the sync data's GUID. | 896 // update. The local copy should have received the sync data's GUID. |
| 894 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 897 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 895 // Check changes for the UPDATE. | 898 // Check changes for the UPDATE. |
| 896 ASSERT_TRUE(processor()->contains_guid("key1")); | 899 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 897 csync::SyncChange key1_change = processor()->change_for_guid("key1"); | 900 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); |
| 898 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, key1_change.change_type()); | 901 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); |
| 899 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); | 902 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); |
| 900 | 903 |
| 901 // The key2 keyword conflict results in the local copy winning, so ensure it | 904 // The key2 keyword conflict results in the local copy winning, so ensure it |
| 902 // retains the original keyword, and that an update to the sync copy is pushed | 905 // retains the original keyword, and that an update to the sync copy is pushed |
| 903 // upstream to Sync. Both TemplateURLs should be found locally, however. | 906 // upstream to Sync. Both TemplateURLs should be found locally, however. |
| 904 const TemplateURL* key2 = model()->GetTemplateURLForGUID("bbb"); | 907 const TemplateURL* key2 = model()->GetTemplateURLForGUID("bbb"); |
| 905 EXPECT_TRUE(key2); | 908 EXPECT_TRUE(key2); |
| 906 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword()); | 909 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword()); |
| 907 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 910 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 908 // Check changes for the UPDATE. | 911 // Check changes for the UPDATE. |
| 909 ASSERT_TRUE(processor()->contains_guid("key2")); | 912 ASSERT_TRUE(processor()->contains_guid("key2")); |
| 910 csync::SyncChange key2_change = processor()->change_for_guid("key2"); | 913 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); |
| 911 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, key2_change.change_type()); | 914 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); |
| 912 EXPECT_EQ("key2.com", GetKeyword(key2_change.sync_data())); | 915 EXPECT_EQ("key2.com", GetKeyword(key2_change.sync_data())); |
| 913 | 916 |
| 914 // The last TemplateURL should have had no conflicts and was just added. It | 917 // The last TemplateURL should have had no conflicts and was just added. It |
| 915 // should not have replaced the third local TemplateURL. | 918 // should not have replaced the third local TemplateURL. |
| 916 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); | 919 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); |
| 917 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 920 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
| 918 | 921 |
| 919 // Two UPDATEs and two ADDs. | 922 // Two UPDATEs and two ADDs. |
| 920 EXPECT_EQ(4U, processor()->change_list_size()); | 923 EXPECT_EQ(4U, processor()->change_list_size()); |
| 921 // Two ADDs should be pushed up to Sync. | 924 // Two ADDs should be pushed up to Sync. |
| 922 ASSERT_TRUE(processor()->contains_guid("bbb")); | 925 ASSERT_TRUE(processor()->contains_guid("bbb")); |
| 923 EXPECT_EQ(csync::SyncChange::ACTION_ADD, | 926 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
| 924 processor()->change_for_guid("bbb").change_type()); | 927 processor()->change_for_guid("bbb").change_type()); |
| 925 ASSERT_TRUE(processor()->contains_guid("ccc")); | 928 ASSERT_TRUE(processor()->contains_guid("ccc")); |
| 926 EXPECT_EQ(csync::SyncChange::ACTION_ADD, | 929 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
| 927 processor()->change_for_guid("ccc").change_type()); | 930 processor()->change_for_guid("ccc").change_type()); |
| 928 } | 931 } |
| 929 | 932 |
| 930 TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) { | 933 TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) { |
| 931 // GUIDs all differ, so this is data to be added from Sync, but the timestamps | 934 // GUIDs all differ, so this is data to be added from Sync, but the timestamps |
| 932 // from Sync are newer. Set up the local data so that one is a dupe, one has a | 935 // from Sync are newer. Set up the local data so that one is a dupe, one has a |
| 933 // conflicting keyword, and the last has no conflicts (a clean ADD). | 936 // conflicting keyword, and the last has no conflicts (a clean ADD). |
| 934 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", | 937 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", |
| 935 "aaa", 10)); // dupe | 938 "aaa", 10)); // dupe |
| 936 | 939 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 964 | 967 |
| 965 // The last TemplateURL should have had no conflicts and was just added. It | 968 // The last TemplateURL should have had no conflicts and was just added. It |
| 966 // should not have replaced the third local TemplateURL. | 969 // should not have replaced the third local TemplateURL. |
| 967 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); | 970 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); |
| 968 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 971 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
| 969 | 972 |
| 970 // Two ADDs. | 973 // Two ADDs. |
| 971 EXPECT_EQ(2U, processor()->change_list_size()); | 974 EXPECT_EQ(2U, processor()->change_list_size()); |
| 972 // Two ADDs should be pushed up to Sync. | 975 // Two ADDs should be pushed up to Sync. |
| 973 ASSERT_TRUE(processor()->contains_guid("bbb")); | 976 ASSERT_TRUE(processor()->contains_guid("bbb")); |
| 974 EXPECT_EQ(csync::SyncChange::ACTION_ADD, | 977 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
| 975 processor()->change_for_guid("bbb").change_type()); | 978 processor()->change_for_guid("bbb").change_type()); |
| 976 ASSERT_TRUE(processor()->contains_guid("ccc")); | 979 ASSERT_TRUE(processor()->contains_guid("ccc")); |
| 977 EXPECT_EQ(csync::SyncChange::ACTION_ADD, | 980 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
| 978 processor()->change_for_guid("ccc").change_type()); | 981 processor()->change_for_guid("ccc").change_type()); |
| 979 } | 982 } |
| 980 | 983 |
| 981 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { | 984 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { |
| 982 // We initially have no data. | 985 // We initially have no data. |
| 983 model()->MergeDataAndStartSyncing( | 986 model()->MergeDataAndStartSyncing( |
| 984 syncable::SEARCH_ENGINES, csync::SyncDataList(), | 987 syncable::SEARCH_ENGINES, syncer::SyncDataList(), |
| 985 PassProcessor(), CreateAndPassSyncErrorFactory()); | 988 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 986 | 989 |
| 987 // Set up a bunch of ADDs. | 990 // Set up a bunch of ADDs. |
| 988 csync::SyncChangeList changes; | 991 syncer::SyncChangeList changes; |
| 989 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 992 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 990 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1"))); | 993 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1"))); |
| 991 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 994 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 992 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", "key2"))); | 995 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", "key2"))); |
| 993 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 996 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 994 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3"))); | 997 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3"))); |
| 995 | 998 |
| 996 model()->ProcessSyncChanges(FROM_HERE, changes); | 999 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 997 | 1000 |
| 998 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1001 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 999 EXPECT_EQ(0U, processor()->change_list_size()); | 1002 EXPECT_EQ(0U, processor()->change_list_size()); |
| 1000 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 1003 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 1001 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1004 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1002 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 1005 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
| 1003 } | 1006 } |
| 1004 | 1007 |
| 1005 TEST_F(TemplateURLServiceSyncTest, ProcessChangesNoConflicts) { | 1008 TEST_F(TemplateURLServiceSyncTest, ProcessChangesNoConflicts) { |
| 1006 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1009 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1007 CreateInitialSyncData(), PassProcessor(), | 1010 CreateInitialSyncData(), PassProcessor(), |
| 1008 CreateAndPassSyncErrorFactory()); | 1011 CreateAndPassSyncErrorFactory()); |
| 1009 | 1012 |
| 1010 // Process different types of changes, without conflicts. | 1013 // Process different types of changes, without conflicts. |
| 1011 csync::SyncChangeList changes; | 1014 syncer::SyncChangeList changes; |
| 1012 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 1015 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1013 CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", "key4"))); | 1016 CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", "key4"))); |
| 1014 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_UPDATE, | 1017 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1015 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", | 1018 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", |
| 1016 "key2"))); | 1019 "key2"))); |
| 1017 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_DELETE, | 1020 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_DELETE, |
| 1018 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3"))); | 1021 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key3"))); |
| 1019 | 1022 |
| 1020 model()->ProcessSyncChanges(FROM_HERE, changes); | 1023 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1021 | 1024 |
| 1022 // Add one, remove one, update one, so the number shouldn't change. | 1025 // Add one, remove one, update one, so the number shouldn't change. |
| 1023 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1026 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1024 EXPECT_EQ(0U, processor()->change_list_size()); | 1027 EXPECT_EQ(0U, processor()->change_list_size()); |
| 1025 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 1028 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 1026 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1029 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1027 const TemplateURL* turl = model()->GetTemplateURLForGUID("key2"); | 1030 const TemplateURL* turl = model()->GetTemplateURLForGUID("key2"); |
| 1028 EXPECT_TRUE(turl); | 1031 EXPECT_TRUE(turl); |
| 1029 EXPECT_EQ(ASCIIToUTF16("newkeyword"), turl->keyword()); | 1032 EXPECT_EQ(ASCIIToUTF16("newkeyword"), turl->keyword()); |
| 1030 EXPECT_EQ("http://new.com", turl->url()); | 1033 EXPECT_EQ("http://new.com", turl->url()); |
| 1031 EXPECT_FALSE(model()->GetTemplateURLForGUID("key3")); | 1034 EXPECT_FALSE(model()->GetTemplateURLForGUID("key3")); |
| 1032 EXPECT_TRUE(model()->GetTemplateURLForGUID("key4")); | 1035 EXPECT_TRUE(model()->GetTemplateURLForGUID("key4")); |
| 1033 } | 1036 } |
| 1034 | 1037 |
| 1035 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsSyncWins) { | 1038 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsSyncWins) { |
| 1036 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1039 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1037 CreateInitialSyncData(), PassProcessor(), | 1040 CreateInitialSyncData(), PassProcessor(), |
| 1038 CreateAndPassSyncErrorFactory()); | 1041 CreateAndPassSyncErrorFactory()); |
| 1039 | 1042 |
| 1040 // Process different types of changes, with conflicts. Note that all this data | 1043 // Process different types of changes, with conflicts. Note that all this data |
| 1041 // has a newer timestamp, so Sync will win in these scenarios. | 1044 // has a newer timestamp, so Sync will win in these scenarios. |
| 1042 csync::SyncChangeList changes; | 1045 syncer::SyncChangeList changes; |
| 1043 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 1046 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1044 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa"))); | 1047 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa"))); |
| 1045 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_UPDATE, | 1048 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1046 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1"))); | 1049 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1"))); |
| 1047 | 1050 |
| 1048 model()->ProcessSyncChanges(FROM_HERE, changes); | 1051 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1049 | 1052 |
| 1050 // Add one, update one, so we're up to 4. | 1053 // Add one, update one, so we're up to 4. |
| 1051 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1054 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1052 // Sync is always newer here, so it should always win. We should create | 1055 // Sync is always newer here, so it should always win. We should create |
| 1053 // SyncChanges for the changes to the local entities, since they're synced | 1056 // SyncChanges for the changes to the local entities, since they're synced |
| 1054 // too. | 1057 // too. |
| 1055 EXPECT_EQ(2U, processor()->change_list_size()); | 1058 EXPECT_EQ(2U, processor()->change_list_size()); |
| 1056 ASSERT_TRUE(processor()->contains_guid("key2")); | 1059 ASSERT_TRUE(processor()->contains_guid("key2")); |
| 1057 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, | 1060 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
| 1058 processor()->change_for_guid("key2").change_type()); | 1061 processor()->change_for_guid("key2").change_type()); |
| 1059 ASSERT_TRUE(processor()->contains_guid("key3")); | 1062 ASSERT_TRUE(processor()->contains_guid("key3")); |
| 1060 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, | 1063 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
| 1061 processor()->change_for_guid("key3").change_type()); | 1064 processor()->change_for_guid("key3").change_type()); |
| 1062 | 1065 |
| 1063 // aaa conflicts with key2 and wins, forcing key2's keyword to update. | 1066 // aaa conflicts with key2 and wins, forcing key2's keyword to update. |
| 1064 EXPECT_TRUE(model()->GetTemplateURLForGUID("aaa")); | 1067 EXPECT_TRUE(model()->GetTemplateURLForGUID("aaa")); |
| 1065 EXPECT_EQ(model()->GetTemplateURLForGUID("aaa"), | 1068 EXPECT_EQ(model()->GetTemplateURLForGUID("aaa"), |
| 1066 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2"))); | 1069 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2"))); |
| 1067 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1070 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1068 EXPECT_EQ(model()->GetTemplateURLForGUID("key2"), | 1071 EXPECT_EQ(model()->GetTemplateURLForGUID("key2"), |
| 1069 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2.com"))); | 1072 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2.com"))); |
| 1070 // key1 update conflicts with key3 and wins, forcing key3's keyword to update. | 1073 // key1 update conflicts with key3 and wins, forcing key3's keyword to update. |
| 1071 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 1074 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 1072 EXPECT_EQ(model()->GetTemplateURLForGUID("key1"), | 1075 EXPECT_EQ(model()->GetTemplateURLForGUID("key1"), |
| 1073 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); | 1076 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); |
| 1074 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 1077 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
| 1075 EXPECT_EQ(model()->GetTemplateURLForGUID("key3"), | 1078 EXPECT_EQ(model()->GetTemplateURLForGUID("key3"), |
| 1076 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3.com"))); | 1079 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3.com"))); |
| 1077 } | 1080 } |
| 1078 | 1081 |
| 1079 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsLocalWins) { | 1082 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsLocalWins) { |
| 1080 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1083 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1081 CreateInitialSyncData(), PassProcessor(), | 1084 CreateInitialSyncData(), PassProcessor(), |
| 1082 CreateAndPassSyncErrorFactory()); | 1085 CreateAndPassSyncErrorFactory()); |
| 1083 | 1086 |
| 1084 // Process different types of changes, with conflicts. Note that all this data | 1087 // Process different types of changes, with conflicts. Note that all this data |
| 1085 // has an older timestamp, so the local data will win in these scenarios. | 1088 // has an older timestamp, so the local data will win in these scenarios. |
| 1086 csync::SyncChangeList changes; | 1089 syncer::SyncChangeList changes; |
| 1087 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 1090 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1088 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa", | 1091 CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://new.com", "aaa", |
| 1089 10))); | 1092 10))); |
| 1090 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_UPDATE, | 1093 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1091 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1", | 1094 CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", "key1", |
| 1092 10))); | 1095 10))); |
| 1093 | 1096 |
| 1094 model()->ProcessSyncChanges(FROM_HERE, changes); | 1097 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1095 | 1098 |
| 1096 // Add one, update one, so we're up to 4. | 1099 // Add one, update one, so we're up to 4. |
| 1097 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1100 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1098 // Local data wins twice so two updates are pushed up to Sync. | 1101 // Local data wins twice so two updates are pushed up to Sync. |
| 1099 EXPECT_EQ(2U, processor()->change_list_size()); | 1102 EXPECT_EQ(2U, processor()->change_list_size()); |
| 1100 | 1103 |
| 1101 // aaa conflicts with key2 and loses, forcing it's keyword to update. | 1104 // aaa conflicts with key2 and loses, forcing it's keyword to update. |
| 1102 EXPECT_TRUE(model()->GetTemplateURLForGUID("aaa")); | 1105 EXPECT_TRUE(model()->GetTemplateURLForGUID("aaa")); |
| 1103 EXPECT_EQ(model()->GetTemplateURLForGUID("aaa"), | 1106 EXPECT_EQ(model()->GetTemplateURLForGUID("aaa"), |
| 1104 model()->GetTemplateURLForKeyword(ASCIIToUTF16("new.com"))); | 1107 model()->GetTemplateURLForKeyword(ASCIIToUTF16("new.com"))); |
| 1105 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1108 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1106 EXPECT_EQ(model()->GetTemplateURLForGUID("key2"), | 1109 EXPECT_EQ(model()->GetTemplateURLForGUID("key2"), |
| 1107 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2"))); | 1110 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2"))); |
| 1108 // key1 update conflicts with key3 and loses, forcing key1's keyword to | 1111 // key1 update conflicts with key3 and loses, forcing key1's keyword to |
| 1109 // update. | 1112 // update. |
| 1110 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 1113 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
| 1111 EXPECT_EQ(model()->GetTemplateURLForGUID("key1"), | 1114 EXPECT_EQ(model()->GetTemplateURLForGUID("key1"), |
| 1112 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3.com"))); | 1115 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3.com"))); |
| 1113 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 1116 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
| 1114 EXPECT_EQ(model()->GetTemplateURLForGUID("key3"), | 1117 EXPECT_EQ(model()->GetTemplateURLForGUID("key3"), |
| 1115 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); | 1118 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); |
| 1116 | 1119 |
| 1117 ASSERT_TRUE(processor()->contains_guid("aaa")); | 1120 ASSERT_TRUE(processor()->contains_guid("aaa")); |
| 1118 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, | 1121 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
| 1119 processor()->change_for_guid("aaa").change_type()); | 1122 processor()->change_for_guid("aaa").change_type()); |
| 1120 ASSERT_TRUE(processor()->contains_guid("key1")); | 1123 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 1121 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, | 1124 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
| 1122 processor()->change_for_guid("key1").change_type()); | 1125 processor()->change_for_guid("key1").change_type()); |
| 1123 } | 1126 } |
| 1124 | 1127 |
| 1125 TEST_F(TemplateURLServiceSyncTest, RemoveUpdatedURLOnConflict) { | 1128 TEST_F(TemplateURLServiceSyncTest, RemoveUpdatedURLOnConflict) { |
| 1126 // Updating a local replaceable URL to have the same keyword as a local | 1129 // Updating a local replaceable URL to have the same keyword as a local |
| 1127 // non-replaceable URL should result in the former being removed from the | 1130 // non-replaceable URL should result in the former being removed from the |
| 1128 // model entirely. | 1131 // model entirely. |
| 1129 csync::SyncDataList initial_data; | 1132 syncer::SyncDataList initial_data; |
| 1130 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync"), | 1133 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync"), |
| 1131 "http://sync.com", "sync", 100, true)); | 1134 "http://sync.com", "sync", 100, true)); |
| 1132 initial_data.push_back( | 1135 initial_data.push_back( |
| 1133 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 1136 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 1134 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1137 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1135 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1138 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1136 | 1139 |
| 1137 TemplateURL* new_turl = | 1140 TemplateURL* new_turl = |
| 1138 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://local.com", "local"); | 1141 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://local.com", "local"); |
| 1139 model()->Add(new_turl); | 1142 model()->Add(new_turl); |
| 1140 | 1143 |
| 1141 csync::SyncChangeList changes; | 1144 syncer::SyncChangeList changes; |
| 1142 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_UPDATE, | 1145 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1143 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://sync.com", "sync", | 1146 CreateTestTemplateURL(ASCIIToUTF16("local"), "http://sync.com", "sync", |
| 1144 110, true))); | 1147 110, true))); |
| 1145 model()->ProcessSyncChanges(FROM_HERE, changes); | 1148 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1146 | 1149 |
| 1147 EXPECT_EQ(1U, model()->GetTemplateURLs().size()); | 1150 EXPECT_EQ(1U, model()->GetTemplateURLs().size()); |
| 1148 EXPECT_EQ("local", | 1151 EXPECT_EQ("local", |
| 1149 model()->GetTemplateURLForKeyword(ASCIIToUTF16("local"))->sync_guid()); | 1152 model()->GetTemplateURLForKeyword(ASCIIToUTF16("local"))->sync_guid()); |
| 1150 EXPECT_EQ(1U, processor()->change_list_size()); | 1153 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1151 ASSERT_TRUE(processor()->contains_guid("sync")); | 1154 ASSERT_TRUE(processor()->contains_guid("sync")); |
| 1152 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, | 1155 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
| 1153 processor()->change_for_guid("sync").change_type()); | 1156 processor()->change_for_guid("sync").change_type()); |
| 1154 } | 1157 } |
| 1155 | 1158 |
| 1156 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { | 1159 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { |
| 1157 // Ensure that ProcessTemplateURLChange is called and pushes the correct | 1160 // Ensure that ProcessTemplateURLChange is called and pushes the correct |
| 1158 // changes to Sync whenever local changes are made to TemplateURLs. | 1161 // changes to Sync whenever local changes are made to TemplateURLs. |
| 1159 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1162 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1160 CreateInitialSyncData(), PassProcessor(), | 1163 CreateInitialSyncData(), PassProcessor(), |
| 1161 CreateAndPassSyncErrorFactory()); | 1164 CreateAndPassSyncErrorFactory()); |
| 1162 | 1165 |
| 1163 // Add a new search engine. | 1166 // Add a new search engine. |
| 1164 TemplateURL* new_turl = | 1167 TemplateURL* new_turl = |
| 1165 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); | 1168 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); |
| 1166 model()->Add(new_turl); | 1169 model()->Add(new_turl); |
| 1167 EXPECT_EQ(1U, processor()->change_list_size()); | 1170 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1168 ASSERT_TRUE(processor()->contains_guid("new")); | 1171 ASSERT_TRUE(processor()->contains_guid("new")); |
| 1169 csync::SyncChange change = processor()->change_for_guid("new"); | 1172 syncer::SyncChange change = processor()->change_for_guid("new"); |
| 1170 EXPECT_EQ(csync::SyncChange::ACTION_ADD, change.change_type()); | 1173 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type()); |
| 1171 EXPECT_EQ("baidu", GetKeyword(change.sync_data())); | 1174 EXPECT_EQ("baidu", GetKeyword(change.sync_data())); |
| 1172 EXPECT_EQ("http://baidu.cn", GetURL(change.sync_data())); | 1175 EXPECT_EQ("http://baidu.cn", GetURL(change.sync_data())); |
| 1173 | 1176 |
| 1174 // Change a keyword. | 1177 // Change a keyword. |
| 1175 TemplateURL* existing_turl = model()->GetTemplateURLForGUID("key1"); | 1178 TemplateURL* existing_turl = model()->GetTemplateURLForGUID("key1"); |
| 1176 model()->ResetTemplateURL(existing_turl, existing_turl->short_name(), | 1179 model()->ResetTemplateURL(existing_turl, existing_turl->short_name(), |
| 1177 ASCIIToUTF16("k"), existing_turl->url()); | 1180 ASCIIToUTF16("k"), existing_turl->url()); |
| 1178 EXPECT_EQ(1U, processor()->change_list_size()); | 1181 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1179 ASSERT_TRUE(processor()->contains_guid("key1")); | 1182 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 1180 change = processor()->change_for_guid("key1"); | 1183 change = processor()->change_for_guid("key1"); |
| 1181 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, change.change_type()); | 1184 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
| 1182 EXPECT_EQ("k", GetKeyword(change.sync_data())); | 1185 EXPECT_EQ("k", GetKeyword(change.sync_data())); |
| 1183 | 1186 |
| 1184 // Remove an existing search engine. | 1187 // Remove an existing search engine. |
| 1185 existing_turl = model()->GetTemplateURLForGUID("key2"); | 1188 existing_turl = model()->GetTemplateURLForGUID("key2"); |
| 1186 model()->Remove(existing_turl); | 1189 model()->Remove(existing_turl); |
| 1187 EXPECT_EQ(1U, processor()->change_list_size()); | 1190 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1188 ASSERT_TRUE(processor()->contains_guid("key2")); | 1191 ASSERT_TRUE(processor()->contains_guid("key2")); |
| 1189 change = processor()->change_for_guid("key2"); | 1192 change = processor()->change_for_guid("key2"); |
| 1190 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, change.change_type()); | 1193 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); |
| 1191 } | 1194 } |
| 1192 | 1195 |
| 1193 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithLocalExtensions) { | 1196 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithLocalExtensions) { |
| 1194 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1197 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1195 CreateInitialSyncData(), PassProcessor(), | 1198 CreateInitialSyncData(), PassProcessor(), |
| 1196 CreateAndPassSyncErrorFactory()); | 1199 CreateAndPassSyncErrorFactory()); |
| 1197 | 1200 |
| 1198 // Add some extension keywords locally. These shouldn't be synced. | 1201 // Add some extension keywords locally. These shouldn't be synced. |
| 1199 TemplateURL* extension1 = CreateTestTemplateURL(ASCIIToUTF16("keyword1"), | 1202 TemplateURL* extension1 = CreateTestTemplateURL(ASCIIToUTF16("keyword1"), |
| 1200 std::string(chrome::kExtensionScheme) + "://extension1"); | 1203 std::string(chrome::kExtensionScheme) + "://extension1"); |
| 1201 model()->Add(extension1); | 1204 model()->Add(extension1); |
| 1202 TemplateURL* extension2 = CreateTestTemplateURL(ASCIIToUTF16("keyword2"), | 1205 TemplateURL* extension2 = CreateTestTemplateURL(ASCIIToUTF16("keyword2"), |
| 1203 std::string(chrome::kExtensionScheme) + "://extension2"); | 1206 std::string(chrome::kExtensionScheme) + "://extension2"); |
| 1204 model()->Add(extension2); | 1207 model()->Add(extension2); |
| 1205 EXPECT_EQ(0U, processor()->change_list_size()); | 1208 EXPECT_EQ(0U, processor()->change_list_size()); |
| 1206 | 1209 |
| 1207 // Create some sync changes that will conflict with the extension keywords. | 1210 // Create some sync changes that will conflict with the extension keywords. |
| 1208 csync::SyncChangeList changes; | 1211 syncer::SyncChangeList changes; |
| 1209 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 1212 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1210 CreateTestTemplateURL(ASCIIToUTF16("keyword1"), "http://aaa.com", | 1213 CreateTestTemplateURL(ASCIIToUTF16("keyword1"), "http://aaa.com", |
| 1211 std::string(), 100, true))); | 1214 std::string(), 100, true))); |
| 1212 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 1215 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1213 CreateTestTemplateURL(ASCIIToUTF16("keyword2"), "http://bbb.com"))); | 1216 CreateTestTemplateURL(ASCIIToUTF16("keyword2"), "http://bbb.com"))); |
| 1214 model()->ProcessSyncChanges(FROM_HERE, changes); | 1217 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1215 | 1218 |
| 1216 // The synced keywords should be added unchanged, and the result of | 1219 // The synced keywords should be added unchanged, and the result of |
| 1217 // GetTemplateURLForKeyword() for each keyword should depend on whether the | 1220 // GetTemplateURLForKeyword() for each keyword should depend on whether the |
| 1218 // synced keyword is replaceable or not. | 1221 // synced keyword is replaceable or not. |
| 1219 EXPECT_EQ(extension1, | 1222 EXPECT_EQ(extension1, |
| 1220 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); | 1223 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); |
| 1221 EXPECT_FALSE(model()->GetTemplateURLForHost("aaa.com") == NULL); | 1224 EXPECT_FALSE(model()->GetTemplateURLForHost("aaa.com") == NULL); |
| 1222 TemplateURL* url_for_keyword2 = | 1225 TemplateURL* url_for_keyword2 = |
| 1223 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2")); | 1226 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2")); |
| 1224 EXPECT_NE(extension2, url_for_keyword2); | 1227 EXPECT_NE(extension2, url_for_keyword2); |
| 1225 EXPECT_EQ("http://bbb.com", url_for_keyword2->url()); | 1228 EXPECT_EQ("http://bbb.com", url_for_keyword2->url()); |
| 1226 // Note that extensions don't use host-based keywords, so we can't check that | 1229 // Note that extensions don't use host-based keywords, so we can't check that |
| 1227 // |extension2| is still in the model using GetTemplateURLForHost(); and we | 1230 // |extension2| is still in the model using GetTemplateURLForHost(); and we |
| 1228 // have to create a full-fledged Extension to use | 1231 // have to create a full-fledged Extension to use |
| 1229 // GetTemplateURLForExtension(), which is annoying, so just grab all the URLs | 1232 // GetTemplateURLForExtension(), which is annoying, so just grab all the URLs |
| 1230 // from the model and search for |extension2| within them. | 1233 // from the model and search for |extension2| within them. |
| 1231 TemplateURLService::TemplateURLVector template_urls( | 1234 TemplateURLService::TemplateURLVector template_urls( |
| 1232 model()->GetTemplateURLs()); | 1235 model()->GetTemplateURLs()); |
| 1233 EXPECT_FALSE(std::find(template_urls.begin(), template_urls.end(), | 1236 EXPECT_FALSE(std::find(template_urls.begin(), template_urls.end(), |
| 1234 extension2) == template_urls.end()); | 1237 extension2) == template_urls.end()); |
| 1235 } | 1238 } |
| 1236 | 1239 |
| 1237 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordMigrated) { | 1240 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordMigrated) { |
| 1238 // Create a couple of sync entries with autogenerated keywords. | 1241 // Create a couple of sync entries with autogenerated keywords. |
| 1239 csync::SyncDataList initial_data; | 1242 syncer::SyncDataList initial_data; |
| 1240 scoped_ptr<TemplateURL> turl( | 1243 scoped_ptr<TemplateURL> turl( |
| 1241 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); | 1244 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); |
| 1242 initial_data.push_back( | 1245 initial_data.push_back( |
| 1243 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1246 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1244 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1247 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 1245 "{google:baseURL}search?q={searchTerms}", "key2")); | 1248 "{google:baseURL}search?q={searchTerms}", "key2")); |
| 1246 initial_data.push_back( | 1249 initial_data.push_back( |
| 1247 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1250 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1248 | 1251 |
| 1249 // Now try to sync the data locally. | 1252 // Now try to sync the data locally. |
| 1250 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1253 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1251 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1254 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1252 | 1255 |
| 1253 // Both entries should have been added, with explicit keywords. | 1256 // Both entries should have been added, with explicit keywords. |
| 1254 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com"); | 1257 TemplateURL* key1 = model()->GetTemplateURLForHost("key1.com"); |
| 1255 ASSERT_FALSE(key1 == NULL); | 1258 ASSERT_FALSE(key1 == NULL); |
| 1256 EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword()); | 1259 EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword()); |
| 1257 std::string google_hostname( | 1260 std::string google_hostname( |
| 1258 GURL(UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()); | 1261 GURL(UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()); |
| 1259 TemplateURL* key2 = model()->GetTemplateURLForHost(google_hostname); | 1262 TemplateURL* key2 = model()->GetTemplateURLForHost(google_hostname); |
| 1260 ASSERT_FALSE(key2 == NULL); | 1263 ASSERT_FALSE(key2 == NULL); |
| 1261 string16 google_keyword(net::StripWWW(ASCIIToUTF16(google_hostname))); | 1264 string16 google_keyword(net::StripWWW(ASCIIToUTF16(google_hostname))); |
| 1262 EXPECT_EQ(google_keyword, key2->keyword()); | 1265 EXPECT_EQ(google_keyword, key2->keyword()); |
| 1263 | 1266 |
| 1264 // We should also have gotten some corresponding UPDATEs pushed upstream. | 1267 // We should also have gotten some corresponding UPDATEs pushed upstream. |
| 1265 EXPECT_GE(processor()->change_list_size(), 2U); | 1268 EXPECT_GE(processor()->change_list_size(), 2U); |
| 1266 ASSERT_TRUE(processor()->contains_guid("key1")); | 1269 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 1267 csync::SyncChange key1_change = processor()->change_for_guid("key1"); | 1270 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); |
| 1268 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, key1_change.change_type()); | 1271 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); |
| 1269 EXPECT_EQ("key1.com", GetKeyword(key1_change.sync_data())); | 1272 EXPECT_EQ("key1.com", GetKeyword(key1_change.sync_data())); |
| 1270 ASSERT_TRUE(processor()->contains_guid("key2")); | 1273 ASSERT_TRUE(processor()->contains_guid("key2")); |
| 1271 csync::SyncChange key2_change = processor()->change_for_guid("key2"); | 1274 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); |
| 1272 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, key2_change.change_type()); | 1275 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); |
| 1273 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); | 1276 EXPECT_EQ(google_keyword, UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); |
| 1274 } | 1277 } |
| 1275 | 1278 |
| 1276 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { | 1279 TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) { |
| 1277 // Sync brings in some autogenerated keywords, but the generated keywords we | 1280 // Sync brings in some autogenerated keywords, but the generated keywords we |
| 1278 // try to create conflict with ones in the model. | 1281 // try to create conflict with ones in the model. |
| 1279 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( | 1282 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( |
| 1280 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); | 1283 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); |
| 1281 TemplateURL* google = CreateTestTemplateURL(google_keyword, | 1284 TemplateURL* google = CreateTestTemplateURL(google_keyword, |
| 1282 "{google:baseURL}1/search?q={searchTerms}"); | 1285 "{google:baseURL}1/search?q={searchTerms}"); |
| 1283 model()->Add(google); | 1286 model()->Add(google); |
| 1284 TemplateURL* other = | 1287 TemplateURL* other = |
| 1285 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo"); | 1288 CreateTestTemplateURL(ASCIIToUTF16("other.com"), "http://other.com/foo"); |
| 1286 model()->Add(other); | 1289 model()->Add(other); |
| 1287 csync::SyncDataList initial_data; | 1290 syncer::SyncDataList initial_data; |
| 1288 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"), | 1291 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("sync1"), |
| 1289 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50)); | 1292 "{google:baseURL}2/search?q={searchTerms}", "sync1", 50)); |
| 1290 initial_data.push_back( | 1293 initial_data.push_back( |
| 1291 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1294 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1292 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"), | 1295 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("sync2"), |
| 1293 "http://other.com/search?q={searchTerms}", "sync2", 150)); | 1296 "http://other.com/search?q={searchTerms}", "sync2", 150)); |
| 1294 initial_data.push_back( | 1297 initial_data.push_back( |
| 1295 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1298 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1296 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1299 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1297 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1300 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1298 | 1301 |
| 1299 // In this case, the conflicts should be handled just like any other keyword | 1302 // In this case, the conflicts should be handled just like any other keyword |
| 1300 // conflicts -- the later-modified TemplateURL is assumed to be authoritative. | 1303 // conflicts -- the later-modified TemplateURL is assumed to be authoritative. |
| 1301 EXPECT_EQ(google_keyword, google->keyword()); | 1304 EXPECT_EQ(google_keyword, google->keyword()); |
| 1302 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), | 1305 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), |
| 1303 model()->GetTemplateURLForGUID("sync1")->keyword()); | 1306 model()->GetTemplateURLForGUID("sync1")->keyword()); |
| 1304 EXPECT_EQ(ASCIIToUTF16("other.com_"), other->keyword()); | 1307 EXPECT_EQ(ASCIIToUTF16("other.com_"), other->keyword()); |
| 1305 EXPECT_EQ(ASCIIToUTF16("other.com"), | 1308 EXPECT_EQ(ASCIIToUTF16("other.com"), |
| 1306 model()->GetTemplateURLForGUID("sync2")->keyword()); | 1309 model()->GetTemplateURLForGUID("sync2")->keyword()); |
| 1307 | 1310 |
| 1308 // Both synced URLs should have associated UPDATEs, since both needed their | 1311 // Both synced URLs should have associated UPDATEs, since both needed their |
| 1309 // keywords to be generated (and sync1 needed conflict resolution as well). | 1312 // keywords to be generated (and sync1 needed conflict resolution as well). |
| 1310 EXPECT_GE(processor()->change_list_size(), 2U); | 1313 EXPECT_GE(processor()->change_list_size(), 2U); |
| 1311 ASSERT_TRUE(processor()->contains_guid("sync1")); | 1314 ASSERT_TRUE(processor()->contains_guid("sync1")); |
| 1312 csync::SyncChange sync1_change = processor()->change_for_guid("sync1"); | 1315 syncer::SyncChange sync1_change = processor()->change_for_guid("sync1"); |
| 1313 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, sync1_change.change_type()); | 1316 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync1_change.change_type()); |
| 1314 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), | 1317 EXPECT_EQ(google_keyword + ASCIIToUTF16("_"), |
| 1315 UTF8ToUTF16(GetKeyword(sync1_change.sync_data()))); | 1318 UTF8ToUTF16(GetKeyword(sync1_change.sync_data()))); |
| 1316 ASSERT_TRUE(processor()->contains_guid("sync2")); | 1319 ASSERT_TRUE(processor()->contains_guid("sync2")); |
| 1317 csync::SyncChange sync2_change = processor()->change_for_guid("sync2"); | 1320 syncer::SyncChange sync2_change = processor()->change_for_guid("sync2"); |
| 1318 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, sync2_change.change_type()); | 1321 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, sync2_change.change_type()); |
| 1319 EXPECT_EQ("other.com", GetKeyword(sync2_change.sync_data())); | 1322 EXPECT_EQ("other.com", GetKeyword(sync2_change.sync_data())); |
| 1320 } | 1323 } |
| 1321 | 1324 |
| 1322 TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) { | 1325 TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) { |
| 1323 // Sync brings in two autogenerated keywords and both use Google base URLs. | 1326 // Sync brings in two autogenerated keywords and both use Google base URLs. |
| 1324 // We make the first older so that it will get renamed once before the second | 1327 // We make the first older so that it will get renamed once before the second |
| 1325 // and then again once after (when we resolve conflicts for the second). | 1328 // and then again once after (when we resolve conflicts for the second). |
| 1326 csync::SyncDataList initial_data; | 1329 syncer::SyncDataList initial_data; |
| 1327 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1330 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 1328 "{google:baseURL}1/search?q={searchTerms}", "key1", 50)); | 1331 "{google:baseURL}1/search?q={searchTerms}", "key1", 50)); |
| 1329 initial_data.push_back( | 1332 initial_data.push_back( |
| 1330 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1333 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1331 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1334 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 1332 "{google:baseURL}2/search?q={searchTerms}", "key2")); | 1335 "{google:baseURL}2/search?q={searchTerms}", "key2")); |
| 1333 initial_data.push_back( | 1336 initial_data.push_back( |
| 1334 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); | 1337 CreateCustomSyncData(*turl, true, turl->url(), turl->sync_guid())); |
| 1335 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1338 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1336 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1339 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1337 | 1340 |
| 1338 // We should still have coalesced the updates to one each. | 1341 // We should still have coalesced the updates to one each. |
| 1339 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( | 1342 string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL( |
| 1340 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); | 1343 UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host()))); |
| 1341 TemplateURL* keyword1 = | 1344 TemplateURL* keyword1 = |
| 1342 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); | 1345 model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_")); |
| 1343 ASSERT_FALSE(keyword1 == NULL); | 1346 ASSERT_FALSE(keyword1 == NULL); |
| 1344 EXPECT_EQ("key1", keyword1->sync_guid()); | 1347 EXPECT_EQ("key1", keyword1->sync_guid()); |
| 1345 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); | 1348 TemplateURL* keyword2 = model()->GetTemplateURLForKeyword(google_keyword); |
| 1346 ASSERT_FALSE(keyword2 == NULL); | 1349 ASSERT_FALSE(keyword2 == NULL); |
| 1347 EXPECT_EQ("key2", keyword2->sync_guid()); | 1350 EXPECT_EQ("key2", keyword2->sync_guid()); |
| 1348 EXPECT_GE(processor()->change_list_size(), 2U); | 1351 EXPECT_GE(processor()->change_list_size(), 2U); |
| 1349 ASSERT_TRUE(processor()->contains_guid("key1")); | 1352 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 1350 csync::SyncChange key1_change = processor()->change_for_guid("key1"); | 1353 syncer::SyncChange key1_change = processor()->change_for_guid("key1"); |
| 1351 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, key1_change.change_type()); | 1354 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key1_change.change_type()); |
| 1352 EXPECT_EQ(keyword1->keyword(), | 1355 EXPECT_EQ(keyword1->keyword(), |
| 1353 UTF8ToUTF16(GetKeyword(key1_change.sync_data()))); | 1356 UTF8ToUTF16(GetKeyword(key1_change.sync_data()))); |
| 1354 ASSERT_TRUE(processor()->contains_guid("key2")); | 1357 ASSERT_TRUE(processor()->contains_guid("key2")); |
| 1355 csync::SyncChange key2_change = processor()->change_for_guid("key2"); | 1358 syncer::SyncChange key2_change = processor()->change_for_guid("key2"); |
| 1356 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, key2_change.change_type()); | 1359 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, key2_change.change_type()); |
| 1357 EXPECT_EQ(keyword2->keyword(), | 1360 EXPECT_EQ(keyword2->keyword(), |
| 1358 UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); | 1361 UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); |
| 1359 } | 1362 } |
| 1360 | 1363 |
| 1361 TEST_F(TemplateURLServiceSyncTest, DuplicateEncodingsRemoved) { | 1364 TEST_F(TemplateURLServiceSyncTest, DuplicateEncodingsRemoved) { |
| 1362 // Create a sync entry with duplicate encodings. | 1365 // Create a sync entry with duplicate encodings. |
| 1363 csync::SyncDataList initial_data; | 1366 syncer::SyncDataList initial_data; |
| 1364 | 1367 |
| 1365 TemplateURLData data; | 1368 TemplateURLData data; |
| 1366 data.short_name = ASCIIToUTF16("test"); | 1369 data.short_name = ASCIIToUTF16("test"); |
| 1367 data.SetKeyword(ASCIIToUTF16("keyword")); | 1370 data.SetKeyword(ASCIIToUTF16("keyword")); |
| 1368 data.SetURL("http://test/%s"); | 1371 data.SetURL("http://test/%s"); |
| 1369 data.input_encodings.push_back("UTF-8"); | 1372 data.input_encodings.push_back("UTF-8"); |
| 1370 data.input_encodings.push_back("UTF-8"); | 1373 data.input_encodings.push_back("UTF-8"); |
| 1371 data.input_encodings.push_back("UTF-16"); | 1374 data.input_encodings.push_back("UTF-16"); |
| 1372 data.input_encodings.push_back("UTF-8"); | 1375 data.input_encodings.push_back("UTF-8"); |
| 1373 data.input_encodings.push_back("Big5"); | 1376 data.input_encodings.push_back("Big5"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1387 | 1390 |
| 1388 // The entry should have been added, with duplicate encodings removed. | 1391 // The entry should have been added, with duplicate encodings removed. |
| 1389 TemplateURL* keyword = | 1392 TemplateURL* keyword = |
| 1390 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1393 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
| 1391 ASSERT_FALSE(keyword == NULL); | 1394 ASSERT_FALSE(keyword == NULL); |
| 1392 EXPECT_EQ(4U, keyword->input_encodings().size()); | 1395 EXPECT_EQ(4U, keyword->input_encodings().size()); |
| 1393 | 1396 |
| 1394 // We should also have gotten a corresponding UPDATE pushed upstream. | 1397 // We should also have gotten a corresponding UPDATE pushed upstream. |
| 1395 EXPECT_GE(processor()->change_list_size(), 1U); | 1398 EXPECT_GE(processor()->change_list_size(), 1U); |
| 1396 ASSERT_TRUE(processor()->contains_guid("keyword")); | 1399 ASSERT_TRUE(processor()->contains_guid("keyword")); |
| 1397 csync::SyncChange keyword_change = processor()->change_for_guid("keyword"); | 1400 syncer::SyncChange keyword_change = processor()->change_for_guid("keyword"); |
| 1398 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, keyword_change.change_type()); | 1401 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, keyword_change.change_type()); |
| 1399 EXPECT_EQ("UTF-8;UTF-16;Big5;Windows-1252", keyword_change.sync_data(). | 1402 EXPECT_EQ("UTF-8;UTF-16;Big5;Windows-1252", keyword_change.sync_data(). |
| 1400 GetSpecifics().search_engine().input_encodings()); | 1403 GetSpecifics().search_engine().input_encodings()); |
| 1401 } | 1404 } |
| 1402 | 1405 |
| 1403 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { | 1406 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { |
| 1404 // Start off B with some empty data. | 1407 // Start off B with some empty data. |
| 1405 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1408 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1406 CreateInitialSyncData(), PassProcessor(), | 1409 CreateInitialSyncData(), PassProcessor(), |
| 1407 CreateAndPassSyncErrorFactory()); | 1410 CreateAndPassSyncErrorFactory()); |
| 1408 | 1411 |
| 1409 // Merge A and B. All of B's data should transfer over to A, which initially | 1412 // Merge A and B. All of B's data should transfer over to A, which initially |
| 1410 // has no data. | 1413 // has no data. |
| 1411 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( | 1414 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( |
| 1412 new SyncChangeProcessorDelegate(model_b())); | 1415 new SyncChangeProcessorDelegate(model_b())); |
| 1413 model_a()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1416 model_a()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1414 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES), | 1417 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES), |
| 1415 delegate_b.PassAs<csync::SyncChangeProcessor>(), | 1418 delegate_b.PassAs<syncer::SyncChangeProcessor>(), |
| 1416 CreateAndPassSyncErrorFactory()); | 1419 CreateAndPassSyncErrorFactory()); |
| 1417 | 1420 |
| 1418 // They should be consistent. | 1421 // They should be consistent. |
| 1419 AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES), | 1422 AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES), |
| 1420 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES)); | 1423 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES)); |
| 1421 } | 1424 } |
| 1422 | 1425 |
| 1423 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) { | 1426 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) { |
| 1424 // Start off B with some empty data. | 1427 // Start off B with some empty data. |
| 1425 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1428 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1426 CreateInitialSyncData(), PassProcessor(), | 1429 CreateInitialSyncData(), PassProcessor(), |
| 1427 CreateAndPassSyncErrorFactory()); | 1430 CreateAndPassSyncErrorFactory()); |
| 1428 | 1431 |
| 1429 // Set up A so we have some interesting duplicates and conflicts. | 1432 // Set up A so we have some interesting duplicates and conflicts. |
| 1430 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", | 1433 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", |
| 1431 "key4")); // Added | 1434 "key4")); // Added |
| 1432 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", | 1435 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", |
| 1433 "key2")); // Merge - Copy of key2. | 1436 "key2")); // Merge - Copy of key2. |
| 1434 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", | 1437 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", |
| 1435 "key5", 10)); // Merge - Dupe of key3. | 1438 "key5", 10)); // Merge - Dupe of key3. |
| 1436 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key6.com", | 1439 model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key6.com", |
| 1437 "key6", 10)); // Conflict with key1 | 1440 "key6", 10)); // Conflict with key1 |
| 1438 | 1441 |
| 1439 // Merge A and B. | 1442 // Merge A and B. |
| 1440 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( | 1443 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( |
| 1441 new SyncChangeProcessorDelegate(model_b())); | 1444 new SyncChangeProcessorDelegate(model_b())); |
| 1442 model_a()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1445 model_a()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1443 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES), | 1446 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES), |
| 1444 delegate_b.PassAs<csync::SyncChangeProcessor>(), | 1447 delegate_b.PassAs<syncer::SyncChangeProcessor>(), |
| 1445 CreateAndPassSyncErrorFactory()); | 1448 CreateAndPassSyncErrorFactory()); |
| 1446 | 1449 |
| 1447 // They should be consistent. | 1450 // They should be consistent. |
| 1448 AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES), | 1451 AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES), |
| 1449 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES)); | 1452 model_b()->GetAllSyncData(syncable::SEARCH_ENGINES)); |
| 1450 } | 1453 } |
| 1451 | 1454 |
| 1452 TEST_F(TemplateURLServiceSyncTest, StopSyncing) { | 1455 TEST_F(TemplateURLServiceSyncTest, StopSyncing) { |
| 1453 csync::SyncError error = | 1456 syncer::SyncError error = |
| 1454 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1457 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1455 CreateInitialSyncData(), PassProcessor(), | 1458 CreateInitialSyncData(), PassProcessor(), |
| 1456 CreateAndPassSyncErrorFactory()); | 1459 CreateAndPassSyncErrorFactory()); |
| 1457 ASSERT_FALSE(error.IsSet()); | 1460 ASSERT_FALSE(error.IsSet()); |
| 1458 model()->StopSyncing(syncable::SEARCH_ENGINES); | 1461 model()->StopSyncing(syncable::SEARCH_ENGINES); |
| 1459 | 1462 |
| 1460 csync::SyncChangeList changes; | 1463 syncer::SyncChangeList changes; |
| 1461 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_UPDATE, | 1464 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1462 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", | 1465 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", |
| 1463 "key2"))); | 1466 "key2"))); |
| 1464 error = model()->ProcessSyncChanges(FROM_HERE, changes); | 1467 error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1465 EXPECT_TRUE(error.IsSet()); | 1468 EXPECT_TRUE(error.IsSet()); |
| 1466 | 1469 |
| 1467 // Ensure that the sync changes were not accepted. | 1470 // Ensure that the sync changes were not accepted. |
| 1468 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1471 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1469 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword"))); | 1472 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword"))); |
| 1470 } | 1473 } |
| 1471 | 1474 |
| 1472 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnInitialSync) { | 1475 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnInitialSync) { |
| 1473 processor()->set_erroneous(true); | 1476 processor()->set_erroneous(true); |
| 1474 csync::SyncError error = | 1477 syncer::SyncError error = |
| 1475 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1478 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1476 CreateInitialSyncData(), PassProcessor(), | 1479 CreateInitialSyncData(), PassProcessor(), |
| 1477 CreateAndPassSyncErrorFactory()); | 1480 CreateAndPassSyncErrorFactory()); |
| 1478 EXPECT_TRUE(error.IsSet()); | 1481 EXPECT_TRUE(error.IsSet()); |
| 1479 | 1482 |
| 1480 // Ensure that if the initial merge was erroneous, then subsequence attempts | 1483 // Ensure that if the initial merge was erroneous, then subsequence attempts |
| 1481 // to push data into the local model are rejected, since the model was never | 1484 // to push data into the local model are rejected, since the model was never |
| 1482 // successfully associated with Sync in the first place. | 1485 // successfully associated with Sync in the first place. |
| 1483 csync::SyncChangeList changes; | 1486 syncer::SyncChangeList changes; |
| 1484 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_UPDATE, | 1487 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1485 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", | 1488 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", |
| 1486 "key2"))); | 1489 "key2"))); |
| 1487 processor()->set_erroneous(false); | 1490 processor()->set_erroneous(false); |
| 1488 error = model()->ProcessSyncChanges(FROM_HERE, changes); | 1491 error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1489 EXPECT_TRUE(error.IsSet()); | 1492 EXPECT_TRUE(error.IsSet()); |
| 1490 | 1493 |
| 1491 // Ensure that the sync changes were not accepted. | 1494 // Ensure that the sync changes were not accepted. |
| 1492 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 1495 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
| 1493 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword"))); | 1496 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("newkeyword"))); |
| 1494 } | 1497 } |
| 1495 | 1498 |
| 1496 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnLaterSync) { | 1499 TEST_F(TemplateURLServiceSyncTest, SyncErrorOnLaterSync) { |
| 1497 // Ensure that if the SyncProcessor succeeds in the initial merge, but fails | 1500 // Ensure that if the SyncProcessor succeeds in the initial merge, but fails |
| 1498 // in future ProcessSyncChanges, we still return an error. | 1501 // in future ProcessSyncChanges, we still return an error. |
| 1499 csync::SyncError error = | 1502 syncer::SyncError error = |
| 1500 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1503 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1501 CreateInitialSyncData(), PassProcessor(), | 1504 CreateInitialSyncData(), PassProcessor(), |
| 1502 CreateAndPassSyncErrorFactory()); | 1505 CreateAndPassSyncErrorFactory()); |
| 1503 ASSERT_FALSE(error.IsSet()); | 1506 ASSERT_FALSE(error.IsSet()); |
| 1504 | 1507 |
| 1505 csync::SyncChangeList changes; | 1508 syncer::SyncChangeList changes; |
| 1506 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_UPDATE, | 1509 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1507 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", | 1510 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), "http://new.com", |
| 1508 "key2"))); | 1511 "key2"))); |
| 1509 processor()->set_erroneous(true); | 1512 processor()->set_erroneous(true); |
| 1510 error = model()->ProcessSyncChanges(FROM_HERE, changes); | 1513 error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1511 EXPECT_TRUE(error.IsSet()); | 1514 EXPECT_TRUE(error.IsSet()); |
| 1512 } | 1515 } |
| 1513 | 1516 |
| 1514 TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) { | 1517 TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) { |
| 1515 // Ensure that a second merge with the same data as the first does not | 1518 // Ensure that a second merge with the same data as the first does not |
| 1516 // actually update the local data. | 1519 // actually update the local data. |
| 1517 csync::SyncDataList initial_data; | 1520 syncer::SyncDataList initial_data; |
| 1518 initial_data.push_back(CreateInitialSyncData()[0]); | 1521 initial_data.push_back(CreateInitialSyncData()[0]); |
| 1519 | 1522 |
| 1520 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", | 1523 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", |
| 1521 "key1", 10)); // earlier | 1524 "key1", 10)); // earlier |
| 1522 | 1525 |
| 1523 csync::SyncError error = | 1526 syncer::SyncError error = |
| 1524 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1527 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1525 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); | 1528 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1526 ASSERT_FALSE(error.IsSet()); | 1529 ASSERT_FALSE(error.IsSet()); |
| 1527 | 1530 |
| 1528 // We should have updated the original TemplateURL with Sync's version. | 1531 // We should have updated the original TemplateURL with Sync's version. |
| 1529 // Keep a copy of it so we can compare it after we re-merge. | 1532 // Keep a copy of it so we can compare it after we re-merge. |
| 1530 TemplateURL* key1_url = model()->GetTemplateURLForGUID("key1"); | 1533 TemplateURL* key1_url = model()->GetTemplateURLForGUID("key1"); |
| 1531 ASSERT_TRUE(key1_url); | 1534 ASSERT_TRUE(key1_url); |
| 1532 scoped_ptr<TemplateURL> updated_turl(new TemplateURL(key1_url->profile(), | 1535 scoped_ptr<TemplateURL> updated_turl(new TemplateURL(key1_url->profile(), |
| 1533 key1_url->data())); | 1536 key1_url->data())); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1552 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); | 1555 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1553 ASSERT_FALSE(error.IsSet()); | 1556 ASSERT_FALSE(error.IsSet()); |
| 1554 | 1557 |
| 1555 // Check that the TemplateURL was not modified. | 1558 // Check that the TemplateURL was not modified. |
| 1556 const TemplateURL* reupdated_turl = model()->GetTemplateURLForGUID("key1"); | 1559 const TemplateURL* reupdated_turl = model()->GetTemplateURLForGUID("key1"); |
| 1557 ASSERT_TRUE(reupdated_turl); | 1560 ASSERT_TRUE(reupdated_turl); |
| 1558 AssertEquals(*updated_turl, *reupdated_turl); | 1561 AssertEquals(*updated_turl, *reupdated_turl); |
| 1559 } | 1562 } |
| 1560 | 1563 |
| 1561 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultGUIDArrivesFirst) { | 1564 TEST_F(TemplateURLServiceSyncTest, SyncedDefaultGUIDArrivesFirst) { |
| 1562 csync::SyncDataList initial_data = CreateInitialSyncData(); | 1565 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1563 // The default search provider should support replacement. | 1566 // The default search provider should support replacement. |
| 1564 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1567 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 1565 "http://key2.com/{searchTerms}", "key2", 90)); | 1568 "http://key2.com/{searchTerms}", "key2", 90)); |
| 1566 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1569 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
| 1567 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1570 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1568 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1571 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1569 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); | 1572 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); |
| 1570 | 1573 |
| 1571 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1574 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1572 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | 1575 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); |
| 1573 ASSERT_TRUE(default_search); | 1576 ASSERT_TRUE(default_search); |
| 1574 | 1577 |
| 1575 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in | 1578 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in |
| 1576 // the model yet. Ensure that the default has not changed in any way. | 1579 // the model yet. Ensure that the default has not changed in any way. |
| 1577 profile_a()->GetTestingPrefService()->SetString( | 1580 profile_a()->GetTestingPrefService()->SetString( |
| 1578 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); | 1581 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); |
| 1579 | 1582 |
| 1580 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1583 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); |
| 1581 | 1584 |
| 1582 // Bring in a random new search engine with a different GUID. Ensure that | 1585 // Bring in a random new search engine with a different GUID. Ensure that |
| 1583 // it doesn't change the default. | 1586 // it doesn't change the default. |
| 1584 csync::SyncChangeList changes1; | 1587 syncer::SyncChangeList changes1; |
| 1585 changes1.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 1588 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1586 CreateTestTemplateURL(ASCIIToUTF16("random"), "http://random.com", | 1589 CreateTestTemplateURL(ASCIIToUTF16("random"), "http://random.com", |
| 1587 "random"))); | 1590 "random"))); |
| 1588 model()->ProcessSyncChanges(FROM_HERE, changes1); | 1591 model()->ProcessSyncChanges(FROM_HERE, changes1); |
| 1589 | 1592 |
| 1590 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1593 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1591 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1594 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); |
| 1592 | 1595 |
| 1593 // Finally, bring in the expected entry with the right GUID. Ensure that | 1596 // Finally, bring in the expected entry with the right GUID. Ensure that |
| 1594 // the default has changed to the new search engine. | 1597 // the default has changed to the new search engine. |
| 1595 csync::SyncChangeList changes2; | 1598 syncer::SyncChangeList changes2; |
| 1596 changes2.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 1599 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1597 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", | 1600 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", |
| 1598 "newdefault"))); | 1601 "newdefault"))); |
| 1599 model()->ProcessSyncChanges(FROM_HERE, changes2); | 1602 model()->ProcessSyncChanges(FROM_HERE, changes2); |
| 1600 | 1603 |
| 1601 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1604 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1602 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); | 1605 ASSERT_NE(default_search, model()->GetDefaultSearchProvider()); |
| 1603 ASSERT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); | 1606 ASSERT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1604 } | 1607 } |
| 1605 | 1608 |
| 1606 TEST_F(TemplateURLServiceSyncTest, DefaultGuidDeletedAndReplaced) { | 1609 TEST_F(TemplateURLServiceSyncTest, DefaultGuidDeletedAndReplaced) { |
| 1607 csync::SyncDataList initial_data; | 1610 syncer::SyncDataList initial_data; |
| 1608 // The default search provider should support replacement. | 1611 // The default search provider should support replacement. |
| 1609 scoped_ptr<TemplateURL> turl1(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1612 scoped_ptr<TemplateURL> turl1(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 1610 "http://key1.com/{searchTerms}", "key1", 90)); | 1613 "http://key1.com/{searchTerms}", "key1", 90)); |
| 1611 // Create a second default search provider for the | 1614 // Create a second default search provider for the |
| 1612 // FindNewDefaultSearchProvider method to find. | 1615 // FindNewDefaultSearchProvider method to find. |
| 1613 TemplateURLData data; | 1616 TemplateURLData data; |
| 1614 data.short_name = ASCIIToUTF16("unittest"); | 1617 data.short_name = ASCIIToUTF16("unittest"); |
| 1615 data.SetKeyword(ASCIIToUTF16("key2")); | 1618 data.SetKeyword(ASCIIToUTF16("key2")); |
| 1616 data.SetURL("http://key2.com/{searchTerms}"); | 1619 data.SetURL("http://key2.com/{searchTerms}"); |
| 1617 data.favicon_url = GURL("http://favicon.url"); | 1620 data.favicon_url = GURL("http://favicon.url"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1631 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1634 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1632 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key1")); | 1635 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key1")); |
| 1633 ASSERT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); | 1636 ASSERT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1634 | 1637 |
| 1635 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1638 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1636 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | 1639 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); |
| 1637 ASSERT_TRUE(default_search); | 1640 ASSERT_TRUE(default_search); |
| 1638 | 1641 |
| 1639 // Delete the old default. This will change the default to the next available | 1642 // Delete the old default. This will change the default to the next available |
| 1640 // (turl2), but should not affect the synced preference. | 1643 // (turl2), but should not affect the synced preference. |
| 1641 csync::SyncChangeList changes1; | 1644 syncer::SyncChangeList changes1; |
| 1642 changes1.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_DELETE, | 1645 changes1.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_DELETE, |
| 1643 turl1.release())); | 1646 turl1.release())); |
| 1644 model()->ProcessSyncChanges(FROM_HERE, changes1); | 1647 model()->ProcessSyncChanges(FROM_HERE, changes1); |
| 1645 | 1648 |
| 1646 EXPECT_EQ(1U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1649 EXPECT_EQ(1U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1647 EXPECT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); | 1650 EXPECT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1648 EXPECT_EQ("key1", profile_a()->GetTestingPrefService()->GetString( | 1651 EXPECT_EQ("key1", profile_a()->GetTestingPrefService()->GetString( |
| 1649 prefs::kSyncedDefaultSearchProviderGUID)); | 1652 prefs::kSyncedDefaultSearchProviderGUID)); |
| 1650 | 1653 |
| 1651 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in | 1654 // Change kSyncedDefaultSearchProviderGUID to a GUID that does not exist in |
| 1652 // the model yet. Ensure that the default has not changed in any way. | 1655 // the model yet. Ensure that the default has not changed in any way. |
| 1653 profile_a()->GetTestingPrefService()->SetString( | 1656 profile_a()->GetTestingPrefService()->SetString( |
| 1654 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); | 1657 prefs::kSyncedDefaultSearchProviderGUID, "newdefault"); |
| 1655 | 1658 |
| 1656 ASSERT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); | 1659 ASSERT_EQ("key2", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1657 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( | 1660 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( |
| 1658 prefs::kSyncedDefaultSearchProviderGUID)); | 1661 prefs::kSyncedDefaultSearchProviderGUID)); |
| 1659 | 1662 |
| 1660 // Finally, bring in the expected entry with the right GUID. Ensure that | 1663 // Finally, bring in the expected entry with the right GUID. Ensure that |
| 1661 // the default has changed to the new search engine. | 1664 // the default has changed to the new search engine. |
| 1662 csync::SyncChangeList changes2; | 1665 syncer::SyncChangeList changes2; |
| 1663 changes2.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 1666 changes2.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1664 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", | 1667 CreateTestTemplateURL(ASCIIToUTF16("new"), "http://new.com/{searchTerms}", |
| 1665 "newdefault"))); | 1668 "newdefault"))); |
| 1666 model()->ProcessSyncChanges(FROM_HERE, changes2); | 1669 model()->ProcessSyncChanges(FROM_HERE, changes2); |
| 1667 | 1670 |
| 1668 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1671 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1669 EXPECT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); | 1672 EXPECT_EQ("newdefault", model()->GetDefaultSearchProvider()->sync_guid()); |
| 1670 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( | 1673 EXPECT_EQ("newdefault", profile_a()->GetTestingPrefService()->GetString( |
| 1671 prefs::kSyncedDefaultSearchProviderGUID)); | 1674 prefs::kSyncedDefaultSearchProviderGUID)); |
| 1672 } | 1675 } |
| 1673 | 1676 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1686 // Set kSyncedDefaultSearchProviderGUID to something that is not yet in | 1689 // Set kSyncedDefaultSearchProviderGUID to something that is not yet in |
| 1687 // the model but is expected in the initial sync. Ensure that this doesn't | 1690 // the model but is expected in the initial sync. Ensure that this doesn't |
| 1688 // change our default since we're not quite syncing yet. | 1691 // change our default since we're not quite syncing yet. |
| 1689 profile_a()->GetTestingPrefService()->SetString( | 1692 profile_a()->GetTestingPrefService()->SetString( |
| 1690 prefs::kSyncedDefaultSearchProviderGUID, "key2"); | 1693 prefs::kSyncedDefaultSearchProviderGUID, "key2"); |
| 1691 | 1694 |
| 1692 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1695 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); |
| 1693 | 1696 |
| 1694 // Now sync the initial data, which will include the search engine entry | 1697 // Now sync the initial data, which will include the search engine entry |
| 1695 // destined to become the new default. | 1698 // destined to become the new default. |
| 1696 csync::SyncDataList initial_data = CreateInitialSyncData(); | 1699 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1697 // The default search provider should support replacement. | 1700 // The default search provider should support replacement. |
| 1698 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), | 1701 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), |
| 1699 "http://key2.com/{searchTerms}", "key2", 90)); | 1702 "http://key2.com/{searchTerms}", "key2", 90)); |
| 1700 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1703 initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
| 1701 | 1704 |
| 1702 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1705 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1703 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1706 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1704 | 1707 |
| 1705 // Ensure that the new default has been set. | 1708 // Ensure that the new default has been set. |
| 1706 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1709 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1720 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); | 1723 const TemplateURL* default_search = model()->GetDefaultSearchProvider(); |
| 1721 ASSERT_TRUE(default_search); | 1724 ASSERT_TRUE(default_search); |
| 1722 | 1725 |
| 1723 // Set kSyncedDefaultSearchProviderGUID to the current default. | 1726 // Set kSyncedDefaultSearchProviderGUID to the current default. |
| 1724 profile_a()->GetTestingPrefService()->SetString( | 1727 profile_a()->GetTestingPrefService()->SetString( |
| 1725 prefs::kSyncedDefaultSearchProviderGUID, kGUID); | 1728 prefs::kSyncedDefaultSearchProviderGUID, kGUID); |
| 1726 | 1729 |
| 1727 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1730 EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); |
| 1728 | 1731 |
| 1729 // Now sync the initial data. | 1732 // Now sync the initial data. |
| 1730 csync::SyncDataList initial_data = CreateInitialSyncData(); | 1733 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1731 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1734 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1732 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1735 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1733 | 1736 |
| 1734 // Ensure that the new entries were added and the default has not changed. | 1737 // Ensure that the new entries were added and the default has not changed. |
| 1735 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1738 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1736 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); | 1739 ASSERT_EQ(default_search, model()->GetDefaultSearchProvider()); |
| 1737 } | 1740 } |
| 1738 | 1741 |
| 1739 TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { | 1742 TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { |
| 1740 // First start off with a few entries and make sure we can set an unmanaged | 1743 // First start off with a few entries and make sure we can set an unmanaged |
| 1741 // default search provider. | 1744 // default search provider. |
| 1742 csync::SyncDataList initial_data = CreateInitialSyncData(); | 1745 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1743 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1746 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1744 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1747 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1745 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); | 1748 model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); |
| 1746 | 1749 |
| 1747 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1750 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1748 ASSERT_FALSE(model()->is_default_search_managed()); | 1751 ASSERT_FALSE(model()->is_default_search_managed()); |
| 1749 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 1752 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
| 1750 | 1753 |
| 1751 // Change the default search provider to a managed one. | 1754 // Change the default search provider to a managed one. |
| 1752 const char kName[] = "manageddefault"; | 1755 const char kName[] = "manageddefault"; |
| 1753 const char kSearchURL[] = "http://manageddefault.com/search?t={searchTerms}"; | 1756 const char kSearchURL[] = "http://manageddefault.com/search?t={searchTerms}"; |
| 1754 const char kIconURL[] = "http://manageddefault.com/icon.jpg"; | 1757 const char kIconURL[] = "http://manageddefault.com/icon.jpg"; |
| 1755 const char kEncodings[] = "UTF-16;UTF-32"; | 1758 const char kEncodings[] = "UTF-16;UTF-32"; |
| 1756 test_util_a_.SetManagedDefaultSearchPreferences(true, kName, kName, | 1759 test_util_a_.SetManagedDefaultSearchPreferences(true, kName, kName, |
| 1757 kSearchURL, std::string(), kIconURL, kEncodings); | 1760 kSearchURL, std::string(), kIconURL, kEncodings); |
| 1758 const TemplateURL* dsp_turl = model()->GetDefaultSearchProvider(); | 1761 const TemplateURL* dsp_turl = model()->GetDefaultSearchProvider(); |
| 1759 | 1762 |
| 1760 EXPECT_TRUE(model()->is_default_search_managed()); | 1763 EXPECT_TRUE(model()->is_default_search_managed()); |
| 1761 | 1764 |
| 1762 // Add a new entry from Sync. It should still sync in despite the default | 1765 // Add a new entry from Sync. It should still sync in despite the default |
| 1763 // being managed. | 1766 // being managed. |
| 1764 csync::SyncChangeList changes; | 1767 syncer::SyncChangeList changes; |
| 1765 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_ADD, | 1768 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
| 1766 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), | 1769 CreateTestTemplateURL(ASCIIToUTF16("newkeyword"), |
| 1767 "http://new.com/{searchTerms}", | 1770 "http://new.com/{searchTerms}", |
| 1768 "newdefault"))); | 1771 "newdefault"))); |
| 1769 model()->ProcessSyncChanges(FROM_HERE, changes); | 1772 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1770 | 1773 |
| 1771 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1774 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1772 | 1775 |
| 1773 // Change kSyncedDefaultSearchProviderGUID to point to the new entry and | 1776 // Change kSyncedDefaultSearchProviderGUID to point to the new entry and |
| 1774 // ensure that the DSP remains managed. | 1777 // ensure that the DSP remains managed. |
| 1775 profile_a()->GetTestingPrefService()->SetString( | 1778 profile_a()->GetTestingPrefService()->SetString( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1789 } | 1792 } |
| 1790 | 1793 |
| 1791 TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) { | 1794 TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) { |
| 1792 // If the value from Sync is a duplicate of the local default and is newer, it | 1795 // If the value from Sync is a duplicate of the local default and is newer, it |
| 1793 // should safely replace the local value and set as the new default. | 1796 // should safely replace the local value and set as the new default. |
| 1794 TemplateURL* default_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1797 TemplateURL* default_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 1795 "http://key1.com/{searchTerms}", "whateverguid", 10); | 1798 "http://key1.com/{searchTerms}", "whateverguid", 10); |
| 1796 model()->Add(default_turl); | 1799 model()->Add(default_turl); |
| 1797 model()->SetDefaultSearchProvider(default_turl); | 1800 model()->SetDefaultSearchProvider(default_turl); |
| 1798 | 1801 |
| 1799 csync::SyncDataList initial_data = CreateInitialSyncData(); | 1802 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1800 // The key1 entry should be a duplicate of the default. | 1803 // The key1 entry should be a duplicate of the default. |
| 1801 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 1804 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 1802 "http://key1.com/{searchTerms}", "key1", 90)); | 1805 "http://key1.com/{searchTerms}", "key1", 90)); |
| 1803 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1806 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
| 1804 | 1807 |
| 1805 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1808 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1806 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1809 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1807 | 1810 |
| 1808 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1811 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1809 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); | 1812 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); |
| 1810 EXPECT_EQ(model()->GetDefaultSearchProvider(), | 1813 EXPECT_EQ(model()->GetDefaultSearchProvider(), |
| 1811 model()->GetTemplateURLForGUID("key1")); | 1814 model()->GetTemplateURLForGUID("key1")); |
| 1812 } | 1815 } |
| 1813 | 1816 |
| 1814 TEST_F(TemplateURLServiceSyncTest, LocalDefaultWinsConflict) { | 1817 TEST_F(TemplateURLServiceSyncTest, LocalDefaultWinsConflict) { |
| 1815 // We expect that the local default always wins keyword conflict resolution. | 1818 // We expect that the local default always wins keyword conflict resolution. |
| 1816 const string16 keyword(ASCIIToUTF16("key1")); | 1819 const string16 keyword(ASCIIToUTF16("key1")); |
| 1817 TemplateURL* default_turl = CreateTestTemplateURL(keyword, | 1820 TemplateURL* default_turl = CreateTestTemplateURL(keyword, |
| 1818 "http://whatever.com/{searchTerms}", "whateverguid", 10); | 1821 "http://whatever.com/{searchTerms}", "whateverguid", 10); |
| 1819 model()->Add(default_turl); | 1822 model()->Add(default_turl); |
| 1820 model()->SetDefaultSearchProvider(default_turl); | 1823 model()->SetDefaultSearchProvider(default_turl); |
| 1821 | 1824 |
| 1822 csync::SyncDataList initial_data = CreateInitialSyncData(); | 1825 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
| 1823 // The key1 entry should be different from the default but conflict in the | 1826 // The key1 entry should be different from the default but conflict in the |
| 1824 // keyword. | 1827 // keyword. |
| 1825 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(keyword, | 1828 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(keyword, |
| 1826 "http://key1.com/{searchTerms}", "key1", 90)); | 1829 "http://key1.com/{searchTerms}", "key1", 90)); |
| 1827 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 1830 initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
| 1828 | 1831 |
| 1829 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1832 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1830 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1833 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1831 | 1834 |
| 1832 // The conflicting TemplateURL should be added, but it should have lost | 1835 // The conflicting TemplateURL should be added, but it should have lost |
| 1833 // conflict resolution against the default. | 1836 // conflict resolution against the default. |
| 1834 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1837 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
| 1835 const TemplateURL* winner = model()->GetTemplateURLForGUID("whateverguid"); | 1838 const TemplateURL* winner = model()->GetTemplateURLForGUID("whateverguid"); |
| 1836 ASSERT_TRUE(winner); | 1839 ASSERT_TRUE(winner); |
| 1837 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner); | 1840 EXPECT_EQ(model()->GetDefaultSearchProvider(), winner); |
| 1838 EXPECT_EQ(keyword, winner->keyword()); | 1841 EXPECT_EQ(keyword, winner->keyword()); |
| 1839 const TemplateURL* loser = model()->GetTemplateURLForGUID("key1"); | 1842 const TemplateURL* loser = model()->GetTemplateURLForGUID("key1"); |
| 1840 ASSERT_TRUE(loser); | 1843 ASSERT_TRUE(loser); |
| 1841 EXPECT_EQ(ASCIIToUTF16("key1.com"), loser->keyword()); | 1844 EXPECT_EQ(ASCIIToUTF16("key1.com"), loser->keyword()); |
| 1842 } | 1845 } |
| 1843 | 1846 |
| 1844 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { | 1847 TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { |
| 1845 // Create a couple of bogus entries to sync. | 1848 // Create a couple of bogus entries to sync. |
| 1846 csync::SyncDataList initial_data; | 1849 syncer::SyncDataList initial_data; |
| 1847 scoped_ptr<TemplateURL> turl( | 1850 scoped_ptr<TemplateURL> turl( |
| 1848 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); | 1851 CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1")); |
| 1849 initial_data.push_back( | 1852 initial_data.push_back( |
| 1850 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid())); | 1853 CreateCustomSyncData(*turl, false, std::string(), turl->sync_guid())); |
| 1851 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); | 1854 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); |
| 1852 initial_data.push_back( | 1855 initial_data.push_back( |
| 1853 CreateCustomSyncData(*turl, false, turl->url(), std::string())); | 1856 CreateCustomSyncData(*turl, false, turl->url(), std::string())); |
| 1854 | 1857 |
| 1855 // Now try to sync the data locally. | 1858 // Now try to sync the data locally. |
| 1856 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1859 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1857 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1860 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1858 | 1861 |
| 1859 // Nothing should have been added, and both bogus entries should be marked for | 1862 // Nothing should have been added, and both bogus entries should be marked for |
| 1860 // deletion. | 1863 // deletion. |
| 1861 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 1864 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
| 1862 EXPECT_EQ(2U, processor()->change_list_size()); | 1865 EXPECT_EQ(2U, processor()->change_list_size()); |
| 1863 ASSERT_TRUE(processor()->contains_guid("key1")); | 1866 ASSERT_TRUE(processor()->contains_guid("key1")); |
| 1864 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, | 1867 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
| 1865 processor()->change_for_guid("key1").change_type()); | 1868 processor()->change_for_guid("key1").change_type()); |
| 1866 ASSERT_TRUE(processor()->contains_guid(std::string())); | 1869 ASSERT_TRUE(processor()->contains_guid(std::string())); |
| 1867 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, | 1870 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
| 1868 processor()->change_for_guid(std::string()).change_type()); | 1871 processor()->change_for_guid(std::string()).change_type()); |
| 1869 } | 1872 } |
| 1870 | 1873 |
| 1871 TEST_F(TemplateURLServiceSyncTest, PreSyncDeletes) { | 1874 TEST_F(TemplateURLServiceSyncTest, PreSyncDeletes) { |
| 1872 model()->pre_sync_deletes_.insert("key1"); | 1875 model()->pre_sync_deletes_.insert("key1"); |
| 1873 model()->pre_sync_deletes_.insert("key2"); | 1876 model()->pre_sync_deletes_.insert("key2"); |
| 1874 model()->pre_sync_deletes_.insert("aaa"); | 1877 model()->pre_sync_deletes_.insert("aaa"); |
| 1875 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("whatever"), | 1878 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("whatever"), |
| 1876 "http://key1.com", "bbb")); | 1879 "http://key1.com", "bbb")); |
| 1877 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1880 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1878 CreateInitialSyncData(), PassProcessor(), | 1881 CreateInitialSyncData(), PassProcessor(), |
| 1879 CreateAndPassSyncErrorFactory()); | 1882 CreateAndPassSyncErrorFactory()); |
| 1880 | 1883 |
| 1881 // We expect the model to have GUIDs {bbb, key3} after our initial merge. | 1884 // We expect the model to have GUIDs {bbb, key3} after our initial merge. |
| 1882 EXPECT_TRUE(model()->GetTemplateURLForGUID("bbb")); | 1885 EXPECT_TRUE(model()->GetTemplateURLForGUID("bbb")); |
| 1883 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 1886 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
| 1884 csync::SyncChange change = processor()->change_for_guid("key1"); | 1887 syncer::SyncChange change = processor()->change_for_guid("key1"); |
| 1885 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, change.change_type()); | 1888 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); |
| 1886 change = processor()->change_for_guid("key2"); | 1889 change = processor()->change_for_guid("key2"); |
| 1887 EXPECT_EQ(csync::SyncChange::ACTION_DELETE, change.change_type()); | 1890 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, change.change_type()); |
| 1888 // "aaa" should have been pruned out on account of not being from Sync. | 1891 // "aaa" should have been pruned out on account of not being from Sync. |
| 1889 EXPECT_FALSE(processor()->contains_guid("aaa")); | 1892 EXPECT_FALSE(processor()->contains_guid("aaa")); |
| 1890 // The set of pre-sync deletes should be cleared so they're not reused if | 1893 // The set of pre-sync deletes should be cleared so they're not reused if |
| 1891 // MergeDataAndStartSyncing gets called again. | 1894 // MergeDataAndStartSyncing gets called again. |
| 1892 EXPECT_TRUE(model()->pre_sync_deletes_.empty()); | 1895 EXPECT_TRUE(model()->pre_sync_deletes_.empty()); |
| 1893 } | 1896 } |
| 1894 | 1897 |
| 1895 TEST_F(TemplateURLServiceSyncTest, PreSyncUpdates) { | 1898 TEST_F(TemplateURLServiceSyncTest, PreSyncUpdates) { |
| 1896 const char* kNewKeyword = "somethingnew"; | 1899 const char* kNewKeyword = "somethingnew"; |
| 1897 // Fetch the prepopulate search engines so we know what they are. | 1900 // Fetch the prepopulate search engines so we know what they are. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1925 ASCIIToUTF16(kNewKeyword)); | 1928 ASCIIToUTF16(kNewKeyword)); |
| 1926 base::Time new_timestamp = added_turl->last_modified(); | 1929 base::Time new_timestamp = added_turl->last_modified(); |
| 1927 EXPECT_GE(new_timestamp, pre_merge_time); | 1930 EXPECT_GE(new_timestamp, pre_merge_time); |
| 1928 ASSERT_TRUE(added_turl); | 1931 ASSERT_TRUE(added_turl); |
| 1929 std::string sync_guid = added_turl->sync_guid(); | 1932 std::string sync_guid = added_turl->sync_guid(); |
| 1930 | 1933 |
| 1931 // Bring down a copy of the prepopulate engine from Sync with the old values, | 1934 // Bring down a copy of the prepopulate engine from Sync with the old values, |
| 1932 // including the old timestamp and the same GUID. Ensure that it loses | 1935 // including the old timestamp and the same GUID. Ensure that it loses |
| 1933 // conflict resolution against the local value, and an update is sent to the | 1936 // conflict resolution against the local value, and an update is sent to the |
| 1934 // server. The new timestamp should be preserved. | 1937 // server. The new timestamp should be preserved. |
| 1935 csync::SyncDataList initial_data; | 1938 syncer::SyncDataList initial_data; |
| 1936 data_copy.SetKeyword(original_keyword); | 1939 data_copy.SetKeyword(original_keyword); |
| 1937 data_copy.sync_guid = sync_guid; | 1940 data_copy.sync_guid = sync_guid; |
| 1938 scoped_ptr<TemplateURL> sync_turl( | 1941 scoped_ptr<TemplateURL> sync_turl( |
| 1939 new TemplateURL(prepop_turls[0]->profile(), data_copy)); | 1942 new TemplateURL(prepop_turls[0]->profile(), data_copy)); |
| 1940 initial_data.push_back( | 1943 initial_data.push_back( |
| 1941 TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl)); | 1944 TemplateURLService::CreateSyncDataFromTemplateURL(*sync_turl)); |
| 1942 | 1945 |
| 1943 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1946 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
| 1944 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); | 1947 initial_data, PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1945 | 1948 |
| 1946 ASSERT_EQ(added_turl, model()->GetTemplateURLForKeyword( | 1949 ASSERT_EQ(added_turl, model()->GetTemplateURLForKeyword( |
| 1947 ASCIIToUTF16(kNewKeyword))); | 1950 ASCIIToUTF16(kNewKeyword))); |
| 1948 EXPECT_EQ(new_timestamp, added_turl->last_modified()); | 1951 EXPECT_EQ(new_timestamp, added_turl->last_modified()); |
| 1949 csync::SyncChange change = processor()->change_for_guid(sync_guid); | 1952 syncer::SyncChange change = processor()->change_for_guid(sync_guid); |
| 1950 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, change.change_type()); | 1953 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
| 1951 EXPECT_EQ(kNewKeyword, | 1954 EXPECT_EQ(kNewKeyword, |
| 1952 change.sync_data().GetSpecifics().search_engine().keyword()); | 1955 change.sync_data().GetSpecifics().search_engine().keyword()); |
| 1953 EXPECT_EQ(new_timestamp, base::Time::FromInternalValue( | 1956 EXPECT_EQ(new_timestamp, base::Time::FromInternalValue( |
| 1954 change.sync_data().GetSpecifics().search_engine().last_modified())); | 1957 change.sync_data().GetSpecifics().search_engine().last_modified())); |
| 1955 } | 1958 } |
| 1956 | 1959 |
| 1957 TEST_F(TemplateURLServiceSyncTest, SyncBaseURLs) { | 1960 TEST_F(TemplateURLServiceSyncTest, SyncBaseURLs) { |
| 1958 // Verify that bringing in a remote TemplateURL that uses Google base URLs | 1961 // Verify that bringing in a remote TemplateURL that uses Google base URLs |
| 1959 // causes it to get a local keyword that matches the local base URL. | 1962 // causes it to get a local keyword that matches the local base URL. |
| 1960 test_util_a_.SetGoogleBaseURL(GURL("http://google.com/")); | 1963 test_util_a_.SetGoogleBaseURL(GURL("http://google.com/")); |
| 1961 csync::SyncDataList initial_data; | 1964 syncer::SyncDataList initial_data; |
| 1962 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL( | 1965 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL( |
| 1963 ASCIIToUTF16("google.co.uk"), "{google:baseURL}search?q={searchTerms}", | 1966 ASCIIToUTF16("google.co.uk"), "{google:baseURL}search?q={searchTerms}", |
| 1964 "guid")); | 1967 "guid")); |
| 1965 initial_data.push_back( | 1968 initial_data.push_back( |
| 1966 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 1969 TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 1967 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 1970 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
| 1968 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1971 PassProcessor(), CreateAndPassSyncErrorFactory()); |
| 1969 TemplateURL* synced_turl = model()->GetTemplateURLForGUID("guid"); | 1972 TemplateURL* synced_turl = model()->GetTemplateURLForGUID("guid"); |
| 1970 ASSERT_TRUE(synced_turl); | 1973 ASSERT_TRUE(synced_turl); |
| 1971 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword()); | 1974 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword()); |
| 1972 EXPECT_EQ(0U, processor()->change_list_size()); | 1975 EXPECT_EQ(0U, processor()->change_list_size()); |
| 1973 | 1976 |
| 1974 // Remote updates to this URL's keyword should be silently ignored. | 1977 // Remote updates to this URL's keyword should be silently ignored. |
| 1975 csync::SyncChangeList changes; | 1978 syncer::SyncChangeList changes; |
| 1976 changes.push_back(CreateTestSyncChange(csync::SyncChange::ACTION_UPDATE, | 1979 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_UPDATE, |
| 1977 CreateTestTemplateURL(ASCIIToUTF16("google.de"), | 1980 CreateTestTemplateURL(ASCIIToUTF16("google.de"), |
| 1978 "{google:baseURL}search?q={searchTerms}", "guid"))); | 1981 "{google:baseURL}search?q={searchTerms}", "guid"))); |
| 1979 model()->ProcessSyncChanges(FROM_HERE, changes); | 1982 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 1980 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword()); | 1983 EXPECT_EQ(ASCIIToUTF16("google.com"), synced_turl->keyword()); |
| 1981 EXPECT_EQ(0U, processor()->change_list_size()); | 1984 EXPECT_EQ(0U, processor()->change_list_size()); |
| 1982 | 1985 |
| 1983 // A local change to the Google base URL should update the keyword and | 1986 // A local change to the Google base URL should update the keyword and |
| 1984 // generate a sync change. | 1987 // generate a sync change. |
| 1985 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); | 1988 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); |
| 1986 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); | 1989 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); |
| 1987 EXPECT_EQ(1U, processor()->change_list_size()); | 1990 EXPECT_EQ(1U, processor()->change_list_size()); |
| 1988 ASSERT_TRUE(processor()->contains_guid("guid")); | 1991 ASSERT_TRUE(processor()->contains_guid("guid")); |
| 1989 csync::SyncChange change(processor()->change_for_guid("guid")); | 1992 syncer::SyncChange change(processor()->change_for_guid("guid")); |
| 1990 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, change.change_type()); | 1993 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); |
| 1991 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); | 1994 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); |
| 1992 } | 1995 } |
| OLD | NEW |