| 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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 // Ensure that verbatim is always generated without other suggestions. | 1014 // Ensure that verbatim is always generated without other suggestions. |
| 1035 // TODO(msw): Ensure verbatimrelevance is respected (except suppression). | 1015 // TODO(msw): Ensure verbatimrelevance is respected (except suppression). |
| 1036 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", | 1016 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":1}]", |
| 1037 { "a", kNotApplicable, kNotApplicable, kNotApplicable }, std::string() }, | 1017 { "a", kNotApplicable, kNotApplicable, kNotApplicable }, std::string() }, |
| 1038 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", | 1018 { "[\"a\",[],[],[],{\"google:verbatimrelevance\":0}]", |
| 1039 { "a", kNotApplicable, kNotApplicable, kNotApplicable }, std::string() }, | 1019 { "a", kNotApplicable, kNotApplicable, kNotApplicable }, std::string() }, |
| 1040 }; | 1020 }; |
| 1041 | 1021 |
| 1042 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1022 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1043 QueryForInput(ASCIIToUTF16("a"), false, false); | 1023 QueryForInput(ASCIIToUTF16("a"), false, false); |
| 1044 net::TestURLFetcher* fetcher = WaitUntilURLFetcherIsReady( | 1024 net::TestURLFetcher* fetcher = |
| 1045 SearchProvider::kDefaultProviderURLFetcherID); | 1025 test_factory_.GetFetcherByID( |
| 1026 SearchProvider::kDefaultProviderURLFetcherID); |
| 1046 ASSERT_TRUE(fetcher); | 1027 ASSERT_TRUE(fetcher); |
| 1047 fetcher->set_response_code(200); | 1028 fetcher->set_response_code(200); |
| 1048 fetcher->SetResponseString(cases[i].json); | 1029 fetcher->SetResponseString(cases[i].json); |
| 1049 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1030 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1050 RunTillProviderDone(); | 1031 RunTillProviderDone(); |
| 1051 | 1032 |
| 1052 const std::string description = "for input with json=" + cases[i].json; | 1033 const std::string description = "for input with json=" + cases[i].json; |
| 1053 const ACMatches& matches = provider_->matches(); | 1034 const ACMatches& matches = provider_->matches(); |
| 1054 // The top match must inline and score as highly as calculated verbatim. | 1035 // The top match must inline and score as highly as calculated verbatim. |
| 1055 ASSERT_FALSE(matches.empty()); | 1036 ASSERT_FALSE(matches.empty()); |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 { "a2.com", false }, | 1480 { "a2.com", false }, |
| 1500 { "a", true }, | 1481 { "a", true }, |
| 1501 { "k a", false } }, | 1482 { "k a", false } }, |
| 1502 "3" }, | 1483 "3" }, |
| 1503 }; | 1484 }; |
| 1504 | 1485 |
| 1505 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1486 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1506 QueryForInput(ASCIIToUTF16("k a"), false, true); | 1487 QueryForInput(ASCIIToUTF16("k a"), false, true); |
| 1507 | 1488 |
| 1508 // Set up a default fetcher with no results. | 1489 // Set up a default fetcher with no results. |
| 1509 net::TestURLFetcher* default_fetcher = WaitUntilURLFetcherIsReady( | 1490 net::TestURLFetcher* default_fetcher = |
| 1510 SearchProvider::kDefaultProviderURLFetcherID); | 1491 test_factory_.GetFetcherByID( |
| 1492 SearchProvider::kDefaultProviderURLFetcherID); |
| 1511 ASSERT_TRUE(default_fetcher); | 1493 ASSERT_TRUE(default_fetcher); |
| 1512 default_fetcher->set_response_code(200); | 1494 default_fetcher->set_response_code(200); |
| 1513 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); | 1495 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); |
| 1514 default_fetcher = NULL; | 1496 default_fetcher = NULL; |
| 1515 | 1497 |
| 1516 // Set up a keyword fetcher with provided results. | 1498 // Set up a keyword fetcher with provided results. |
| 1517 net::TestURLFetcher* keyword_fetcher = WaitUntilURLFetcherIsReady( | 1499 net::TestURLFetcher* keyword_fetcher = |
| 1518 SearchProvider::kKeywordProviderURLFetcherID); | 1500 test_factory_.GetFetcherByID( |
| 1501 SearchProvider::kKeywordProviderURLFetcherID); |
| 1519 ASSERT_TRUE(keyword_fetcher); | 1502 ASSERT_TRUE(keyword_fetcher); |
| 1520 keyword_fetcher->set_response_code(200); | 1503 keyword_fetcher->set_response_code(200); |
| 1521 keyword_fetcher->SetResponseString(cases[i].json); | 1504 keyword_fetcher->SetResponseString(cases[i].json); |
| 1522 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); | 1505 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); |
| 1523 keyword_fetcher = NULL; | 1506 keyword_fetcher = NULL; |
| 1524 RunTillProviderDone(); | 1507 RunTillProviderDone(); |
| 1525 | 1508 |
| 1526 const std::string description = "for input with json=" + cases[i].json; | 1509 const std::string description = "for input with json=" + cases[i].json; |
| 1527 const ACMatches& matches = provider_->matches(); | 1510 const ACMatches& matches = provider_->matches(); |
| 1528 // The top match must inline and score as highly as calculated verbatim. | 1511 // 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... |
| 1619 "{\"google:suggesttype\":[\"QUERY\", \"QUERY\", \"NAVIGATION\"," | 1602 "{\"google:suggesttype\":[\"QUERY\", \"QUERY\", \"NAVIGATION\"," |
| 1620 "\"NAVIGATION\"]," | 1603 "\"NAVIGATION\"]," |
| 1621 // A verbatim query for URL-like input scores 850, so the navigation | 1604 // A verbatim query for URL-like input scores 850, so the navigation |
| 1622 // scores here should bracket it. | 1605 // scores here should bracket it. |
| 1623 "\"google:suggestrelevance\":[9999, 9998, 900, 800]}]", | 1606 "\"google:suggestrelevance\":[9999, 9998, 900, 800]}]", |
| 1624 { "a.com/1", "a.com", "a.com/2", "a1", kNotApplicable, kNotApplicable } }, | 1607 { "a.com/1", "a.com", "a.com/2", "a1", kNotApplicable, kNotApplicable } }, |
| 1625 }; | 1608 }; |
| 1626 | 1609 |
| 1627 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1610 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1628 QueryForInput(cases[i].input, false, false); | 1611 QueryForInput(cases[i].input, false, false); |
| 1629 net::TestURLFetcher* fetcher = WaitUntilURLFetcherIsReady( | 1612 net::TestURLFetcher* fetcher = |
| 1630 SearchProvider::kDefaultProviderURLFetcherID); | 1613 test_factory_.GetFetcherByID( |
| 1614 SearchProvider::kDefaultProviderURLFetcherID); |
| 1631 ASSERT_TRUE(fetcher); | 1615 ASSERT_TRUE(fetcher); |
| 1632 fetcher->set_response_code(200); | 1616 fetcher->set_response_code(200); |
| 1633 fetcher->SetResponseString(cases[i].json); | 1617 fetcher->SetResponseString(cases[i].json); |
| 1634 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1618 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1635 RunTillProviderDone(); | 1619 RunTillProviderDone(); |
| 1636 | 1620 |
| 1637 const std::string description = "for input with json=" + cases[i].json; | 1621 const std::string description = "for input with json=" + cases[i].json; |
| 1638 const ACMatches& matches = provider_->matches(); | 1622 const ACMatches& matches = provider_->matches(); |
| 1639 | 1623 |
| 1640 // Ensure no extra matches are present. | 1624 // Ensure no extra matches are present. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1719 "\"google:verbatimrelevance\":9999}]", | 1703 "\"google:verbatimrelevance\":9999}]", |
| 1720 { "a.com", "abc.com", "a.com/a", kNotApplicable }, | 1704 { "a.com", "abc.com", "a.com/a", kNotApplicable }, |
| 1721 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 1705 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 1722 AutocompleteMatchType::NAVSUGGEST, | 1706 AutocompleteMatchType::NAVSUGGEST, |
| 1723 AutocompleteMatchType::SEARCH_SUGGEST, | 1707 AutocompleteMatchType::SEARCH_SUGGEST, |
| 1724 AutocompleteMatchType::NUM_TYPES } }, | 1708 AutocompleteMatchType::NUM_TYPES } }, |
| 1725 }; | 1709 }; |
| 1726 | 1710 |
| 1727 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 1711 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 1728 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); | 1712 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); |
| 1729 net::TestURLFetcher* fetcher = WaitUntilURLFetcherIsReady( | 1713 net::TestURLFetcher* fetcher = |
| 1730 SearchProvider::kDefaultProviderURLFetcherID); | 1714 test_factory_.GetFetcherByID( |
| 1715 SearchProvider::kDefaultProviderURLFetcherID); |
| 1731 ASSERT_TRUE(fetcher); | 1716 ASSERT_TRUE(fetcher); |
| 1732 fetcher->set_response_code(200); | 1717 fetcher->set_response_code(200); |
| 1733 fetcher->SetResponseString(cases[i].json); | 1718 fetcher->SetResponseString(cases[i].json); |
| 1734 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1719 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1735 RunTillProviderDone(); | 1720 RunTillProviderDone(); |
| 1736 | 1721 |
| 1737 size_t j = 0; | 1722 size_t j = 0; |
| 1738 const ACMatches& matches = provider_->matches(); | 1723 const ACMatches& matches = provider_->matches(); |
| 1739 // Ensure that the returned matches equal the expectations. | 1724 // Ensure that the returned matches equal the expectations. |
| 1740 for (; j < matches.size(); ++j) { | 1725 for (; j < matches.size(); ++j) { |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2172 } else { | 2157 } else { |
| 2173 ASSERT_NE(sug_end, sug_it) << "Failed to find " << suggestion; | 2158 ASSERT_NE(sug_end, sug_it) << "Failed to find " << suggestion; |
| 2174 EXPECT_EQ(ASCIIToUTF16(suggestion), sug_it->suggestion()); | 2159 EXPECT_EQ(ASCIIToUTF16(suggestion), sug_it->suggestion()); |
| 2175 ++sug_it; | 2160 ++sug_it; |
| 2176 } | 2161 } |
| 2177 } | 2162 } |
| 2178 EXPECT_EQ(sug_end, sug_it); | 2163 EXPECT_EQ(sug_end, sug_it); |
| 2179 EXPECT_EQ(nav_end, nav_it); | 2164 EXPECT_EQ(nav_end, nav_it); |
| 2180 } | 2165 } |
| 2181 } | 2166 } |
| OLD | NEW |