OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 data.SetKeyword(keyword); | 262 data.SetKeyword(keyword); |
263 data.SetURL(url); | 263 data.SetURL(url); |
264 data.favicon_url = GURL("http://favicon.url"); | 264 data.favicon_url = GURL("http://favicon.url"); |
265 data.safe_for_autoreplace = true; | 265 data.safe_for_autoreplace = true; |
266 data.date_created = Time::FromTimeT(100); | 266 data.date_created = Time::FromTimeT(100); |
267 data.last_modified = Time::FromTimeT(last_mod); | 267 data.last_modified = Time::FromTimeT(last_mod); |
268 data.created_by_policy = created_by_policy; | 268 data.created_by_policy = created_by_policy; |
269 data.prepopulate_id = 999999; | 269 data.prepopulate_id = 999999; |
270 if (!guid.empty()) | 270 if (!guid.empty()) |
271 data.sync_guid = guid; | 271 data.sync_guid = guid; |
272 return new TemplateURL(data); | 272 return new TemplateURL(NULL, data); |
273 } | 273 } |
274 | 274 |
275 void TemplateURLServiceSyncTest::AssertEquals(const TemplateURL& expected, | 275 void TemplateURLServiceSyncTest::AssertEquals(const TemplateURL& expected, |
276 const TemplateURL& actual) const { | 276 const TemplateURL& actual) const { |
277 ASSERT_EQ(expected.short_name(), actual.short_name()); | 277 ASSERT_EQ(expected.short_name(), actual.short_name()); |
278 ASSERT_EQ(expected.keyword(), actual.keyword()); | 278 ASSERT_EQ(expected.keyword(), actual.keyword()); |
279 ASSERT_EQ(expected.url(), actual.url()); | 279 ASSERT_EQ(expected.url(), actual.url()); |
280 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); | 280 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); |
281 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); | 281 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); |
282 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); | 282 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 "key3", 90)); | 326 "key3", 90)); |
327 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); | 327 list.push_back(TemplateURLService::CreateSyncDataFromTemplateURL(*turl)); |
328 | 328 |
329 return list; | 329 return list; |
330 } | 330 } |
331 | 331 |
332 TemplateURL* TemplateURLServiceSyncTest::Deserialize( | 332 TemplateURL* TemplateURLServiceSyncTest::Deserialize( |
333 const SyncData& sync_data) { | 333 const SyncData& sync_data) { |
334 SyncChangeList dummy; | 334 SyncChangeList dummy; |
335 return TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(NULL, | 335 return TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(NULL, |
336 sync_data, &dummy); | 336 NULL, sync_data, &dummy); |
337 } | 337 } |
338 | 338 |
339 | 339 |
340 // Actual tests --------------------------------------------------------------- | 340 // Actual tests --------------------------------------------------------------- |
341 | 341 |
342 TEST_F(TemplateURLServiceSyncTest, SerializeDeserialize) { | 342 TEST_F(TemplateURLServiceSyncTest, SerializeDeserialize) { |
343 // Create a TemplateURL and convert it into a sync specific type. | 343 // Create a TemplateURL and convert it into a sync specific type. |
344 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("unittest"), | 344 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("unittest"), |
345 "http://www.unittest.com/")); | 345 "http://www.unittest.com/")); |
346 SyncData sync_data = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); | 346 SyncData sync_data = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 "key1", 10)); // earlier | 1079 "key1", 10)); // earlier |
1080 | 1080 |
1081 SyncError error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1081 SyncError error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
1082 initial_data, PassProcessor()); | 1082 initial_data, PassProcessor()); |
1083 ASSERT_FALSE(error.IsSet()); | 1083 ASSERT_FALSE(error.IsSet()); |
1084 | 1084 |
1085 // We should have updated the original TemplateURL with Sync's version. | 1085 // We should have updated the original TemplateURL with Sync's version. |
1086 // Keep a copy of it so we can compare it after we re-merge. | 1086 // Keep a copy of it so we can compare it after we re-merge. |
1087 const TemplateURL* key1_url = model()->GetTemplateURLForGUID("key1"); | 1087 const TemplateURL* key1_url = model()->GetTemplateURLForGUID("key1"); |
1088 ASSERT_TRUE(key1_url); | 1088 ASSERT_TRUE(key1_url); |
1089 scoped_ptr<TemplateURL> updated_turl(new TemplateURL(key1_url->data())); | 1089 scoped_ptr<TemplateURL> updated_turl(new TemplateURL( |
| 1090 const_cast<TemplateURL*>(key1_url)->profile(), key1_url->data())); |
1090 EXPECT_EQ(Time::FromTimeT(90), updated_turl->last_modified()); | 1091 EXPECT_EQ(Time::FromTimeT(90), updated_turl->last_modified()); |
1091 | 1092 |
1092 // Modify a single field of the initial data. This should not be updated in | 1093 // Modify a single field of the initial data. This should not be updated in |
1093 // the second merge, as the last_modified timestamp remains the same. | 1094 // the second merge, as the last_modified timestamp remains the same. |
1094 scoped_ptr<TemplateURL> temp_turl(Deserialize(initial_data[0])); | 1095 scoped_ptr<TemplateURL> temp_turl(Deserialize(initial_data[0])); |
1095 TemplateURLData data(temp_turl->data()); | 1096 TemplateURLData data(temp_turl->data()); |
1096 data.short_name = ASCIIToUTF16("SomethingDifferent"); | 1097 data.short_name = ASCIIToUTF16("SomethingDifferent"); |
1097 temp_turl.reset(new TemplateURL(data)); | 1098 temp_turl.reset(new TemplateURL(temp_turl->profile(), data)); |
1098 initial_data.clear(); | 1099 initial_data.clear(); |
1099 initial_data.push_back( | 1100 initial_data.push_back( |
1100 TemplateURLService::CreateSyncDataFromTemplateURL(*temp_turl)); | 1101 TemplateURLService::CreateSyncDataFromTemplateURL(*temp_turl)); |
1101 | 1102 |
1102 // Remerge the data again. This simulates shutting down and syncing again | 1103 // Remerge the data again. This simulates shutting down and syncing again |
1103 // at a different time, but the cloud data has not changed. | 1104 // at a different time, but the cloud data has not changed. |
1104 model()->StopSyncing(syncable::SEARCH_ENGINES); | 1105 model()->StopSyncing(syncable::SEARCH_ENGINES); |
1105 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( | 1106 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( |
1106 sync_processor_.get())); | 1107 sync_processor_.get())); |
1107 error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, | 1108 error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 // deletion. | 1298 // deletion. |
1298 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 1299 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
1299 EXPECT_EQ(2U, processor()->change_list_size()); | 1300 EXPECT_EQ(2U, processor()->change_list_size()); |
1300 ASSERT_TRUE(processor()->contains_guid("key1")); | 1301 ASSERT_TRUE(processor()->contains_guid("key1")); |
1301 EXPECT_EQ(SyncChange::ACTION_DELETE, | 1302 EXPECT_EQ(SyncChange::ACTION_DELETE, |
1302 processor()->change_for_guid("key1").change_type()); | 1303 processor()->change_for_guid("key1").change_type()); |
1303 ASSERT_TRUE(processor()->contains_guid(std::string())); | 1304 ASSERT_TRUE(processor()->contains_guid(std::string())); |
1304 EXPECT_EQ(SyncChange::ACTION_DELETE, | 1305 EXPECT_EQ(SyncChange::ACTION_DELETE, |
1305 processor()->change_for_guid(std::string()).change_type()); | 1306 processor()->change_for_guid(std::string()).change_type()); |
1306 } | 1307 } |
OLD | NEW |