| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, | 149 content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 1, |
| 150 100 }, | 150 100 }, |
| 151 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F3", "query", "query", | 151 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F3", "query", "query", |
| 152 "https://www.google.com/search?q=query", "query", "0,0", | 152 "https://www.google.com/search?q=query", "query", "0,0", |
| 153 "Google Search", "0,4", content::PAGE_TRANSITION_GENERATED, | 153 "Google Search", "0,4", content::PAGE_TRANSITION_GENERATED, |
| 154 AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100 }, | 154 AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100 }, |
| 155 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F4", "word", "www.word", | 155 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F4", "word", "www.word", |
| 156 "https://www.google.com/search?q=www.word", "www.word", "0,0", | 156 "https://www.google.com/search?q=www.word", "www.word", "0,0", |
| 157 "Google Search", "0,4", content::PAGE_TRANSITION_GENERATED, | 157 "Google Search", "0,4", content::PAGE_TRANSITION_GENERATED, |
| 158 AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100 }, | 158 AutocompleteMatchType::SEARCH_HISTORY, "", 1, 100 }, |
| 159 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F5", "about:o", "chrome://omnibox", | |
| 160 "chrome://omnibox/", "about:omnibox", "0,3,10,1", "", "", | |
| 161 content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::NAVSUGGEST, "", | |
| 162 1, 100 }, | |
| 163 { "BD85DBA2-8C29-49F9-84AE-48E1E90880F6", "www/real sp", | |
| 164 "http://www/real space/long-url-with-space.html", | |
| 165 "http://www/real%20space/long-url-with-space.html", | |
| 166 "www/real space/long-url-with-space.html", "0,3,11,1", | |
| 167 "Page With Space; Input with Space", "0,0", | |
| 168 content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", | |
| 169 1, 100 }, | |
| 170 }; | 159 }; |
| 171 | 160 |
| 172 } // namespace | 161 } // namespace |
| 173 | 162 |
| 174 | 163 |
| 175 // ClassifyTest --------------------------------------------------------------- | 164 // ClassifyTest --------------------------------------------------------------- |
| 176 | 165 |
| 177 // Helper class to make running tests of ClassifyAllMatchesInString() more | 166 // Helper class to make running tests of ClassifyAllMatchesInString() more |
| 178 // convenient. | 167 // convenient. |
| 179 class ClassifyTest { | 168 class ClassifyTest { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 // non-droppable prefix. ("www.", for instance, is not droppable for | 425 // non-droppable prefix. ("www.", for instance, is not droppable for |
| 437 // queries.) | 426 // queries.) |
| 438 text = ASCIIToUTF16("word"); | 427 text = ASCIIToUTF16("word"); |
| 439 expected_url = "https://www.google.com/search?q=www.word"; | 428 expected_url = "https://www.google.com/search?q=www.word"; |
| 440 expected_urls.clear(); | 429 expected_urls.clear(); |
| 441 expected_urls.push_back( | 430 expected_urls.push_back( |
| 442 ExpectedURLAndAllowedToBeDefault(expected_url, false)); | 431 ExpectedURLAndAllowedToBeDefault(expected_url, false)); |
| 443 RunTest(text, false, expected_urls, expected_url, base::string16()); | 432 RunTest(text, false, expected_urls, expected_url, base::string16()); |
| 444 } | 433 } |
| 445 | 434 |
| 446 // These tests are like those in SimpleSingleMatch but more complex, | |
| 447 // involving URLs that need to be fixed up to match properly. | |
| 448 TEST_F(ShortcutsProviderTest, TrickySingleMatch) { | |
| 449 // Test that about: URLs are fixed up/transformed to chrome:// URLs. | |
| 450 base::string16 text(ASCIIToUTF16("about:o")); | |
| 451 std::string expected_url("chrome://omnibox/"); | |
| 452 ExpectedURLs expected_urls; | |
| 453 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); | |
| 454 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16("mnibox")); | |
| 455 | |
| 456 // Same test with prevent inline autocomplete. | |
| 457 expected_urls.clear(); | |
| 458 expected_urls.push_back( | |
| 459 ExpectedURLAndAllowedToBeDefault(expected_url, false)); | |
| 460 // The match will have an |inline_autocompletion| set, but the value will not | |
| 461 // be used because |allowed_to_be_default_match| will be false. | |
| 462 RunTest(text, true, expected_urls, expected_url, ASCIIToUTF16("mnibox")); | |
| 463 | |
| 464 // Test that an input with a space can match URLs with a (escaped) space. | |
| 465 // This would fail if we didn't try to lookup the un-fixed-up string. | |
| 466 text = ASCIIToUTF16("www/real sp"); | |
| 467 expected_url = "http://www/real%20space/long-url-with-space.html"; | |
| 468 expected_urls.clear(); | |
| 469 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault(expected_url, true)); | |
| 470 RunTest(text, false, expected_urls, expected_url, | |
| 471 ASCIIToUTF16("ace/long-url-with-space.html")); | |
| 472 | |
| 473 // Same test with prevent inline autocomplete. | |
| 474 expected_urls.clear(); | |
| 475 expected_urls.push_back( | |
| 476 ExpectedURLAndAllowedToBeDefault(expected_url, false)); | |
| 477 // The match will have an |inline_autocompletion| set, but the value will not | |
| 478 // be used because |allowed_to_be_default_match| will be false. | |
| 479 RunTest(text, true, expected_urls, expected_url, | |
| 480 ASCIIToUTF16("ace/long-url-with-space.html")); | |
| 481 } | |
| 482 | |
| 483 TEST_F(ShortcutsProviderTest, MultiMatch) { | 435 TEST_F(ShortcutsProviderTest, MultiMatch) { |
| 484 base::string16 text(ASCIIToUTF16("NEWS")); | 436 base::string16 text(ASCIIToUTF16("NEWS")); |
| 485 ExpectedURLs expected_urls; | 437 ExpectedURLs expected_urls; |
| 486 // Scores high because of completion length. | 438 // Scores high because of completion length. |
| 487 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( | 439 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( |
| 488 "http://slashdot.org/", false)); | 440 "http://slashdot.org/", false)); |
| 489 // Scores high because of visit count. | 441 // Scores high because of visit count. |
| 490 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( | 442 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( |
| 491 "http://sports.yahoo.com/", false)); | 443 "http://sports.yahoo.com/", false)); |
| 492 // Scores high because of visit count but less match span, | 444 // Scores high because of visit count but less match span, |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 content::NotificationService::current()->Notify( | 718 content::NotificationService::current()->Notify( |
| 767 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 719 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 768 content::Source<Profile>(&profile_), | 720 content::Source<Profile>(&profile_), |
| 769 content::Details<extensions::UnloadedExtensionInfo>(&details)); | 721 content::Details<extensions::UnloadedExtensionInfo>(&details)); |
| 770 | 722 |
| 771 // Now the URL should have disappeared. | 723 // Now the URL should have disappeared. |
| 772 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); | 724 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); |
| 773 } | 725 } |
| 774 | 726 |
| 775 } // namespace history | 727 } // namespace history |
| OLD | NEW |