| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/shortcuts_provider.h" | 5 #include "chrome/browser/autocomplete/shortcuts_provider.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F9", "notrailing.com/", | 179 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F9", "notrailing.com/", |
| 180 "http://notrailing.com", "http://notrailing.com/", "No Trailing Slash", | 180 "http://notrailing.com", "http://notrailing.com/", "No Trailing Slash", |
| 181 "0,1", "No Trailing Slash on fill_into_edit", "0,1", | 181 "0,1", "No Trailing Slash on fill_into_edit", "0,1", |
| 182 content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", | 182 content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", |
| 183 1, 100 }, | 183 1, 100 }, |
| 184 { "BD85DBA2-8C29-49F9-84AE-48E1E90880FA", "http:///foo.com", | 184 { "BD85DBA2-8C29-49F9-84AE-48E1E90880FA", "http:///foo.com", |
| 185 "http://foo.com", "http://foo.com/", "Foo - Typo in Input", | 185 "http://foo.com", "http://foo.com/", "Foo - Typo in Input", |
| 186 "0,1", "Foo - Typo in Input Corrected in fill_into_edit", "0,1", | 186 "0,1", "Foo - Typo in Input Corrected in fill_into_edit", "0,1", |
| 187 content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", | 187 content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", |
| 188 1, 100 }, | 188 1, 100 }, |
| 189 { "BD85DBA2-8C29-49F9-84AE-48E1E90880FB", "trailing1 ", |
| 190 "http://trailing1.com", "http://trailing1.com/", |
| 191 "Trailing1 - Space in Shortcut", "0,1", |
| 192 "Trailing1 - Space in Shortcut", "0,1", content::PAGE_TRANSITION_TYPED, |
| 193 AutocompleteMatchType::HISTORY_URL, "", 1, 100 }, |
| 194 { "BD85DBA2-8C29-49F9-84AE-48E1E90880FC", "about:trailing2 ", |
| 195 "chrome://trailing2blah", "chrome://trailing2blah/", |
| 196 "Trailing2 - Space in Shortcut", "0,1", |
| 197 "Trailing2 - Space in Shortcut", "0,1", content::PAGE_TRANSITION_TYPED, |
| 198 AutocompleteMatchType::HISTORY_URL, "", 1, 100 }, |
| 189 }; | 199 }; |
| 190 | 200 |
| 191 } // namespace | 201 } // namespace |
| 192 | 202 |
| 193 | 203 |
| 194 // ClassifyTest --------------------------------------------------------------- | 204 // ClassifyTest --------------------------------------------------------------- |
| 195 | 205 |
| 196 // Helper class to make running tests of ClassifyAllMatchesInString() more | 206 // Helper class to make running tests of ClassifyAllMatchesInString() more |
| 197 // convenient. | 207 // convenient. |
| 198 class ClassifyTest { | 208 class ClassifyTest { |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 RunTest(text, true, expected_urls, expected_url, base::string16()); | 514 RunTest(text, true, expected_urls, expected_url, base::string16()); |
| 505 | 515 |
| 506 // Test when the user input has a typo that can be fixed up for matching | 516 // Test when the user input has a typo that can be fixed up for matching |
| 507 // fill_into_edit. This should still be allowed to be default. | 517 // fill_into_edit. This should still be allowed to be default. |
| 508 text = ASCIIToUTF16("http:///foo.com"); | 518 text = ASCIIToUTF16("http:///foo.com"); |
| 509 expected_url = "http://foo.com/"; | 519 expected_url = "http://foo.com/"; |
| 510 expected_urls.clear(); | 520 expected_urls.clear(); |
| 511 expected_urls.push_back( | 521 expected_urls.push_back( |
| 512 ExpectedURLAndAllowedToBeDefault(expected_url, true)); | 522 ExpectedURLAndAllowedToBeDefault(expected_url, true)); |
| 513 RunTest(text, true, expected_urls, expected_url, base::string16()); | 523 RunTest(text, true, expected_urls, expected_url, base::string16()); |
| 524 |
| 525 // A foursome of tests to verify that trailing spaces prevent the shortcut |
| 526 // from being allowed to be the default match. For each of two tests, we |
| 527 // first verify that the match is allowed to be default without the trailing |
| 528 // space but is not allowed to be default with the trailing space. In both |
| 529 // of these with-trailing-space cases, we actually get an |
| 530 // inline_autocompletion, though it's never used because the match is |
| 531 // prohibited from being default. |
| 532 text = ASCIIToUTF16("trailing1"); |
| 533 expected_url = "http://trailing1.com/"; |
| 534 expected_urls.clear(); |
| 535 expected_urls.push_back( |
| 536 ExpectedURLAndAllowedToBeDefault(expected_url, true)); |
| 537 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(".com")); |
| 538 text = ASCIIToUTF16("trailing1 "); |
| 539 expected_urls.clear(); |
| 540 expected_urls.push_back( |
| 541 ExpectedURLAndAllowedToBeDefault(expected_url, false)); |
| 542 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(".com")); |
| 543 text = ASCIIToUTF16("about:trailing2"); |
| 544 expected_url = "chrome://trailing2blah/"; |
| 545 expected_urls.clear(); |
| 546 expected_urls.push_back( |
| 547 ExpectedURLAndAllowedToBeDefault(expected_url, true)); |
| 548 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("blah")); |
| 549 text = ASCIIToUTF16("about:trailing2 "); |
| 550 expected_urls.clear(); |
| 551 expected_urls.push_back( |
| 552 ExpectedURLAndAllowedToBeDefault(expected_url, false)); |
| 553 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("blah")); |
| 514 } | 554 } |
| 515 | 555 |
| 516 TEST_F(ShortcutsProviderTest, MultiMatch) { | 556 TEST_F(ShortcutsProviderTest, MultiMatch) { |
| 517 base::string16 text(ASCIIToUTF16("NEWS")); | 557 base::string16 text(ASCIIToUTF16("NEWS")); |
| 518 ExpectedURLs expected_urls; | 558 ExpectedURLs expected_urls; |
| 519 // Scores high because of completion length. | 559 // Scores high because of completion length. |
| 520 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( | 560 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( |
| 521 "http://slashdot.org/", false)); | 561 "http://slashdot.org/", false)); |
| 522 // Scores high because of visit count. | 562 // Scores high because of visit count. |
| 523 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( | 563 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 extensions::UnloadedExtensionInfo details( | 844 extensions::UnloadedExtensionInfo details( |
| 805 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); | 845 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); |
| 806 content::NotificationService::current()->Notify( | 846 content::NotificationService::current()->Notify( |
| 807 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 847 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| 808 content::Source<Profile>(&profile_), | 848 content::Source<Profile>(&profile_), |
| 809 content::Details<extensions::UnloadedExtensionInfo>(&details)); | 849 content::Details<extensions::UnloadedExtensionInfo>(&details)); |
| 810 | 850 |
| 811 // Now the URL should have disappeared. | 851 // Now the URL should have disappeared. |
| 812 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); | 852 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); |
| 813 } | 853 } |
| OLD | NEW |