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 pair of tests to verify that trailing spaces prevent the shortcut from |
| 526 // being allowed to be the default match. In both of these cases, we actually |
| 527 // get an inline_autocompletion, though it's never used because the match is |
| 528 // prohibited from being default |
| 529 text = ASCIIToUTF16("trailing1 "); |
| 530 expected_url = "http://trailing1.com/"; |
| 531 expected_urls.clear(); |
| 532 expected_urls.push_back( |
| 533 ExpectedURLAndAllowedToBeDefault(expected_url, false)); |
| 534 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(".com")); |
| 535 text = ASCIIToUTF16("about:trailing2 "); |
| 536 expected_url = "chrome://trailing2blah/"; |
| 537 expected_urls.clear(); |
| 538 expected_urls.push_back( |
| 539 ExpectedURLAndAllowedToBeDefault(expected_url, false)); |
| 540 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("blah")); |
514 } | 541 } |
515 | 542 |
516 TEST_F(ShortcutsProviderTest, MultiMatch) { | 543 TEST_F(ShortcutsProviderTest, MultiMatch) { |
517 base::string16 text(ASCIIToUTF16("NEWS")); | 544 base::string16 text(ASCIIToUTF16("NEWS")); |
518 ExpectedURLs expected_urls; | 545 ExpectedURLs expected_urls; |
519 // Scores high because of completion length. | 546 // Scores high because of completion length. |
520 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( | 547 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( |
521 "http://slashdot.org/", false)); | 548 "http://slashdot.org/", false)); |
522 // Scores high because of visit count. | 549 // Scores high because of visit count. |
523 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( | 550 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 extensions::UnloadedExtensionInfo details( | 831 extensions::UnloadedExtensionInfo details( |
805 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); | 832 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); |
806 content::NotificationService::current()->Notify( | 833 content::NotificationService::current()->Notify( |
807 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 834 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
808 content::Source<Profile>(&profile_), | 835 content::Source<Profile>(&profile_), |
809 content::Details<extensions::UnloadedExtensionInfo>(&details)); | 836 content::Details<extensions::UnloadedExtensionInfo>(&details)); |
810 | 837 |
811 // Now the URL should have disappeared. | 838 // Now the URL should have disappeared. |
812 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); | 839 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); |
813 } | 840 } |
OLD | NEW |