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

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

Issue 9811022: Misc. small cleanups to minimize TemplateURL refactoring diffs: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/search_engines/template_url.h" 9 #include "chrome/browser/search_engines/template_url.h"
10 #include "chrome/browser/search_engines/template_url_service.h" 10 #include "chrome/browser/search_engines/template_url_service.h"
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); 329 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter));
330 AssertEquals(*service_turl, *deserialized); 330 AssertEquals(*service_turl, *deserialized);
331 } 331 }
332 } 332 }
333 333
334 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoManagedEngines) { 334 TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoManagedEngines) {
335 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); 335 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com"));
336 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com")); 336 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com"));
337 TemplateURL* managed_turl = CreateTestTemplateURL(ASCIIToUTF16("key3"), 337 TemplateURL* managed_turl = CreateTestTemplateURL(ASCIIToUTF16("key3"),
338 "http://key3.com", std::string(), 100, true); 338 "http://key3.com", std::string(), 100, true);
339 managed_turl->set_created_by_policy(true);
340 model()->Add(managed_turl); 339 model()->Add(managed_turl);
341 SyncDataList all_sync_data = 340 SyncDataList all_sync_data =
342 model()->GetAllSyncData(syncable::SEARCH_ENGINES); 341 model()->GetAllSyncData(syncable::SEARCH_ENGINES);
343 342
344 EXPECT_EQ(2U, all_sync_data.size()); 343 EXPECT_EQ(2U, all_sync_data.size());
345 344
346 for (SyncDataList::const_iterator iter = all_sync_data.begin(); 345 for (SyncDataList::const_iterator iter = all_sync_data.begin();
347 iter != all_sync_data.end(); ++iter) { 346 iter != all_sync_data.end(); ++iter) {
348 std::string guid = GetGUID(*iter); 347 std::string guid = GetGUID(*iter);
349 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); 348 const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid);
350 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); 349 scoped_ptr<TemplateURL> deserialized(Deserialize(*iter));
351 ASSERT_FALSE(service_turl->created_by_policy()); 350 ASSERT_FALSE(service_turl->created_by_policy());
352 AssertEquals(*service_turl, *deserialized); 351 AssertEquals(*service_turl, *deserialized);
353 } 352 }
354 } 353 }
355 354
356 TEST_F(TemplateURLServiceSyncTest, UniquifyKeyword) { 355 TEST_F(TemplateURLServiceSyncTest, UniquifyKeyword) {
357 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com")); 356 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com"));
358 // Create a key that conflicts with something in the model. 357 // Create a key that conflicts with something in the model.
359 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"), 358 scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key1"),
360 "http://new.com", "xyz")); 359 "http://new.com", "xyz"));
361 string16 new_keyword = model()->UniquifyKeyword(*turl); 360 string16 new_keyword = model()->UniquifyKeyword(*turl);
362
363 EXPECT_EQ(ASCIIToUTF16("new.com"), new_keyword); 361 EXPECT_EQ(ASCIIToUTF16("new.com"), new_keyword);
364 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); 362 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword));
365 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("new.com"), "http://new.com", 363 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("new.com"), "http://new.com",
366 "xyz")); 364 "xyz"));
367 365
368 // Test a second collision. This time it should be resolved by actually 366 // Test a second collision. This time it should be resolved by actually
369 // modifying the original keyword, since the autogenerated keyword is already 367 // modifying the original keyword, since the autogenerated keyword is already
370 // used. 368 // used.
371 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com")); 369 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com"));
372 new_keyword = model()->UniquifyKeyword(*turl); 370 new_keyword = model()->UniquifyKeyword(*turl);
373
374 EXPECT_EQ(ASCIIToUTF16("key1_"), new_keyword); 371 EXPECT_EQ(ASCIIToUTF16("key1_"), new_keyword);
375 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); 372 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword));
376 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1_"), "http://new.com")); 373 model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1_"), "http://new.com"));
377 374
378 // Test a third collision. This should collide on both the autogenerated 375 // Test a third collision. This should collide on both the autogenerated
379 // keyword and the first uniquification attempt. 376 // keyword and the first uniquification attempt.
380 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com")); 377 turl.reset(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://new.com"));
381 new_keyword = model()->UniquifyKeyword(*turl); 378 new_keyword = model()->UniquifyKeyword(*turl);
382 EXPECT_EQ(ASCIIToUTF16("key1__"), new_keyword); 379 EXPECT_EQ(ASCIIToUTF16("key1__"), new_keyword);
383 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword)); 380 EXPECT_EQ(NULL, model()->GetTemplateURLForKeyword(new_keyword));
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 1211
1215 // The key1 entry should be a duplicate of the default. 1212 // The key1 entry should be a duplicate of the default.
1216 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, 1213 model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES,
1217 CreateInitialSyncData(), processor()); 1214 CreateInitialSyncData(), processor());
1218 1215
1219 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); 1216 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size());
1220 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); 1217 EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid"));
1221 EXPECT_EQ(model()->GetDefaultSearchProvider(), 1218 EXPECT_EQ(model()->GetDefaultSearchProvider(),
1222 model()->GetTemplateURLForGUID("key1")); 1219 model()->GetTemplateURLForGUID("key1"));
1223 } 1220 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698