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

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

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

Powered by Google App Engine
This is Rietveld 408576698