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

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

Issue 338363004: Remove Profile* from TemplateURL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 data.SetURL(url); 103 data.SetURL(url);
104 data.suggestions_url = suggest_url; 104 data.suggestions_url = suggest_url;
105 if (!alternate_url.empty()) 105 if (!alternate_url.empty())
106 data.alternate_urls.push_back(alternate_url); 106 data.alternate_urls.push_back(alternate_url);
107 data.favicon_url = GURL(favicon_url); 107 data.favicon_url = GURL(favicon_url);
108 data.safe_for_autoreplace = safe_for_autoreplace; 108 data.safe_for_autoreplace = safe_for_autoreplace;
109 data.show_in_default_list = show_in_default_list; 109 data.show_in_default_list = show_in_default_list;
110 base::SplitString(encodings, ';', &data.input_encodings); 110 base::SplitString(encodings, ';', &data.input_encodings);
111 data.date_created = date_created; 111 data.date_created = date_created;
112 data.last_modified = last_modified; 112 data.last_modified = last_modified;
113 return new TemplateURL(model->profile(), data); 113 return new TemplateURL(data);
114 } 114 }
115 115
116 TemplateURL* AddKeywordWithDate( 116 TemplateURL* AddKeywordWithDate(
117 TemplateURLService* model, 117 TemplateURLService* model,
118 const std::string& short_name, 118 const std::string& short_name,
119 const std::string& keyword, 119 const std::string& keyword,
120 const std::string& url, 120 const std::string& url,
121 const std::string& suggest_url, 121 const std::string& suggest_url,
122 const std::string& alternate_url, 122 const std::string& alternate_url,
123 const std::string& favicon_url, 123 const std::string& favicon_url,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 void VerifyObserverCount(int expected_changed_count); 188 void VerifyObserverCount(int expected_changed_count);
189 void VerifyObserverFired(); 189 void VerifyObserverFired();
190 TemplateURLService* model() { return test_util_.model(); } 190 TemplateURLService* model() { return test_util_.model(); }
191 const SearchTermsData& search_terms_data() { 191 const SearchTermsData& search_terms_data() {
192 return model()->search_terms_data(); 192 return model()->search_terms_data();
193 } 193 }
194 194
195 protected: 195 protected:
196 TemplateURLServiceTestUtil test_util_; 196 TemplateURLServiceTestUtil test_util_;
197 197
198 void TestGenerateSearchURL(SearchTermsData* search_terms_data) { 198 void TestGenerateSearchURL(const SearchTermsData& search_terms_data) {
199 struct GenerateSearchURLCase { 199 struct GenerateSearchURLCase {
200 const char* test_name; 200 const char* test_name;
201 const char* url; 201 const char* url;
202 const char* expected; 202 const char* expected;
203 } generate_url_cases[] = { 203 } generate_url_cases[] = {
204 { "invalid URL", "foo{searchTerms}", "" }, 204 { "invalid URL", "foo{searchTerms}", "" },
205 { "URL with no replacements", "http://foo/", "http://foo/" }, 205 { "URL with no replacements", "http://foo/", "http://foo/" },
206 { "basic functionality", "http://foo/{searchTerms}", 206 { "basic functionality", "http://foo/{searchTerms}",
207 "http://foo/blah.blah.blah.blah.blah" } 207 "http://foo/blah.blah.blah.blah.blah" }
208 }; 208 };
209 209
210 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) { 210 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) {
211 TemplateURLData data; 211 TemplateURLData data;
212 data.SetURL(generate_url_cases[i].url); 212 data.SetURL(generate_url_cases[i].url);
213 TemplateURL t_url(NULL, data); 213 TemplateURL t_url(data);
214 std::string result; 214 std::string result;
215 if (search_terms_data) { 215 result = TemplateURLService::GenerateSearchURL(
Peter Kasting 2014/06/17 21:07:54 Nit: Combine this with the line above
hashimoto 2014/06/17 21:58:02 Done. Also removed the code below which prints th
216 result = TemplateURLService::GenerateSearchURLUsingTermsData( 216 &t_url, search_terms_data).spec();
217 &t_url, *search_terms_data).spec();
218 } else {
219 result = TemplateURLService::GenerateSearchURL(&t_url).spec();
220 }
221 EXPECT_EQ(result, generate_url_cases[i].expected) 217 EXPECT_EQ(result, generate_url_cases[i].expected)
222 << generate_url_cases[i].test_name << " failed. Expected " 218 << generate_url_cases[i].test_name << " failed. Expected "
223 << generate_url_cases[i].expected << " Actual " << result; 219 << generate_url_cases[i].expected << " Actual " << result;
224 } 220 }
225 } 221 }
226 222
227 223
228 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest); 224 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTest);
229 }; 225 };
230 226
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 data.short_name = ASCIIToUTF16("unittest"); 292 data.short_name = ASCIIToUTF16("unittest");
297 data.SetKeyword(ASCIIToUTF16("unittest")); 293 data.SetKeyword(ASCIIToUTF16("unittest"));
298 data.SetURL("http://www.unittest.com/{searchTerms}"); 294 data.SetURL("http://www.unittest.com/{searchTerms}");
299 data.favicon_url = GURL("http://favicon.url"); 295 data.favicon_url = GURL("http://favicon.url");
300 data.show_in_default_list = true; 296 data.show_in_default_list = true;
301 data.safe_for_autoreplace = safe_for_autoreplace; 297 data.safe_for_autoreplace = safe_for_autoreplace;
302 data.input_encodings.push_back("UTF-8"); 298 data.input_encodings.push_back("UTF-8");
303 data.date_created = Time::FromTimeT(100); 299 data.date_created = Time::FromTimeT(100);
304 data.last_modified = Time::FromTimeT(100); 300 data.last_modified = Time::FromTimeT(100);
305 data.prepopulate_id = prepopulate_id; 301 data.prepopulate_id = prepopulate_id;
306 return new TemplateURL(test_util_.profile(), data); 302 return new TemplateURL(data);
307 } 303 }
308 304
309 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) { 305 void TemplateURLServiceTest::VerifyObserverCount(int expected_changed_count) {
310 EXPECT_EQ(expected_changed_count, test_util_.GetObserverCount()); 306 EXPECT_EQ(expected_changed_count, test_util_.GetObserverCount());
311 test_util_.ResetObserverCount(); 307 test_util_.ResetObserverCount();
312 } 308 }
313 309
314 void TemplateURLServiceTest::VerifyObserverFired() { 310 void TemplateURLServiceTest::VerifyObserverFired() {
315 EXPECT_LE(1, test_util_.GetObserverCount()); 311 EXPECT_LE(1, test_util_.GetObserverCount());
316 test_util_.ResetObserverCount(); 312 test_util_.ResetObserverCount();
(...skipping 13 matching lines...) Expand all
330 326
331 TemplateURLData data; 327 TemplateURLData data;
332 data.short_name = ASCIIToUTF16("google"); 328 data.short_name = ASCIIToUTF16("google");
333 data.SetKeyword(ASCIIToUTF16("keyword")); 329 data.SetKeyword(ASCIIToUTF16("keyword"));
334 data.SetURL("http://www.google.com/foo/bar"); 330 data.SetURL("http://www.google.com/foo/bar");
335 data.favicon_url = GURL("http://favicon.url"); 331 data.favicon_url = GURL("http://favicon.url");
336 data.safe_for_autoreplace = true; 332 data.safe_for_autoreplace = true;
337 data.date_created = Time::FromTimeT(100); 333 data.date_created = Time::FromTimeT(100);
338 data.last_modified = Time::FromTimeT(100); 334 data.last_modified = Time::FromTimeT(100);
339 data.sync_guid = "00000000-0000-0000-0000-000000000001"; 335 data.sync_guid = "00000000-0000-0000-0000-000000000001";
340 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); 336 TemplateURL* t_url = new TemplateURL(data);
341 model()->Add(t_url); 337 model()->Add(t_url);
342 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), 338 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(),
343 NULL)); 339 NULL));
344 VerifyObserverCount(1); 340 VerifyObserverCount(1);
345 base::RunLoop().RunUntilIdle(); 341 base::RunLoop().RunUntilIdle();
346 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 342 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
347 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword())); 343 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(t_url->keyword()));
348 // We need to make a second copy as the model takes ownership of |t_url| and 344 // We need to make a second copy as the model takes ownership of |t_url| and
349 // will delete it. We have to do this after calling Add() since that gives 345 // will delete it. We have to do this after calling Add() since that gives
350 // |t_url| its ID. 346 // |t_url| its ID.
351 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), 347 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
352 t_url->data()));
353 348
354 // Reload the model to verify it was actually saved to the database. 349 // Reload the model to verify it was actually saved to the database.
355 test_util_.ResetModel(true); 350 test_util_.ResetModel(true);
356 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 351 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
357 TemplateURL* loaded_url = 352 TemplateURL* loaded_url =
358 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); 353 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
359 ASSERT_TRUE(loaded_url != NULL); 354 ASSERT_TRUE(loaded_url != NULL);
360 AssertEquals(*cloned_url, *loaded_url); 355 AssertEquals(*cloned_url, *loaded_url);
361 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), 356 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(),
362 NULL)); 357 NULL));
363 358
364 // We expect the last_modified time to be updated to the present time on an 359 // We expect the last_modified time to be updated to the present time on an
365 // explicit reset. We have to set up the expectation here because ResetModel 360 // explicit reset. We have to set up the expectation here because ResetModel
366 // resets the TimeProvider in the TemplateURLService. 361 // resets the TimeProvider in the TemplateURLService.
367 StrictMock<base::MockTimeProvider> mock_time; 362 StrictMock<base::MockTimeProvider> mock_time;
368 model()->set_time_provider(&base::MockTimeProvider::StaticNow); 363 model()->set_time_provider(&base::MockTimeProvider::StaticNow);
369 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); 364 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337)));
370 365
371 // Mutate an element and verify it succeeded. 366 // Mutate an element and verify it succeeded.
372 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"), 367 model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), ASCIIToUTF16("b"),
373 "c"); 368 "c");
374 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); 369 ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name());
375 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); 370 ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword());
376 ASSERT_EQ("c", loaded_url->url()); 371 ASSERT_EQ("c", loaded_url->url());
377 ASSERT_FALSE(loaded_url->safe_for_autoreplace()); 372 ASSERT_FALSE(loaded_url->safe_for_autoreplace());
378 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), 373 ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(),
379 NULL)); 374 NULL));
380 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); 375 ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL));
381 cloned_url.reset(new TemplateURL(loaded_url->profile(), loaded_url->data())); 376 cloned_url.reset(new TemplateURL(loaded_url->data()));
382 base::RunLoop().RunUntilIdle(); 377 base::RunLoop().RunUntilIdle();
383 test_util_.ResetModel(true); 378 test_util_.ResetModel(true);
384 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 379 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
385 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); 380 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b"));
386 ASSERT_TRUE(loaded_url != NULL); 381 ASSERT_TRUE(loaded_url != NULL);
387 AssertEquals(*cloned_url, *loaded_url); 382 AssertEquals(*cloned_url, *loaded_url);
388 // We changed a TemplateURL in the service, so ensure that the time was 383 // We changed a TemplateURL in the service, so ensure that the time was
389 // updated. 384 // updated.
390 ASSERT_EQ(base::Time::FromDoubleT(1337), loaded_url->last_modified()); 385 ASSERT_EQ(base::Time::FromDoubleT(1337), loaded_url->last_modified());
391 386
(...skipping 13 matching lines...) Expand all
405 std::string(), true, "UTF-8", Time(), Time()); 400 std::string(), true, "UTF-8", Time(), Time());
406 VerifyObserverCount(1); 401 VerifyObserverCount(1);
407 402
408 // Test what happens when we try to add a TemplateURL with the same keyword as 403 // Test what happens when we try to add a TemplateURL with the same keyword as
409 // one in the model. 404 // one in the model.
410 TemplateURLData data; 405 TemplateURLData data;
411 data.short_name = ASCIIToUTF16("second"); 406 data.short_name = ASCIIToUTF16("second");
412 data.SetKeyword(ASCIIToUTF16("keyword")); 407 data.SetKeyword(ASCIIToUTF16("keyword"));
413 data.SetURL("http://test2"); 408 data.SetURL("http://test2");
414 data.safe_for_autoreplace = false; 409 data.safe_for_autoreplace = false;
415 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); 410 TemplateURL* t_url = new TemplateURL(data);
416 model()->Add(t_url); 411 model()->Add(t_url);
417 412
418 // Because the old TemplateURL was replaceable and the new one wasn't, the new 413 // Because the old TemplateURL was replaceable and the new one wasn't, the new
419 // one should have replaced the old. 414 // one should have replaced the old.
420 VerifyObserverCount(1); 415 VerifyObserverCount(1);
421 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 416 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
422 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); 417 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name());
423 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); 418 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword());
424 EXPECT_FALSE(t_url->safe_for_autoreplace()); 419 EXPECT_FALSE(t_url->safe_for_autoreplace());
425 420
426 // Now try adding a replaceable TemplateURL. This should just delete the 421 // Now try adding a replaceable TemplateURL. This should just delete the
427 // passed-in URL. 422 // passed-in URL.
428 data.short_name = ASCIIToUTF16("third"); 423 data.short_name = ASCIIToUTF16("third");
429 data.SetURL("http://test3"); 424 data.SetURL("http://test3");
430 data.safe_for_autoreplace = true; 425 data.safe_for_autoreplace = true;
431 model()->Add(new TemplateURL(test_util_.profile(), data)); 426 model()->Add(new TemplateURL(data));
432 VerifyObserverCount(0); 427 VerifyObserverCount(0);
433 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 428 EXPECT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
434 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); 429 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name());
435 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword()); 430 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url->keyword());
436 EXPECT_FALSE(t_url->safe_for_autoreplace()); 431 EXPECT_FALSE(t_url->safe_for_autoreplace());
437 432
438 // Now try adding a non-replaceable TemplateURL again. This should uniquify 433 // Now try adding a non-replaceable TemplateURL again. This should uniquify
439 // the existing entry's keyword. 434 // the existing entry's keyword.
440 data.short_name = ASCIIToUTF16("fourth"); 435 data.short_name = ASCIIToUTF16("fourth");
441 data.SetURL("http://test4"); 436 data.SetURL("http://test4");
442 data.safe_for_autoreplace = false; 437 data.safe_for_autoreplace = false;
443 TemplateURL* t_url2 = new TemplateURL(test_util_.profile(), data); 438 TemplateURL* t_url2 = new TemplateURL(data);
444 model()->Add(t_url2); 439 model()->Add(t_url2);
445 VerifyObserverCount(1); 440 VerifyObserverCount(1);
446 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 441 EXPECT_EQ(t_url2, model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
447 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name()); 442 EXPECT_EQ(ASCIIToUTF16("fourth"), t_url2->short_name());
448 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword()); 443 EXPECT_EQ(ASCIIToUTF16("keyword"), t_url2->keyword());
449 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name()); 444 EXPECT_EQ(ASCIIToUTF16("second"), t_url->short_name());
450 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword()); 445 EXPECT_EQ(ASCIIToUTF16("test2"), t_url->keyword());
451 } 446 }
452 447
453 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) { 448 TEST_F(TemplateURLServiceTest, AddExtensionKeyword) {
(...skipping 12 matching lines...) Expand all
466 461
467 // Add an extension keyword that conflicts with each of the above three 462 // Add an extension keyword that conflicts with each of the above three
468 // keywords. 463 // keywords.
469 TemplateURLData data; 464 TemplateURLData data;
470 data.short_name = ASCIIToUTF16("test"); 465 data.short_name = ASCIIToUTF16("test");
471 data.SetKeyword(ASCIIToUTF16("keyword1")); 466 data.SetKeyword(ASCIIToUTF16("keyword1"));
472 data.SetURL(std::string(extensions::kExtensionScheme) + "://test4"); 467 data.SetURL(std::string(extensions::kExtensionScheme) + "://test4");
473 data.safe_for_autoreplace = false; 468 data.safe_for_autoreplace = false;
474 469
475 // Both replaceable and non-replaceable keywords should be uniquified. 470 // Both replaceable and non-replaceable keywords should be uniquified.
476 TemplateURL* extension1 = new TemplateURL(test_util_.profile(), data); 471 TemplateURL* extension1 = new TemplateURL(data);
477 model()->Add(extension1); 472 model()->Add(extension1);
478 ASSERT_EQ(extension1, 473 ASSERT_EQ(extension1,
479 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1"))); 474 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword1")));
480 EXPECT_EQ(original1, 475 EXPECT_EQ(original1,
481 model()->GetTemplateURLForKeyword(ASCIIToUTF16("test1"))); 476 model()->GetTemplateURLForKeyword(ASCIIToUTF16("test1")));
482 data.SetKeyword(ASCIIToUTF16("keyword2")); 477 data.SetKeyword(ASCIIToUTF16("keyword2"));
483 TemplateURL* extension2 = new TemplateURL(test_util_.profile(), data); 478 TemplateURL* extension2 = new TemplateURL(data);
484 model()->Add(extension2); 479 model()->Add(extension2);
485 ASSERT_EQ(extension2, 480 ASSERT_EQ(extension2,
486 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2"))); 481 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword2")));
487 EXPECT_EQ(original2, 482 EXPECT_EQ(original2,
488 model()->GetTemplateURLForKeyword(ASCIIToUTF16("test2"))); 483 model()->GetTemplateURLForKeyword(ASCIIToUTF16("test2")));
489 484
490 // They should override extension keywords added earlier. 485 // They should override extension keywords added earlier.
491 data.SetKeyword(ASCIIToUTF16("keyword3")); 486 data.SetKeyword(ASCIIToUTF16("keyword3"));
492 TemplateURL* extension3 = new TemplateURL(test_util_.profile(), data); 487 TemplateURL* extension3 = new TemplateURL(data);
493 model()->Add(extension3); 488 model()->Add(extension3);
494 ASSERT_EQ(extension3, 489 ASSERT_EQ(extension3,
495 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3"))); 490 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3")));
496 EXPECT_EQ(original3, 491 EXPECT_EQ(original3,
497 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3_"))); 492 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword3_")));
498 } 493 }
499 494
500 TEST_F(TemplateURLServiceTest, AddSameKeywordWithExtensionPresent) { 495 TEST_F(TemplateURLServiceTest, AddSameKeywordWithExtensionPresent) {
501 test_util_.VerifyLoad(); 496 test_util_.VerifyLoad();
502 497
(...skipping 10 matching lines...) Expand all
513 "replaceable", "keyword", "http://test1", std::string(), std::string(), 508 "replaceable", "keyword", "http://test1", std::string(), std::string(),
514 std::string(), true, "UTF-8", Time(), Time()); 509 std::string(), true, "UTF-8", Time(), Time());
515 510
516 // Adding another replaceable keyword should remove the existing one, but 511 // Adding another replaceable keyword should remove the existing one, but
517 // leave the extension as is. 512 // leave the extension as is.
518 TemplateURLData data; 513 TemplateURLData data;
519 data.short_name = ASCIIToUTF16("name1"); 514 data.short_name = ASCIIToUTF16("name1");
520 data.SetKeyword(ASCIIToUTF16("keyword")); 515 data.SetKeyword(ASCIIToUTF16("keyword"));
521 data.SetURL("http://test3"); 516 data.SetURL("http://test3");
522 data.safe_for_autoreplace = true; 517 data.safe_for_autoreplace = true;
523 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); 518 TemplateURL* t_url = new TemplateURL(data);
524 model()->Add(t_url); 519 model()->Add(t_url);
525 EXPECT_EQ(extension, 520 EXPECT_EQ(extension,
526 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword_"))); 521 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword_")));
527 EXPECT_TRUE(model()->GetTemplateURLForHost("test1") == NULL); 522 EXPECT_TRUE(model()->GetTemplateURLForHost("test1") == NULL);
528 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3")); 523 EXPECT_EQ(t_url, model()->GetTemplateURLForHost("test3"));
529 524
530 // Adding a nonreplaceable keyword should remove the existing replaceable 525 // Adding a nonreplaceable keyword should remove the existing replaceable
531 // keyword. 526 // keyword.
532 data.short_name = ASCIIToUTF16("name2"); 527 data.short_name = ASCIIToUTF16("name2");
533 data.SetURL("http://test4"); 528 data.SetURL("http://test4");
534 data.safe_for_autoreplace = false; 529 data.safe_for_autoreplace = false;
535 TemplateURL* t_url2 = new TemplateURL(test_util_.profile(), data); 530 TemplateURL* t_url2 = new TemplateURL(data);
536 model()->Add(t_url2); 531 model()->Add(t_url2);
537 EXPECT_EQ(t_url2, 532 EXPECT_EQ(t_url2,
538 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); 533 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")));
539 EXPECT_TRUE(model()->GetTemplateURLForHost("test3") == NULL); 534 EXPECT_TRUE(model()->GetTemplateURLForHost("test3") == NULL);
540 EXPECT_EQ(extension, 535 EXPECT_EQ(extension,
541 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword_"))); 536 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword_")));
542 } 537 }
543 538
544 TEST_F(TemplateURLServiceTest, GenerateKeyword) { 539 TEST_F(TemplateURLServiceTest, GenerateKeyword) {
545 ASSERT_EQ(ASCIIToUTF16("foo"), 540 ASSERT_EQ(ASCIIToUTF16("foo"),
546 TemplateURLService::GenerateKeyword(GURL("http://foo"))); 541 TemplateURLService::GenerateKeyword(GURL("http://foo")));
547 // www. should be stripped. 542 // www. should be stripped.
548 ASSERT_EQ(ASCIIToUTF16("foo"), 543 ASSERT_EQ(ASCIIToUTF16("foo"),
549 TemplateURLService::GenerateKeyword(GURL("http://www.foo"))); 544 TemplateURLService::GenerateKeyword(GURL("http://www.foo")));
550 // Make sure we don't get a trailing '/'. 545 // Make sure we don't get a trailing '/'.
551 ASSERT_EQ(ASCIIToUTF16("blah"), 546 ASSERT_EQ(ASCIIToUTF16("blah"),
552 TemplateURLService::GenerateKeyword(GURL("http://blah/"))); 547 TemplateURLService::GenerateKeyword(GURL("http://blah/")));
553 // Don't generate the empty string. 548 // Don't generate the empty string.
554 ASSERT_EQ(ASCIIToUTF16("www"), 549 ASSERT_EQ(ASCIIToUTF16("www"),
555 TemplateURLService::GenerateKeyword(GURL("http://www."))); 550 TemplateURLService::GenerateKeyword(GURL("http://www.")));
556 } 551 }
557 552
558 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { 553 TEST_F(TemplateURLServiceTest, GenerateSearchURL) {
559 TestGenerateSearchURL(NULL);
560 }
561
562 TEST_F(TemplateURLServiceTest, GenerateSearchURLUsingTermsData) {
563 // Run the test for GenerateSearchURLUsingTermsData on the "IO" thread and
564 // wait for it to finish.
565 TestSearchTermsData search_terms_data("http://google.com/"); 554 TestSearchTermsData search_terms_data("http://google.com/");
566 TestGenerateSearchURL(&search_terms_data); 555 TestGenerateSearchURL(search_terms_data);
Peter Kasting 2014/06/17 21:07:54 Nit: If this is now the only caller of this functi
hashimoto 2014/06/17 21:58:03 Done.
567 } 556 }
568 557
569 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { 558 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) {
570 Time now = Time::Now(); 559 Time now = Time::Now();
571 TimeDelta one_day = TimeDelta::FromDays(1); 560 TimeDelta one_day = TimeDelta::FromDays(1);
572 Time month_ago = now - TimeDelta::FromDays(30); 561 Time month_ago = now - TimeDelta::FromDays(30);
573 562
574 // Nothing has been added. 563 // Nothing has been added.
575 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); 564 EXPECT_EQ(0U, model()->GetTemplateURLs().size());
576 565
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 // Add a new TemplateURL. 673 // Add a new TemplateURL.
685 test_util_.VerifyLoad(); 674 test_util_.VerifyLoad();
686 const size_t initial_count = model()->GetTemplateURLs().size(); 675 const size_t initial_count = model()->GetTemplateURLs().size();
687 TemplateURLData data; 676 TemplateURLData data;
688 data.short_name = ASCIIToUTF16("google"); 677 data.short_name = ASCIIToUTF16("google");
689 data.SetKeyword(ASCIIToUTF16("keyword")); 678 data.SetKeyword(ASCIIToUTF16("keyword"));
690 data.SetURL("http://www.google.com/foo/bar"); 679 data.SetURL("http://www.google.com/foo/bar");
691 data.favicon_url = GURL("http://favicon.url"); 680 data.favicon_url = GURL("http://favicon.url");
692 data.date_created = Time::FromTimeT(100); 681 data.date_created = Time::FromTimeT(100);
693 data.last_modified = Time::FromTimeT(100); 682 data.last_modified = Time::FromTimeT(100);
694 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); 683 TemplateURL* t_url = new TemplateURL(data);
695 model()->Add(t_url); 684 model()->Add(t_url);
696 685
697 VerifyObserverCount(1); 686 VerifyObserverCount(1);
698 base::RunLoop().RunUntilIdle(); 687 base::RunLoop().RunUntilIdle();
699 688
700 StrictMock<base::MockTimeProvider> mock_time; 689 StrictMock<base::MockTimeProvider> mock_time;
701 model()->set_time_provider(&base::MockTimeProvider::StaticNow); 690 model()->set_time_provider(&base::MockTimeProvider::StaticNow);
702 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337))); 691 EXPECT_CALL(mock_time, Now()).WillOnce(Return(base::Time::FromDoubleT(1337)));
703 692
704 // Reset the short name, keyword, url and make sure it takes. 693 // Reset the short name, keyword, url and make sure it takes.
705 const base::string16 new_short_name(ASCIIToUTF16("a")); 694 const base::string16 new_short_name(ASCIIToUTF16("a"));
706 const base::string16 new_keyword(ASCIIToUTF16("b")); 695 const base::string16 new_keyword(ASCIIToUTF16("b"));
707 const std::string new_url("c"); 696 const std::string new_url("c");
708 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); 697 model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url);
709 ASSERT_EQ(new_short_name, t_url->short_name()); 698 ASSERT_EQ(new_short_name, t_url->short_name());
710 ASSERT_EQ(new_keyword, t_url->keyword()); 699 ASSERT_EQ(new_keyword, t_url->keyword());
711 ASSERT_EQ(new_url, t_url->url()); 700 ASSERT_EQ(new_url, t_url->url());
712 701
713 // Make sure the mappings in the model were updated. 702 // Make sure the mappings in the model were updated.
714 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(new_keyword)); 703 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(new_keyword));
715 ASSERT_TRUE( 704 ASSERT_TRUE(
716 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL); 705 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL);
717 706
718 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), 707 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
719 t_url->data()));
720 708
721 // Reload the model from the database and make sure the change took. 709 // Reload the model from the database and make sure the change took.
722 test_util_.ResetModel(true); 710 test_util_.ResetModel(true);
723 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 711 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
724 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword); 712 const TemplateURL* read_url = model()->GetTemplateURLForKeyword(new_keyword);
725 ASSERT_TRUE(read_url); 713 ASSERT_TRUE(read_url);
726 AssertEquals(*cloned_url, *read_url); 714 AssertEquals(*cloned_url, *read_url);
727 ASSERT_EQ(base::Time::FromDoubleT(1337), read_url->last_modified()); 715 ASSERT_EQ(base::Time::FromDoubleT(1337), read_url->last_modified());
728 } 716 }
729 717
730 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) { 718 TEST_F(TemplateURLServiceTest, DefaultSearchProvider) {
731 // Add a new TemplateURL. 719 // Add a new TemplateURL.
732 test_util_.VerifyLoad(); 720 test_util_.VerifyLoad();
733 const size_t initial_count = model()->GetTemplateURLs().size(); 721 const size_t initial_count = model()->GetTemplateURLs().size();
734 TemplateURL* t_url = AddKeywordWithDate( 722 TemplateURL* t_url = AddKeywordWithDate(
735 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1", 723 "name1", "key1", "http://foo1/{searchTerms}", "http://sugg1",
736 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time()); 724 std::string(), "http://icon1", true, "UTF-8;UTF-16", Time(), Time());
737 test_util_.ResetObserverCount(); 725 test_util_.ResetObserverCount();
738 726
739 model()->SetUserSelectedDefaultSearchProvider(t_url); 727 model()->SetUserSelectedDefaultSearchProvider(t_url);
740 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); 728 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
741 ASSERT_TRUE(t_url->safe_for_autoreplace()); 729 ASSERT_TRUE(t_url->safe_for_autoreplace());
742 ASSERT_TRUE(t_url->show_in_default_list()); 730 ASSERT_TRUE(t_url->show_in_default_list());
743 731
744 // Setting the default search provider should have caused notification. 732 // Setting the default search provider should have caused notification.
745 VerifyObserverCount(1); 733 VerifyObserverCount(1);
746 base::RunLoop().RunUntilIdle(); 734 base::RunLoop().RunUntilIdle();
747 735
748 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), 736 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
749 t_url->data()));
750 737
751 // Make sure when we reload we get a default search provider. 738 // Make sure when we reload we get a default search provider.
752 test_util_.ResetModel(true); 739 test_util_.ResetModel(true);
753 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 740 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
754 ASSERT_TRUE(model()->GetDefaultSearchProvider()); 741 ASSERT_TRUE(model()->GetDefaultSearchProvider());
755 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); 742 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider());
756 } 743 }
757 744
758 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) { 745 TEST_F(TemplateURLServiceTest, CantReplaceWithSameKeyword) {
759 test_util_.ChangeModelToLoadState(); 746 test_util_.ChangeModelToLoadState();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 test_util_.VerifyLoad(); 797 test_util_.VerifyLoad();
811 798
812 TemplateURLData data; 799 TemplateURLData data;
813 data.short_name = ASCIIToUTF16("a"); 800 data.short_name = ASCIIToUTF16("a");
814 data.safe_for_autoreplace = true; 801 data.safe_for_autoreplace = true;
815 data.SetURL("http://url/{searchTerms}"); 802 data.SetURL("http://url/{searchTerms}");
816 data.suggestions_url = "http://url2"; 803 data.suggestions_url = "http://url2";
817 data.instant_url = "http://instant"; 804 data.instant_url = "http://instant";
818 data.date_created = Time::FromTimeT(100); 805 data.date_created = Time::FromTimeT(100);
819 data.last_modified = Time::FromTimeT(100); 806 data.last_modified = Time::FromTimeT(100);
820 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); 807 TemplateURL* t_url = new TemplateURL(data);
821 model()->Add(t_url); 808 model()->Add(t_url);
822 const TemplateURLID id = t_url->id(); 809 const TemplateURLID id = t_url->id();
823 810
824 model()->SetUserSelectedDefaultSearchProvider(t_url); 811 model()->SetUserSelectedDefaultSearchProvider(t_url);
825 base::RunLoop().RunUntilIdle(); 812 base::RunLoop().RunUntilIdle();
826 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), 813 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
827 t_url->data()));
828 814
829 // Reset the model and don't load it. The template url we set as the default 815 // Reset the model and don't load it. The template url we set as the default
830 // should be pulled from prefs now. 816 // should be pulled from prefs now.
831 test_util_.ResetModel(false); 817 test_util_.ResetModel(false);
832 818
833 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs 819 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs
834 // value are persisted to prefs. 820 // value are persisted to prefs.
835 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); 821 const TemplateURL* default_turl = model()->GetDefaultSearchProvider();
836 ASSERT_TRUE(default_turl); 822 ASSERT_TRUE(default_turl);
837 EXPECT_EQ(ASCIIToUTF16("a"), default_turl->short_name()); 823 EXPECT_EQ(ASCIIToUTF16("a"), default_turl->short_name());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 model()->RegisterOmniboxKeyword("abcdefg", "extension_name", "bing.com"); 864 model()->RegisterOmniboxKeyword("abcdefg", "extension_name", "bing.com");
879 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); 865 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com")));
880 866
881 model()->RepairPrepopulatedSearchEngines(); 867 model()->RepairPrepopulatedSearchEngines();
882 868
883 // Google is default. 869 // Google is default.
884 ASSERT_EQ(google, model()->GetDefaultSearchProvider()); 870 ASSERT_EQ(google, model()->GetDefaultSearchProvider());
885 // The keyword wasn't reverted. 871 // The keyword wasn't reverted.
886 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); 872 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name());
887 EXPECT_EQ("www.google.com", 873 EXPECT_EQ("www.google.com",
888 TemplateURLService::GenerateSearchURL(google).host()); 874 TemplateURLService::GenerateSearchURL(
875 google, model()->search_terms_data()).host());
889 876
890 // Bing was repaired. 877 // Bing was repaired.
891 bing = model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com")); 878 bing = model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"));
892 ASSERT_TRUE(bing); 879 ASSERT_TRUE(bing);
893 EXPECT_EQ(TemplateURL::NORMAL, bing->GetType()); 880 EXPECT_EQ(TemplateURL::NORMAL, bing->GetType());
894 881
895 // User search engine is preserved. 882 // User search engine is preserved.
896 EXPECT_EQ(user_dse, model()->GetTemplateURLForHost("www.goo.com")); 883 EXPECT_EQ(user_dse, model()->GetTemplateURLForHost("www.goo.com"));
897 EXPECT_EQ(ASCIIToUTF16("google.com"), user_dse->keyword()); 884 EXPECT_EQ(ASCIIToUTF16("google.com"), user_dse->keyword());
898 } 885 }
(...skipping 16 matching lines...) Expand all
915 // Verify that the default manager we are getting is the managed one. 902 // Verify that the default manager we are getting is the managed one.
916 TemplateURLData data; 903 TemplateURLData data;
917 data.short_name = ASCIIToUTF16(kName); 904 data.short_name = ASCIIToUTF16(kName);
918 data.SetKeyword(ASCIIToUTF16(kKeyword)); 905 data.SetKeyword(ASCIIToUTF16(kKeyword));
919 data.SetURL(kSearchURL); 906 data.SetURL(kSearchURL);
920 data.favicon_url = GURL(kIconURL); 907 data.favicon_url = GURL(kIconURL);
921 data.show_in_default_list = true; 908 data.show_in_default_list = true;
922 base::SplitString(kEncodings, ';', &data.input_encodings); 909 base::SplitString(kEncodings, ';', &data.input_encodings);
923 data.alternate_urls.push_back(kAlternateURL); 910 data.alternate_urls.push_back(kAlternateURL);
924 data.search_terms_replacement_key = kSearchTermsReplacementKey; 911 data.search_terms_replacement_key = kSearchTermsReplacementKey;
925 scoped_ptr<TemplateURL> expected_managed_default(new TemplateURL( 912 scoped_ptr<TemplateURL> expected_managed_default(new TemplateURL(data));
926 test_util_.profile(), data));
927 EXPECT_TRUE(model()->is_default_search_managed()); 913 EXPECT_TRUE(model()->is_default_search_managed());
928 const TemplateURL* actual_managed_default = 914 const TemplateURL* actual_managed_default =
929 model()->GetDefaultSearchProvider(); 915 model()->GetDefaultSearchProvider();
930 ExpectSimilar(expected_managed_default.get(), actual_managed_default); 916 ExpectSimilar(expected_managed_default.get(), actual_managed_default);
931 917
932 // The following call has no effect on the managed search engine. 918 // The following call has no effect on the managed search engine.
933 model()->RepairPrepopulatedSearchEngines(); 919 model()->RepairPrepopulatedSearchEngines();
934 920
935 EXPECT_TRUE(model()->is_default_search_managed()); 921 EXPECT_TRUE(model()->is_default_search_managed());
936 actual_managed_default = model()->GetDefaultSearchProvider(); 922 actual_managed_default = model()->GetDefaultSearchProvider();
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 1109
1124 // Make sure that load routine doesn't delete prepopulated engines that no 1110 // Make sure that load routine doesn't delete prepopulated engines that no
1125 // longer exist in the prepopulate data if it has been modified by the user. 1111 // longer exist in the prepopulate data if it has been modified by the user.
1126 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { 1112 TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) {
1127 // Create a preloaded template url and add it to a loaded model. 1113 // Create a preloaded template url and add it to a loaded model.
1128 TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999); 1114 TemplateURL* t_url = CreatePreloadedTemplateURL(false, 999999);
1129 test_util_.ChangeModelToLoadState(); 1115 test_util_.ChangeModelToLoadState();
1130 model()->Add(t_url); 1116 model()->Add(t_url);
1131 1117
1132 // Do the copy after t_url is added so that the id is set. 1118 // Do the copy after t_url is added so that the id is set.
1133 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), 1119 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
1134 t_url->data()));
1135 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); 1120 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")));
1136 1121
1137 // Wait for any saves to finish. 1122 // Wait for any saves to finish.
1138 base::RunLoop().RunUntilIdle(); 1123 base::RunLoop().RunUntilIdle();
1139 1124
1140 // Ensure that merging won't clear it if the user has edited it. 1125 // Ensure that merging won't clear it if the user has edited it.
1141 test_util_.ResetModel(true); 1126 test_util_.ResetModel(true);
1142 const TemplateURL* url_for_unittest = 1127 const TemplateURL* url_for_unittest =
1143 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); 1128 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"));
1144 ASSERT_TRUE(url_for_unittest != NULL); 1129 ASSERT_TRUE(url_for_unittest != NULL);
1145 AssertEquals(*cloned_url, *url_for_unittest); 1130 AssertEquals(*cloned_url, *url_for_unittest);
1146 1131
1147 // Wait for any saves to finish. 1132 // Wait for any saves to finish.
1148 base::RunLoop().RunUntilIdle(); 1133 base::RunLoop().RunUntilIdle();
1149 1134
1150 // Reload the model to verify that save/reload retains the item. 1135 // Reload the model to verify that save/reload retains the item.
1151 test_util_.ResetModel(true); 1136 test_util_.ResetModel(true);
1152 ASSERT_TRUE( 1137 ASSERT_TRUE(
1153 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); 1138 model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL);
1154 } 1139 }
1155 1140
1156 // Make sure that load routine doesn't delete 1141 // Make sure that load routine doesn't delete
1157 // prepopulated engines that no longer exist in the prepopulate data if 1142 // prepopulated engines that no longer exist in the prepopulate data if
1158 // it has been modified by the user. 1143 // it has been modified by the user.
1159 TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) { 1144 TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) {
1160 test_util_.VerifyLoad(); 1145 test_util_.VerifyLoad();
1161 // Verify that the default search provider is set to something. 1146 // Verify that the default search provider is set to something.
1162 TemplateURL* default_search = model()->GetDefaultSearchProvider(); 1147 TemplateURL* default_search = model()->GetDefaultSearchProvider();
1163 ASSERT_TRUE(default_search != NULL); 1148 ASSERT_TRUE(default_search != NULL);
1164 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(default_search->profile(), 1149 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(default_search->data()));
1165 default_search->data()));
1166 1150
1167 // Wait for any saves to finish. 1151 // Wait for any saves to finish.
1168 base::RunLoop().RunUntilIdle(); 1152 base::RunLoop().RunUntilIdle();
1169 1153
1170 // Reload the model and check that the default search provider 1154 // Reload the model and check that the default search provider
1171 // was properly saved. 1155 // was properly saved.
1172 test_util_.ResetModel(true); 1156 test_util_.ResetModel(true);
1173 default_search = model()->GetDefaultSearchProvider(); 1157 default_search = model()->GetDefaultSearchProvider();
1174 ASSERT_TRUE(default_search != NULL); 1158 ASSERT_TRUE(default_search != NULL);
1175 AssertEquals(*cloned_url, *default_search); 1159 AssertEquals(*cloned_url, *default_search);
1176 } 1160 }
1177 1161
1178 // Make sure that the load routine doesn't delete 1162 // Make sure that the load routine doesn't delete
1179 // prepopulated engines that no longer exist in the prepopulate data if 1163 // prepopulated engines that no longer exist in the prepopulate data if
1180 // it is the default search provider. 1164 // it is the default search provider.
1181 TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) { 1165 TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
1182 // Set the default search provider to a preloaded template url which 1166 // Set the default search provider to a preloaded template url which
1183 // is not in the current set of preloaded template urls and save 1167 // is not in the current set of preloaded template urls and save
1184 // the result. 1168 // the result.
1185 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999); 1169 TemplateURL* t_url = CreatePreloadedTemplateURL(true, 999999);
1186 test_util_.ChangeModelToLoadState(); 1170 test_util_.ChangeModelToLoadState();
1187 model()->Add(t_url); 1171 model()->Add(t_url);
1188 model()->SetUserSelectedDefaultSearchProvider(t_url); 1172 model()->SetUserSelectedDefaultSearchProvider(t_url);
1189 // Do the copy after t_url is added and set as default so that its 1173 // Do the copy after t_url is added and set as default so that its
1190 // internal state is correct. 1174 // internal state is correct.
1191 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(), 1175 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
1192 t_url->data()));
1193 1176
1194 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); 1177 ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")));
1195 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); 1178 ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
1196 base::RunLoop().RunUntilIdle(); 1179 base::RunLoop().RunUntilIdle();
1197 1180
1198 // Ensure that merging won't clear the prepopulated template url 1181 // Ensure that merging won't clear the prepopulated template url
1199 // which is no longer present if it's the default engine. 1182 // which is no longer present if it's the default engine.
1200 test_util_.ResetModel(true); 1183 test_util_.ResetModel(true);
1201 { 1184 {
1202 const TemplateURL* keyword_url = 1185 const TemplateURL* keyword_url =
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 // Verify that the default manager we are getting is the managed one. 1283 // Verify that the default manager we are getting is the managed one.
1301 TemplateURLData data; 1284 TemplateURLData data;
1302 data.short_name = ASCIIToUTF16(kName); 1285 data.short_name = ASCIIToUTF16(kName);
1303 data.SetKeyword(ASCIIToUTF16(kKeyword)); 1286 data.SetKeyword(ASCIIToUTF16(kKeyword));
1304 data.SetURL(kSearchURL); 1287 data.SetURL(kSearchURL);
1305 data.favicon_url = GURL(kIconURL); 1288 data.favicon_url = GURL(kIconURL);
1306 data.show_in_default_list = true; 1289 data.show_in_default_list = true;
1307 base::SplitString(kEncodings, ';', &data.input_encodings); 1290 base::SplitString(kEncodings, ';', &data.input_encodings);
1308 data.alternate_urls.push_back(kAlternateURL); 1291 data.alternate_urls.push_back(kAlternateURL);
1309 data.search_terms_replacement_key = kSearchTermsReplacementKey; 1292 data.search_terms_replacement_key = kSearchTermsReplacementKey;
1310 Profile* profile = test_util_.profile(); 1293 scoped_ptr<TemplateURL> expected_managed_default1(new TemplateURL(data));
1311 scoped_ptr<TemplateURL> expected_managed_default1(new TemplateURL(profile,
1312 data));
1313 const TemplateURL* actual_managed_default = 1294 const TemplateURL* actual_managed_default =
1314 model()->GetDefaultSearchProvider(); 1295 model()->GetDefaultSearchProvider();
1315 ExpectSimilar(expected_managed_default1.get(), actual_managed_default); 1296 ExpectSimilar(expected_managed_default1.get(), actual_managed_default);
1316 EXPECT_TRUE(actual_managed_default->show_in_default_list()); 1297 EXPECT_TRUE(actual_managed_default->show_in_default_list());
1317 1298
1318 // Update the managed preference and check that the model has changed. 1299 // Update the managed preference and check that the model has changed.
1319 const char kNewName[] = "test2"; 1300 const char kNewName[] = "test2";
1320 const char kNewKeyword[] = "other.com"; 1301 const char kNewKeyword[] = "other.com";
1321 const char kNewSearchURL[] = "http://other.com/search?t={searchTerms}"; 1302 const char kNewSearchURL[] = "http://other.com/search?t={searchTerms}";
1322 const char kNewSuggestURL[] = "http://other.com/suggest?t={searchTerms}"; 1303 const char kNewSuggestURL[] = "http://other.com/suggest?t={searchTerms}";
1323 test_util_.SetManagedDefaultSearchPreferences(true, kNewName, kNewKeyword, 1304 test_util_.SetManagedDefaultSearchPreferences(true, kNewName, kNewKeyword,
1324 kNewSearchURL, kNewSuggestURL, std::string(), std::string(), 1305 kNewSearchURL, kNewSuggestURL, std::string(), std::string(),
1325 std::string(), std::string()); 1306 std::string(), std::string());
1326 VerifyObserverFired(); 1307 VerifyObserverFired();
1327 EXPECT_TRUE(model()->is_default_search_managed()); 1308 EXPECT_TRUE(model()->is_default_search_managed());
1328 EXPECT_EQ(initial_count + 2, model()->GetTemplateURLs().size()); 1309 EXPECT_EQ(initial_count + 2, model()->GetTemplateURLs().size());
1329 1310
1330 // Verify that the default manager we are now getting is the correct one. 1311 // Verify that the default manager we are now getting is the correct one.
1331 TemplateURLData data2; 1312 TemplateURLData data2;
1332 data2.short_name = ASCIIToUTF16(kNewName); 1313 data2.short_name = ASCIIToUTF16(kNewName);
1333 data2.SetKeyword(ASCIIToUTF16(kNewKeyword)); 1314 data2.SetKeyword(ASCIIToUTF16(kNewKeyword));
1334 data2.SetURL(kNewSearchURL); 1315 data2.SetURL(kNewSearchURL);
1335 data2.suggestions_url = kNewSuggestURL; 1316 data2.suggestions_url = kNewSuggestURL;
1336 data2.show_in_default_list = true; 1317 data2.show_in_default_list = true;
1337 scoped_ptr<TemplateURL> expected_managed_default2(new TemplateURL(profile, 1318 scoped_ptr<TemplateURL> expected_managed_default2(new TemplateURL(data2));
1338 data2));
1339 actual_managed_default = model()->GetDefaultSearchProvider(); 1319 actual_managed_default = model()->GetDefaultSearchProvider();
1340 ExpectSimilar(expected_managed_default2.get(), actual_managed_default); 1320 ExpectSimilar(expected_managed_default2.get(), actual_managed_default);
1341 EXPECT_EQ(actual_managed_default->show_in_default_list(), true); 1321 EXPECT_EQ(actual_managed_default->show_in_default_list(), true);
1342 1322
1343 // Remove all the managed prefs and check that we are no longer managed. 1323 // Remove all the managed prefs and check that we are no longer managed.
1344 test_util_.RemoveManagedDefaultSearchPreferences(); 1324 test_util_.RemoveManagedDefaultSearchPreferences();
1345 VerifyObserverFired(); 1325 VerifyObserverFired();
1346 EXPECT_FALSE(model()->is_default_search_managed()); 1326 EXPECT_FALSE(model()->is_default_search_managed());
1347 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 1327 EXPECT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
1348 1328
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) { 1382 TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) {
1403 // Add a new TemplateURL. 1383 // Add a new TemplateURL.
1404 test_util_.VerifyLoad(); 1384 test_util_.VerifyLoad();
1405 const size_t initial_count = model()->GetTemplateURLs().size(); 1385 const size_t initial_count = model()->GetTemplateURLs().size();
1406 1386
1407 TemplateURLData data; 1387 TemplateURLData data;
1408 data.short_name = ASCIIToUTF16("google"); 1388 data.short_name = ASCIIToUTF16("google");
1409 data.SetKeyword(ASCIIToUTF16("keyword")); 1389 data.SetKeyword(ASCIIToUTF16("keyword"));
1410 data.SetURL("http://www.google.com/foo/bar"); 1390 data.SetURL("http://www.google.com/foo/bar");
1411 data.sync_guid.clear(); 1391 data.sync_guid.clear();
1412 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); 1392 TemplateURL* t_url = new TemplateURL(data);
1413 model()->Add(t_url); 1393 model()->Add(t_url);
1414 1394
1415 VerifyObserverCount(1); 1395 VerifyObserverCount(1);
1416 base::RunLoop().RunUntilIdle(); 1396 base::RunLoop().RunUntilIdle();
1417 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 1397 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
1418 1398
1419 // Reload the model to verify it was actually saved to the database and 1399 // Reload the model to verify it was actually saved to the database and
1420 // assigned a new GUID when brought back. 1400 // assigned a new GUID when brought back.
1421 test_util_.ResetModel(true); 1401 test_util_.ResetModel(true);
1422 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 1402 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
(...skipping 16 matching lines...) Expand all
1439 data.SetURL("http://www.google.com/foo/bar"); 1419 data.SetURL("http://www.google.com/foo/bar");
1440 std::vector<std::string> encodings; 1420 std::vector<std::string> encodings;
1441 data.input_encodings.push_back("UTF-8"); 1421 data.input_encodings.push_back("UTF-8");
1442 data.input_encodings.push_back("UTF-8"); 1422 data.input_encodings.push_back("UTF-8");
1443 data.input_encodings.push_back("UTF-16"); 1423 data.input_encodings.push_back("UTF-16");
1444 data.input_encodings.push_back("UTF-8"); 1424 data.input_encodings.push_back("UTF-8");
1445 data.input_encodings.push_back("Big5"); 1425 data.input_encodings.push_back("Big5");
1446 data.input_encodings.push_back("UTF-16"); 1426 data.input_encodings.push_back("UTF-16");
1447 data.input_encodings.push_back("Big5"); 1427 data.input_encodings.push_back("Big5");
1448 data.input_encodings.push_back("Windows-1252"); 1428 data.input_encodings.push_back("Windows-1252");
1449 TemplateURL* t_url = new TemplateURL(test_util_.profile(), data); 1429 TemplateURL* t_url = new TemplateURL(data);
1450 model()->Add(t_url); 1430 model()->Add(t_url);
1451 1431
1452 VerifyObserverCount(1); 1432 VerifyObserverCount(1);
1453 base::RunLoop().RunUntilIdle(); 1433 base::RunLoop().RunUntilIdle();
1454 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); 1434 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
1455 const TemplateURL* loaded_url = 1435 const TemplateURL* loaded_url =
1456 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); 1436 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"));
1457 ASSERT_TRUE(loaded_url != NULL); 1437 ASSERT_TRUE(loaded_url != NULL);
1458 EXPECT_EQ(8U, loaded_url->input_encodings().size()); 1438 EXPECT_EQ(8U, loaded_url->input_encodings().size());
1459 1439
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 // Verify that the default manager we are getting is the managed one. 1525 // Verify that the default manager we are getting is the managed one.
1546 TemplateURLData data; 1526 TemplateURLData data;
1547 data.short_name = ASCIIToUTF16(kName); 1527 data.short_name = ASCIIToUTF16(kName);
1548 data.SetKeyword(ASCIIToUTF16(kKeyword)); 1528 data.SetKeyword(ASCIIToUTF16(kKeyword));
1549 data.SetURL(kSearchURL); 1529 data.SetURL(kSearchURL);
1550 data.favicon_url = GURL(kIconURL); 1530 data.favicon_url = GURL(kIconURL);
1551 data.show_in_default_list = true; 1531 data.show_in_default_list = true;
1552 base::SplitString(kEncodings, ';', &data.input_encodings); 1532 base::SplitString(kEncodings, ';', &data.input_encodings);
1553 data.alternate_urls.push_back(kAlternateURL); 1533 data.alternate_urls.push_back(kAlternateURL);
1554 data.search_terms_replacement_key = kSearchTermsReplacementKey; 1534 data.search_terms_replacement_key = kSearchTermsReplacementKey;
1555 scoped_ptr<TemplateURL> expected_managed_default(new TemplateURL( 1535 scoped_ptr<TemplateURL> expected_managed_default(new TemplateURL(data));
1556 test_util_.profile(), data));
1557 EXPECT_TRUE(model()->is_default_search_managed()); 1536 EXPECT_TRUE(model()->is_default_search_managed());
1558 const TemplateURL* actual_managed_default = 1537 const TemplateURL* actual_managed_default =
1559 model()->GetDefaultSearchProvider(); 1538 model()->GetDefaultSearchProvider();
1560 ExpectSimilar(expected_managed_default.get(), actual_managed_default); 1539 ExpectSimilar(expected_managed_default.get(), actual_managed_default);
1561 1540
1562 TemplateURL* ext_dse = CreateKeywordWithDate( 1541 TemplateURL* ext_dse = CreateKeywordWithDate(
1563 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}", 1542 model(), "ext1", "ext1", "http://www.ext1.com/s?q={searchTerms}",
1564 std::string(), std::string(), std::string(), 1543 std::string(), std::string(), std::string(),
1565 true, true, "UTF-8", Time(), Time()); 1544 true, true, "UTF-8", Time(), Time());
1566 scoped_ptr<AssociatedExtensionInfo> extension_info( 1545 scoped_ptr<AssociatedExtensionInfo> extension_info(
1567 new AssociatedExtensionInfo); 1546 new AssociatedExtensionInfo);
1568 extension_info->wants_to_be_default_engine = true; 1547 extension_info->wants_to_be_default_engine = true;
1569 extension_info->extension_id = "ext1"; 1548 extension_info->extension_id = "ext1";
1570 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); 1549 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass());
1571 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); 1550 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1")));
1572 EXPECT_TRUE(model()->is_default_search_managed()); 1551 EXPECT_TRUE(model()->is_default_search_managed());
1573 actual_managed_default = model()->GetDefaultSearchProvider(); 1552 actual_managed_default = model()->GetDefaultSearchProvider();
1574 ExpectSimilar(expected_managed_default.get(), actual_managed_default); 1553 ExpectSimilar(expected_managed_default.get(), actual_managed_default);
1575 } 1554 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698