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

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

Issue 10676012: De-dupe input encodings in TemplateURLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 EXPECT_EQ(SyncChange::ACTION_UPDATE, key1_change.change_type()); 1345 EXPECT_EQ(SyncChange::ACTION_UPDATE, key1_change.change_type());
1346 EXPECT_EQ(keyword1->keyword(), 1346 EXPECT_EQ(keyword1->keyword(),
1347 UTF8ToUTF16(GetKeyword(key1_change.sync_data()))); 1347 UTF8ToUTF16(GetKeyword(key1_change.sync_data())));
1348 ASSERT_TRUE(processor()->contains_guid("key2")); 1348 ASSERT_TRUE(processor()->contains_guid("key2"));
1349 SyncChange key2_change = processor()->change_for_guid("key2"); 1349 SyncChange key2_change = processor()->change_for_guid("key2");
1350 EXPECT_EQ(SyncChange::ACTION_UPDATE, key2_change.change_type()); 1350 EXPECT_EQ(SyncChange::ACTION_UPDATE, key2_change.change_type());
1351 EXPECT_EQ(keyword2->keyword(), 1351 EXPECT_EQ(keyword2->keyword(),
1352 UTF8ToUTF16(GetKeyword(key2_change.sync_data()))); 1352 UTF8ToUTF16(GetKeyword(key2_change.sync_data())));
1353 } 1353 }
1354 1354
1355 TEST_F(TemplateURLServiceSyncTest, DuplicateEncodingsRemoved) {
1356 // Create a sync entry with duplicate encodings.
1357 SyncDataList initial_data;
1358
1359 TemplateURLData data;
1360 data.short_name = ASCIIToUTF16("test");
1361 data.SetKeyword(ASCIIToUTF16("keyword"));
1362 data.SetURL("http://test/%s");
1363 data.input_encodings.push_back("UTF-8");
1364 data.input_encodings.push_back("UTF-8");
1365 data.input_encodings.push_back("UTF-16");
1366 data.input_encodings.push_back("UTF-8");
1367 data.input_encodings.push_back("Big5");
1368 data.input_encodings.push_back("UTF-16");
1369 data.input_encodings.push_back("Big5");
1370 data.input_encodings.push_back("Windows-1252");
1371 data.date_created = Time::FromTimeT(100);
1372 data.last_modified = Time::FromTimeT(100);
1373 data.sync_guid = "keyword";
1374 scoped_ptr<TemplateURL> turl(new TemplateURL(NULL, data));
1375 initial_data.push_back(
1376 TemplateURLService::CreateSyncDataFromTemplateURL(*turl));
1377
1378 // Now try to sync the data locally.
1379 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data,
1380 PassProcessor(), CreateAndPassSyncErrorFactory());
1381
1382 // The entry should have been added, with duplicate encodings removed.
1383 TemplateURL* keyword =
1384 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
1385 ASSERT_FALSE(keyword == NULL);
1386 EXPECT_EQ(4U, keyword->input_encodings().size());
1387
1388 // We should also have gotten a corresponding UPDATE pushed upstream.
1389 EXPECT_GE(processor()->change_list_size(), 1U);
1390 ASSERT_TRUE(processor()->contains_guid("keyword"));
1391 SyncChange keyword_change = processor()->change_for_guid("keyword");
1392 EXPECT_EQ(SyncChange::ACTION_UPDATE, keyword_change.change_type());
1393 EXPECT_EQ("UTF-8;UTF-16;Big5;Windows-1252", keyword_change.sync_data().
1394 GetSpecifics().search_engine().input_encodings());
1395 }
1396
1355 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { 1397 TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) {
1356 // Start off B with some empty data. 1398 // Start off B with some empty data.
1357 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, 1399 model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1358 CreateInitialSyncData(), PassProcessor(), 1400 CreateInitialSyncData(), PassProcessor(),
1359 CreateAndPassSyncErrorFactory()); 1401 CreateAndPassSyncErrorFactory());
1360 1402
1361 // Merge A and B. All of B's data should transfer over to A, which initially 1403 // Merge A and B. All of B's data should transfer over to A, which initially
1362 // has no data. 1404 // has no data.
1363 scoped_ptr<SyncChangeProcessorDelegate> delegate_b( 1405 scoped_ptr<SyncChangeProcessorDelegate> delegate_b(
1364 new SyncChangeProcessorDelegate(model_b())); 1406 new SyncChangeProcessorDelegate(model_b()));
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 // A local change to the Google base URL should update the keyword and 1973 // A local change to the Google base URL should update the keyword and
1932 // generate a sync change. 1974 // generate a sync change.
1933 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/")); 1975 test_util_a_.SetGoogleBaseURL(GURL("http://google.co.in/"));
1934 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword()); 1976 EXPECT_EQ(ASCIIToUTF16("google.co.in"), synced_turl->keyword());
1935 EXPECT_EQ(1U, processor()->change_list_size()); 1977 EXPECT_EQ(1U, processor()->change_list_size());
1936 ASSERT_TRUE(processor()->contains_guid("guid")); 1978 ASSERT_TRUE(processor()->contains_guid("guid"));
1937 SyncChange change(processor()->change_for_guid("guid")); 1979 SyncChange change(processor()->change_for_guid("guid"));
1938 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); 1980 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
1939 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data())); 1981 EXPECT_EQ("google.co.in", GetKeyword(change.sync_data()));
1940 } 1982 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_service.cc ('k') | chrome/browser/search_engines/template_url_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698