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/base_paths.h" | 5 #include "base/base_paths.h" |
6 #include "base/command_line.h" | |
Joao da Silva
2012/09/28 11:46:10
used?
beaudoin
2012/10/02 17:43:29
Done.
| |
6 #include "base/string_util.h" | 7 #include "base/string_util.h" |
7 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/rlz/rlz.h" | 10 #include "chrome/browser/rlz/rlz.h" |
10 #include "chrome/browser/search_engines/search_terms_data.h" | 11 #include "chrome/browser/search_engines/search_terms_data.h" |
11 #include "chrome/browser/search_engines/template_url.h" | 12 #include "chrome/browser/search_engines/template_url.h" |
13 #include "chrome/common/chrome_switches.h" | |
Joao da Silva
2012/09/28 11:46:10
used?
beaudoin
2012/10/02 17:43:29
Done.
| |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 #if defined(ENABLE_RLZ) | 16 #if defined(ENABLE_RLZ) |
15 #include "chrome/browser/google/google_util.h" | 17 #include "chrome/browser/google/google_util.h" |
16 #endif | 18 #endif |
17 | 19 |
18 // TestSearchTermsData -------------------------------------------------------- | 20 // TestSearchTermsData -------------------------------------------------------- |
19 | 21 |
20 // Simple implementation of SearchTermsData. | 22 // Simple implementation of SearchTermsData. |
21 class TestSearchTermsData : public SearchTermsData { | 23 class TestSearchTermsData : public SearchTermsData { |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 TemplateURL url(NULL, data); | 636 TemplateURL url(NULL, data); |
635 TemplateURLRef::Replacements replacements; | 637 TemplateURLRef::Replacements replacements; |
636 bool valid = false; | 638 bool valid = false; |
637 EXPECT_EQ("{", | 639 EXPECT_EQ("{", |
638 url.url_ref().ParseURL("{{searchTerms}", &replacements, &valid)); | 640 url.url_ref().ParseURL("{{searchTerms}", &replacements, &valid)); |
639 ASSERT_EQ(1U, replacements.size()); | 641 ASSERT_EQ(1U, replacements.size()); |
640 EXPECT_EQ(1U, replacements[0].index); | 642 EXPECT_EQ(1U, replacements[0].index); |
641 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); | 643 EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); |
642 EXPECT_TRUE(valid); | 644 EXPECT_TRUE(valid); |
643 } | 645 } |
646 | |
647 TEST_F(TemplateURLTest, GetURLNoInstantURL) { | |
648 TemplateURLData data; | |
649 data.SetURL("http://google.com/?q={searchTerms}"); | |
650 data.suggestions_url = "http://google.com/suggest?q={searchTerms}"; | |
651 data.alternate_urls.push_back("http://google.com/alt?q={searchTerms}"); | |
652 data.alternate_urls.push_back("{google:baseURL}/alt/#q={searchTerms}"); | |
653 TemplateURL url(NULL, data); | |
654 ASSERT_EQ(3U, url.URLCount()); | |
655 EXPECT_EQ("http://google.com/alt?q={searchTerms}", url.GetURL(0)); | |
656 EXPECT_EQ("{google:baseURL}/alt/#q={searchTerms}", url.GetURL(1)); | |
657 EXPECT_EQ("http://google.com/?q={searchTerms}", url.GetURL(2)); | |
658 } | |
659 | |
660 TEST_F(TemplateURLTest, GetURLNoSuggestionsURL) { | |
661 TemplateURLData data; | |
662 data.SetURL("http://google.com/?q={searchTerms}"); | |
663 data.instant_url = "http://google.com/instant#q={searchTerms}"; | |
664 data.alternate_urls.push_back("http://google.com/alt?q={searchTerms}"); | |
665 data.alternate_urls.push_back("{google:baseURL}/alt/#q={searchTerms}"); | |
666 TemplateURL url(NULL, data); | |
667 ASSERT_EQ(3U, url.URLCount()); | |
668 EXPECT_EQ("http://google.com/alt?q={searchTerms}", url.GetURL(0)); | |
669 EXPECT_EQ("{google:baseURL}/alt/#q={searchTerms}", url.GetURL(1)); | |
670 EXPECT_EQ("http://google.com/?q={searchTerms}", url.GetURL(2)); | |
671 } | |
672 | |
673 TEST_F(TemplateURLTest, GetURLOnlyOneURL) { | |
674 TemplateURLData data; | |
675 data.SetURL("http://www.google.co.uk/"); | |
676 TemplateURL url(NULL, data); | |
677 ASSERT_EQ(1U, url.URLCount()); | |
678 EXPECT_EQ("http://www.google.co.uk/", url.GetURL(0)); | |
679 } | |
680 | |
681 TEST_F(TemplateURLTest, ExtractSearchTermsFromURL) { | |
682 TemplateURLData data; | |
683 data.SetURL("http://google.com/?q={searchTerms}"); | |
684 data.instant_url = "http://google.com/instant#q={searchTerms}"; | |
685 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}"); | |
686 data.alternate_urls.push_back("http://google.com/alt/?ext=foo&q={searchTerms}# ref=bar"); | |
Joao da Silva
2012/09/28 11:46:10
nit: line length
beaudoin
2012/10/02 17:43:29
Done.
| |
687 TemplateURL url(NULL, data); | |
688 string16 result; | |
689 | |
690 EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( | |
691 GURL("http://google.com/?q=something"), &result)); | |
692 EXPECT_EQ(string16(), result); | |
693 | |
694 EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( | |
695 GURL("http://google.com/?q=something#espv=1"), &result)); | |
696 EXPECT_EQ(string16(), result); | |
697 | |
698 EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL( | |
699 GURL("http://google.com/?q=something&espv=1"), &result)); | |
700 EXPECT_EQ(ASCIIToUTF16("something"), result); | |
701 | |
702 EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( | |
703 GURL("http://google.ca/?q=something&espv=1"), &result)); | |
704 EXPECT_EQ(string16(), result); | |
705 | |
706 EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( | |
707 GURL("http://google.com/foo/?q=foo&espv=1"), &result)); | |
708 EXPECT_EQ(string16(), result); | |
709 | |
710 EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( | |
711 GURL("https://google.com/?q=foo&espv=1"), &result)); | |
712 EXPECT_EQ(string16(), result); | |
713 | |
714 EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( | |
715 GURL("http://google.com:8080/?q=foo&espv=1"), &result)); | |
716 EXPECT_EQ(string16(), result); | |
717 | |
718 EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL( | |
719 GURL("http://google.com/?q=1+2+3&b=456&espv=1"), &result)); | |
720 EXPECT_EQ(ASCIIToUTF16("1 2 3"), result); | |
721 | |
722 EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL( | |
723 GURL("http://google.com/alt/?espv=1&q=123#q=456"), &result)); | |
724 EXPECT_EQ(ASCIIToUTF16("456"), result); | |
725 | |
726 EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL( | |
727 GURL("http://google.com/alt/?espv=1&a=012&q=123&b=456#f=789"), &result)); | |
728 EXPECT_EQ(ASCIIToUTF16("123"), result); | |
729 | |
730 EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL(GURL( | |
731 "http://google.com/alt/?a=012&q=123&espv=1&b=456#j=abc&q=789&h=def9"), | |
732 &result)); | |
733 EXPECT_EQ(ASCIIToUTF16("789"), result); | |
734 | |
735 EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( | |
736 GURL("http://google.com/alt/?espv=1&q="), &result)); | |
737 EXPECT_EQ(string16(), result); | |
738 | |
739 EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( | |
740 GURL("http://google.com/alt/?q=&espv=1"), &result)); | |
741 EXPECT_EQ(string16(), result); | |
742 | |
743 EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( | |
744 GURL("http://google.com/alt/?espv=1#q="), &result)); | |
745 EXPECT_EQ(string16(), result); | |
746 | |
747 EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( | |
748 GURL("http://google.com/alt/?espv=1&q=#q="), &result)); | |
749 EXPECT_EQ(string16(), result); | |
750 | |
751 EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( | |
752 GURL("http://google.com/alt/?espv=1&q=123#q="), &result)); | |
753 EXPECT_EQ(string16(), result); | |
754 | |
755 EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL( | |
756 GURL("http://google.com/alt/?espv=1&q=#q=123"), &result)); | |
757 EXPECT_EQ(ASCIIToUTF16("123"), result); | |
758 } | |
OLD | NEW |