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/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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 data.safe_for_autoreplace = false; | 503 data.safe_for_autoreplace = false; |
504 TemplateURL* t_url2 = new TemplateURL(data); | 504 TemplateURL* t_url2 = new TemplateURL(data); |
505 model()->Add(t_url2); | 505 model()->Add(t_url2); |
506 EXPECT_EQ(t_url2, | 506 EXPECT_EQ(t_url2, |
507 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); | 507 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
508 EXPECT_TRUE(model()->GetTemplateURLForHost("test3") == NULL); | 508 EXPECT_TRUE(model()->GetTemplateURLForHost("test3") == NULL); |
509 EXPECT_EQ(extension, | 509 EXPECT_EQ(extension, |
510 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword_"))); | 510 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword_"))); |
511 } | 511 } |
512 | 512 |
513 TEST_F(TemplateURLServiceTest, GenerateKeyword) { | |
514 ASSERT_EQ(ASCIIToUTF16("foo"), | |
515 TemplateURLService::GenerateKeyword(GURL("http://foo"))); | |
516 // www. should be stripped. | |
517 ASSERT_EQ(ASCIIToUTF16("foo"), | |
518 TemplateURLService::GenerateKeyword(GURL("http://www.foo"))); | |
519 // Make sure we don't get a trailing '/'. | |
520 ASSERT_EQ(ASCIIToUTF16("blah"), | |
521 TemplateURLService::GenerateKeyword(GURL("http://blah/"))); | |
522 // Don't generate the empty string. | |
523 ASSERT_EQ(ASCIIToUTF16("www"), | |
524 TemplateURLService::GenerateKeyword(GURL("http://www."))); | |
525 } | |
526 | |
527 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { | |
528 TestSearchTermsData search_terms_data("http://google.com/"); | |
529 | |
530 struct GenerateSearchURLCase { | |
531 const char* test_name; | |
532 const char* url; | |
533 const char* expected; | |
534 } generate_url_cases[] = { | |
535 { "invalid URL", "foo{searchTerms}", "" }, | |
536 { "URL with no replacements", "http://foo/", "http://foo/" }, | |
537 { "basic functionality", "http://foo/{searchTerms}", | |
538 "http://foo/blah.blah.blah.blah.blah" } | |
539 }; | |
540 | |
541 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) { | |
542 TemplateURLData data; | |
543 data.SetURL(generate_url_cases[i].url); | |
544 TemplateURL t_url(data); | |
545 std::string result = TemplateURLService::GenerateSearchURL( | |
546 &t_url, search_terms_data).spec(); | |
547 EXPECT_EQ(result, generate_url_cases[i].expected) | |
548 << generate_url_cases[i].test_name << " failed."; | |
549 } | |
550 } | |
551 | |
552 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { | 513 TEST_F(TemplateURLServiceTest, ClearBrowsingData_Keywords) { |
553 Time now = Time::Now(); | 514 Time now = Time::Now(); |
554 TimeDelta one_day = TimeDelta::FromDays(1); | 515 TimeDelta one_day = TimeDelta::FromDays(1); |
555 Time month_ago = now - TimeDelta::FromDays(30); | 516 Time month_ago = now - TimeDelta::FromDays(30); |
556 | 517 |
557 // Nothing has been added. | 518 // Nothing has been added. |
558 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); | 519 EXPECT_EQ(0U, model()->GetTemplateURLs().size()); |
559 | 520 |
560 // Create one with a 0 time. | 521 // Create one with a 0 time. |
561 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", | 522 AddKeywordWithDate("name1", "key1", "http://foo1", "http://suggest1", |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 model()->RegisterOmniboxKeyword("abcdefg", "extension_name", "bing.com"); | 819 model()->RegisterOmniboxKeyword("abcdefg", "extension_name", "bing.com"); |
859 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); | 820 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com"))); |
860 | 821 |
861 model()->RepairPrepopulatedSearchEngines(); | 822 model()->RepairPrepopulatedSearchEngines(); |
862 | 823 |
863 // Google is default. | 824 // Google is default. |
864 ASSERT_EQ(google, model()->GetDefaultSearchProvider()); | 825 ASSERT_EQ(google, model()->GetDefaultSearchProvider()); |
865 // The keyword wasn't reverted. | 826 // The keyword wasn't reverted. |
866 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); | 827 EXPECT_EQ(ASCIIToUTF16("trash"), google->short_name()); |
867 EXPECT_EQ("www.google.com", | 828 EXPECT_EQ("www.google.com", |
868 TemplateURLService::GenerateSearchURL( | 829 google->GenerateSearchURL(model()->search_terms_data()).host()); |
869 google, model()->search_terms_data()).host()); | |
870 | 830 |
871 // Bing was repaired. | 831 // Bing was repaired. |
872 bing = model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com")); | 832 bing = model()->GetTemplateURLForKeyword(ASCIIToUTF16("bing.com")); |
873 ASSERT_TRUE(bing); | 833 ASSERT_TRUE(bing); |
874 EXPECT_EQ(TemplateURL::NORMAL, bing->GetType()); | 834 EXPECT_EQ(TemplateURL::NORMAL, bing->GetType()); |
875 | 835 |
876 // User search engine is preserved. | 836 // User search engine is preserved. |
877 EXPECT_EQ(user_dse, model()->GetTemplateURLForHost("www.goo.com")); | 837 EXPECT_EQ(user_dse, model()->GetTemplateURLForHost("www.goo.com")); |
878 EXPECT_EQ(ASCIIToUTF16("google.com"), user_dse->keyword()); | 838 EXPECT_EQ(ASCIIToUTF16("google.com"), user_dse->keyword()); |
879 } | 839 } |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 scoped_ptr<AssociatedExtensionInfo> extension_info( | 1499 scoped_ptr<AssociatedExtensionInfo> extension_info( |
1540 new AssociatedExtensionInfo); | 1500 new AssociatedExtensionInfo); |
1541 extension_info->wants_to_be_default_engine = true; | 1501 extension_info->wants_to_be_default_engine = true; |
1542 extension_info->extension_id = "ext1"; | 1502 extension_info->extension_id = "ext1"; |
1543 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); | 1503 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); |
1544 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1504 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
1545 EXPECT_TRUE(model()->is_default_search_managed()); | 1505 EXPECT_TRUE(model()->is_default_search_managed()); |
1546 actual_managed_default = model()->GetDefaultSearchProvider(); | 1506 actual_managed_default = model()->GetDefaultSearchProvider(); |
1547 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1507 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1548 } | 1508 } |
OLD | NEW |