| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/autocomplete/history_url_provider.h" | 10 #include "chrome/browser/autocomplete/history_url_provider.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 {"http://www.17173.com/", "Domain with number", 3, 3}, | 81 {"http://www.17173.com/", "Domain with number", 3, 3}, |
| 82 | 82 |
| 83 // URLs to test exact-matching behavior. | 83 // URLs to test exact-matching behavior. |
| 84 {"http://go/", "Intranet URL", 1, 1}, | 84 {"http://go/", "Intranet URL", 1, 1}, |
| 85 {"http://gooey/", "Intranet URL 2", 5, 5}, | 85 {"http://gooey/", "Intranet URL 2", 5, 5}, |
| 86 | 86 |
| 87 // URLs for testing offset adjustment. | 87 // URLs for testing offset adjustment. |
| 88 {"http://www.\xEA\xB5\x90\xEC\x9C\xA1.kr/", "Korean", 2, 2}, | 88 {"http://www.\xEA\xB5\x90\xEC\x9C\xA1.kr/", "Korean", 2, 2}, |
| 89 {"http://spaces.com/path%20with%20spaces/foo.html", "Spaces", 2, 2}, | 89 {"http://spaces.com/path%20with%20spaces/foo.html", "Spaces", 2, 2}, |
| 90 {"http://ms/c++%20style%20guide", "Style guide", 2, 2}, | 90 {"http://ms/c++%20style%20guide", "Style guide", 2, 2}, |
| 91 |
| 92 // URLs for testing ctrl-enter behavior. |
| 93 {"http://binky/", "Intranet binky", 2, 2}, |
| 94 {"http://winky/", "Intranet winky", 2, 2}, |
| 95 {"http://www.winky.com/", "Internet winky", 5, 0}, |
| 91 }; | 96 }; |
| 92 | 97 |
| 93 class HistoryURLProviderTest : public testing::Test, | 98 class HistoryURLProviderTest : public testing::Test, |
| 94 public ACProviderListener { | 99 public ACProviderListener { |
| 95 public: | 100 public: |
| 96 HistoryURLProviderTest() | 101 HistoryURLProviderTest() |
| 97 : ui_thread_(ChromeThread::UI, &message_loop_), | 102 : ui_thread_(ChromeThread::UI, &message_loop_), |
| 98 file_thread_(ChromeThread::FILE, &message_loop_) {} | 103 file_thread_(ChromeThread::FILE, &message_loop_) {} |
| 99 | 104 |
| 100 // ACProviderListener | 105 // ACProviderListener |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 bool prevent_inline_autocomplete, | 190 bool prevent_inline_autocomplete, |
| 186 const std::string* expected_urls, | 191 const std::string* expected_urls, |
| 187 size_t num_results) { | 192 size_t num_results) { |
| 188 AutocompleteInput input(text, desired_tld, prevent_inline_autocomplete, | 193 AutocompleteInput input(text, desired_tld, prevent_inline_autocomplete, |
| 189 false, false); | 194 false, false); |
| 190 autocomplete_->Start(input, false); | 195 autocomplete_->Start(input, false); |
| 191 if (!autocomplete_->done()) | 196 if (!autocomplete_->done()) |
| 192 MessageLoop::current()->Run(); | 197 MessageLoop::current()->Run(); |
| 193 | 198 |
| 194 matches_ = autocomplete_->matches(); | 199 matches_ = autocomplete_->matches(); |
| 195 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text; | 200 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text |
| 201 << "\nTLD: \"" << desired_tld << "\""; |
| 196 for (size_t i = 0; i < num_results; ++i) | 202 for (size_t i = 0; i < num_results; ++i) |
| 197 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec()); | 203 EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec()); |
| 198 } | 204 } |
| 199 | 205 |
| 200 void HistoryURLProviderTest::RunAdjustOffsetTest(const std::wstring text, | 206 void HistoryURLProviderTest::RunAdjustOffsetTest(const std::wstring text, |
| 201 size_t expected_offset) { | 207 size_t expected_offset) { |
| 202 AutocompleteInput input(text, std::wstring(), false, false, false); | 208 AutocompleteInput input(text, std::wstring(), false, false, false); |
| 203 autocomplete_->Start(input, false); | 209 autocomplete_->Start(input, false); |
| 204 if (!autocomplete_->done()) | 210 if (!autocomplete_->done()) |
| 205 MessageLoop::current()->Run(); | 211 MessageLoop::current()->Run(); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 const std::string results_1[] = {"http://www.wytmatch.com/"}; | 359 const std::string results_1[] = {"http://www.wytmatch.com/"}; |
| 354 RunTest(L"wytmatch", L"com", false, results_1, arraysize(results_1)); | 360 RunTest(L"wytmatch", L"com", false, results_1, arraysize(results_1)); |
| 355 | 361 |
| 356 const std::string results_2[] = {"http://wytmatch%20foo%20bar/"}; | 362 const std::string results_2[] = {"http://wytmatch%20foo%20bar/"}; |
| 357 RunTest(L"http://wytmatch foo bar", std::wstring(), false, results_2, | 363 RunTest(L"http://wytmatch foo bar", std::wstring(), false, results_2, |
| 358 arraysize(results_2)); | 364 arraysize(results_2)); |
| 359 | 365 |
| 360 const std::string results_3[] = {"https://wytmatch%20foo%20bar/"}; | 366 const std::string results_3[] = {"https://wytmatch%20foo%20bar/"}; |
| 361 RunTest(L"https://wytmatch foo bar", std::wstring(), false, results_3, | 367 RunTest(L"https://wytmatch foo bar", std::wstring(), false, results_3, |
| 362 arraysize(results_3)); | 368 arraysize(results_3)); |
| 369 |
| 370 // Test the corner case where a user has fully typed a previously visited |
| 371 // intranet address and is now hitting ctrl-enter, which completes to a |
| 372 // previously unvisted internet domain. |
| 373 const std::string binky_results[] = {"http://binky/"}; |
| 374 const std::string binky_com_results[] = { |
| 375 "http://www.binky.com/", |
| 376 "http://binky/", |
| 377 }; |
| 378 RunTest(L"binky", std::wstring(), false, binky_results, |
| 379 arraysize(binky_results)); |
| 380 RunTest(L"binky", L"com", false, binky_com_results, |
| 381 arraysize(binky_com_results)); |
| 382 |
| 383 // Test the related case where a user has fully typed a previously visited |
| 384 // intranet address and is now hitting ctrl-enter, which completes to a |
| 385 // previously visted internet domain. |
| 386 const std::string winky_results[] = { |
| 387 "http://winky/", |
| 388 "http://www.winky.com/", |
| 389 }; |
| 390 const std::string winky_com_results[] = { |
| 391 "http://www.winky.com/", |
| 392 "http://winky/", |
| 393 }; |
| 394 RunTest(L"winky", std::wstring(), false, winky_results, |
| 395 arraysize(winky_results)); |
| 396 RunTest(L"winky", L"com", false, winky_com_results, |
| 397 arraysize(winky_com_results)); |
| 363 } | 398 } |
| 364 | 399 |
| 365 TEST_F(HistoryURLProviderTest, Fixup) { | 400 TEST_F(HistoryURLProviderTest, Fixup) { |
| 366 // Test for various past crashes we've had. | 401 // Test for various past crashes we've had. |
| 367 RunTest(L"\\", std::wstring(), false, NULL, 0); | 402 RunTest(L"\\", std::wstring(), false, NULL, 0); |
| 368 RunTest(L"#", std::wstring(), false, NULL, 0); | 403 RunTest(L"#", std::wstring(), false, NULL, 0); |
| 369 RunTest(L"%20", std::wstring(), false, NULL, 0); | 404 RunTest(L"%20", std::wstring(), false, NULL, 0); |
| 370 RunTest(L"\uff65@s", std::wstring(), false, NULL, 0); | 405 RunTest(L"\uff65@s", std::wstring(), false, NULL, 0); |
| 371 RunTest(L"\u2015\u2015@ \uff7c", std::wstring(), false, NULL, 0); | 406 RunTest(L"\u2015\u2015@ \uff7c", std::wstring(), false, NULL, 0); |
| 372 | 407 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 std::string navigation_1[] = {"http://test.com/"}; | 452 std::string navigation_1[] = {"http://test.com/"}; |
| 418 RunTest(L"test.com", std::wstring(), false, navigation_1, | 453 RunTest(L"test.com", std::wstring(), false, navigation_1, |
| 419 arraysize(navigation_1)); | 454 arraysize(navigation_1)); |
| 420 | 455 |
| 421 std::string navigation_2[] = {"http://slash/"}; | 456 std::string navigation_2[] = {"http://slash/"}; |
| 422 RunTest(L"slash", std::wstring(), false, navigation_2, | 457 RunTest(L"slash", std::wstring(), false, navigation_2, |
| 423 arraysize(navigation_2)); | 458 arraysize(navigation_2)); |
| 424 | 459 |
| 425 RunTest(L"this is a query", std::wstring(), false, NULL, 0); | 460 RunTest(L"this is a query", std::wstring(), false, NULL, 0); |
| 426 } | 461 } |
| OLD | NEW |