| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 arraysize(winky_results)); | 437 arraysize(winky_results)); |
| 438 RunTest(ASCIIToUTF16("winky"), ASCIIToUTF16("com"), false, winky_com_results, | 438 RunTest(ASCIIToUTF16("winky"), ASCIIToUTF16("com"), false, winky_com_results, |
| 439 arraysize(winky_com_results)); | 439 arraysize(winky_com_results)); |
| 440 } | 440 } |
| 441 | 441 |
| 442 TEST_F(HistoryURLProviderTest, Fixup) { | 442 TEST_F(HistoryURLProviderTest, Fixup) { |
| 443 // Test for various past crashes we've had. | 443 // Test for various past crashes we've had. |
| 444 RunTest(ASCIIToUTF16("\\"), string16(), false, NULL, 0); | 444 RunTest(ASCIIToUTF16("\\"), string16(), false, NULL, 0); |
| 445 RunTest(ASCIIToUTF16("#"), string16(), false, NULL, 0); | 445 RunTest(ASCIIToUTF16("#"), string16(), false, NULL, 0); |
| 446 RunTest(ASCIIToUTF16("%20"), string16(), false, NULL, 0); | 446 RunTest(ASCIIToUTF16("%20"), string16(), false, NULL, 0); |
| 447 RunTest(WideToUTF16(L"\uff65@s"), string16(), false, NULL, 0); | 447 const std::string fixup_crash[] = {"http://%EF%BD%A5@s/"}; |
| 448 RunTest(WideToUTF16(L"\uff65@s"), string16(), false, fixup_crash, |
| 449 arraysize(fixup_crash)); |
| 448 RunTest(WideToUTF16(L"\u2015\u2015@ \uff7c"), string16(), false, NULL, 0); | 450 RunTest(WideToUTF16(L"\u2015\u2015@ \uff7c"), string16(), false, NULL, 0); |
| 449 | 451 |
| 450 // Fixing up "file:" should result in an inline autocomplete offset of just | 452 // Fixing up "file:" should result in an inline autocomplete offset of just |
| 451 // after "file:", not just after "file://". | 453 // after "file:", not just after "file://". |
| 452 const string16 input_1(ASCIIToUTF16("file:")); | 454 const string16 input_1(ASCIIToUTF16("file:")); |
| 453 const std::string fixup_1[] = {"file:///C:/foo.txt"}; | 455 const std::string fixup_1[] = {"file:///C:/foo.txt"}; |
| 454 ASSERT_NO_FATAL_FAILURE(RunTest(input_1, string16(), false, fixup_1, | 456 ASSERT_NO_FATAL_FAILURE(RunTest(input_1, string16(), false, fixup_1, |
| 455 arraysize(fixup_1))); | 457 arraysize(fixup_1))); |
| 456 EXPECT_EQ(input_1.length(), matches_.front().inline_autocomplete_offset); | 458 EXPECT_EQ(input_1.length(), matches_.front().inline_autocomplete_offset); |
| 457 | 459 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 MessageLoop::current()->Run(); | 542 MessageLoop::current()->Run(); |
| 541 | 543 |
| 542 // None of the matches should attempt to autocomplete. | 544 // None of the matches should attempt to autocomplete. |
| 543 matches_ = autocomplete_->matches(); | 545 matches_ = autocomplete_->matches(); |
| 544 for (size_t i = 0; i < matches_.size(); ++i) | 546 for (size_t i = 0; i < matches_.size(); ++i) |
| 545 EXPECT_EQ(string16::npos, matches_[i].inline_autocomplete_offset); | 547 EXPECT_EQ(string16::npos, matches_[i].inline_autocomplete_offset); |
| 546 } | 548 } |
| 547 | 549 |
| 548 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) { | 550 TEST_F(HistoryURLProviderTest, TreatEmailsAsSearches) { |
| 549 // Visiting foo.com should not make this string be treated as a navigation. | 551 // Visiting foo.com should not make this string be treated as a navigation. |
| 550 RunTest(ASCIIToUTF16("user@foo.com"), string16(), false, NULL, 0); | 552 // That means the result should be scored at 1200 ("what you typed") and not |
| 553 // 1400+. |
| 554 const std::string expected[] = {"http://user@foo.com/"}; |
| 555 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("user@foo.com"), string16(), |
| 556 false, expected, arraysize(expected))); |
| 557 EXPECT_EQ(1200, matches_[0].relevance); |
| 551 } | 558 } |
| 552 | 559 |
| 553 TEST_F(HistoryURLProviderTest, IntranetURLsWithPaths) { | 560 TEST_F(HistoryURLProviderTest, IntranetURLsWithPaths) { |
| 554 struct TestCase { | 561 struct TestCase { |
| 555 const char* input; | 562 const char* input; |
| 556 bool has_output; | 563 int relevance; |
| 557 } test_cases[] = { | 564 } test_cases[] = { |
| 558 { "fooey", false }, | 565 { "fooey", 0 }, |
| 559 { "fooey/", true }, | 566 { "fooey/", 1200 }, // 1200 for URL would still navigate by default. |
| 560 { "fooey/a", false }, | 567 { "fooey/a", 1200 }, // 1200 for UNKNOWN would not. |
| 561 { "fooey/a b", false }, | 568 { "fooey/a b", 1200 }, // Also UNKNOWN. |
| 562 { "gooey", true }, | 569 { "gooey", 1410 }, |
| 563 { "gooey/", true }, | 570 { "gooey/", 1410 }, |
| 564 { "gooey/a", true }, | 571 { "gooey/a", 1400 }, |
| 565 { "gooey/a b", true }, | 572 { "gooey/a b", 1400 }, |
| 566 }; | 573 }; |
| 567 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 574 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 568 const std::string output[1] = { | 575 SCOPED_TRACE(test_cases[i].input); |
| 569 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec() | 576 if (test_cases[i].relevance == 0) { |
| 570 }; | 577 RunTest(ASCIIToUTF16(test_cases[i].input), string16(), false, NULL, 0); |
| 571 RunTest(ASCIIToUTF16(test_cases[i].input), string16(), false, | 578 } else { |
| 572 test_cases[i].has_output ? output : NULL, | 579 const std::string output[] = { |
| 573 test_cases[i].has_output ? 1 : 0); | 580 URLFixerUpper::FixupURL(test_cases[i].input, std::string()).spec() |
| 581 }; |
| 582 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), |
| 583 string16(), false, output, arraysize(output))); |
| 584 EXPECT_EQ(test_cases[i].relevance, matches_[0].relevance); |
| 585 } |
| 574 } | 586 } |
| 575 } | 587 } |
| 576 | 588 |
| 577 // Makes sure autocompletion happens for intranet sites that have been | 589 // Makes sure autocompletion happens for intranet sites that have been |
| 578 // previoulsy visited. | 590 // previoulsy visited. |
| 579 TEST_F(HistoryURLProviderTest, IntranetURLCompletion) { | 591 TEST_F(HistoryURLProviderTest, IntranetURLCompletion) { |
| 580 sort_matches_ = true; | 592 sort_matches_ = true; |
| 581 | 593 |
| 582 const std::string expected1[] = { | 594 const std::string expected1[] = { |
| 583 "http://intra/three", | 595 "http://intra/three", |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 "\\@st" | 648 "\\@st" |
| 637 }; | 649 }; |
| 638 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 650 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 639 AutocompleteInput input(ASCIIToUTF16(test_cases[i]), string16(), false, | 651 AutocompleteInput input(ASCIIToUTF16(test_cases[i]), string16(), false, |
| 640 false, true, AutocompleteInput::ALL_MATCHES); | 652 false, true, AutocompleteInput::ALL_MATCHES); |
| 641 autocomplete_->Start(input, false); | 653 autocomplete_->Start(input, false); |
| 642 if (!autocomplete_->done()) | 654 if (!autocomplete_->done()) |
| 643 MessageLoop::current()->Run(); | 655 MessageLoop::current()->Run(); |
| 644 } | 656 } |
| 645 } | 657 } |
| OLD | NEW |