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/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 TemplateURLService::GenerateKeyword(GURL("http://blah/foo"), true)); | 484 TemplateURLService::GenerateKeyword(GURL("http://blah/foo"), true)); |
485 ASSERT_EQ(ASCIIToUTF16("blah"), | 485 ASSERT_EQ(ASCIIToUTF16("blah"), |
486 TemplateURLService::GenerateKeyword(GURL("http://blah/foo"), | 486 TemplateURLService::GenerateKeyword(GURL("http://blah/foo"), |
487 false)); | 487 false)); |
488 // FTP shouldn't generate a keyword. | 488 // FTP shouldn't generate a keyword. |
489 ASSERT_EQ(string16(), | 489 ASSERT_EQ(string16(), |
490 TemplateURLService::GenerateKeyword(GURL("ftp://blah/"), true)); | 490 TemplateURLService::GenerateKeyword(GURL("ftp://blah/"), true)); |
491 // Make sure we don't get a trailing / | 491 // Make sure we don't get a trailing / |
492 ASSERT_EQ(ASCIIToUTF16("blah"), | 492 ASSERT_EQ(ASCIIToUTF16("blah"), |
493 TemplateURLService::GenerateKeyword(GURL("http://blah/"), true)); | 493 TemplateURLService::GenerateKeyword(GURL("http://blah/"), true)); |
494 // Don't generate the empty string. | |
Peter Kasting
2012/04/10 01:24:33
I added this condition to GenerateKeyword() a litt
| |
495 ASSERT_EQ(ASCIIToUTF16("www"), | |
496 TemplateURLService::GenerateKeyword(GURL("http://www."), false)); | |
494 } | 497 } |
495 | 498 |
496 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { | 499 TEST_F(TemplateURLServiceTest, GenerateSearchURL) { |
497 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( | 500 scoped_refptr<TestGenerateSearchURL> test_generate_search_url( |
498 new TestGenerateSearchURL(NULL)); | 501 new TestGenerateSearchURL(NULL)); |
499 test_generate_search_url->RunTest(); | 502 test_generate_search_url->RunTest(); |
500 EXPECT_TRUE(test_generate_search_url->passed()); | 503 EXPECT_TRUE(test_generate_search_url->passed()); |
501 } | 504 } |
502 | 505 |
503 TEST_F(TemplateURLServiceTest, GenerateSearchURLUsingTermsData) { | 506 TEST_F(TemplateURLServiceTest, GenerateSearchURLUsingTermsData) { |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); | 791 scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data())); |
789 | 792 |
790 // Reset the model and don't load it. The template url we set as the default | 793 // Reset the model and don't load it. The template url we set as the default |
791 // should be pulled from prefs now. | 794 // should be pulled from prefs now. |
792 test_util_.ResetModel(false); | 795 test_util_.ResetModel(false); |
793 | 796 |
794 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs | 797 // NOTE: This doesn't use AssertEquals as only a subset of the TemplateURLs |
795 // value are persisted to prefs. | 798 // value are persisted to prefs. |
796 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); | 799 const TemplateURL* default_turl = model()->GetDefaultSearchProvider(); |
797 ASSERT_TRUE(default_turl); | 800 ASSERT_TRUE(default_turl); |
798 ASSERT_EQ("http://url", default_turl->url()); | 801 EXPECT_EQ(ASCIIToUTF16("a"), default_turl->short_name()); |
799 ASSERT_EQ("http://url2", default_turl->suggestions_url()); | 802 EXPECT_EQ("http://url", default_turl->url()); |
803 EXPECT_EQ("http://url2", default_turl->suggestions_url()); | |
800 EXPECT_EQ("http://instant", default_turl->instant_url()); | 804 EXPECT_EQ("http://instant", default_turl->instant_url()); |
801 ASSERT_EQ(ASCIIToUTF16("a"), default_turl->short_name()); | 805 EXPECT_EQ(id, default_turl->id()); |
802 ASSERT_EQ(id, default_turl->id()); | |
803 | 806 |
804 // Now do a load and make sure the default search provider really takes. | 807 // Now do a load and make sure the default search provider really takes. |
805 test_util_.VerifyLoad(); | 808 test_util_.VerifyLoad(); |
806 | 809 |
807 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 810 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
808 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); | 811 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); |
809 } | 812 } |
810 | 813 |
811 TEST_F(TemplateURLServiceTest, BuildQueryTerms) { | 814 TEST_F(TemplateURLServiceTest, BuildQueryTerms) { |
812 struct TestData { | 815 struct TestData { |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1330 | 1333 |
1331 // Reload the model to verify it was actually saved to the database and | 1334 // Reload the model to verify it was actually saved to the database and |
1332 // assigned a new GUID when brought back. | 1335 // assigned a new GUID when brought back. |
1333 test_util_.ResetModel(true); | 1336 test_util_.ResetModel(true); |
1334 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1337 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1335 const TemplateURL* loaded_url = | 1338 const TemplateURL* loaded_url = |
1336 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1339 model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
1337 ASSERT_TRUE(loaded_url != NULL); | 1340 ASSERT_TRUE(loaded_url != NULL); |
1338 ASSERT_FALSE(loaded_url->sync_guid().empty()); | 1341 ASSERT_FALSE(loaded_url->sync_guid().empty()); |
1339 } | 1342 } |
OLD | NEW |