| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 24 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 25 #include "chrome/browser/search/search.h" | 25 #include "chrome/browser/search/search.h" |
| 26 #include "chrome/browser/search_engines/template_url.h" | 26 #include "chrome/browser/search_engines/template_url.h" |
| 27 #include "chrome/browser/search_engines/template_url_service.h" | 27 #include "chrome/browser/search_engines/template_url_service.h" |
| 28 #include "chrome/browser/search_engines/template_url_service_factory.h" | 28 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 29 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/metrics/entropy_provider.h" | 30 #include "chrome/common/metrics/entropy_provider.h" |
| 31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/test/base/testing_browser_process.h" | 32 #include "chrome/test/base/testing_browser_process.h" |
| 33 #include "chrome/test/base/testing_profile.h" | 33 #include "chrome/test/base/testing_profile.h" |
| 34 #include "content/public/test/test_browser_thread.h" | 34 #include "content/public/test/test_browser_thread_bundle.h" |
| 35 #include "net/url_request/test_url_fetcher_factory.h" | 35 #include "net/url_request/test_url_fetcher_factory.h" |
| 36 #include "net/url_request/url_request_status.h" | 36 #include "net/url_request/url_request_status.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 38 | 38 |
| 39 | 39 |
| 40 // SearchProviderTest --------------------------------------------------------- | 40 // SearchProviderTest --------------------------------------------------------- |
| 41 | 41 |
| 42 // The following environment is configured for these tests: | 42 // The following environment is configured for these tests: |
| 43 // . The TemplateURL default_t_url_ is set as the default provider. | 43 // . The TemplateURL default_t_url_ is set as the default provider. |
| 44 // . The TemplateURL keyword_t_url_ is added to the TemplateURLService. This | 44 // . The TemplateURL keyword_t_url_ is added to the TemplateURLService. This |
| (...skipping 26 matching lines...) Expand all Loading... |
| 71 const string16 input; | 71 const string16 input; |
| 72 const size_t num_results; | 72 const size_t num_results; |
| 73 const ResultInfo output[3]; | 73 const ResultInfo output[3]; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 SearchProviderTest() | 76 SearchProviderTest() |
| 77 : default_t_url_(NULL), | 77 : default_t_url_(NULL), |
| 78 term1_(ASCIIToUTF16("term1")), | 78 term1_(ASCIIToUTF16("term1")), |
| 79 keyword_t_url_(NULL), | 79 keyword_t_url_(NULL), |
| 80 keyword_term_(ASCIIToUTF16("keyword")), | 80 keyword_term_(ASCIIToUTF16("keyword")), |
| 81 ui_thread_(content::BrowserThread::UI, &message_loop_), | 81 run_loop_(NULL) { |
| 82 io_thread_(content::BrowserThread::IO), | |
| 83 quit_when_done_(false) { | |
| 84 io_thread_.Start(); | |
| 85 } | 82 } |
| 86 | 83 |
| 87 static void SetUpTestCase(); | 84 static void SetUpTestCase(); |
| 88 static void TearDownTestCase(); | 85 static void TearDownTestCase(); |
| 89 | 86 |
| 90 // See description above class for what this registers. | 87 // See description above class for what this registers. |
| 91 virtual void SetUp() OVERRIDE; | 88 virtual void SetUp() OVERRIDE; |
| 92 virtual void TearDown() OVERRIDE; | 89 virtual void TearDown() OVERRIDE; |
| 93 | 90 |
| 94 void RunTest(TestData* cases, int num_cases, bool prefer_keyword); | 91 void RunTest(TestData* cases, int num_cases, bool prefer_keyword); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 110 AutocompleteMatch* match); | 107 AutocompleteMatch* match); |
| 111 | 108 |
| 112 // Looks for a match in |provider_| with destination |url|. Sets |match| to | 109 // Looks for a match in |provider_| with destination |url|. Sets |match| to |
| 113 // it if found. Returns whether |match| was set. | 110 // it if found. Returns whether |match| was set. |
| 114 bool FindMatchWithDestination(const GURL& url, AutocompleteMatch* match); | 111 bool FindMatchWithDestination(const GURL& url, AutocompleteMatch* match); |
| 115 | 112 |
| 116 // AutocompleteProviderListener: | 113 // AutocompleteProviderListener: |
| 117 // If we're waiting for the provider to finish, this exits the message loop. | 114 // If we're waiting for the provider to finish, this exits the message loop. |
| 118 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE; | 115 virtual void OnProviderUpdate(bool updated_matches) OVERRIDE; |
| 119 | 116 |
| 120 // Waits until the provider instantiates a URLFetcher and returns it. | |
| 121 net::TestURLFetcher* WaitUntilURLFetcherIsReady(int fetcher_id); | |
| 122 | |
| 123 // Runs a nested message loop until provider_ is done. The message loop is | 117 // Runs a nested message loop until provider_ is done. The message loop is |
| 124 // exited by way of OnProviderUpdate. | 118 // exited by way of OnProviderUpdate. |
| 125 void RunTillProviderDone(); | 119 void RunTillProviderDone(); |
| 126 | 120 |
| 127 // Invokes Start on provider_, then runs all pending tasks. | 121 // Invokes Start on provider_, then runs all pending tasks. |
| 128 void QueryForInput(const string16& text, | 122 void QueryForInput(const string16& text, |
| 129 bool prevent_inline_autocomplete, | 123 bool prevent_inline_autocomplete, |
| 130 bool prefer_keyword); | 124 bool prefer_keyword); |
| 131 | 125 |
| 132 // Calls QueryForInput(), finishes any suggest query, then if |wyt_match| is | 126 // Calls QueryForInput(), finishes any suggest query, then if |wyt_match| is |
| 133 // non-NULL, sets it to the "what you typed" entry for |text|. | 127 // non-NULL, sets it to the "what you typed" entry for |text|. |
| 134 void QueryForInputAndSetWYTMatch(const string16& text, | 128 void QueryForInputAndSetWYTMatch(const string16& text, |
| 135 AutocompleteMatch* wyt_match); | 129 AutocompleteMatch* wyt_match); |
| 136 | 130 |
| 137 // Notifies the URLFetcher for the suggest query corresponding to the default | 131 // Notifies the URLFetcher for the suggest query corresponding to the default |
| 138 // search provider that it's done. | 132 // search provider that it's done. |
| 139 // Be sure and wrap calls to this in ASSERT_NO_FATAL_FAILURE. | 133 // Be sure and wrap calls to this in ASSERT_NO_FATAL_FAILURE. |
| 140 void FinishDefaultSuggestQuery(); | 134 void FinishDefaultSuggestQuery(); |
| 141 | 135 |
| 142 // See description above class for details of these fields. | 136 // See description above class for details of these fields. |
| 143 TemplateURL* default_t_url_; | 137 TemplateURL* default_t_url_; |
| 144 const string16 term1_; | 138 const string16 term1_; |
| 145 GURL term1_url_; | 139 GURL term1_url_; |
| 146 TemplateURL* keyword_t_url_; | 140 TemplateURL* keyword_t_url_; |
| 147 const string16 keyword_term_; | 141 const string16 keyword_term_; |
| 148 GURL keyword_url_; | 142 GURL keyword_url_; |
| 149 | 143 |
| 150 base::MessageLoopForUI message_loop_; | 144 content::TestBrowserThreadBundle thread_bundle_; |
| 151 content::TestBrowserThread ui_thread_; | |
| 152 content::TestBrowserThread io_thread_; | |
| 153 | 145 |
| 154 // URLFetcherFactory implementation registered. | 146 // URLFetcherFactory implementation registered. |
| 155 net::TestURLFetcherFactory test_factory_; | 147 net::TestURLFetcherFactory test_factory_; |
| 156 | 148 |
| 157 // Profile we use. | 149 // Profile we use. |
| 158 TestingProfile profile_; | 150 TestingProfile profile_; |
| 159 | 151 |
| 160 // The provider. | 152 // The provider. |
| 161 scoped_refptr<SearchProvider> provider_; | 153 scoped_refptr<SearchProvider> provider_; |
| 162 | 154 |
| 163 // If true, OnProviderUpdate exits out of the current message loop. | 155 // If non-NULL, OnProviderUpdate quits the current |run_loop_|. |
| 164 bool quit_when_done_; | 156 base::RunLoop* run_loop_; |
| 165 | 157 |
| 166 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); | 158 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); |
| 167 }; | 159 }; |
| 168 | 160 |
| 169 // static | 161 // static |
| 170 base::FieldTrialList* SearchProviderTest::field_trial_list_ = NULL; | 162 base::FieldTrialList* SearchProviderTest::field_trial_list_ = NULL; |
| 171 const std::string SearchProviderTest::kNotApplicable = "Not Applicable"; | 163 const std::string SearchProviderTest::kNotApplicable = "Not Applicable"; |
| 172 | 164 |
| 173 // static | 165 // static |
| 174 void SearchProviderTest::SetUpTestCase() { | 166 void SearchProviderTest::SetUpTestCase() { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // Keywords are updated by the InMemoryHistoryBackend only after the message | 223 // Keywords are updated by the InMemoryHistoryBackend only after the message |
| 232 // has been processed on the history thread. Block until history processes all | 224 // has been processed on the history thread. Block until history processes all |
| 233 // requests to ensure the InMemoryDatabase is the state we expect it. | 225 // requests to ensure the InMemoryDatabase is the state we expect it. |
| 234 profile_.BlockUntilHistoryProcessesPendingRequests(); | 226 profile_.BlockUntilHistoryProcessesPendingRequests(); |
| 235 | 227 |
| 236 provider_ = new SearchProvider(this, &profile_); | 228 provider_ = new SearchProvider(this, &profile_); |
| 237 provider_->kMinimumTimeBetweenSuggestQueriesMs = 0; | 229 provider_->kMinimumTimeBetweenSuggestQueriesMs = 0; |
| 238 } | 230 } |
| 239 | 231 |
| 240 void SearchProviderTest::TearDown() { | 232 void SearchProviderTest::TearDown() { |
| 241 message_loop_.RunUntilIdle(); | 233 base::RunLoop().RunUntilIdle(); |
| 242 | 234 |
| 243 // Shutdown the provider before the profile. | 235 // Shutdown the provider before the profile. |
| 244 provider_ = NULL; | 236 provider_ = NULL; |
| 245 } | 237 } |
| 246 | 238 |
| 247 void SearchProviderTest::RunTest(TestData* cases, | 239 void SearchProviderTest::RunTest(TestData* cases, |
| 248 int num_cases, | 240 int num_cases, |
| 249 bool prefer_keyword) { | 241 bool prefer_keyword) { |
| 250 ACMatches matches; | 242 ACMatches matches; |
| 251 for (int i = 0; i < num_cases; ++i) { | 243 for (int i = 0; i < num_cases; ++i) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 266 diagnostic_details; | 258 diagnostic_details; |
| 267 EXPECT_EQ(cases[i].output[j].fill_into_edit, | 259 EXPECT_EQ(cases[i].output[j].fill_into_edit, |
| 268 matches[j].fill_into_edit) << | 260 matches[j].fill_into_edit) << |
| 269 diagnostic_details; | 261 diagnostic_details; |
| 270 } | 262 } |
| 271 } | 263 } |
| 272 } | 264 } |
| 273 } | 265 } |
| 274 | 266 |
| 275 void SearchProviderTest::OnProviderUpdate(bool updated_matches) { | 267 void SearchProviderTest::OnProviderUpdate(bool updated_matches) { |
| 276 if (quit_when_done_ && provider_->done()) { | 268 if (run_loop_ && provider_->done()) { |
| 277 quit_when_done_ = false; | 269 run_loop_->Quit(); |
| 278 message_loop_.Quit(); | 270 run_loop_ = NULL; |
| 279 } | 271 } |
| 280 } | 272 } |
| 281 | 273 |
| 282 net::TestURLFetcher* SearchProviderTest::WaitUntilURLFetcherIsReady( | |
| 283 int fetcher_id) { | |
| 284 net::TestURLFetcher* url_fetcher = test_factory_.GetFetcherByID(fetcher_id); | |
| 285 for (; !url_fetcher; url_fetcher = test_factory_.GetFetcherByID(fetcher_id)) | |
| 286 message_loop_.RunUntilIdle(); | |
| 287 return url_fetcher; | |
| 288 } | |
| 289 | |
| 290 void SearchProviderTest::RunTillProviderDone() { | 274 void SearchProviderTest::RunTillProviderDone() { |
| 291 if (provider_->done()) | 275 if (provider_->done()) |
| 292 return; | 276 return; |
| 293 | 277 |
| 294 quit_when_done_ = true; | |
| 295 #if defined(OS_ANDROID) | |
| 296 // Android doesn't have Run(), only Start(). | |
| 297 message_loop_.Start(); | |
| 298 #else | |
| 299 base::RunLoop run_loop; | 278 base::RunLoop run_loop; |
| 279 run_loop_ = &run_loop; |
| 300 run_loop.Run(); | 280 run_loop.Run(); |
| 301 #endif | |
| 302 } | 281 } |
| 303 | 282 |
| 304 void SearchProviderTest::QueryForInput(const string16& text, | 283 void SearchProviderTest::QueryForInput(const string16& text, |
| 305 bool prevent_inline_autocomplete, | 284 bool prevent_inline_autocomplete, |
| 306 bool prefer_keyword) { | 285 bool prefer_keyword) { |
| 307 // Start a query. | 286 // Start a query. |
| 308 AutocompleteInput input(text, string16::npos, string16(), GURL(), | 287 AutocompleteInput input(text, string16::npos, string16(), GURL(), |
| 309 prevent_inline_autocomplete, | 288 prevent_inline_autocomplete, |
| 310 prefer_keyword, true, AutocompleteInput::ALL_MATCHES); | 289 prefer_keyword, true, AutocompleteInput::ALL_MATCHES); |
| 311 provider_->Start(input, false); | 290 provider_->Start(input, false); |
| 312 | 291 |
| 313 // RunUntilIdle so that the task scheduled by SearchProvider to create the | 292 // RunUntilIdle so that the task scheduled by SearchProvider to create the |
| 314 // URLFetchers runs. | 293 // URLFetchers runs. |
| 315 message_loop_.RunUntilIdle(); | 294 base::RunLoop().RunUntilIdle(); |
| 316 } | 295 } |
| 317 | 296 |
| 318 void SearchProviderTest::QueryForInputAndSetWYTMatch( | 297 void SearchProviderTest::QueryForInputAndSetWYTMatch( |
| 319 const string16& text, | 298 const string16& text, |
| 320 AutocompleteMatch* wyt_match) { | 299 AutocompleteMatch* wyt_match) { |
| 321 QueryForInput(text, false, false); | 300 QueryForInput(text, false, false); |
| 322 profile_.BlockUntilHistoryProcessesPendingRequests(); | 301 profile_.BlockUntilHistoryProcessesPendingRequests(); |
| 323 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); | 302 ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery()); |
| 324 if (!wyt_match) | 303 if (!wyt_match) |
| 325 return; | 304 return; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 i != provider_->matches().end(); ++i) { | 344 i != provider_->matches().end(); ++i) { |
| 366 if (i->destination_url == url) { | 345 if (i->destination_url == url) { |
| 367 *match = *i; | 346 *match = *i; |
| 368 return true; | 347 return true; |
| 369 } | 348 } |
| 370 } | 349 } |
| 371 return false; | 350 return false; |
| 372 } | 351 } |
| 373 | 352 |
| 374 void SearchProviderTest::FinishDefaultSuggestQuery() { | 353 void SearchProviderTest::FinishDefaultSuggestQuery() { |
| 375 net::TestURLFetcher* default_fetcher = WaitUntilURLFetcherIsReady( | 354 net::TestURLFetcher* default_fetcher = |
| 376 SearchProvider::kDefaultProviderURLFetcherID); | 355 test_factory_.GetFetcherByID( |
| 356 SearchProvider::kDefaultProviderURLFetcherID); |
| 377 ASSERT_TRUE(default_fetcher); | 357 ASSERT_TRUE(default_fetcher); |
| 378 | 358 |
| 379 // Tell the SearchProvider the default suggest query is done. | 359 // Tell the SearchProvider the default suggest query is done. |
| 380 default_fetcher->set_response_code(200); | 360 default_fetcher->set_response_code(200); |
| 381 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); | 361 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); |
| 382 } | 362 } |
| 383 | 363 |
| 384 | 364 |
| 385 // Actual Tests --------------------------------------------------------------- | 365 // Actual Tests --------------------------------------------------------------- |
| 386 | 366 |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 // Ensure that verbatim is always generated without other suggestions. | 1013 // Ensure that verbatim is always generated without other suggestions. |
| 1034 // TODO(msw): Ensure verbatimrelevance is respected (except suppression). | 1014 // TODO(msw): Ensure verbatimrelevance is respected (except suppression). |
| 1035 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", | 1015 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", |
| 1036 { "a", kNotApplicable, kNotApplicable, kNotApplicable } }, | 1016 { "a", kNotApplicable, kNotApplicable, kNotApplicable } }, |
| 1037 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", | 1017 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", |
| 1038 { "a", kNotApplicable, kNotApplicable, kNotApplicable } }, | 1018 { "a", kNotApplicable, kNotApplicable, kNotApplicable } }, |
| 1039 }; | 1019 }; |
| 1040 | 1020 |
| 1041 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1021 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1042 QueryForInput(ASCIIToUTF16("a"), false, false); | 1022 QueryForInput(ASCIIToUTF16("a"), false, false); |
| 1043 net::TestURLFetcher* fetcher = WaitUntilURLFetcherIsReady( | 1023 net::TestURLFetcher* fetcher = |
| 1044 SearchProvider::kDefaultProviderURLFetcherID); | 1024 test_factory_.GetFetcherByID( |
| 1025 SearchProvider::kDefaultProviderURLFetcherID); |
| 1045 ASSERT_TRUE(fetcher); | 1026 ASSERT_TRUE(fetcher); |
| 1046 fetcher->set_response_code(200); | 1027 fetcher->set_response_code(200); |
| 1047 fetcher->SetResponseString(cases[i].json); | 1028 fetcher->SetResponseString(cases[i].json); |
| 1048 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1029 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1049 RunTillProviderDone(); | 1030 RunTillProviderDone(); |
| 1050 | 1031 |
| 1051 const std::string description = "for input with json=" + cases[i].json; | 1032 const std::string description = "for input with json=" + cases[i].json; |
| 1052 const ACMatches& matches = provider_->matches(); | 1033 const ACMatches& matches = provider_->matches(); |
| 1053 // The top match must inline and score as highly as calculated verbatim. | 1034 // The top match must inline and score as highly as calculated verbatim. |
| 1054 ASSERT_FALSE(matches.empty()); | 1035 ASSERT_FALSE(matches.empty()); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 { "a1.com", false }, | 1438 { "a1.com", false }, |
| 1458 { "a2.com", false }, | 1439 { "a2.com", false }, |
| 1459 { "a", true }, | 1440 { "a", true }, |
| 1460 { "k a", false } } }, | 1441 { "k a", false } } }, |
| 1461 }; | 1442 }; |
| 1462 | 1443 |
| 1463 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1444 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1464 QueryForInput(ASCIIToUTF16("k a"), false, true); | 1445 QueryForInput(ASCIIToUTF16("k a"), false, true); |
| 1465 | 1446 |
| 1466 // Set up a default fetcher with no results. | 1447 // Set up a default fetcher with no results. |
| 1467 net::TestURLFetcher* default_fetcher = WaitUntilURLFetcherIsReady( | 1448 net::TestURLFetcher* default_fetcher = |
| 1468 SearchProvider::kDefaultProviderURLFetcherID); | 1449 test_factory_.GetFetcherByID( |
| 1450 SearchProvider::kDefaultProviderURLFetcherID); |
| 1469 ASSERT_TRUE(default_fetcher); | 1451 ASSERT_TRUE(default_fetcher); |
| 1470 default_fetcher->set_response_code(200); | 1452 default_fetcher->set_response_code(200); |
| 1471 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); | 1453 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); |
| 1472 default_fetcher = NULL; | 1454 default_fetcher = NULL; |
| 1473 | 1455 |
| 1474 // Set up a keyword fetcher with provided results. | 1456 // Set up a keyword fetcher with provided results. |
| 1475 net::TestURLFetcher* keyword_fetcher = WaitUntilURLFetcherIsReady( | 1457 net::TestURLFetcher* keyword_fetcher = |
| 1476 SearchProvider::kKeywordProviderURLFetcherID); | 1458 test_factory_.GetFetcherByID( |
| 1459 SearchProvider::kKeywordProviderURLFetcherID); |
| 1477 ASSERT_TRUE(keyword_fetcher); | 1460 ASSERT_TRUE(keyword_fetcher); |
| 1478 keyword_fetcher->set_response_code(200); | 1461 keyword_fetcher->set_response_code(200); |
| 1479 keyword_fetcher->SetResponseString(cases[i].json); | 1462 keyword_fetcher->SetResponseString(cases[i].json); |
| 1480 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); | 1463 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); |
| 1481 keyword_fetcher = NULL; | 1464 keyword_fetcher = NULL; |
| 1482 RunTillProviderDone(); | 1465 RunTillProviderDone(); |
| 1483 | 1466 |
| 1484 const std::string description = "for input with json=" + cases[i].json; | 1467 const std::string description = "for input with json=" + cases[i].json; |
| 1485 const ACMatches& matches = provider_->matches(); | 1468 const ACMatches& matches = provider_->matches(); |
| 1486 // The top match must inline and score as highly as calculated verbatim. | 1469 // The top match must inline and score as highly as calculated verbatim. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1577 "{\"google:suggesttype\":[\"QUERY\", \"QUERY\", \"NAVIGATION\"," | 1560 "{\"google:suggesttype\":[\"QUERY\", \"QUERY\", \"NAVIGATION\"," |
| 1578 "\"NAVIGATION\"]," | 1561 "\"NAVIGATION\"]," |
| 1579 // A verbatim query for URL-like input scores 850, so the navigation | 1562 // A verbatim query for URL-like input scores 850, so the navigation |
| 1580 // scores here should bracket it. | 1563 // scores here should bracket it. |
| 1581 "\"google:suggestrelevance\":[9999, 9998, 900, 800]}]", | 1564 "\"google:suggestrelevance\":[9999, 9998, 900, 800]}]", |
| 1582 { "a.com/1", "a.com", "a.com/2", "a1", kNotApplicable, kNotApplicable } }, | 1565 { "a.com/1", "a.com", "a.com/2", "a1", kNotApplicable, kNotApplicable } }, |
| 1583 }; | 1566 }; |
| 1584 | 1567 |
| 1585 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1568 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1586 QueryForInput(cases[i].input, false, false); | 1569 QueryForInput(cases[i].input, false, false); |
| 1587 net::TestURLFetcher* fetcher = WaitUntilURLFetcherIsReady( | 1570 net::TestURLFetcher* fetcher = |
| 1588 SearchProvider::kDefaultProviderURLFetcherID); | 1571 test_factory_.GetFetcherByID( |
| 1572 SearchProvider::kDefaultProviderURLFetcherID); |
| 1589 ASSERT_TRUE(fetcher); | 1573 ASSERT_TRUE(fetcher); |
| 1590 fetcher->set_response_code(200); | 1574 fetcher->set_response_code(200); |
| 1591 fetcher->SetResponseString(cases[i].json); | 1575 fetcher->SetResponseString(cases[i].json); |
| 1592 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1576 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1593 RunTillProviderDone(); | 1577 RunTillProviderDone(); |
| 1594 | 1578 |
| 1595 const std::string description = "for input with json=" + cases[i].json; | 1579 const std::string description = "for input with json=" + cases[i].json; |
| 1596 const ACMatches& matches = provider_->matches(); | 1580 const ACMatches& matches = provider_->matches(); |
| 1597 | 1581 |
| 1598 // Ensure no extra matches are present. | 1582 // Ensure no extra matches are present. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 "\"google:verbatimrelevance\":9999}]", | 1661 "\"google:verbatimrelevance\":9999}]", |
| 1678 { "a.com", "abc.com", "a.com/a", kNotApplicable }, | 1662 { "a.com", "abc.com", "a.com/a", kNotApplicable }, |
| 1679 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 1663 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 1680 AutocompleteMatchType::NAVSUGGEST, | 1664 AutocompleteMatchType::NAVSUGGEST, |
| 1681 AutocompleteMatchType::SEARCH_SUGGEST, | 1665 AutocompleteMatchType::SEARCH_SUGGEST, |
| 1682 AutocompleteMatchType::NUM_TYPES } }, | 1666 AutocompleteMatchType::NUM_TYPES } }, |
| 1683 }; | 1667 }; |
| 1684 | 1668 |
| 1685 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1669 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1686 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); | 1670 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); |
| 1687 net::TestURLFetcher* fetcher = WaitUntilURLFetcherIsReady( | 1671 net::TestURLFetcher* fetcher = |
| 1688 SearchProvider::kDefaultProviderURLFetcherID); | 1672 test_factory_.GetFetcherByID( |
| 1673 SearchProvider::kDefaultProviderURLFetcherID); |
| 1689 ASSERT_TRUE(fetcher); | 1674 ASSERT_TRUE(fetcher); |
| 1690 fetcher->set_response_code(200); | 1675 fetcher->set_response_code(200); |
| 1691 fetcher->SetResponseString(cases[i].json); | 1676 fetcher->SetResponseString(cases[i].json); |
| 1692 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1677 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1693 RunTillProviderDone(); | 1678 RunTillProviderDone(); |
| 1694 | 1679 |
| 1695 size_t j = 0; | 1680 size_t j = 0; |
| 1696 const ACMatches& matches = provider_->matches(); | 1681 const ACMatches& matches = provider_->matches(); |
| 1697 // Ensure that the returned matches equal the expectations. | 1682 // Ensure that the returned matches equal the expectations. |
| 1698 for (; j < matches.size(); ++j) { | 1683 for (; j < matches.size(); ++j) { |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2117 } else { | 2102 } else { |
| 2118 ASSERT_NE(sug_end, sug_it) << "Failed to find " << suggestion; | 2103 ASSERT_NE(sug_end, sug_it) << "Failed to find " << suggestion; |
| 2119 EXPECT_EQ(ASCIIToUTF16(suggestion), sug_it->suggestion()); | 2104 EXPECT_EQ(ASCIIToUTF16(suggestion), sug_it->suggestion()); |
| 2120 ++sug_it; | 2105 ++sug_it; |
| 2121 } | 2106 } |
| 2122 } | 2107 } |
| 2123 EXPECT_EQ(sug_end, sug_it); | 2108 EXPECT_EQ(sug_end, sug_it); |
| 2124 EXPECT_EQ(nav_end, nav_it); | 2109 EXPECT_EQ(nav_end, nav_it); |
| 2125 } | 2110 } |
| 2126 } | 2111 } |
| OLD | NEW |