| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/omnibox/browser/search_provider.h" | 5 #include "components/omnibox/browser/search_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 2731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2742 { "?abc.com", "http://www.abc.com", | 2742 { "?abc.com", "http://www.abc.com", |
| 2743 "?www.abc.com", std::string(), true, true }, | 2743 "?www.abc.com", std::string(), true, true }, |
| 2744 }; | 2744 }; |
| 2745 | 2745 |
| 2746 for (size_t i = 0; i < arraysize(cases); ++i) { | 2746 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 2747 // First test regular mode. | 2747 // First test regular mode. |
| 2748 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); | 2748 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); |
| 2749 SearchSuggestionParser::NavigationResult result( | 2749 SearchSuggestionParser::NavigationResult result( |
| 2750 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), | 2750 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), |
| 2751 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), | 2751 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), |
| 2752 false, 0, false, ASCIIToUTF16(cases[i].input), std::string()); | 2752 false, 0, false, ASCIIToUTF16(cases[i].input)); |
| 2753 result.set_received_after_last_keystroke(false); | 2753 result.set_received_after_last_keystroke(false); |
| 2754 AutocompleteMatch match(provider_->NavigationToMatch(result)); | 2754 AutocompleteMatch match(provider_->NavigationToMatch(result)); |
| 2755 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | 2755 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
| 2756 match.inline_autocompletion); | 2756 match.inline_autocompletion); |
| 2757 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); | 2757 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); |
| 2758 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_regular_mode, | 2758 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_regular_mode, |
| 2759 match.allowed_to_be_default_match); | 2759 match.allowed_to_be_default_match); |
| 2760 | 2760 |
| 2761 // Then test prevent-inline-autocomplete mode. | 2761 // Then test prevent-inline-autocomplete mode. |
| 2762 QueryForInput(ASCIIToUTF16(cases[i].input), true, false); | 2762 QueryForInput(ASCIIToUTF16(cases[i].input), true, false); |
| 2763 SearchSuggestionParser::NavigationResult result_prevent_inline( | 2763 SearchSuggestionParser::NavigationResult result_prevent_inline( |
| 2764 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), | 2764 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), |
| 2765 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), | 2765 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), |
| 2766 false, 0, false, ASCIIToUTF16(cases[i].input), std::string()); | 2766 false, 0, false, ASCIIToUTF16(cases[i].input)); |
| 2767 result_prevent_inline.set_received_after_last_keystroke(false); | 2767 result_prevent_inline.set_received_after_last_keystroke(false); |
| 2768 AutocompleteMatch match_prevent_inline( | 2768 AutocompleteMatch match_prevent_inline( |
| 2769 provider_->NavigationToMatch(result_prevent_inline)); | 2769 provider_->NavigationToMatch(result_prevent_inline)); |
| 2770 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | 2770 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
| 2771 match_prevent_inline.inline_autocompletion); | 2771 match_prevent_inline.inline_autocompletion); |
| 2772 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), | 2772 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), |
| 2773 match_prevent_inline.fill_into_edit); | 2773 match_prevent_inline.fill_into_edit); |
| 2774 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode, | 2774 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode, |
| 2775 match_prevent_inline.allowed_to_be_default_match); | 2775 match_prevent_inline.allowed_to_be_default_match); |
| 2776 } | 2776 } |
| 2777 } | 2777 } |
| 2778 | 2778 |
| 2779 // Verifies that "http://" is not trimmed for input that is a leading substring. | 2779 // Verifies that "http://" is not trimmed for input that is a leading substring. |
| 2780 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { | 2780 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { |
| 2781 const base::string16 input(ASCIIToUTF16("ht")); | 2781 const base::string16 input(ASCIIToUTF16("ht")); |
| 2782 const base::string16 url(ASCIIToUTF16("http://a.com")); | 2782 const base::string16 url(ASCIIToUTF16("http://a.com")); |
| 2783 SearchSuggestionParser::NavigationResult result( | 2783 SearchSuggestionParser::NavigationResult result( |
| 2784 ChromeAutocompleteSchemeClassifier(&profile_), GURL(url), | 2784 ChromeAutocompleteSchemeClassifier(&profile_), GURL(url), |
| 2785 AutocompleteMatchType::NAVSUGGEST, | 2785 AutocompleteMatchType::NAVSUGGEST, |
| 2786 base::string16(), std::string(), false, 0, false, input, std::string()); | 2786 base::string16(), std::string(), false, 0, false, input); |
| 2787 result.set_received_after_last_keystroke(false); | 2787 result.set_received_after_last_keystroke(false); |
| 2788 | 2788 |
| 2789 // Check the offset and strings when inline autocompletion is allowed. | 2789 // Check the offset and strings when inline autocompletion is allowed. |
| 2790 QueryForInput(input, false, false); | 2790 QueryForInput(input, false, false); |
| 2791 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); | 2791 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); |
| 2792 EXPECT_EQ(url, match_inline.fill_into_edit); | 2792 EXPECT_EQ(url, match_inline.fill_into_edit); |
| 2793 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); | 2793 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); |
| 2794 EXPECT_TRUE(match_inline.allowed_to_be_default_match); | 2794 EXPECT_TRUE(match_inline.allowed_to_be_default_match); |
| 2795 EXPECT_EQ(url, match_inline.contents); | 2795 EXPECT_EQ(url, match_inline.contents); |
| 2796 | 2796 |
| 2797 // Check the same strings when inline autocompletion is prevented. | 2797 // Check the same strings when inline autocompletion is prevented. |
| 2798 QueryForInput(input, true, false); | 2798 QueryForInput(input, true, false); |
| 2799 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); | 2799 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); |
| 2800 EXPECT_EQ(url, match_prevent.fill_into_edit); | 2800 EXPECT_EQ(url, match_prevent.fill_into_edit); |
| 2801 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); | 2801 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); |
| 2802 EXPECT_EQ(url, match_prevent.contents); | 2802 EXPECT_EQ(url, match_prevent.contents); |
| 2803 } | 2803 } |
| 2804 | 2804 |
| 2805 // Verifies that input "w" marks a more significant domain label than "www.". | 2805 // Verifies that input "w" marks a more significant domain label than "www.". |
| 2806 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { | 2806 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { |
| 2807 QueryForInput(ASCIIToUTF16("w"), false, false); | 2807 QueryForInput(ASCIIToUTF16("w"), false, false); |
| 2808 SearchSuggestionParser::NavigationResult result( | 2808 SearchSuggestionParser::NavigationResult result( |
| 2809 ChromeAutocompleteSchemeClassifier(&profile_), | 2809 ChromeAutocompleteSchemeClassifier(&profile_), |
| 2810 GURL("http://www.wow.com"), AutocompleteMatchType::NAVSUGGEST, | 2810 GURL("http://www.wow.com"), AutocompleteMatchType::NAVSUGGEST, |
| 2811 base::string16(), std::string(), false, 0, false, ASCIIToUTF16("w"), | 2811 base::string16(), std::string(), false, 0, false, ASCIIToUTF16("w")); |
| 2812 std::string()); | |
| 2813 result.set_received_after_last_keystroke(false); | 2812 result.set_received_after_last_keystroke(false); |
| 2814 AutocompleteMatch match(provider_->NavigationToMatch(result)); | 2813 AutocompleteMatch match(provider_->NavigationToMatch(result)); |
| 2815 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); | 2814 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); |
| 2816 EXPECT_TRUE(match.allowed_to_be_default_match); | 2815 EXPECT_TRUE(match.allowed_to_be_default_match); |
| 2817 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); | 2816 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); |
| 2818 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); | 2817 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); |
| 2819 | 2818 |
| 2820 // Ensure that the match for input "w" is marked on "wow" and not "www". | 2819 // Ensure that the match for input "w" is marked on "wow" and not "www". |
| 2821 ASSERT_EQ(3U, match.contents_class.size()); | 2820 ASSERT_EQ(3U, match.contents_class.size()); |
| 2822 EXPECT_EQ(0U, match.contents_class[0].offset); | 2821 EXPECT_EQ(0U, match.contents_class[0].offset); |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3598 } | 3597 } |
| 3599 | 3598 |
| 3600 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { | 3599 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { |
| 3601 AutocompleteInput input( | 3600 AutocompleteInput input( |
| 3602 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), | 3601 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), |
| 3603 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, | 3602 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, |
| 3604 ChromeAutocompleteSchemeClassifier(&profile_)); | 3603 ChromeAutocompleteSchemeClassifier(&profile_)); |
| 3605 provider_->Start(input, false); | 3604 provider_->Start(input, false); |
| 3606 EXPECT_TRUE(provider_->matches().empty()); | 3605 EXPECT_TRUE(provider_->matches().empty()); |
| 3607 } | 3606 } |
| OLD | NEW |