Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: chrome/browser/autocomplete/search_provider_unittest.cc

Issue 12623029: Upstreaming mechanism to add query refinement to omnibox searches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed ChromeOS. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 message_loop_.Start(); 250 message_loop_.Start();
251 #else 251 #else
252 base::RunLoop run_loop; 252 base::RunLoop run_loop;
253 run_loop.Run(); 253 run_loop.Run();
254 #endif 254 #endif
255 } 255 }
256 256
257 void SearchProviderTest::QueryForInput(const string16& text, 257 void SearchProviderTest::QueryForInput(const string16& text,
258 bool prevent_inline_autocomplete) { 258 bool prevent_inline_autocomplete) {
259 // Start a query. 259 // Start a query.
260 AutocompleteInput input(text, string16::npos, string16(), 260 AutocompleteInput input(text, string16::npos, string16(), GURL(),
261 prevent_inline_autocomplete, 261 prevent_inline_autocomplete,
262 false, true, AutocompleteInput::ALL_MATCHES); 262 false, true, AutocompleteInput::ALL_MATCHES);
263 provider_->Start(input, false); 263 provider_->Start(input, false);
264 264
265 // RunUntilIdle so that the task scheduled by SearchProvider to create the 265 // RunUntilIdle so that the task scheduled by SearchProvider to create the
266 // URLFetchers runs. 266 // URLFetchers runs.
267 message_loop_.RunUntilIdle(); 267 message_loop_.RunUntilIdle();
268 } 268 }
269 269
270 void SearchProviderTest::QueryForInputAndSetWYTMatch( 270 void SearchProviderTest::QueryForInputAndSetWYTMatch(
(...skipping 17 matching lines...) Expand all
288 288
289 // Shutdown the provider before the profile. 289 // Shutdown the provider before the profile.
290 provider_ = NULL; 290 provider_ = NULL;
291 } 291 }
292 292
293 void SearchProviderTest::RunTest(TestData* cases, 293 void SearchProviderTest::RunTest(TestData* cases,
294 int num_cases, 294 int num_cases,
295 bool prefer_keyword) { 295 bool prefer_keyword) {
296 ACMatches matches; 296 ACMatches matches;
297 for (int i = 0; i < num_cases; ++i) { 297 for (int i = 0; i < num_cases; ++i) {
298 AutocompleteInput input(cases[i].input, string16::npos, string16(), 298 AutocompleteInput input(cases[i].input, string16::npos, string16(), GURL(),
299 false, prefer_keyword, true, 299 false, prefer_keyword, true,
300 AutocompleteInput::ALL_MATCHES); 300 AutocompleteInput::ALL_MATCHES);
301 provider_->Start(input, false); 301 provider_->Start(input, false);
302 matches = provider_->matches(); 302 matches = provider_->matches();
303 string16 diagnostic_details = ASCIIToUTF16("Input was: ") + cases[i].input + 303 string16 diagnostic_details = ASCIIToUTF16("Input was: ") + cases[i].input +
304 ASCIIToUTF16("; prefer_keyword was: ") + 304 ASCIIToUTF16("; prefer_keyword was: ") +
305 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false")); 305 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false"));
306 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details; 306 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details;
307 if (matches.size() == cases[i].num_results) { 307 if (matches.size() == cases[i].num_results) {
308 for (size_t j = 0; j < cases[i].num_results; ++j) { 308 for (size_t j = 0; j < cases[i].num_results; ++j) {
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 // Verifies AutocompleteControllers return results (including keyword 842 // Verifies AutocompleteControllers return results (including keyword
843 // results) in the right order and set descriptions for them correctly. 843 // results) in the right order and set descriptions for them correctly.
844 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) { 844 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) {
845 // Add an entry that corresponds to a keyword search with 'term2'. 845 // Add an entry that corresponds to a keyword search with 'term2'.
846 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); 846 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1);
847 profile_.BlockUntilHistoryProcessesPendingRequests(); 847 profile_.BlockUntilHistoryProcessesPendingRequests();
848 848
849 AutocompleteController controller(&profile_, NULL, 849 AutocompleteController controller(&profile_, NULL,
850 AutocompleteProvider::TYPE_SEARCH); 850 AutocompleteProvider::TYPE_SEARCH);
851 controller.Start(AutocompleteInput( 851 controller.Start(AutocompleteInput(
852 ASCIIToUTF16("k t"), string16::npos, string16(), false, false, true, 852 ASCIIToUTF16("k t"), string16::npos, string16(), GURL(), false, false,
853 AutocompleteInput::ALL_MATCHES)); 853 true, AutocompleteInput::ALL_MATCHES));
854 const AutocompleteResult& result = controller.result(); 854 const AutocompleteResult& result = controller.result();
855 855
856 // There should be three matches, one for the keyword history, one for 856 // There should be three matches, one for the keyword history, one for
857 // keyword provider's what-you-typed, and one for the default provider's 857 // keyword provider's what-you-typed, and one for the default provider's
858 // what you typed, in that order. 858 // what you typed, in that order.
859 ASSERT_EQ(3u, result.size()); 859 ASSERT_EQ(3u, result.size());
860 EXPECT_EQ(AutocompleteMatch::SEARCH_HISTORY, result.match_at(0).type); 860 EXPECT_EQ(AutocompleteMatch::SEARCH_HISTORY, result.match_at(0).type);
861 EXPECT_EQ(AutocompleteMatch::SEARCH_OTHER_ENGINE, result.match_at(1).type); 861 EXPECT_EQ(AutocompleteMatch::SEARCH_OTHER_ENGINE, result.match_at(1).type);
862 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, result.match_at(2).type); 862 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, result.match_at(2).type);
863 EXPECT_GT(result.match_at(0).relevance, result.match_at(1).relevance); 863 EXPECT_GT(result.match_at(0).relevance, result.match_at(1).relevance);
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 1873 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
1874 match.contents_class[0].style); 1874 match.contents_class[0].style);
1875 EXPECT_EQ(4U, match.contents_class[1].offset); 1875 EXPECT_EQ(4U, match.contents_class[1].offset);
1876 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL | 1876 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL |
1877 AutocompleteMatch::ACMatchClassification::MATCH, 1877 AutocompleteMatch::ACMatchClassification::MATCH,
1878 match.contents_class[1].style); 1878 match.contents_class[1].style);
1879 EXPECT_EQ(5U, match.contents_class[2].offset); 1879 EXPECT_EQ(5U, match.contents_class[2].offset);
1880 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL, 1880 EXPECT_EQ(AutocompleteMatch::ACMatchClassification::URL,
1881 match.contents_class[2].style); 1881 match.contents_class[2].style);
1882 } 1882 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698