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 "chrome/browser/autocomplete/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 3336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3347 if (suggestion == kNotApplicable) | 3347 if (suggestion == kNotApplicable) |
3348 break; | 3348 break; |
3349 if (cases[i].results[j].is_navigation_result) { | 3349 if (cases[i].results[j].is_navigation_result) { |
3350 provider_->default_results_.navigation_results.push_back( | 3350 provider_->default_results_.navigation_results.push_back( |
3351 SearchProvider::NavigationResult( | 3351 SearchProvider::NavigationResult( |
3352 *provider_.get(), GURL(suggestion), string16(), false, | 3352 *provider_.get(), GURL(suggestion), string16(), false, |
3353 cases[i].results[j].relevance, false)); | 3353 cases[i].results[j].relevance, false)); |
3354 } else { | 3354 } else { |
3355 provider_->default_results_.suggest_results.push_back( | 3355 provider_->default_results_.suggest_results.push_back( |
3356 SearchProvider::SuggestResult(ASCIIToUTF16(suggestion), string16(), | 3356 SearchProvider::SuggestResult(ASCIIToUTF16(suggestion), string16(), |
3357 string16(), std::string(), false, | 3357 string16(), std::string(), |
3358 std::string(), false, | |
3358 cases[i].results[j].relevance, | 3359 cases[i].results[j].relevance, |
3359 false, false)); | 3360 false, false)); |
3360 } | 3361 } |
3361 } | 3362 } |
3362 | 3363 |
3363 provider_->input_ = AutocompleteInput( | 3364 provider_->input_ = AutocompleteInput( |
3364 ASCIIToUTF16(cases[i].omnibox_input), string16::npos, string16(), | 3365 ASCIIToUTF16(cases[i].omnibox_input), string16::npos, string16(), |
3365 GURL(), AutocompleteInput::INVALID_SPEC, false, false, true, | 3366 GURL(), AutocompleteInput::INVALID_SPEC, false, false, true, |
3366 AutocompleteInput::ALL_MATCHES); | 3367 AutocompleteInput::ALL_MATCHES); |
3367 provider_->RemoveAllStaleResults(); | 3368 provider_->RemoveAllStaleResults(); |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3828 EXPECT_EQ(cases[i].matches[j].type, matches[j].type); | 3829 EXPECT_EQ(cases[i].matches[j].type, matches[j].type); |
3829 } | 3830 } |
3830 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) { | 3831 for (; j < ARRAYSIZE_UNSAFE(cases[i].matches); ++j) { |
3831 SCOPED_TRACE("and match: " + base::IntToString(j)); | 3832 SCOPED_TRACE("and match: " + base::IntToString(j)); |
3832 EXPECT_EQ(cases[i].matches[j].contents, kNotApplicable); | 3833 EXPECT_EQ(cases[i].matches[j].contents, kNotApplicable); |
3833 EXPECT_EQ(cases[i].matches[j].type, AutocompleteMatchType::NUM_TYPES); | 3834 EXPECT_EQ(cases[i].matches[j].type, AutocompleteMatchType::NUM_TYPES); |
3834 } | 3835 } |
3835 } | 3836 } |
3836 } | 3837 } |
3837 | 3838 |
3839 // Test that deletion url gets set on an AutocompleteMatch when available for a | |
3840 // personalized query. | |
3841 TEST_F(SearchProviderTest, ParseDeletionUrl) { | |
3842 struct Match { | |
3843 std::string contents; | |
3844 std::string deletion_url; | |
3845 AutocompleteMatchType::Type type; | |
3846 }; | |
3847 | |
3848 const Match kEmptyMatch = { | |
3849 kNotApplicable, "", AutocompleteMatchType::NUM_TYPES}; | |
Peter Kasting
2013/11/27 21:58:19
Nit: "" -> std::string()
Place '}' on the start o
Maria
2013/11/28 00:17:03
Done.
| |
3850 | |
3851 const char url[] = "https://www.google.com/complete/deleteitems" | |
3852 "?delq=ab&client=chrome&deltok=xsrf123"; | |
3853 | |
3854 struct { | |
3855 const std::string input_text; | |
3856 const std::string response_json; | |
3857 const Match matches[4]; | |
3858 } cases[] = { | |
3859 // Personalized query comes with a deletion url | |
Peter Kasting
2013/11/27 21:58:19
Nit: How about:
A deletion URL on a personalized
Maria
2013/11/28 00:17:03
Done.
| |
3860 { "a", | |
3861 "[\"a\",[\"ab\", \"ac\"],[],[]," | |
3862 "{\"google:suggesttype\":[\"PERSONALIZED_QUERY\",\"QUERY\"]," | |
3863 "\"google:suggestrelevance\":[1, 2]," | |
3864 "\"google:suggestdetail\":[{\"du\":" | |
3865 "\"https://www.google.com/complete/deleteitems?delq=ab&client=chrome" | |
3866 "&deltok=xsrf123\"}, {}]}]", | |
3867 { { "a", "", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED }, | |
3868 { "ac", "", AutocompleteMatchType::SEARCH_SUGGEST }, | |
3869 { "ab", url, AutocompleteMatchType::SEARCH_SUGGEST }, | |
3870 kEmptyMatch, | |
3871 }, | |
3872 }, | |
3873 // Personalized query, but no deletion url in response -- old server case | |
Peter Kasting
2013/11/27 21:58:19
Nit: How about:
Personalized queries without dele
Maria
2013/11/28 00:17:03
Done.
| |
3874 { "a", | |
3875 "[\"a\",[\"ab\", \"ac\"],[],[]," | |
3876 "{\"google:suggesttype\":[\"PERSONALIZED_QUERY\",\"QUERY\"]," | |
3877 "\"google:suggestrelevance\":[1, 2]," | |
3878 "\"google:suggestdetail\":[{}, {}]}]", | |
3879 { { "a", "", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED }, | |
3880 { "ac", "", AutocompleteMatchType::SEARCH_SUGGEST }, | |
3881 { "ab", "", AutocompleteMatchType::SEARCH_SUGGEST }, | |
3882 kEmptyMatch, | |
3883 }, | |
3884 }, | |
3885 // Unexpected: non-personalized query comes with a deletion url, this | |
3886 // should be ignored. | |
Peter Kasting
2013/11/27 21:58:19
Is there any particular reason why we should ignor
Maria
2013/11/28 00:17:03
During results parsing we don't bother looking at
Peter Kasting
2013/11/28 00:44:17
I left a comment on that code.
| |
3887 { "a", | |
3888 "[\"a\",[\"ab\", \"ac\"],[],[]," | |
3889 "{\"google:suggesttype\":[\"PERSONALIZED_QUERY\",\"QUERY\"]," | |
3890 "\"google:suggestrelevance\":[1, 2]," | |
3891 "\"google:suggestdetail\":[{\"du\":\"" | |
3892 "https://www.google.com/complete/deleteitems?delq=ab&" | |
3893 "client=chrome&deltok=xsrf123\"}, {\"du\":\"" | |
3894 "https://www.google.com/complete/deleteitems?delq=ab&" | |
3895 "client=chrome&deltok=xsrf123\"}]}]", | |
3896 { { "a", "", AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED }, | |
3897 { "ac", "", AutocompleteMatchType::SEARCH_SUGGEST }, | |
3898 { "ab", url, AutocompleteMatchType::SEARCH_SUGGEST }, | |
3899 kEmptyMatch, | |
3900 }, | |
3901 }, | |
3902 }; | |
3903 | |
3904 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | |
3905 QueryForInput(ASCIIToUTF16(cases[i].input_text), false, false); | |
3906 | |
3907 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | |
3908 SearchProvider::kDefaultProviderURLFetcherID); | |
3909 ASSERT_TRUE(fetcher); | |
3910 fetcher->set_response_code(200); | |
3911 fetcher->SetResponseString(cases[i].response_json); | |
3912 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
3913 | |
3914 RunTillProviderDone(); | |
3915 | |
3916 const ACMatches& matches = provider_->matches(); | |
3917 ASSERT_FALSE(matches.empty()); | |
3918 | |
3919 SCOPED_TRACE("for input with json = " + cases[i].response_json); | |
3920 | |
3921 for (size_t j = 0; j < matches.size(); ++j) { | |
3922 const Match& match = cases[i].matches[j]; | |
3923 SCOPED_TRACE(" and match index: " + base::IntToString(j)); | |
3924 EXPECT_EQ(match.contents, UTF16ToUTF8(matches[j].contents)); | |
3925 EXPECT_EQ(match.deletion_url, matches[j].GetAdditionalInfo( | |
3926 "deletion_url")); | |
3927 } | |
3928 } | |
3929 } | |
3838 | 3930 |
3839 TEST_F(SearchProviderTest, ReflectsBookmarkBarState) { | 3931 TEST_F(SearchProviderTest, ReflectsBookmarkBarState) { |
3840 profile_.GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, false); | 3932 profile_.GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, false); |
3841 string16 term = term1_.substr(0, term1_.length() - 1); | 3933 string16 term = term1_.substr(0, term1_.length() - 1); |
3842 QueryForInput(term, true, false); | 3934 QueryForInput(term, true, false); |
3843 ASSERT_FALSE(provider_->matches().empty()); | 3935 ASSERT_FALSE(provider_->matches().empty()); |
3844 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 3936 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
3845 provider_->matches()[0].type); | 3937 provider_->matches()[0].type); |
3846 ASSERT_TRUE(provider_->matches()[0].search_terms_args != NULL); | 3938 ASSERT_TRUE(provider_->matches()[0].search_terms_args != NULL); |
3847 EXPECT_FALSE(provider_->matches()[0].search_terms_args->bookmark_bar_pinned); | 3939 EXPECT_FALSE(provider_->matches()[0].search_terms_args->bookmark_bar_pinned); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3974 AutocompleteInput::OTHER, &profile_)); | 4066 AutocompleteInput::OTHER, &profile_)); |
3975 encrypted_types.Remove(syncer::SESSIONS); | 4067 encrypted_types.Remove(syncer::SESSIONS); |
3976 service->OnEncryptedTypesChanged(encrypted_types, false); | 4068 service->OnEncryptedTypesChanged(encrypted_types, false); |
3977 | 4069 |
3978 // Check that there were no side effects from previous tests. | 4070 // Check that there were no side effects from previous tests. |
3979 EXPECT_TRUE(SearchProvider::CanSendURL( | 4071 EXPECT_TRUE(SearchProvider::CanSendURL( |
3980 GURL("http://www.google.com/search"), | 4072 GURL("http://www.google.com/search"), |
3981 GURL("https://www.google.com/complete/search"), &google_template_url, | 4073 GURL("https://www.google.com/complete/search"), &google_template_url, |
3982 AutocompleteInput::OTHER, &profile_)); | 4074 AutocompleteInput::OTHER, &profile_)); |
3983 } | 4075 } |
4076 | |
4077 TEST_F(SearchProviderTest, TestDeleteMatch_HasDeletionUrlSuccess) { | |
4078 AutocompleteMatch m( | |
Peter Kasting
2013/11/27 21:58:19
Tiny nit: |match| would be a better name than |m|
Maria
2013/11/28 00:17:03
Done.
| |
4079 provider_, | |
Peter Kasting
2013/11/27 21:58:19
Nit: For an arg list this short, I'd just wrap as:
Maria
2013/11/28 00:17:03
Done.
| |
4080 0, | |
4081 true, | |
4082 AutocompleteMatchType::SEARCH_SUGGEST); | |
4083 m.RecordAdditionalInfo(SearchProvider::kDeletionUrlKey, | |
4084 "https://www.google.com/complete/deleteitem?q=foo"); | |
4085 provider_->matches_.push_back(m); | |
4086 provider_->DeleteMatch(m); | |
Peter Kasting
2013/11/27 21:58:19
Seems like after this line, we should check that |
Maria
2013/11/28 00:17:03
Done.
| |
4087 // Set up a default fetcher with provided results. | |
4088 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | |
4089 SearchProvider::kDeletionURLFetcherID); | |
4090 ASSERT_TRUE(fetcher); | |
4091 fetcher->set_response_code(200); | |
4092 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
4093 ASSERT_TRUE(provider_->deletion_handlers_.empty()); | |
4094 } | |
4095 | |
4096 TEST_F(SearchProviderTest, TestDeleteMatch_HasDeletionUrlFailure) { | |
4097 AutocompleteMatch m( | |
4098 provider_, | |
4099 0, | |
4100 true, | |
4101 AutocompleteMatchType::SEARCH_SUGGEST); | |
4102 m.RecordAdditionalInfo(SearchProvider::kDeletionUrlKey, | |
4103 "https://www.google.com/complete/deleteitem?q=foo"); | |
4104 provider_->matches_.push_back(m); | |
4105 provider_->DeleteMatch(m); | |
4106 // Set up a default fetcher with provided results. | |
4107 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | |
4108 SearchProvider::kDeletionURLFetcherID); | |
4109 ASSERT_TRUE(fetcher); | |
4110 fetcher->set_response_code(500); | |
4111 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
4112 ASSERT_TRUE(provider_->deletion_handlers_.empty()); | |
4113 } | |
OLD | NEW |