| 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 2489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2500 { | 2500 { |
| 2501 // Reset the session and check that bits are reset. | 2501 // Reset the session and check that bits are reset. |
| 2502 provider_->ResetSession(); | 2502 provider_->ResetSession(); |
| 2503 ProvidersInfo providers_info; | 2503 ProvidersInfo providers_info; |
| 2504 provider_->AddProviderInfo(&providers_info); | 2504 provider_->AddProviderInfo(&providers_info); |
| 2505 ASSERT_EQ(1U, providers_info.size()); | 2505 ASSERT_EQ(1U, providers_info.size()); |
| 2506 EXPECT_EQ(0, providers_info[0].field_trial_triggered_size()); | 2506 EXPECT_EQ(0, providers_info[0].field_trial_triggered_size()); |
| 2507 EXPECT_EQ(0, providers_info[0].field_trial_triggered_in_session_size()); | 2507 EXPECT_EQ(0, providers_info[0].field_trial_triggered_in_session_size()); |
| 2508 } | 2508 } |
| 2509 } | 2509 } |
| 2510 // A basic test that verifies the specific type identifier parsing logic. |
| 2511 TEST_F(SearchProviderTest, SpecificTypeIdentifierParsing) { |
| 2512 struct Match { |
| 2513 std::string contents; |
| 2514 int subtype_identifier; |
| 2515 }; |
| 2516 |
| 2517 struct { |
| 2518 const std::string input_text; |
| 2519 const std::string provider_response_json; |
| 2520 // The order of the expected matches is not important. |
| 2521 const Match expected_matches[2]; |
| 2522 } cases[] = { |
| 2523 // Check that the specific type is set to 0 when these values are not |
| 2524 // provide in the response. |
| 2525 {"a", |
| 2526 "[\"a\",[\"ab\",\"http://b.com\"],[],[], " |
| 2527 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]}]", |
| 2528 {{"ab", 0}, {"b.com", 0}}}, |
| 2529 |
| 2530 // Check that the specific type works for zero-suggest suggestions. |
| 2531 {"c", |
| 2532 "[\"c\",[\"cd\",\"http://d.com\"],[],[], " |
| 2533 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," |
| 2534 "\"google:subtypeid\":[1, 3]}]", |
| 2535 {{"cd", 1}, {"d.com", 3}}}, |
| 2536 |
| 2537 // Check that the specific type is set to zero when the number of |
| 2538 // suggestions is smaller than the number of id's provided. |
| 2539 {"foo", |
| 2540 "[\"foo\",[\"foo bar\", \"foo baz\"],[],[], " |
| 2541 "{\"google:suggesttype\":[\"QUERY\", \"QUERY\"]," |
| 2542 "\"google:subtypeid\":[1, 2, 3]}]", |
| 2543 {{"foo bar", 0}, {"foo baz", 0}}}, |
| 2544 |
| 2545 // Check that the specific type is set to zero when the number of |
| 2546 // suggestions is larger than the number of id's provided. |
| 2547 {"bar", |
| 2548 "[\"bar\",[\"bar foo\", \"bar foz\"],[],[], " |
| 2549 "{\"google:suggesttype\":[\"QUERY\", \"QUERY\"]," |
| 2550 "\"google:subtypeid\":[1]}]", |
| 2551 {{"bar foo", 0}, {"bar foz", 0}}}, |
| 2552 |
| 2553 // Check that ids stick to their suggestions when these are reordered |
| 2554 // based on suggetion relevance values. |
| 2555 {"e", |
| 2556 "[\"e\",[\"ef\",\"http://e.com\"],[],[], " |
| 2557 "{\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," |
| 2558 "\"google:suggestrelevance\":[9300, 9800]," |
| 2559 "\"google:subtypeid\":[2, 4]}]", |
| 2560 {{"ef", 2}, {"e.com", 4}}}}; |
| 2561 |
| 2562 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 2563 QueryForInputAndWaitForFetcherResponses( |
| 2564 ASCIIToUTF16(cases[i].input_text), false, |
| 2565 cases[i].provider_response_json, std::string()); |
| 2566 |
| 2567 // Check for the match and field trial triggered bits. |
| 2568 const ACMatches& matches = provider_->matches(); |
| 2569 ASSERT_FALSE(matches.empty()); |
| 2570 for (size_t j = 0; j < arraysize(cases[i].expected_matches); ++j) { |
| 2571 if (cases[i].expected_matches[j].contents == kNotApplicable) |
| 2572 continue; |
| 2573 AutocompleteMatch match; |
| 2574 EXPECT_TRUE(FindMatchWithContents( |
| 2575 ASCIIToUTF16(cases[i].expected_matches[j].contents), &match)); |
| 2576 EXPECT_EQ(cases[i].expected_matches[j].subtype_identifier, |
| 2577 match.subtype_identifier); |
| 2578 } |
| 2579 } |
| 2580 } |
| 2510 | 2581 |
| 2511 // Verifies inline autocompletion of navigational results. | 2582 // Verifies inline autocompletion of navigational results. |
| 2512 TEST_F(SearchProviderTest, NavigationInline) { | 2583 TEST_F(SearchProviderTest, NavigationInline) { |
| 2513 struct { | 2584 struct { |
| 2514 const std::string input; | 2585 const std::string input; |
| 2515 const std::string url; | 2586 const std::string url; |
| 2516 // Test the expected fill_into_edit, which may drop "http://". | 2587 // Test the expected fill_into_edit, which may drop "http://". |
| 2517 // Some cases do not trim "http://" to match from the start of the scheme. | 2588 // Some cases do not trim "http://" to match from the start of the scheme. |
| 2518 const std::string fill_into_edit; | 2589 const std::string fill_into_edit; |
| 2519 const std::string inline_autocompletion; | 2590 const std::string inline_autocompletion; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 "https://abc.com/path/file.htm?q=x#foo", | 2731 "https://abc.com/path/file.htm?q=x#foo", |
| 2661 "c.com/path/file.htm?q=x#foo", true, false }, | 2732 "c.com/path/file.htm?q=x#foo", true, false }, |
| 2662 | 2733 |
| 2663 }; | 2734 }; |
| 2664 | 2735 |
| 2665 for (size_t i = 0; i < arraysize(cases); ++i) { | 2736 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 2666 // First test regular mode. | 2737 // First test regular mode. |
| 2667 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); | 2738 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); |
| 2668 SearchSuggestionParser::NavigationResult result( | 2739 SearchSuggestionParser::NavigationResult result( |
| 2669 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), | 2740 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), |
| 2670 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), | 2741 AutocompleteMatchType::NAVSUGGEST, 0, base::string16(), std::string(), |
| 2671 false, 0, false, ASCIIToUTF16(cases[i].input)); | 2742 false, 0, false, ASCIIToUTF16(cases[i].input)); |
| 2672 result.set_received_after_last_keystroke(false); | 2743 result.set_received_after_last_keystroke(false); |
| 2673 AutocompleteMatch match(provider_->NavigationToMatch(result)); | 2744 AutocompleteMatch match(provider_->NavigationToMatch(result)); |
| 2674 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | 2745 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
| 2675 match.inline_autocompletion); | 2746 match.inline_autocompletion); |
| 2676 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); | 2747 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, | 2748 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_regular_mode, |
| 2678 match.allowed_to_be_default_match); | 2749 match.allowed_to_be_default_match); |
| 2679 | 2750 |
| 2680 // Then test prevent-inline-autocomplete mode. | 2751 // Then test prevent-inline-autocomplete mode. |
| 2681 QueryForInput(ASCIIToUTF16(cases[i].input), true, false); | 2752 QueryForInput(ASCIIToUTF16(cases[i].input), true, false); |
| 2682 SearchSuggestionParser::NavigationResult result_prevent_inline( | 2753 SearchSuggestionParser::NavigationResult result_prevent_inline( |
| 2683 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), | 2754 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), |
| 2684 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), | 2755 AutocompleteMatchType::NAVSUGGEST, 0, base::string16(), std::string(), |
| 2685 false, 0, false, ASCIIToUTF16(cases[i].input)); | 2756 false, 0, false, ASCIIToUTF16(cases[i].input)); |
| 2686 result_prevent_inline.set_received_after_last_keystroke(false); | 2757 result_prevent_inline.set_received_after_last_keystroke(false); |
| 2687 AutocompleteMatch match_prevent_inline( | 2758 AutocompleteMatch match_prevent_inline( |
| 2688 provider_->NavigationToMatch(result_prevent_inline)); | 2759 provider_->NavigationToMatch(result_prevent_inline)); |
| 2689 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | 2760 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
| 2690 match_prevent_inline.inline_autocompletion); | 2761 match_prevent_inline.inline_autocompletion); |
| 2691 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), | 2762 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), |
| 2692 match_prevent_inline.fill_into_edit); | 2763 match_prevent_inline.fill_into_edit); |
| 2693 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode, | 2764 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode, |
| 2694 match_prevent_inline.allowed_to_be_default_match); | 2765 match_prevent_inline.allowed_to_be_default_match); |
| 2695 } | 2766 } |
| 2696 } | 2767 } |
| 2697 | 2768 |
| 2698 // Verifies that "http://" is not trimmed for input that is a leading substring. | 2769 // Verifies that "http://" is not trimmed for input that is a leading substring. |
| 2699 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { | 2770 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { |
| 2700 const base::string16 input(ASCIIToUTF16("ht")); | 2771 const base::string16 input(ASCIIToUTF16("ht")); |
| 2701 const base::string16 url(ASCIIToUTF16("http://a.com")); | 2772 const base::string16 url(ASCIIToUTF16("http://a.com")); |
| 2702 SearchSuggestionParser::NavigationResult result( | 2773 SearchSuggestionParser::NavigationResult result( |
| 2703 ChromeAutocompleteSchemeClassifier(&profile_), GURL(url), | 2774 ChromeAutocompleteSchemeClassifier(&profile_), GURL(url), |
| 2704 AutocompleteMatchType::NAVSUGGEST, | 2775 AutocompleteMatchType::NAVSUGGEST, 0, base::string16(), std::string(), |
| 2705 base::string16(), std::string(), false, 0, false, input); | 2776 false, 0, false, input); |
| 2706 result.set_received_after_last_keystroke(false); | 2777 result.set_received_after_last_keystroke(false); |
| 2707 | 2778 |
| 2708 // Check the offset and strings when inline autocompletion is allowed. | 2779 // Check the offset and strings when inline autocompletion is allowed. |
| 2709 QueryForInput(input, false, false); | 2780 QueryForInput(input, false, false); |
| 2710 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); | 2781 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); |
| 2711 EXPECT_EQ(url, match_inline.fill_into_edit); | 2782 EXPECT_EQ(url, match_inline.fill_into_edit); |
| 2712 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); | 2783 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); |
| 2713 EXPECT_TRUE(match_inline.allowed_to_be_default_match); | 2784 EXPECT_TRUE(match_inline.allowed_to_be_default_match); |
| 2714 EXPECT_EQ(url, match_inline.contents); | 2785 EXPECT_EQ(url, match_inline.contents); |
| 2715 | 2786 |
| 2716 // Check the same strings when inline autocompletion is prevented. | 2787 // Check the same strings when inline autocompletion is prevented. |
| 2717 QueryForInput(input, true, false); | 2788 QueryForInput(input, true, false); |
| 2718 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); | 2789 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); |
| 2719 EXPECT_EQ(url, match_prevent.fill_into_edit); | 2790 EXPECT_EQ(url, match_prevent.fill_into_edit); |
| 2720 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); | 2791 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); |
| 2721 EXPECT_EQ(url, match_prevent.contents); | 2792 EXPECT_EQ(url, match_prevent.contents); |
| 2722 } | 2793 } |
| 2723 | 2794 |
| 2724 // Verifies that input "w" marks a more significant domain label than "www.". | 2795 // Verifies that input "w" marks a more significant domain label than "www.". |
| 2725 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { | 2796 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { |
| 2726 QueryForInput(ASCIIToUTF16("w"), false, false); | 2797 QueryForInput(ASCIIToUTF16("w"), false, false); |
| 2727 SearchSuggestionParser::NavigationResult result( | 2798 SearchSuggestionParser::NavigationResult result( |
| 2728 ChromeAutocompleteSchemeClassifier(&profile_), | 2799 ChromeAutocompleteSchemeClassifier(&profile_), GURL("http://www.wow.com"), |
| 2729 GURL("http://www.wow.com"), AutocompleteMatchType::NAVSUGGEST, | 2800 AutocompleteMatchType::NAVSUGGEST, 0, base::string16(), std::string(), |
| 2730 base::string16(), std::string(), false, 0, false, ASCIIToUTF16("w")); | 2801 false, 0, false, ASCIIToUTF16("w")); |
| 2731 result.set_received_after_last_keystroke(false); | 2802 result.set_received_after_last_keystroke(false); |
| 2732 AutocompleteMatch match(provider_->NavigationToMatch(result)); | 2803 AutocompleteMatch match(provider_->NavigationToMatch(result)); |
| 2733 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); | 2804 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); |
| 2734 EXPECT_TRUE(match.allowed_to_be_default_match); | 2805 EXPECT_TRUE(match.allowed_to_be_default_match); |
| 2735 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); | 2806 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); |
| 2736 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); | 2807 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); |
| 2737 | 2808 |
| 2738 // Ensure that the match for input "w" is marked on "wow" and not "www". | 2809 // Ensure that the match for input "w" is marked on "wow" and not "www". |
| 2739 ASSERT_EQ(3U, match.contents_class.size()); | 2810 ASSERT_EQ(3U, match.contents_class.size()); |
| 2740 EXPECT_EQ(0U, match.contents_class[0].offset); | 2811 EXPECT_EQ(0U, match.contents_class[0].offset); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2850 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 2921 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 2851 false }; | 2922 false }; |
| 2852 | 2923 |
| 2853 struct { | 2924 struct { |
| 2854 const std::string input_text; | 2925 const std::string input_text; |
| 2855 bool prefer_keyword_provider_results; | 2926 bool prefer_keyword_provider_results; |
| 2856 const std::string default_provider_response_json; | 2927 const std::string default_provider_response_json; |
| 2857 const std::string keyword_provider_response_json; | 2928 const std::string keyword_provider_response_json; |
| 2858 const Match matches[5]; | 2929 const Match matches[5]; |
| 2859 } cases[] = { | 2930 } cases[] = { |
| 2860 // Default provider response does not have prefetch details. Ensure that the | 2931 // Default provider response does not have prefetch details. Ensure that |
| 2861 // suggestions are not marked as prefetch query. | 2932 // the suggestions are not marked as prefetch query. |
| 2862 { "a", | 2933 { |
| 2863 false, | 2934 "a", |
| 2864 "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", | 2935 false, |
| 2865 std::string(), | 2936 "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", |
| 2866 { { "a", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false }, | 2937 std::string(), |
| 2867 { "c", false, AutocompleteMatchType::SEARCH_SUGGEST, false }, | 2938 {{"a", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false}, |
| 2868 { "b", false, AutocompleteMatchType::SEARCH_SUGGEST, false }, | 2939 {"c", false, AutocompleteMatchType::SEARCH_SUGGEST, false}, |
| 2869 kEmptyMatch, | 2940 {"b", false, AutocompleteMatchType::SEARCH_SUGGEST, false}, |
| 2870 kEmptyMatch | 2941 kEmptyMatch, |
| 2942 kEmptyMatch}, |
| 2871 }, | 2943 }, |
| 2872 }, | 2944 // Ensure that default provider suggest response prefetch details are |
| 2873 // Ensure that default provider suggest response prefetch details are | 2945 // parsed and recorded in AutocompleteMatch. |
| 2874 // parsed and recorded in AutocompleteMatch. | 2946 { |
| 2875 { "ab", | 2947 "ab", |
| 2876 false, | 2948 false, |
| 2877 "[\"ab\",[\"abc\", \"http://b.com\", \"http://c.com\"],[],[]," | 2949 "[\"ab\",[\"abc\", \"http://b.com\", \"http://c.com\"],[],[]," |
| 2878 "{\"google:clientdata\":{\"phi\": 0}," | 2950 "{\"google:clientdata\":{\"phi\": 0}," |
| 2879 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\", \"NAVIGATION\"]," | 2951 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\", \"NAVIGATION\"]," |
| 2880 "\"google:suggestrelevance\":[999, 12, 1]}]", | 2952 "\"google:suggestrelevance\":[999, 12, 1]}]", |
| 2881 std::string(), | 2953 std::string(), |
| 2882 { { "ab", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false }, | 2954 {{"ab", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false}, |
| 2883 { "abc", true, AutocompleteMatchType::SEARCH_SUGGEST, false }, | 2955 {"abc", true, AutocompleteMatchType::SEARCH_SUGGEST, false}, |
| 2884 { "b.com", false, AutocompleteMatchType::NAVSUGGEST, false }, | 2956 {"b.com", false, AutocompleteMatchType::NAVSUGGEST, false}, |
| 2885 { "c.com", false, AutocompleteMatchType::NAVSUGGEST, false }, | 2957 {"c.com", false, AutocompleteMatchType::NAVSUGGEST, false}, |
| 2886 kEmptyMatch | 2958 kEmptyMatch}, |
| 2887 }, | 2959 }, |
| 2888 }, | 2960 // Default provider suggest response has prefetch details. |
| 2889 // Default provider suggest response has prefetch details. | 2961 // SEARCH_WHAT_YOU_TYPE suggestion outranks SEARCH_SUGGEST suggestion for |
| 2890 // SEARCH_WHAT_YOU_TYPE suggestion outranks SEARCH_SUGGEST suggestion for | 2962 // the same query string. Ensure that the prefetch details from |
| 2891 // the same query string. Ensure that the prefetch details from | 2963 // SEARCH_SUGGEST match are set onto SEARCH_WHAT_YOU_TYPE match. |
| 2892 // SEARCH_SUGGEST match are set onto SEARCH_WHAT_YOU_TYPE match. | 2964 { |
| 2893 { "ab", | 2965 "ab", |
| 2894 false, | 2966 false, |
| 2895 "[\"ab\",[\"ab\", \"http://ab.com\"],[],[]," | 2967 "[\"ab\",[\"ab\", \"http://ab.com\"],[],[]," |
| 2896 "{\"google:clientdata\":{\"phi\": 0}," | 2968 "{\"google:clientdata\":{\"phi\": 0}," |
| 2897 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," | 2969 "\"google:suggesttype\":[\"QUERY\", \"NAVIGATION\"]," |
| 2898 "\"google:suggestrelevance\":[99, 98]}]", | 2970 "\"google:suggestrelevance\":[99, 98]}]", |
| 2899 std::string(), | 2971 std::string(), |
| 2900 { {"ab", true, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false }, | 2972 {{"ab", true, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false}, |
| 2901 {"ab.com", false, AutocompleteMatchType::NAVSUGGEST, false }, | 2973 {"ab.com", false, AutocompleteMatchType::NAVSUGGEST, false}, |
| 2902 kEmptyMatch, | 2974 kEmptyMatch, |
| 2903 kEmptyMatch, | 2975 kEmptyMatch, |
| 2904 kEmptyMatch | 2976 kEmptyMatch}, |
| 2905 }, | 2977 }, |
| 2906 }, | 2978 // Default provider response has prefetch details. We prefer keyword |
| 2907 // Default provider response has prefetch details. We prefer keyword | 2979 // provider results. Ensure that prefetch bit for a suggestion from the |
| 2908 // provider results. Ensure that prefetch bit for a suggestion from the | 2980 // default search provider does not get copied onto a higher-scoring match |
| 2909 // default search provider does not get copied onto a higher-scoring match | 2981 // for the same query string from the keyword provider. |
| 2910 // for the same query string from the keyword provider. | 2982 { |
| 2911 { "k a", | 2983 "k a", |
| 2912 true, | 2984 true, |
| 2913 "[\"k a\",[\"a\", \"ab\"],[],[], {\"google:clientdata\":{\"phi\": 0}," | 2985 "[\"k a\",[\"a\", \"ab\"],[],[], {\"google:clientdata\":{\"phi\": 0}," |
| 2914 "\"google:suggesttype\":[\"QUERY\", \"QUERY\"]," | 2986 "\"google:suggesttype\":[\"QUERY\", \"QUERY\"]," |
| 2915 "\"google:suggestrelevance\":[9, 12]}]", | 2987 "\"google:suggestrelevance\":[9, 12]}]", |
| 2916 "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", | 2988 "[\"a\",[\"b\", \"c\"],[],[],{\"google:suggestrelevance\":[1, 2]}]", |
| 2917 { { "a", false, AutocompleteMatchType::SEARCH_OTHER_ENGINE, true}, | 2989 {{"a", false, AutocompleteMatchType::SEARCH_OTHER_ENGINE, true}, |
| 2918 { "k a", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false }, | 2990 {"k a", false, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, false}, |
| 2919 { "ab", false, AutocompleteMatchType::SEARCH_SUGGEST, false }, | 2991 {"ab", false, AutocompleteMatchType::SEARCH_SUGGEST, false}, |
| 2920 { "c", false, AutocompleteMatchType::SEARCH_SUGGEST, true }, | 2992 {"c", false, AutocompleteMatchType::SEARCH_SUGGEST, true}, |
| 2921 { "b", false, AutocompleteMatchType::SEARCH_SUGGEST, true } | 2993 {"b", false, AutocompleteMatchType::SEARCH_SUGGEST, true}}, |
| 2922 }, | 2994 }}; |
| 2923 } | |
| 2924 }; | |
| 2925 | 2995 |
| 2926 for (size_t i = 0; i < arraysize(cases); ++i) { | 2996 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 2927 QueryForInputAndWaitForFetcherResponses( | 2997 QueryForInputAndWaitForFetcherResponses( |
| 2928 ASCIIToUTF16(cases[i].input_text), | 2998 ASCIIToUTF16(cases[i].input_text), |
| 2929 cases[i].prefer_keyword_provider_results, | 2999 cases[i].prefer_keyword_provider_results, |
| 2930 cases[i].default_provider_response_json, | 3000 cases[i].default_provider_response_json, |
| 2931 cases[i].prefer_keyword_provider_results ? | 3001 cases[i].prefer_keyword_provider_results ? |
| 2932 cases[i].keyword_provider_response_json : std::string()); | 3002 cases[i].keyword_provider_response_json : std::string()); |
| 2933 | 3003 |
| 2934 const std::string description = | 3004 const std::string description = |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3467 ASSERT_FALSE(provider_->answers_cache_.empty()); | 3537 ASSERT_FALSE(provider_->answers_cache_.empty()); |
| 3468 | 3538 |
| 3469 // Without scored results, no answers will be retrieved. | 3539 // Without scored results, no answers will be retrieved. |
| 3470 AnswersQueryData answer = provider_->FindAnswersPrefetchData(); | 3540 AnswersQueryData answer = provider_->FindAnswersPrefetchData(); |
| 3471 EXPECT_TRUE(answer.full_query_text.empty()); | 3541 EXPECT_TRUE(answer.full_query_text.empty()); |
| 3472 EXPECT_TRUE(answer.query_type.empty()); | 3542 EXPECT_TRUE(answer.query_type.empty()); |
| 3473 | 3543 |
| 3474 // Inject a scored result, which will trigger answer retrieval. | 3544 // Inject a scored result, which will trigger answer retrieval. |
| 3475 base::string16 query = base::ASCIIToUTF16("weather los angeles"); | 3545 base::string16 query = base::ASCIIToUTF16("weather los angeles"); |
| 3476 SearchSuggestionParser::SuggestResult suggest_result( | 3546 SearchSuggestionParser::SuggestResult suggest_result( |
| 3477 query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(), | 3547 query, AutocompleteMatchType::SEARCH_HISTORY, 0, query, base::string16(), |
| 3478 base::string16(), base::string16(), base::string16(), nullptr, | 3548 base::string16(), base::string16(), base::string16(), nullptr, |
| 3479 std::string(), std::string(), false, 1200, false, false, query); | 3549 std::string(), std::string(), false, 1200, false, false, query); |
| 3480 QueryForInput(ASCIIToUTF16("weather l"), false, false); | 3550 QueryForInput(ASCIIToUTF16("weather l"), false, false); |
| 3481 provider_->transformed_default_history_results_.push_back(suggest_result); | 3551 provider_->transformed_default_history_results_.push_back(suggest_result); |
| 3482 answer = provider_->FindAnswersPrefetchData(); | 3552 answer = provider_->FindAnswersPrefetchData(); |
| 3483 EXPECT_EQ(base::ASCIIToUTF16("weather los angeles"), answer.full_query_text); | 3553 EXPECT_EQ(base::ASCIIToUTF16("weather los angeles"), answer.full_query_text); |
| 3484 EXPECT_EQ(base::ASCIIToUTF16("2334"), answer.query_type); | 3554 EXPECT_EQ(base::ASCIIToUTF16("2334"), answer.query_type); |
| 3485 } | 3555 } |
| 3486 | 3556 |
| 3487 TEST_F(SearchProviderTest, RemoveExtraAnswers) { | 3557 TEST_F(SearchProviderTest, RemoveExtraAnswers) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3566 EXPECT_TRUE(fetcher); | 3636 EXPECT_TRUE(fetcher); |
| 3567 // Even if the fetcher returns results, we should still have no suggestions | 3637 // Even if the fetcher returns results, we should still have no suggestions |
| 3568 // (though the provider should now be done). | 3638 // (though the provider should now be done). |
| 3569 fetcher->set_response_code(200); | 3639 fetcher->set_response_code(200); |
| 3570 fetcher->SetResponseString(R"(["",["a", "b"],[],[],{}])"); | 3640 fetcher->SetResponseString(R"(["",["a", "b"],[],[],{}])"); |
| 3571 fetcher->delegate()->OnURLFetchComplete(fetcher); | 3641 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 3572 RunTillProviderDone(); | 3642 RunTillProviderDone(); |
| 3573 EXPECT_TRUE(provider_->done()); | 3643 EXPECT_TRUE(provider_->done()); |
| 3574 EXPECT_TRUE(provider_->matches().empty()); | 3644 EXPECT_TRUE(provider_->matches().empty()); |
| 3575 } | 3645 } |
| OLD | NEW |