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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 se_specifics->set_short_name(base::UTF16ToUTF8(turl.short_name())); | 70 se_specifics->set_short_name(base::UTF16ToUTF8(turl.short_name())); |
71 se_specifics->set_keyword( | 71 se_specifics->set_keyword( |
72 autogenerate_keyword ? std::string() : base::UTF16ToUTF8(turl.keyword())); | 72 autogenerate_keyword ? std::string() : base::UTF16ToUTF8(turl.keyword())); |
73 se_specifics->set_favicon_url(turl.favicon_url().spec()); | 73 se_specifics->set_favicon_url(turl.favicon_url().spec()); |
74 se_specifics->set_url(url); | 74 se_specifics->set_url(url); |
75 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); | 75 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); |
76 se_specifics->set_originating_url(turl.originating_url().spec()); | 76 se_specifics->set_originating_url(turl.originating_url().spec()); |
77 se_specifics->set_date_created(turl.date_created().ToInternalValue()); | 77 se_specifics->set_date_created(turl.date_created().ToInternalValue()); |
78 se_specifics->set_input_encodings( | 78 se_specifics->set_input_encodings( |
79 base::JoinString(turl.input_encodings(), ";")); | 79 base::JoinString(turl.input_encodings(), ";")); |
80 se_specifics->set_show_in_default_list(turl.show_in_default_list()); | |
81 se_specifics->set_suggestions_url(turl.suggestions_url()); | 80 se_specifics->set_suggestions_url(turl.suggestions_url()); |
82 se_specifics->set_prepopulate_id(prepopulate_id == -1 ? turl.prepopulate_id() | 81 se_specifics->set_prepopulate_id(prepopulate_id == -1 ? turl.prepopulate_id() |
83 : prepopulate_id); | 82 : prepopulate_id); |
84 se_specifics->set_autogenerate_keyword(autogenerate_keyword); | 83 se_specifics->set_autogenerate_keyword(autogenerate_keyword); |
85 se_specifics->set_instant_url(turl.instant_url()); | 84 se_specifics->set_instant_url(turl.instant_url()); |
86 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); | 85 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); |
87 se_specifics->set_sync_guid(sync_guid); | 86 se_specifics->set_sync_guid(sync_guid); |
88 return syncer::SyncData::CreateLocalData(turl.sync_guid(), // Must be valid! | 87 return syncer::SyncData::CreateLocalData(turl.sync_guid(), // Must be valid! |
89 se_specifics->keyword(), specifics); | 88 se_specifics->keyword(), specifics); |
90 } | 89 } |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 return base::MakeUnique<TemplateURL>(data); | 302 return base::MakeUnique<TemplateURL>(data); |
304 } | 303 } |
305 | 304 |
306 void TemplateURLServiceSyncTest::AssertEquals(const TemplateURL& expected, | 305 void TemplateURLServiceSyncTest::AssertEquals(const TemplateURL& expected, |
307 const TemplateURL& actual) const { | 306 const TemplateURL& actual) const { |
308 ASSERT_EQ(expected.short_name(), actual.short_name()); | 307 ASSERT_EQ(expected.short_name(), actual.short_name()); |
309 ASSERT_EQ(expected.keyword(), actual.keyword()); | 308 ASSERT_EQ(expected.keyword(), actual.keyword()); |
310 ASSERT_EQ(expected.url(), actual.url()); | 309 ASSERT_EQ(expected.url(), actual.url()); |
311 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); | 310 ASSERT_EQ(expected.suggestions_url(), actual.suggestions_url()); |
312 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); | 311 ASSERT_EQ(expected.favicon_url(), actual.favicon_url()); |
313 ASSERT_EQ(expected.show_in_default_list(), actual.show_in_default_list()); | |
314 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); | 312 ASSERT_EQ(expected.safe_for_autoreplace(), actual.safe_for_autoreplace()); |
315 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); | 313 ASSERT_EQ(expected.input_encodings(), actual.input_encodings()); |
316 ASSERT_EQ(expected.date_created(), actual.date_created()); | 314 ASSERT_EQ(expected.date_created(), actual.date_created()); |
317 ASSERT_EQ(expected.last_modified(), actual.last_modified()); | 315 ASSERT_EQ(expected.last_modified(), actual.last_modified()); |
318 } | 316 } |
319 | 317 |
320 void TemplateURLServiceSyncTest::AssertEquals( | 318 void TemplateURLServiceSyncTest::AssertEquals( |
321 const syncer::SyncDataList& data1, | 319 const syncer::SyncDataList& data1, |
322 const syncer::SyncDataList& data2) const { | 320 const syncer::SyncDataList& data2) const { |
323 SyncDataMap map1 = TemplateURLService::CreateGUIDToSyncDataMap(data1); | 321 SyncDataMap map1 = TemplateURLService::CreateGUIDToSyncDataMap(data1); |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 | 1084 |
1087 model()->RegisterOmniboxKeyword("extension2", "unittest", "keyword2", | 1085 model()->RegisterOmniboxKeyword("extension2", "unittest", "keyword2", |
1088 "http://extension2"); | 1086 "http://extension2"); |
1089 TemplateURL* extension2 = | 1087 TemplateURL* extension2 = |
1090 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2")); | 1088 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2")); |
1091 ASSERT_TRUE(extension2); | 1089 ASSERT_TRUE(extension2); |
1092 EXPECT_EQ(0U, processor()->change_list_size()); | 1090 EXPECT_EQ(0U, processor()->change_list_size()); |
1093 | 1091 |
1094 // Create some sync changes that will conflict with the extension keywords. | 1092 // Create some sync changes that will conflict with the extension keywords. |
1095 syncer::SyncChangeList changes; | 1093 syncer::SyncChangeList changes; |
1096 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1094 changes.push_back(CreateTestSyncChange( |
1097 CreateTestTemplateURL(ASCIIToUTF16("keyword1"), "http://aaa.com", | 1095 syncer::SyncChange::ACTION_ADD, |
1098 std::string(), 100, true))); | 1096 CreateTestTemplateURL(ASCIIToUTF16("keyword1"), "http://aaa.com", |
| 1097 std::string(), 100, true, false, 0))); |
1099 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, | 1098 changes.push_back(CreateTestSyncChange(syncer::SyncChange::ACTION_ADD, |
1100 CreateTestTemplateURL(ASCIIToUTF16("keyword2"), "http://bbb.com"))); | 1099 CreateTestTemplateURL(ASCIIToUTF16("keyword2"), "http://bbb.com"))); |
1101 model()->ProcessSyncChanges(FROM_HERE, changes); | 1100 model()->ProcessSyncChanges(FROM_HERE, changes); |
1102 | 1101 |
1103 EXPECT_FALSE(model()->GetTemplateURLForHost("aaa.com") == NULL); | 1102 EXPECT_FALSE(model()->GetTemplateURLForHost("aaa.com") == NULL); |
1104 EXPECT_EQ(extension1, | 1103 EXPECT_EQ(extension1, |
1105 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); | 1104 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); |
1106 TemplateURL* url_for_keyword2 = | 1105 TemplateURL* url_for_keyword2 = |
1107 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2")); | 1106 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2")); |
1108 EXPECT_NE(extension2, url_for_keyword2); | 1107 EXPECT_NE(extension2, url_for_keyword2); |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 data.SetShortName(ASCIIToUTF16("unittest")); | 1517 data.SetShortName(ASCIIToUTF16("unittest")); |
1519 data.SetKeyword(ASCIIToUTF16("key2")); | 1518 data.SetKeyword(ASCIIToUTF16("key2")); |
1520 data.SetURL("http://key2.com/{searchTerms}"); | 1519 data.SetURL("http://key2.com/{searchTerms}"); |
1521 data.favicon_url = GURL("http://favicon.url"); | 1520 data.favicon_url = GURL("http://favicon.url"); |
1522 data.safe_for_autoreplace = false; | 1521 data.safe_for_autoreplace = false; |
1523 data.date_created = Time::FromTimeT(100); | 1522 data.date_created = Time::FromTimeT(100); |
1524 data.last_modified = Time::FromTimeT(100); | 1523 data.last_modified = Time::FromTimeT(100); |
1525 data.created_by_policy = false; | 1524 data.created_by_policy = false; |
1526 data.prepopulate_id = 999999; | 1525 data.prepopulate_id = 999999; |
1527 data.sync_guid = "key2"; | 1526 data.sync_guid = "key2"; |
1528 data.show_in_default_list = true; | |
1529 std::unique_ptr<TemplateURL> turl2(new TemplateURL(data)); | 1527 std::unique_ptr<TemplateURL> turl2(new TemplateURL(data)); |
1530 initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL( | 1528 initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL( |
1531 *turl1)); | 1529 *turl1)); |
1532 initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL( | 1530 initial_data.push_back(TemplateURLService::CreateSyncDataFromTemplateURL( |
1533 *turl2)); | 1531 *turl2)); |
1534 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, | 1532 model()->MergeDataAndStartSyncing(syncer::SEARCH_ENGINES, initial_data, |
1535 PassProcessor(), CreateAndPassSyncErrorFactory()); | 1533 PassProcessor(), CreateAndPassSyncErrorFactory()); |
1536 model()->SetUserSelectedDefaultSearchProvider( | 1534 model()->SetUserSelectedDefaultSearchProvider( |
1537 model()->GetTemplateURLForGUID("key1")); | 1535 model()->GetTemplateURLForGUID("key1")); |
1538 ASSERT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); | 1536 ASSERT_EQ("key1", model()->GetDefaultSearchProvider()->sync_guid()); |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2317 | 2315 |
2318 TEST_F(TemplateURLServiceSyncTest, NonAsciiKeywordDoesNotCrash) { | 2316 TEST_F(TemplateURLServiceSyncTest, NonAsciiKeywordDoesNotCrash) { |
2319 model()->Add(CreateTestTemplateURL(UTF8ToUTF16("\xf0\xaf\xa6\x8d"), | 2317 model()->Add(CreateTestTemplateURL(UTF8ToUTF16("\xf0\xaf\xa6\x8d"), |
2320 "http://key1.com")); | 2318 "http://key1.com")); |
2321 syncer::SyncDataList initial_data = CreateInitialSyncData(); | 2319 syncer::SyncDataList initial_data = CreateInitialSyncData(); |
2322 | 2320 |
2323 model()->MergeDataAndStartSyncing( | 2321 model()->MergeDataAndStartSyncing( |
2324 syncer::SEARCH_ENGINES, initial_data, PassProcessor(), | 2322 syncer::SEARCH_ENGINES, initial_data, PassProcessor(), |
2325 CreateAndPassSyncErrorFactory()); | 2323 CreateAndPassSyncErrorFactory()); |
2326 } | 2324 } |
OLD | NEW |