OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/autocomplete/history_url_provider.h" | 9 #include "chrome/browser/autocomplete/history_url_provider.h" |
10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 bool prevent_inline_autocomplete, | 179 bool prevent_inline_autocomplete, |
180 const std::string* expected_urls, | 180 const std::string* expected_urls, |
181 size_t num_results) { | 181 size_t num_results) { |
182 AutocompleteInput input(text, desired_tld, prevent_inline_autocomplete, | 182 AutocompleteInput input(text, desired_tld, prevent_inline_autocomplete, |
183 false, false); | 183 false, false); |
184 autocomplete_->Start(input, false); | 184 autocomplete_->Start(input, false); |
185 if (!autocomplete_->done()) | 185 if (!autocomplete_->done()) |
186 MessageLoop::current()->Run(); | 186 MessageLoop::current()->Run(); |
187 | 187 |
188 matches_ = autocomplete_->matches(); | 188 matches_ = autocomplete_->matches(); |
189 ASSERT_EQ(num_results, matches_.size()); | 189 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text; |
190 for (size_t i = 0; i < num_results; ++i) | 190 for (size_t i = 0; i < num_results; ++i) |
191 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec()); | 191 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec()); |
192 } | 192 } |
193 | 193 |
194 TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { | 194 TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { |
195 // Test that hosts get synthesized below popular pages. | 195 // Test that hosts get synthesized below popular pages. |
196 const std::string expected_nonsynth[] = { | 196 const std::string expected_nonsynth[] = { |
197 "http://slashdot.org/favorite_page.html", | 197 "http://slashdot.org/favorite_page.html", |
198 "http://slashdot.org/", | 198 "http://slashdot.org/", |
199 }; | 199 }; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // all but the first one (A) should be culled. We should get the default | 335 // all but the first one (A) should be culled. We should get the default |
336 // "what you typed" result, plus this one. | 336 // "what you typed" result, plus this one. |
337 const std::wstring typing(L"http://redirects/"); | 337 const std::wstring typing(L"http://redirects/"); |
338 const std::string expected_results[] = { | 338 const std::string expected_results[] = { |
339 WideToUTF8(typing), | 339 WideToUTF8(typing), |
340 redirect[0].url}; | 340 redirect[0].url}; |
341 RunTest(typing, std::wstring(), true, expected_results, | 341 RunTest(typing, std::wstring(), true, expected_results, |
342 arraysize(expected_results)); | 342 arraysize(expected_results)); |
343 } | 343 } |
344 | 344 |
| 345 TEST_F(HistoryURLProviderTest, WhatYouTyped) { |
| 346 // Make sure we suggest a What You Typed match at the right times. |
| 347 RunTest(L"wytmatch", std::wstring(), false, NULL, 0); |
| 348 RunTest(L"wytmatch foo bar", std::wstring(), false, NULL, 0); |
| 349 RunTest(L"wytmatch+foo+bar", std::wstring(), false, NULL, 0); |
| 350 RunTest(L"wytmatch+foo+bar.com", std::wstring(), false, NULL, 0); |
| 351 |
| 352 const std::string results_1[] = {"http://www.wytmatch.com/"}; |
| 353 RunTest(L"wytmatch", L"com", false, results_1, arraysize(results_1)); |
| 354 |
| 355 const std::string results_2[] = {"http://wytmatch%20foo%20bar/"}; |
| 356 RunTest(L"http://wytmatch foo bar", std::wstring(), false, results_2, |
| 357 arraysize(results_2)); |
| 358 |
| 359 const std::string results_3[] = {"https://wytmatch%20foo%20bar/"}; |
| 360 RunTest(L"https://wytmatch foo bar", std::wstring(), false, results_3, |
| 361 arraysize(results_3)); |
| 362 } |
| 363 |
345 TEST_F(HistoryURLProviderTest, Fixup) { | 364 TEST_F(HistoryURLProviderTest, Fixup) { |
346 // Test for various past crashes we've had. | 365 // Test for various past crashes we've had. |
347 RunTest(L"\\", std::wstring(), false, NULL, 0); | 366 RunTest(L"\\", std::wstring(), false, NULL, 0); |
348 RunTest(L"#", std::wstring(), false, NULL, 0); | 367 RunTest(L"#", std::wstring(), false, NULL, 0); |
349 RunTest(L"%20", std::wstring(), false, NULL, 0); | 368 RunTest(L"%20", std::wstring(), false, NULL, 0); |
350 RunTest(L"\uff65@s", std::wstring(), false, NULL, 0); | 369 RunTest(L"\uff65@s", std::wstring(), false, NULL, 0); |
351 RunTest(L"\u2015\u2015@ \uff7c", std::wstring(), false, NULL, 0); | 370 RunTest(L"\u2015\u2015@ \uff7c", std::wstring(), false, NULL, 0); |
352 | 371 |
353 // Fixing up "file:" should result in an inline autocomplete offset of just | 372 // Fixing up "file:" should result in an inline autocomplete offset of just |
354 // after "file:", not just after "file://". | 373 // after "file:", not just after "file://". |
(...skipping 10 matching lines...) Expand all Loading... |
365 "http://bogussite.com/a", | 384 "http://bogussite.com/a", |
366 "http://bogussite.com/b", | 385 "http://bogussite.com/b", |
367 "http://bogussite.com/c", | 386 "http://bogussite.com/c", |
368 }; | 387 }; |
369 ASSERT_NO_FATAL_FAILURE(RunTest(input_2, std::wstring(), false, fixup_2, | 388 ASSERT_NO_FATAL_FAILURE(RunTest(input_2, std::wstring(), false, fixup_2, |
370 arraysize(fixup_2))); | 389 arraysize(fixup_2))); |
371 EXPECT_EQ(input_2.length(), matches_.front().inline_autocomplete_offset); | 390 EXPECT_EQ(input_2.length(), matches_.front().inline_autocomplete_offset); |
372 | 391 |
373 // Adding a TLD to a small number like "56" should result in "www.56.com" | 392 // Adding a TLD to a small number like "56" should result in "www.56.com" |
374 // rather than "0.0.0.56.com". | 393 // rather than "0.0.0.56.com". |
375 std::string fixup_3[] = {"http://www.56.com/"}; | 394 const std::string fixup_3[] = {"http://www.56.com/"}; |
376 RunTest(L"56", L"com", true, fixup_3, arraysize(fixup_3)); | 395 RunTest(L"56", L"com", true, fixup_3, arraysize(fixup_3)); |
377 | 396 |
378 // An input looks like a IP address like "127.0.0.1" should result in | 397 // An input looks like a IP address like "127.0.0.1" should result in |
379 // "http://127.0.0.1/". | 398 // "http://127.0.0.1/". |
380 std::string fixup_4[] = {"http://127.0.0.1/"}; | 399 const std::string fixup_4[] = {"http://127.0.0.1/"}; |
381 RunTest(L"127.0.0.1", std::wstring(), false, fixup_4, arraysize(fixup_4)); | 400 RunTest(L"127.0.0.1", std::wstring(), false, fixup_4, arraysize(fixup_4)); |
382 | 401 |
383 // An number "17173" should result in "http://www.17173.com/" in db. | 402 // An number "17173" should result in "http://www.17173.com/" in db. |
384 std::string fixup_5[] = {"http://www.17173.com/"}; | 403 const std::string fixup_5[] = {"http://www.17173.com/"}; |
385 RunTest(L"17173", std::wstring(), false, fixup_5, arraysize(fixup_5)); | 404 RunTest(L"17173", std::wstring(), false, fixup_5, arraysize(fixup_5)); |
386 } | 405 } |
OLD | NEW |