Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: chrome/browser/search_engines/template_url_service_sync_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698