Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
|
Mark P
2017/03/21 19:54:24
Please add a test here that we're parsing / extrac
gcomanici
2017/03/22 02:39:03
Done.
| |
| 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 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| (...skipping 2649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2661 "c.com/path/file.htm?q=x#foo", true, false }, | 2661 "c.com/path/file.htm?q=x#foo", true, false }, |
| 2662 | 2662 |
| 2663 }; | 2663 }; |
| 2664 | 2664 |
| 2665 for (size_t i = 0; i < arraysize(cases); ++i) { | 2665 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 2666 // First test regular mode. | 2666 // First test regular mode. |
| 2667 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); | 2667 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); |
| 2668 SearchSuggestionParser::NavigationResult result( | 2668 SearchSuggestionParser::NavigationResult result( |
| 2669 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), | 2669 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), |
| 2670 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), | 2670 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), |
| 2671 false, 0, false, ASCIIToUTF16(cases[i].input)); | 2671 false, 0, false, ASCIIToUTF16(cases[i].input), 0); |
| 2672 result.set_received_after_last_keystroke(false); | 2672 result.set_received_after_last_keystroke(false); |
| 2673 AutocompleteMatch match(provider_->NavigationToMatch(result)); | 2673 AutocompleteMatch match(provider_->NavigationToMatch(result)); |
| 2674 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | 2674 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
| 2675 match.inline_autocompletion); | 2675 match.inline_autocompletion); |
| 2676 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); | 2676 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); |
| 2677 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_regular_mode, | 2677 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_regular_mode, |
| 2678 match.allowed_to_be_default_match); | 2678 match.allowed_to_be_default_match); |
| 2679 | 2679 |
| 2680 // Then test prevent-inline-autocomplete mode. | 2680 // Then test prevent-inline-autocomplete mode. |
| 2681 QueryForInput(ASCIIToUTF16(cases[i].input), true, false); | 2681 QueryForInput(ASCIIToUTF16(cases[i].input), true, false); |
| 2682 SearchSuggestionParser::NavigationResult result_prevent_inline( | 2682 SearchSuggestionParser::NavigationResult result_prevent_inline( |
| 2683 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), | 2683 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), |
| 2684 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), | 2684 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), |
| 2685 false, 0, false, ASCIIToUTF16(cases[i].input)); | 2685 false, 0, false, ASCIIToUTF16(cases[i].input), 0); |
| 2686 result_prevent_inline.set_received_after_last_keystroke(false); | 2686 result_prevent_inline.set_received_after_last_keystroke(false); |
| 2687 AutocompleteMatch match_prevent_inline( | 2687 AutocompleteMatch match_prevent_inline( |
| 2688 provider_->NavigationToMatch(result_prevent_inline)); | 2688 provider_->NavigationToMatch(result_prevent_inline)); |
| 2689 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | 2689 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
| 2690 match_prevent_inline.inline_autocompletion); | 2690 match_prevent_inline.inline_autocompletion); |
| 2691 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), | 2691 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), |
| 2692 match_prevent_inline.fill_into_edit); | 2692 match_prevent_inline.fill_into_edit); |
| 2693 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode, | 2693 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode, |
| 2694 match_prevent_inline.allowed_to_be_default_match); | 2694 match_prevent_inline.allowed_to_be_default_match); |
| 2695 } | 2695 } |
| 2696 } | 2696 } |
| 2697 | 2697 |
| 2698 // Verifies that "http://" is not trimmed for input that is a leading substring. | 2698 // Verifies that "http://" is not trimmed for input that is a leading substring. |
| 2699 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { | 2699 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { |
| 2700 const base::string16 input(ASCIIToUTF16("ht")); | 2700 const base::string16 input(ASCIIToUTF16("ht")); |
| 2701 const base::string16 url(ASCIIToUTF16("http://a.com")); | 2701 const base::string16 url(ASCIIToUTF16("http://a.com")); |
| 2702 SearchSuggestionParser::NavigationResult result( | 2702 SearchSuggestionParser::NavigationResult result( |
| 2703 ChromeAutocompleteSchemeClassifier(&profile_), GURL(url), | 2703 ChromeAutocompleteSchemeClassifier(&profile_), GURL(url), |
| 2704 AutocompleteMatchType::NAVSUGGEST, | 2704 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), false, |
| 2705 base::string16(), std::string(), false, 0, false, input); | 2705 0, false, input, 0); |
| 2706 result.set_received_after_last_keystroke(false); | 2706 result.set_received_after_last_keystroke(false); |
| 2707 | 2707 |
| 2708 // Check the offset and strings when inline autocompletion is allowed. | 2708 // Check the offset and strings when inline autocompletion is allowed. |
| 2709 QueryForInput(input, false, false); | 2709 QueryForInput(input, false, false); |
| 2710 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); | 2710 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); |
| 2711 EXPECT_EQ(url, match_inline.fill_into_edit); | 2711 EXPECT_EQ(url, match_inline.fill_into_edit); |
| 2712 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); | 2712 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); |
| 2713 EXPECT_TRUE(match_inline.allowed_to_be_default_match); | 2713 EXPECT_TRUE(match_inline.allowed_to_be_default_match); |
| 2714 EXPECT_EQ(url, match_inline.contents); | 2714 EXPECT_EQ(url, match_inline.contents); |
| 2715 | 2715 |
| 2716 // Check the same strings when inline autocompletion is prevented. | 2716 // Check the same strings when inline autocompletion is prevented. |
| 2717 QueryForInput(input, true, false); | 2717 QueryForInput(input, true, false); |
| 2718 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); | 2718 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); |
| 2719 EXPECT_EQ(url, match_prevent.fill_into_edit); | 2719 EXPECT_EQ(url, match_prevent.fill_into_edit); |
| 2720 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); | 2720 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); |
| 2721 EXPECT_EQ(url, match_prevent.contents); | 2721 EXPECT_EQ(url, match_prevent.contents); |
| 2722 } | 2722 } |
| 2723 | 2723 |
| 2724 // Verifies that input "w" marks a more significant domain label than "www.". | 2724 // Verifies that input "w" marks a more significant domain label than "www.". |
| 2725 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { | 2725 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { |
| 2726 QueryForInput(ASCIIToUTF16("w"), false, false); | 2726 QueryForInput(ASCIIToUTF16("w"), false, false); |
| 2727 SearchSuggestionParser::NavigationResult result( | 2727 SearchSuggestionParser::NavigationResult result( |
| 2728 ChromeAutocompleteSchemeClassifier(&profile_), | 2728 ChromeAutocompleteSchemeClassifier(&profile_), GURL("http://www.wow.com"), |
| 2729 GURL("http://www.wow.com"), AutocompleteMatchType::NAVSUGGEST, | 2729 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), false, |
| 2730 base::string16(), std::string(), false, 0, false, ASCIIToUTF16("w")); | 2730 0, false, ASCIIToUTF16("w"), 0); |
| 2731 result.set_received_after_last_keystroke(false); | 2731 result.set_received_after_last_keystroke(false); |
| 2732 AutocompleteMatch match(provider_->NavigationToMatch(result)); | 2732 AutocompleteMatch match(provider_->NavigationToMatch(result)); |
| 2733 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); | 2733 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); |
| 2734 EXPECT_TRUE(match.allowed_to_be_default_match); | 2734 EXPECT_TRUE(match.allowed_to_be_default_match); |
| 2735 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); | 2735 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); |
| 2736 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); | 2736 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); |
| 2737 | 2737 |
| 2738 // Ensure that the match for input "w" is marked on "wow" and not "www". | 2738 // Ensure that the match for input "w" is marked on "wow" and not "www". |
| 2739 ASSERT_EQ(3U, match.contents_class.size()); | 2739 ASSERT_EQ(3U, match.contents_class.size()); |
| 2740 EXPECT_EQ(0U, match.contents_class[0].offset); | 2740 EXPECT_EQ(0U, match.contents_class[0].offset); |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3566 EXPECT_TRUE(fetcher); | 3566 EXPECT_TRUE(fetcher); |
| 3567 // Even if the fetcher returns results, we should still have no suggestions | 3567 // Even if the fetcher returns results, we should still have no suggestions |
| 3568 // (though the provider should now be done). | 3568 // (though the provider should now be done). |
| 3569 fetcher->set_response_code(200); | 3569 fetcher->set_response_code(200); |
| 3570 fetcher->SetResponseString(R"(["",["a", "b"],[],[],{}])"); | 3570 fetcher->SetResponseString(R"(["",["a", "b"],[],[],{}])"); |
| 3571 fetcher->delegate()->OnURLFetchComplete(fetcher); | 3571 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 3572 RunTillProviderDone(); | 3572 RunTillProviderDone(); |
| 3573 EXPECT_TRUE(provider_->done()); | 3573 EXPECT_TRUE(provider_->done()); |
| 3574 EXPECT_TRUE(provider_->matches().empty()); | 3574 EXPECT_TRUE(provider_->matches().empty()); |
| 3575 } | 3575 } |
| OLD | NEW |