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/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderEnabled); | 75 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderEnabled); |
76 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderName); | 76 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderName); |
77 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderSuggestURL); | 77 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderSuggestURL); |
78 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderIconURL); | 78 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderIconURL); |
79 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderEncodings); | 79 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderEncodings); |
80 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderKeyword); | 80 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderKeyword); |
81 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderID); | 81 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderID); |
82 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderPrepopulateID); | 82 pref_service->RemoveManagedPref(prefs::kDefaultSearchProviderPrepopulateID); |
83 } | 83 } |
84 | 84 |
| 85 |
| 86 // TestChangeProcessor -------------------------------------------------------- |
| 87 |
85 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed | 88 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed |
86 // back up to Sync. | 89 // back up to Sync. |
87 class TestChangeProcessor : public SyncChangeProcessor { | 90 class TestChangeProcessor : public SyncChangeProcessor { |
88 public: | 91 public: |
89 TestChangeProcessor() : erroneous_(false) { | 92 TestChangeProcessor(); |
90 } | 93 virtual ~TestChangeProcessor(); |
91 virtual ~TestChangeProcessor() { } | |
92 | 94 |
93 // Store a copy of all the changes passed in so we can examine them later. | 95 // Store a copy of all the changes passed in so we can examine them later. |
94 virtual SyncError ProcessSyncChanges( | 96 virtual SyncError ProcessSyncChanges( |
95 const tracked_objects::Location& from_here, | 97 const tracked_objects::Location& from_here, |
96 const SyncChangeList& change_list) { | 98 const SyncChangeList& change_list) OVERRIDE; |
97 if (erroneous_) | |
98 return SyncError(FROM_HERE, "Some error.", syncable::SEARCH_ENGINES); | |
99 | 99 |
100 change_map_.erase(change_map_.begin(), change_map_.end()); | 100 bool contains_guid(const std::string& guid) const { |
101 for (SyncChangeList::const_iterator iter = change_list.begin(); | 101 return change_map_.count(guid) != 0; |
102 iter != change_list.end(); ++iter) { | |
103 change_map_[GetGUID(iter->sync_data())] = *iter; | |
104 } | |
105 | |
106 return SyncError(); | |
107 } | 102 } |
108 | 103 |
109 bool ContainsGUID(const std::string& guid) { | 104 SyncChange change_for_guid(const std::string& guid) const { |
110 return change_map_.find(guid) != change_map_.end(); | 105 DCHECK(contains_guid(guid)); |
111 } | 106 return change_map_.find(guid)->second; |
112 | |
113 SyncChange GetChangeByGUID(const std::string& guid) { | |
114 DCHECK(ContainsGUID(guid)); | |
115 return change_map_[guid]; | |
116 } | 107 } |
117 | 108 |
118 int change_list_size() { return change_map_.size(); } | 109 int change_list_size() { return change_map_.size(); } |
119 | 110 |
120 void set_erroneous(bool erroneous) { erroneous_ = erroneous; } | 111 void set_erroneous(bool erroneous) { erroneous_ = erroneous; } |
121 | 112 |
122 private: | 113 private: |
123 // Track the changes received in ProcessSyncChanges. | 114 // Track the changes received in ProcessSyncChanges. |
124 std::map<std::string, SyncChange> change_map_; | 115 std::map<std::string, SyncChange> change_map_; |
125 bool erroneous_; | 116 bool erroneous_; |
126 | 117 |
127 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); | 118 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); |
128 }; | 119 }; |
129 | 120 |
| 121 TestChangeProcessor::TestChangeProcessor() : erroneous_(false) { |
| 122 } |
| 123 |
| 124 TestChangeProcessor::~TestChangeProcessor() { |
| 125 } |
| 126 |
| 127 SyncError TestChangeProcessor::ProcessSyncChanges( |
| 128 const tracked_objects::Location& from_here, |
| 129 const SyncChangeList& change_list) { |
| 130 if (erroneous_) |
| 131 return SyncError(FROM_HERE, "Some error.", syncable::SEARCH_ENGINES); |
| 132 |
| 133 change_map_.erase(change_map_.begin(), change_map_.end()); |
| 134 for (SyncChangeList::const_iterator iter = change_list.begin(); |
| 135 iter != change_list.end(); ++iter) |
| 136 change_map_[GetGUID(iter->sync_data())] = *iter; |
| 137 return SyncError(); |
| 138 } |
| 139 |
| 140 |
| 141 // SyncChangeProcessorDelegate ------------------------------------------------ |
| 142 |
130 class SyncChangeProcessorDelegate : public SyncChangeProcessor { | 143 class SyncChangeProcessorDelegate : public SyncChangeProcessor { |
131 public: | 144 public: |
132 explicit SyncChangeProcessorDelegate(SyncChangeProcessor* recipient) | 145 explicit SyncChangeProcessorDelegate(SyncChangeProcessor* recipient); |
133 : recipient_(recipient) { | 146 virtual ~SyncChangeProcessorDelegate(); |
134 DCHECK(recipient_); | |
135 } | |
136 virtual ~SyncChangeProcessorDelegate() {} | |
137 | 147 |
138 // SyncChangeProcessor implementation. | 148 // SyncChangeProcessor implementation. |
139 virtual SyncError ProcessSyncChanges( | 149 virtual SyncError ProcessSyncChanges( |
140 const tracked_objects::Location& from_here, | 150 const tracked_objects::Location& from_here, |
141 const SyncChangeList& change_list) OVERRIDE { | 151 const SyncChangeList& change_list) OVERRIDE; |
142 return recipient_->ProcessSyncChanges(from_here, change_list); | |
143 } | |
144 | 152 |
145 private: | 153 private: |
146 // The recipient of all sync changes. | 154 // The recipient of all sync changes. |
147 SyncChangeProcessor* recipient_; | 155 SyncChangeProcessor* recipient_; |
148 | 156 |
149 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); | 157 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); |
150 }; | 158 }; |
151 | 159 |
| 160 SyncChangeProcessorDelegate::SyncChangeProcessorDelegate( |
| 161 SyncChangeProcessor* recipient) |
| 162 : recipient_(recipient) { |
| 163 DCHECK(recipient_); |
| 164 } |
| 165 |
| 166 SyncChangeProcessorDelegate::~SyncChangeProcessorDelegate() { |
| 167 } |
| 168 |
| 169 SyncError SyncChangeProcessorDelegate::ProcessSyncChanges( |
| 170 const tracked_objects::Location& from_here, |
| 171 const SyncChangeList& change_list) { |
| 172 return recipient_->ProcessSyncChanges(from_here, change_list); |
| 173 } |
| 174 |
| 175 } // namespace |
| 176 |
| 177 |
| 178 // TemplateURLServiceSyncTest ------------------------------------------------- |
| 179 |
152 class TemplateURLServiceSyncTest : public testing::Test { | 180 class TemplateURLServiceSyncTest : public testing::Test { |
153 public: | 181 public: |
154 typedef TemplateURLService::SyncDataMap SyncDataMap; | 182 typedef TemplateURLService::SyncDataMap SyncDataMap; |
155 | 183 |
156 TemplateURLServiceSyncTest() | 184 TemplateURLServiceSyncTest(); |
157 : sync_processor_(new TestChangeProcessor), | |
158 sync_processor_delegate_(new SyncChangeProcessorDelegate( | |
159 sync_processor_.get())) {} | |
160 | 185 |
161 virtual void SetUp() { | 186 virtual void SetUp() OVERRIDE; |
162 profile_a_.reset(new TestingProfile); | |
163 TemplateURLServiceFactory::GetInstance()->RegisterUserPrefsOnProfile( | |
164 profile_a_.get()); | |
165 model_a_.reset(new TemplateURLService(profile_a_.get())); | |
166 model_a_->Load(); | |
167 profile_b_.reset(new TestingProfile); | |
168 TemplateURLServiceFactory::GetInstance()->RegisterUserPrefsOnProfile( | |
169 profile_b_.get()); | |
170 model_b_.reset(new TemplateURLService(profile_b_.get())); | |
171 model_b_->Load(); | |
172 } | |
173 | |
174 virtual void TearDown() { } | |
175 | 187 |
176 TemplateURLService* model() { return model_a_.get(); } | 188 TemplateURLService* model() { return model_a_.get(); } |
177 // For readability, we redefine an accessor for Model A for use in tests that | 189 // For readability, we redefine an accessor for Model A for use in tests that |
178 // involve syncing two models. | 190 // involve syncing two models. |
179 TemplateURLService* model_a() { return model_a_.get(); } | 191 TemplateURLService* model_a() { return model_a_.get(); } |
180 TemplateURLService* model_b() { return model_b_.get(); } | 192 TemplateURLService* model_b() { return model_b_.get(); } |
181 TestChangeProcessor* processor() { return sync_processor_.get(); } | 193 TestChangeProcessor* processor() { return sync_processor_.get(); } |
182 scoped_ptr<SyncChangeProcessor> PassProcessor() { | 194 scoped_ptr<SyncChangeProcessor> PassProcessor(); |
183 return sync_processor_delegate_.PassAs<SyncChangeProcessor>(); | |
184 } | |
185 | 195 |
186 // Create a TemplateURL with some test values. The caller owns the returned | 196 // Create a TemplateURL with some test values. The caller owns the returned |
187 // TemplateURL*. | 197 // TemplateURL*. |
188 TemplateURL* CreateTestTemplateURL(const string16& keyword, | 198 TemplateURL* CreateTestTemplateURL(const string16& keyword, |
189 const std::string& url) const { | |
190 return CreateTestTemplateURL(keyword, url, std::string()); | |
191 } | |
192 | |
193 TemplateURL* CreateTestTemplateURL(const string16& keyword, | |
194 const std::string& url, | 199 const std::string& url, |
195 const std::string& guid) const { | 200 const std::string& guid = std::string(), |
196 return CreateTestTemplateURL(keyword, url, guid, 100); | 201 time_t last_mod = 100, |
197 } | 202 bool created_by_policy = false) const; |
198 | |
199 TemplateURL* CreateTestTemplateURL(const string16& keyword, | |
200 const std::string& url, | |
201 const std::string& guid, | |
202 time_t last_mod) const { | |
203 return CreateTestTemplateURL(keyword, url, guid, last_mod, false); | |
204 } | |
205 | |
206 TemplateURL* CreateTestTemplateURL(const string16& keyword, | |
207 const std::string& url, | |
208 const std::string& guid, | |
209 time_t last_mod, | |
210 bool created_by_policy) const { | |
211 TemplateURL* turl = new TemplateURL(); | |
212 turl->set_short_name(ASCIIToUTF16("unittest")); | |
213 turl->set_keyword(keyword); | |
214 turl->set_safe_for_autoreplace(true); | |
215 turl->set_date_created(Time::FromTimeT(100)); | |
216 turl->set_last_modified(Time::FromTimeT(last_mod)); | |
217 turl->set_created_by_policy(created_by_policy); | |
218 turl->SetPrepopulateId(999999); | |
219 if (!guid.empty()) | |
220 turl->set_sync_guid(guid); | |
221 turl->SetURL(url); | |
222 turl->set_favicon_url(GURL("http://favicon.url")); | |
223 return turl; | |
224 } | |
225 | 203 |
226 // Verifies the two TemplateURLs are equal. | 204 // Verifies the two TemplateURLs are equal. |
227 // TODO(stevet): Share this with TemplateURLServiceTest. | 205 // TODO(stevet): Share this with TemplateURLServiceTest. |
228 void AssertEquals(const TemplateURL& expected, | 206 void AssertEquals(const TemplateURL& expected, |
229 const TemplateURL& actual) const { | 207 const TemplateURL& actual) const; |
230 ASSERT_TRUE(TemplateURLRef::SameUrlRefs(expected.url(), actual.url())); | |
231 ASSERT_TRUE(TemplateURLRef::SameUrlRefs(expected.suggestions_url(), | |
232 actual.suggestions_url())); | |
233 ASSERT_EQ(expected.keyword(), actual.keyword()); | |
234 ASSERT_EQ(expected.short_name(), actual.short_name()); | |
235 ASSERT_EQ(JoinString(expected.input_encodings(), ';'), | |
236 JoinString(actual.input_encodings(), ';')); | |
237 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); | |
238 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); | |
239 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); | |
240 ASSERT_TRUE(expected.date_created() == actual.date_created()); | |
241 ASSERT_TRUE(expected.last_modified() == actual.last_modified()); | |
242 } | |
243 | 208 |
244 // Expect that two SyncDataLists have equal contents, in terms of the | 209 // Expect that two SyncDataLists have equal contents, in terms of the |
245 // sync_guid, keyword, and url fields. | 210 // sync_guid, keyword, and url fields. |
246 void AssertEquals(const SyncDataList& data1, | 211 void AssertEquals(const SyncDataList& data1, |
247 const SyncDataList& data2) const { | 212 const SyncDataList& data2) const; |
248 SyncDataMap map1 = TemplateURLService::CreateGUIDToSyncDataMap(data1); | |
249 SyncDataMap map2 = TemplateURLService::CreateGUIDToSyncDataMap(data2); | |
250 | |
251 for (SyncDataMap::const_iterator iter1 = map1.begin(); | |
252 iter1 != map1.end(); iter1++) { | |
253 SyncDataMap::iterator iter2 = map2.find(iter1->first); | |
254 if (iter2 != map2.end()) { | |
255 ASSERT_EQ(GetKeyword(iter1->second), GetKeyword(iter2->second)); | |
256 ASSERT_EQ(GetURL(iter1->second), GetURL(iter2->second)); | |
257 map2.erase(iter2); | |
258 } | |
259 } | |
260 EXPECT_EQ(0U, map2.size()); | |
261 } | |
262 | 213 |
263 // Convenience helper for creating SyncChanges. Takes ownership of |turl|. | 214 // Convenience helper for creating SyncChanges. Takes ownership of |turl|. |
264 SyncChange CreateTestSyncChange(SyncChange::SyncChangeType type, | 215 SyncChange CreateTestSyncChange(SyncChange::SyncChangeType type, |
265 TemplateURL* turl) const { | 216 TemplateURL* turl) const; |
266 // We take control of the TemplateURL so make sure it's cleaned up after | |
267 // we create data out of it. | |
268 scoped_ptr<TemplateURL> scoped_turl(turl); | |
269 return SyncChange( | |
270 type, TemplateURLService::CreateSyncDataFromTemplateURL(*scoped_turl)); | |
271 } | |
272 | 217 |
273 // 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 |
274 // 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 |
275 // slightly older than CreateTestTemplateURL's default, to test conflict | 220 // slightly older than CreateTestTemplateURL's default, to test conflict |
276 // resolution. | 221 // resolution. |
277 SyncDataList CreateInitialSyncData() const { | 222 SyncDataList CreateInitialSyncData() const; |
278 SyncDataList list; | |
279 | |
280 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), | |
281 "http://key1.com", "key1", 90)); | |
282 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | |
283 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", | |
284 "key2", 90)); | |
285 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | |
286 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", | |
287 "key3", 90)); | |
288 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | |
289 | |
290 return list; | |
291 } | |
292 | 223 |
293 // Syntactic sugar. | 224 // Syntactic sugar. |
294 TemplateURL* Deserialize(const SyncData& sync_data) { | 225 TemplateURL* Deserialize(const SyncData& sync_data); |
295 return TemplateURLService::CreateTemplateURLFromSyncData(sync_data); | |
296 } | |
297 | 226 |
298 protected: | 227 protected: |
299 // We keep two TemplateURLServices to test syncing between them. | 228 // We keep two TemplateURLServices to test syncing between them. |
300 scoped_ptr<TestingProfile> profile_a_; | 229 scoped_ptr<TestingProfile> profile_a_; |
301 scoped_ptr<TemplateURLService> model_a_; | 230 scoped_ptr<TemplateURLService> model_a_; |
302 scoped_ptr<TestingProfile> profile_b_; | 231 scoped_ptr<TestingProfile> profile_b_; |
303 scoped_ptr<TemplateURLService> model_b_; | 232 scoped_ptr<TemplateURLService> model_b_; |
304 | 233 |
305 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. | 234 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. |
306 scoped_ptr<TestChangeProcessor> sync_processor_; | 235 scoped_ptr<TestChangeProcessor> sync_processor_; |
307 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; | 236 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; |
308 | 237 |
309 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest); | 238 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceSyncTest); |
310 }; | 239 }; |
311 | 240 |
312 } // namespace | 241 TemplateURLServiceSyncTest::TemplateURLServiceSyncTest() |
| 242 : sync_processor_(new TestChangeProcessor), |
| 243 sync_processor_delegate_(new SyncChangeProcessorDelegate( |
| 244 sync_processor_.get())) { |
| 245 } |
| 246 |
| 247 void TemplateURLServiceSyncTest::SetUp() { |
| 248 profile_a_.reset(new TestingProfile); |
| 249 TemplateURLServiceFactory::GetInstance()->RegisterUserPrefsOnProfile( |
| 250 profile_a_.get()); |
| 251 model_a_.reset(new TemplateURLService(profile_a_.get())); |
| 252 model_a_->Load(); |
| 253 profile_b_.reset(new TestingProfile); |
| 254 TemplateURLServiceFactory::GetInstance()->RegisterUserPrefsOnProfile( |
| 255 profile_b_.get()); |
| 256 model_b_.reset(new TemplateURLService(profile_b_.get())); |
| 257 model_b_->Load(); |
| 258 } |
| 259 |
| 260 scoped_ptr<SyncChangeProcessor> TemplateURLServiceSyncTest::PassProcessor() { |
| 261 return sync_processor_delegate_.PassAs<SyncChangeProcessor>(); |
| 262 } |
| 263 |
| 264 TemplateURL* TemplateURLServiceSyncTest::CreateTestTemplateURL( |
| 265 const string16& keyword, |
| 266 const std::string& url, |
| 267 const std::string& guid, |
| 268 time_t last_mod, |
| 269 bool created_by_policy) const { |
| 270 TemplateURL* turl = new TemplateURL(); |
| 271 turl->set_short_name(ASCIIToUTF16("unittest")); |
| 272 turl->set_keyword(keyword); |
| 273 turl->set_safe_for_autoreplace(true); |
| 274 turl->set_date_created(Time::FromTimeT(100)); |
| 275 turl->set_last_modified(Time::FromTimeT(last_mod)); |
| 276 turl->set_created_by_policy(created_by_policy); |
| 277 turl->SetPrepopulateId(999999); |
| 278 if (!guid.empty()) |
| 279 turl->set_sync_guid(guid); |
| 280 turl->SetURL(url); |
| 281 turl->set_favicon_url(GURL("http://favicon.url")); |
| 282 return turl; |
| 283 } |
| 284 |
| 285 void TemplateURLServiceSyncTest::AssertEquals(const TemplateURL& expected, |
| 286 const TemplateURL& actual) const { |
| 287 ASSERT_EQ(expected.short_name(), actual.short_name()); |
| 288 ASSERT_EQ(expected.url(), actual.url()); |
| 289 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); |
| 290 ASSERT_EQ(expected.keyword(), actual.keyword()); |
| 291 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); |
| 292 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); |
| 293 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); |
| 294 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); |
| 295 ASSERT_EQ(expected.date_created(), actual.date_created()); |
| 296 ASSERT_EQ(expected.last_modified(), actual.last_modified()); |
| 297 } |
| 298 |
| 299 void TemplateURLServiceSyncTest::AssertEquals(const SyncDataList& data1, |
| 300 const SyncDataList& data2) const { |
| 301 SyncDataMap map1 = TemplateURLService::CreateGUIDToSyncDataMap(data1); |
| 302 SyncDataMap map2 = TemplateURLService::CreateGUIDToSyncDataMap(data2); |
| 303 |
| 304 for (SyncDataMap::const_iterator iter1 = map1.begin(); |
| 305 iter1 != map1.end(); iter1++) { |
| 306 SyncDataMap::iterator iter2 = map2.find(iter1->first); |
| 307 if (iter2 != map2.end()) { |
| 308 ASSERT_EQ(GetKeyword(iter1->second), GetKeyword(iter2->second)); |
| 309 ASSERT_EQ(GetURL(iter1->second), GetURL(iter2->second)); |
| 310 map2.erase(iter2); |
| 311 } |
| 312 } |
| 313 EXPECT_EQ(0U, map2.size()); |
| 314 } |
| 315 |
| 316 SyncChange TemplateURLServiceSyncTest::CreateTestSyncChange( |
| 317 SyncChange::SyncChangeType type, |
| 318 TemplateURL* turl) const { |
| 319 // We take control of the TemplateURL so make sure it's cleaned up after |
| 320 // we create data out of it. |
| 321 scoped_ptr<TemplateURL> scoped_turl(turl); |
| 322 return SyncChange(type, |
| 323 TemplateURLService::CreateSyncDataFromTemplateURL(*scoped_turl)); |
| 324 } |
| 325 |
| 326 SyncDataList TemplateURLServiceSyncTest::CreateInitialSyncData() const { |
| 327 SyncDataList list; |
| 328 |
| 329 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
| 330 "http://key1.com", "key1", 90)); |
| 331 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 332 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com", |
| 333 "key2", 90)); |
| 334 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 335 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key3"), "http://key3.com", |
| 336 "key3", 90)); |
| 337 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
| 338 |
| 339 return list; |
| 340 } |
| 341 |
| 342 TemplateURL* TemplateURLServiceSyncTest::Deserialize( |
| 343 const SyncData& sync_data) { |
| 344 return TemplateURLService::CreateTemplateURLFromSyncData(sync_data); |
| 345 } |
| 346 |
| 347 |
| 348 // Actual tests --------------------------------------------------------------- |
313 | 349 |
314 TEST_F(TemplateURLServiceSyncTest, SerializeDeserialize) { | 350 TEST_F(TemplateURLServiceSyncTest, SerializeDeserialize) { |
315 // Create a TemplateURL and convert it into a sync specific type. | 351 // Create a TemplateURL and convert it into a sync specific type. |
316 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("unittest"), | 352 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("unittest"), |
317 "http://www.unittest.com/")); | 353 "http://www.unittest.com/")); |
318 SyncData sync_data = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 354 SyncData sync_data = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
319 // Convert the specifics back to a TemplateURL. | 355 // Convert the specifics back to a TemplateURL. |
320 scoped_ptr<TemplateURL> deserialized(Deserialize(sync_data)); | 356 scoped_ptr<TemplateURL> deserialized(Deserialize(sync_data)); |
321 EXPECT_TRUE(deserialized.get()); | 357 EXPECT_TRUE(deserialized.get()); |
322 // Ensure that the original and the deserialized TURLs are equal in values. | 358 // Ensure that the original and the deserialized TURLs are equal in values. |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 "http://key2.com")); | 543 "http://key2.com")); |
508 EXPECT_EQ(NULL, model()->FindDuplicateOfSyncTemplateURL(*sync_turl)); | 544 EXPECT_EQ(NULL, model()->FindDuplicateOfSyncTemplateURL(*sync_turl)); |
509 | 545 |
510 // Duplicate. | 546 // Duplicate. |
511 sync_turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), | 547 sync_turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), |
512 "http://key1.com")); | 548 "http://key1.com")); |
513 const TemplateURL* dupe_turl = | 549 const TemplateURL* dupe_turl = |
514 model()->FindDuplicateOfSyncTemplateURL(*sync_turl); | 550 model()->FindDuplicateOfSyncTemplateURL(*sync_turl); |
515 ASSERT_TRUE(dupe_turl); | 551 ASSERT_TRUE(dupe_turl); |
516 EXPECT_EQ(dupe_turl->keyword(), sync_turl->keyword()); | 552 EXPECT_EQ(dupe_turl->keyword(), sync_turl->keyword()); |
517 EXPECT_EQ(dupe_turl->url()->url(), sync_turl->url()->url()); | 553 EXPECT_EQ(dupe_turl->url(), sync_turl->url()); |
518 } | 554 } |
519 | 555 |
520 TEST_F(TemplateURLServiceSyncTest, MergeSyncAndLocalURLDuplicates) { | 556 TEST_F(TemplateURLServiceSyncTest, MergeSyncAndLocalURLDuplicates) { |
521 TemplateURL* original_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), | 557 TemplateURL* original_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
522 "http://key1.com", std::string(), 9000); | 558 "http://key1.com", std::string(), 9000); |
523 model()->Add(original_turl); | 559 model()->Add(original_turl); |
524 TemplateURL* sync_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), | 560 TemplateURL* sync_turl = CreateTestTemplateURL(ASCIIToUTF16("key1"), |
525 "http://key1.com", std::string(), 9001); | 561 "http://key1.com", std::string(), 9001); |
526 SyncChangeList changes; | 562 SyncChangeList changes; |
527 | 563 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 iter != initial_data.end(); ++iter) { | 626 iter != initial_data.end(); ++iter) { |
591 std::string guid = GetGUID(*iter); | 627 std::string guid = GetGUID(*iter); |
592 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); | 628 EXPECT_TRUE(model()->GetTemplateURLForGUID(guid)); |
593 } | 629 } |
594 // All the original TemplateURLs should also remain in the model. | 630 // All the original TemplateURLs should also remain in the model. |
595 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.com"))); | 631 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.com"))); |
596 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("yahoo.com"))); | 632 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("yahoo.com"))); |
597 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); | 633 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); |
598 // Ensure that Sync received the expected changes. | 634 // Ensure that Sync received the expected changes. |
599 EXPECT_EQ(3, processor()->change_list_size()); | 635 EXPECT_EQ(3, processor()->change_list_size()); |
600 EXPECT_TRUE(processor()->ContainsGUID("abc")); | 636 EXPECT_TRUE(processor()->contains_guid("abc")); |
601 EXPECT_TRUE(processor()->ContainsGUID("def")); | 637 EXPECT_TRUE(processor()->contains_guid("def")); |
602 EXPECT_TRUE(processor()->ContainsGUID("xyz")); | 638 EXPECT_TRUE(processor()->contains_guid("xyz")); |
603 } | 639 } |
604 | 640 |
605 TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) { | 641 TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) { |
606 // The local data is the same as the sync data merged in. i.e. - There have | 642 // The local data is the same as the sync data merged in. i.e. - There have |
607 // been no changes since the last time we synced. Even the last_modified | 643 // been no changes since the last time we synced. Even the last_modified |
608 // timestamps are the same. | 644 // timestamps are the same. |
609 SyncDataList initial_data = CreateInitialSyncData(); | 645 SyncDataList initial_data = CreateInitialSyncData(); |
610 for (SyncDataList::const_iterator iter = initial_data.begin(); | 646 for (SyncDataList::const_iterator iter = initial_data.begin(); |
611 iter != initial_data.end(); ++iter) { | 647 iter != initial_data.end(); ++iter) { |
612 TemplateURL* converted = Deserialize(*iter); | 648 TemplateURL* converted = Deserialize(*iter); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 TemplateURLService::CreateSyncDataFromTemplateURL(*turl2_older)); | 683 TemplateURLService::CreateSyncDataFromTemplateURL(*turl2_older)); |
648 | 684 |
649 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, | 685 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, |
650 PassProcessor()); | 686 PassProcessor()); |
651 | 687 |
652 // Both were local updates, so we expect the same count. | 688 // Both were local updates, so we expect the same count. |
653 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 689 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
654 | 690 |
655 // Check that the first replaced the initial Google TemplateURL. | 691 // Check that the first replaced the initial Google TemplateURL. |
656 EXPECT_EQ(turl1, model()->GetTemplateURLForGUID("abc")); | 692 EXPECT_EQ(turl1, model()->GetTemplateURLForGUID("abc")); |
657 EXPECT_EQ("http://google.ca", turl1->url()->url()); | 693 EXPECT_EQ("http://google.ca", turl1->url()); |
658 | 694 |
659 // Check that the second produced an upstream update to the Bing TemplateURL. | 695 // Check that the second produced an upstream update to the Bing TemplateURL. |
660 EXPECT_EQ(1, processor()->change_list_size()); | 696 EXPECT_EQ(1, processor()->change_list_size()); |
661 ASSERT_TRUE(processor()->ContainsGUID("xyz")); | 697 ASSERT_TRUE(processor()->contains_guid("xyz")); |
662 SyncChange change = processor()->GetChangeByGUID("xyz"); | 698 SyncChange change = processor()->change_for_guid("xyz"); |
663 EXPECT_TRUE(change.change_type() == SyncChange::ACTION_UPDATE); | 699 EXPECT_TRUE(change.change_type() == SyncChange::ACTION_UPDATE); |
664 EXPECT_EQ("http://bing.com", GetURL(change.sync_data())); | 700 EXPECT_EQ("http://bing.com", GetURL(change.sync_data())); |
665 } | 701 } |
666 | 702 |
667 TEST_F(TemplateURLServiceSyncTest, MergeAddFromOlderSyncData) { | 703 TEST_F(TemplateURLServiceSyncTest, MergeAddFromOlderSyncData) { |
668 // GUIDs all differ, so this is data to be added from Sync, but the timestamps | 704 // GUIDs all differ, so this is data to be added from Sync, but the timestamps |
669 // from Sync are older. Set up the local data so that one is a dupe, one has a | 705 // from Sync are older. Set up the local data so that one is a dupe, one has a |
670 // conflicting keyword, and the last has no conflicts (a clean ADD). | 706 // conflicting keyword, and the last has no conflicts (a clean ADD). |
671 SyncDataList initial_data = CreateInitialSyncData(); | 707 SyncDataList initial_data = CreateInitialSyncData(); |
672 | 708 |
(...skipping 10 matching lines...) Expand all Loading... |
683 PassProcessor()); | 719 PassProcessor()); |
684 | 720 |
685 // The dupe results in a merge. The other two should be added to the model. | 721 // The dupe results in a merge. The other two should be added to the model. |
686 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 722 EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
687 | 723 |
688 // The key1 duplicate results in the local copy winning. Ensure that Sync's | 724 // The key1 duplicate results in the local copy winning. Ensure that Sync's |
689 // copy was not added, and the local copy is pushed upstream to Sync as an | 725 // copy was not added, and the local copy is pushed upstream to Sync as an |
690 // update. The local copy should have received the sync data's GUID. | 726 // update. The local copy should have received the sync data's GUID. |
691 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 727 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
692 // Check changes for the UPDATE. | 728 // Check changes for the UPDATE. |
693 ASSERT_TRUE(processor()->ContainsGUID("key1")); | 729 ASSERT_TRUE(processor()->contains_guid("key1")); |
694 SyncChange key1_change = processor()->GetChangeByGUID("key1"); | 730 SyncChange key1_change = processor()->change_for_guid("key1"); |
695 EXPECT_EQ(SyncChange::ACTION_UPDATE, key1_change.change_type()); | 731 EXPECT_EQ(SyncChange::ACTION_UPDATE, key1_change.change_type()); |
696 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); | 732 EXPECT_FALSE(model()->GetTemplateURLForGUID("aaa")); |
697 | 733 |
698 // The key2 keyword conflict results in the local copy winning, so ensure it | 734 // The key2 keyword conflict results in the local copy winning, so ensure it |
699 // retains the original keyword, and that an update to the sync copy is pushed | 735 // retains the original keyword, and that an update to the sync copy is pushed |
700 // upstream to Sync. Both TemplateURLs should be found locally, however. | 736 // upstream to Sync. Both TemplateURLs should be found locally, however. |
701 const TemplateURL* key2 = model()->GetTemplateURLForGUID("bbb"); | 737 const TemplateURL* key2 = model()->GetTemplateURLForGUID("bbb"); |
702 EXPECT_TRUE(key2); | 738 EXPECT_TRUE(key2); |
703 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword()); | 739 EXPECT_EQ(ASCIIToUTF16("key2"), key2->keyword()); |
704 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 740 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
705 // Check changes for the UPDATE. | 741 // Check changes for the UPDATE. |
706 ASSERT_TRUE(processor()->ContainsGUID("key2")); | 742 ASSERT_TRUE(processor()->contains_guid("key2")); |
707 SyncChange key2_change = processor()->GetChangeByGUID("key2"); | 743 SyncChange key2_change = processor()->change_for_guid("key2"); |
708 EXPECT_EQ(SyncChange::ACTION_UPDATE, key2_change.change_type()); | 744 EXPECT_EQ(SyncChange::ACTION_UPDATE, key2_change.change_type()); |
709 EXPECT_EQ("key2.com", GetKeyword(key2_change.sync_data())); | 745 EXPECT_EQ("key2.com", GetKeyword(key2_change.sync_data())); |
710 | 746 |
711 // The last TemplateURL should have had no conflicts and was just added. It | 747 // The last TemplateURL should have had no conflicts and was just added. It |
712 // should not have replaced the third local TemplateURL. | 748 // should not have replaced the third local TemplateURL. |
713 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); | 749 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); |
714 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 750 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
715 | 751 |
716 // Two UPDATEs and two ADDs. | 752 // Two UPDATEs and two ADDs. |
717 EXPECT_EQ(4, processor()->change_list_size()); | 753 EXPECT_EQ(4, processor()->change_list_size()); |
718 // Two ADDs should be pushed up to Sync. | 754 // Two ADDs should be pushed up to Sync. |
719 ASSERT_TRUE(processor()->ContainsGUID("bbb")); | 755 ASSERT_TRUE(processor()->contains_guid("bbb")); |
720 EXPECT_EQ(SyncChange::ACTION_ADD, | 756 EXPECT_EQ(SyncChange::ACTION_ADD, |
721 processor()->GetChangeByGUID("bbb").change_type()); | 757 processor()->change_for_guid("bbb").change_type()); |
722 ASSERT_TRUE(processor()->ContainsGUID("ccc")); | 758 ASSERT_TRUE(processor()->contains_guid("ccc")); |
723 EXPECT_EQ(SyncChange::ACTION_ADD, | 759 EXPECT_EQ(SyncChange::ACTION_ADD, |
724 processor()->GetChangeByGUID("ccc").change_type()); | 760 processor()->change_for_guid("ccc").change_type()); |
725 } | 761 } |
726 | 762 |
727 TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) { | 763 TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) { |
728 // GUIDs all differ, so this is data to be added from Sync, but the timestamps | 764 // GUIDs all differ, so this is data to be added from Sync, but the timestamps |
729 // from Sync are newer. Set up the local data so that one is a dupe, one has a | 765 // from Sync are newer. Set up the local data so that one is a dupe, one has a |
730 // conflicting keyword, and the last has no conflicts (a clean ADD). | 766 // conflicting keyword, and the last has no conflicts (a clean ADD). |
731 SyncDataList initial_data = CreateInitialSyncData(); | 767 SyncDataList initial_data = CreateInitialSyncData(); |
732 | 768 |
733 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", | 769 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", |
734 "aaa", 10)); // dupe | 770 "aaa", 10)); // dupe |
(...skipping 26 matching lines...) Expand all Loading... |
761 EXPECT_EQ(ASCIIToUTF16("expected.com"), key2_local->keyword()); | 797 EXPECT_EQ(ASCIIToUTF16("expected.com"), key2_local->keyword()); |
762 | 798 |
763 // The last TemplateURL should have had no conflicts and was just added. It | 799 // The last TemplateURL should have had no conflicts and was just added. It |
764 // should not have replaced the third local TemplateURL. | 800 // should not have replaced the third local TemplateURL. |
765 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); | 801 EXPECT_TRUE(model()->GetTemplateURLForGUID("ccc")); |
766 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 802 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
767 | 803 |
768 // Two ADDs. | 804 // Two ADDs. |
769 EXPECT_EQ(2, processor()->change_list_size()); | 805 EXPECT_EQ(2, processor()->change_list_size()); |
770 // Two ADDs should be pushed up to Sync. | 806 // Two ADDs should be pushed up to Sync. |
771 ASSERT_TRUE(processor()->ContainsGUID("bbb")); | 807 ASSERT_TRUE(processor()->contains_guid("bbb")); |
772 EXPECT_EQ(SyncChange::ACTION_ADD, | 808 EXPECT_EQ(SyncChange::ACTION_ADD, |
773 processor()->GetChangeByGUID("bbb").change_type()); | 809 processor()->change_for_guid("bbb").change_type()); |
774 ASSERT_TRUE(processor()->ContainsGUID("ccc")); | 810 ASSERT_TRUE(processor()->contains_guid("ccc")); |
775 EXPECT_EQ(SyncChange::ACTION_ADD, | 811 EXPECT_EQ(SyncChange::ACTION_ADD, |
776 processor()->GetChangeByGUID("ccc").change_type()); | 812 processor()->change_for_guid("ccc").change_type()); |
777 } | 813 } |
778 | 814 |
779 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { | 815 TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { |
780 // We initially have no data. | 816 // We initially have no data. |
781 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, SyncDataList(), | 817 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, SyncDataList(), |
782 PassProcessor()); | 818 PassProcessor()); |
783 | 819 |
784 // Set up a bunch of ADDs. | 820 // Set up a bunch of ADDs. |
785 SyncChangeList changes; | 821 SyncChangeList changes; |
786 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD, | 822 changes.push_back(CreateTestSyncChange(SyncChange::ACTION_ADD, |
(...skipping 29 matching lines...) Expand all Loading... |
816 model()->ProcessSyncChanges(FROM_HERE, changes); | 852 model()->ProcessSyncChanges(FROM_HERE, changes); |
817 | 853 |
818 // Add one, remove one, update one, so the number shouldn't change. | 854 // Add one, remove one, update one, so the number shouldn't change. |
819 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 855 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
820 EXPECT_EQ(0, processor()->change_list_size()); | 856 EXPECT_EQ(0, processor()->change_list_size()); |
821 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 857 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
822 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); | 858 EXPECT_TRUE(model()->GetTemplateURLForGUID("key2")); |
823 const TemplateURL* turl = model()->GetTemplateURLForGUID("key2"); | 859 const TemplateURL* turl = model()->GetTemplateURLForGUID("key2"); |
824 EXPECT_TRUE(turl); | 860 EXPECT_TRUE(turl); |
825 EXPECT_EQ(ASCIIToUTF16("newkeyword"), turl->keyword()); | 861 EXPECT_EQ(ASCIIToUTF16("newkeyword"), turl->keyword()); |
826 EXPECT_EQ("http://new.com", turl->url()->url()); | 862 EXPECT_EQ("http://new.com", turl->url()); |
827 EXPECT_FALSE(model()->GetTemplateURLForGUID("key3")); | 863 EXPECT_FALSE(model()->GetTemplateURLForGUID("key3")); |
828 EXPECT_TRUE(model()->GetTemplateURLForGUID("key4")); | 864 EXPECT_TRUE(model()->GetTemplateURLForGUID("key4")); |
829 } | 865 } |
830 | 866 |
831 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsSyncWins) { | 867 TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsSyncWins) { |
832 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 868 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
833 CreateInitialSyncData(), PassProcessor()); | 869 CreateInitialSyncData(), PassProcessor()); |
834 | 870 |
835 // Process different types of changes, with conflicts. Note that all this data | 871 // Process different types of changes, with conflicts. Note that all this data |
836 // has a newer timestamp, so Sync will win in these scenarios. | 872 // has a newer timestamp, so Sync will win in these scenarios. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2"))); | 930 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key2"))); |
895 // key1 update conflicts with key3 and loses, forcing key1's keyword to | 931 // key1 update conflicts with key3 and loses, forcing key1's keyword to |
896 // update. | 932 // update. |
897 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); | 933 EXPECT_TRUE(model()->GetTemplateURLForGUID("key1")); |
898 EXPECT_EQ(model()->GetTemplateURLForGUID("key1"), | 934 EXPECT_EQ(model()->GetTemplateURLForGUID("key1"), |
899 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3.com"))); | 935 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3.com"))); |
900 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); | 936 EXPECT_TRUE(model()->GetTemplateURLForGUID("key3")); |
901 EXPECT_EQ(model()->GetTemplateURLForGUID("key3"), | 937 EXPECT_EQ(model()->GetTemplateURLForGUID("key3"), |
902 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); | 938 model()->GetTemplateURLForKeyword(ASCIIToUTF16("key3"))); |
903 | 939 |
904 ASSERT_TRUE(processor()->ContainsGUID("aaa")); | 940 ASSERT_TRUE(processor()->contains_guid("aaa")); |
905 EXPECT_EQ(SyncChange::ACTION_UPDATE, | 941 EXPECT_EQ(SyncChange::ACTION_UPDATE, |
906 processor()->GetChangeByGUID("aaa").change_type()); | 942 processor()->change_for_guid("aaa").change_type()); |
907 ASSERT_TRUE(processor()->ContainsGUID("key1")); | 943 ASSERT_TRUE(processor()->contains_guid("key1")); |
908 EXPECT_EQ(SyncChange::ACTION_UPDATE, | 944 EXPECT_EQ(SyncChange::ACTION_UPDATE, |
909 processor()->GetChangeByGUID("key1").change_type()); | 945 processor()->change_for_guid("key1").change_type()); |
910 } | 946 } |
911 | 947 |
912 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { | 948 TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { |
913 // Ensure that ProcessTemplateURLChange is called and pushes the correct | 949 // Ensure that ProcessTemplateURLChange is called and pushes the correct |
914 // changes to Sync whenever local changes are made to TemplateURLs. | 950 // changes to Sync whenever local changes are made to TemplateURLs. |
915 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 951 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
916 CreateInitialSyncData(), PassProcessor()); | 952 CreateInitialSyncData(), PassProcessor()); |
917 | 953 |
918 // Add a new search engine. | 954 // Add a new search engine. |
919 TemplateURL* new_turl = | 955 TemplateURL* new_turl = |
920 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); | 956 CreateTestTemplateURL(ASCIIToUTF16("baidu"), "http://baidu.cn", "new"); |
921 model()->Add(new_turl); | 957 model()->Add(new_turl); |
922 EXPECT_EQ(1, processor()->change_list_size()); | 958 EXPECT_EQ(1, processor()->change_list_size()); |
923 ASSERT_TRUE(processor()->ContainsGUID("new")); | 959 ASSERT_TRUE(processor()->contains_guid("new")); |
924 SyncChange change = processor()->GetChangeByGUID("new"); | 960 SyncChange change = processor()->change_for_guid("new"); |
925 EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type()); | 961 EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type()); |
926 EXPECT_EQ("baidu", GetKeyword(change.sync_data())); | 962 EXPECT_EQ("baidu", GetKeyword(change.sync_data())); |
927 EXPECT_EQ("http://baidu.cn", GetURL(change.sync_data())); | 963 EXPECT_EQ("http://baidu.cn", GetURL(change.sync_data())); |
928 | 964 |
929 // Change a keyword. | 965 // Change a keyword. |
930 const TemplateURL* existing_turl = model()->GetTemplateURLForGUID("key1"); | 966 const TemplateURL* existing_turl = model()->GetTemplateURLForGUID("key1"); |
931 model()->ResetTemplateURL(existing_turl, existing_turl->short_name(), | 967 model()->ResetTemplateURL(existing_turl, existing_turl->short_name(), |
932 ASCIIToUTF16("k"), existing_turl->url()->url()); | 968 ASCIIToUTF16("k"), existing_turl->url()); |
933 EXPECT_EQ(1, processor()->change_list_size()); | 969 EXPECT_EQ(1, processor()->change_list_size()); |
934 ASSERT_TRUE(processor()->ContainsGUID("key1")); | 970 ASSERT_TRUE(processor()->contains_guid("key1")); |
935 change = processor()->GetChangeByGUID("key1"); | 971 change = processor()->change_for_guid("key1"); |
936 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); | 972 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); |
937 EXPECT_EQ("k", GetKeyword(change.sync_data())); | 973 EXPECT_EQ("k", GetKeyword(change.sync_data())); |
938 | 974 |
939 // Remove an existing search engine. | 975 // Remove an existing search engine. |
940 existing_turl = model()->GetTemplateURLForGUID("key2"); | 976 existing_turl = model()->GetTemplateURLForGUID("key2"); |
941 model()->Remove(existing_turl); | 977 model()->Remove(existing_turl); |
942 EXPECT_EQ(1, processor()->change_list_size()); | 978 EXPECT_EQ(1, processor()->change_list_size()); |
943 ASSERT_TRUE(processor()->ContainsGUID("key2")); | 979 ASSERT_TRUE(processor()->contains_guid("key2")); |
944 change = processor()->GetChangeByGUID("key2"); | 980 change = processor()->change_for_guid("key2"); |
945 EXPECT_EQ(SyncChange::ACTION_DELETE, change.change_type()); | 981 EXPECT_EQ(SyncChange::ACTION_DELETE, change.change_type()); |
946 } | 982 } |
947 | 983 |
948 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { | 984 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { |
949 // Start off B with some empty data. | 985 // Start off B with some empty data. |
950 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 986 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
951 CreateInitialSyncData(), PassProcessor()); | 987 CreateInitialSyncData(), PassProcessor()); |
952 | 988 |
953 // Merge A and B. All of B's data should transfer over to A, which initially | 989 // Merge A and B. All of B's data should transfer over to A, which initially |
954 // has no data. | 990 // has no data. |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 | 1284 |
1249 // The key1 entry should be a duplicate of the default. | 1285 // The key1 entry should be a duplicate of the default. |
1250 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1286 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
1251 CreateInitialSyncData(), PassProcessor()); | 1287 CreateInitialSyncData(), PassProcessor()); |
1252 | 1288 |
1253 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); | 1289 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); |
1254 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); | 1290 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); |
1255 EXPECT_EQ(model()->GetDefaultSearchProvider(), | 1291 EXPECT_EQ(model()->GetDefaultSearchProvider(), |
1256 model()->GetTemplateURLForGUID("key1")); | 1292 model()->GetTemplateURLForGUID("key1")); |
1257 } | 1293 } |
OLD | NEW |