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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 const base::string16 text, | 353 const base::string16 text, |
354 bool prevent_inline_autocomplete, | 354 bool prevent_inline_autocomplete, |
355 const ExpectedURLs& expected_urls, | 355 const ExpectedURLs& expected_urls, |
356 std::string expected_top_result, | 356 std::string expected_top_result, |
357 base::string16 top_result_inline_autocompletion) { | 357 base::string16 top_result_inline_autocompletion) { |
358 base::MessageLoop::current()->RunUntilIdle(); | 358 base::MessageLoop::current()->RunUntilIdle(); |
359 AutocompleteInput input(text, base::string16::npos, std::string(), GURL(), | 359 AutocompleteInput input(text, base::string16::npos, std::string(), GURL(), |
360 metrics::OmniboxEventProto::INVALID_SPEC, | 360 metrics::OmniboxEventProto::INVALID_SPEC, |
361 prevent_inline_autocomplete, false, true, true, | 361 prevent_inline_autocomplete, false, true, true, |
362 ChromeAutocompleteSchemeClassifier(&profile_)); | 362 ChromeAutocompleteSchemeClassifier(&profile_)); |
363 provider_->Start(input, false); | 363 provider_->Start(input, false, false); |
364 EXPECT_TRUE(provider_->done()); | 364 EXPECT_TRUE(provider_->done()); |
365 | 365 |
366 ac_matches_ = provider_->matches(); | 366 ac_matches_ = provider_->matches(); |
367 | 367 |
368 // We should have gotten back at most AutocompleteProvider::kMaxMatches. | 368 // We should have gotten back at most AutocompleteProvider::kMaxMatches. |
369 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); | 369 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); |
370 | 370 |
371 // If the number of expected and actual matches aren't equal then we need | 371 // If the number of expected and actual matches aren't equal then we need |
372 // test no further, but let's do anyway so that we know which URLs failed. | 372 // test no further, but let's do anyway so that we know which URLs failed. |
373 EXPECT_EQ(expected_urls.size(), ac_matches_.size()); | 373 EXPECT_EQ(expected_urls.size(), ac_matches_.size()); |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 match.destination_url = GURL(shortcuts_to_test_delete[3].destination_url); | 814 match.destination_url = GURL(shortcuts_to_test_delete[3].destination_url); |
815 match.contents = ASCIIToUTF16(shortcuts_to_test_delete[3].contents); | 815 match.contents = ASCIIToUTF16(shortcuts_to_test_delete[3].contents); |
816 match.description = ASCIIToUTF16(shortcuts_to_test_delete[3].description); | 816 match.description = ASCIIToUTF16(shortcuts_to_test_delete[3].description); |
817 | 817 |
818 provider_->DeleteMatch(match); | 818 provider_->DeleteMatch(match); |
819 EXPECT_EQ(original_shortcuts_count + 1, backend_->shortcuts_map().size()); | 819 EXPECT_EQ(original_shortcuts_count + 1, backend_->shortcuts_map().size()); |
820 EXPECT_TRUE(backend_->shortcuts_map().end() == | 820 EXPECT_TRUE(backend_->shortcuts_map().end() == |
821 backend_->shortcuts_map().find(ASCIIToUTF16("delete"))); | 821 backend_->shortcuts_map().find(ASCIIToUTF16("delete"))); |
822 } | 822 } |
823 | 823 |
| 824 TEST_F(ShortcutsProviderTest, DoesNotProvideOnFocus) { |
| 825 AutocompleteInput input(ASCIIToUTF16("about:o"), base::string16::npos, |
| 826 std::string(), GURL(), |
| 827 metrics::OmniboxEventProto::INVALID_SPEC, |
| 828 false, false, true, true, |
| 829 ChromeAutocompleteSchemeClassifier(&profile_)); |
| 830 provider_->Start(input, false, true); |
| 831 EXPECT_TRUE(provider_->matches().empty()); |
| 832 } |
| 833 |
824 #if defined(ENABLE_EXTENSIONS) | 834 #if defined(ENABLE_EXTENSIONS) |
825 TEST_F(ShortcutsProviderTest, Extension) { | 835 TEST_F(ShortcutsProviderTest, Extension) { |
826 // Try an input string that matches an extension URL. | 836 // Try an input string that matches an extension URL. |
827 base::string16 text(ASCIIToUTF16("echo")); | 837 base::string16 text(ASCIIToUTF16("echo")); |
828 std::string expected_url( | 838 std::string expected_url( |
829 "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo"); | 839 "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo"); |
830 ExpectedURLs expected_urls; | 840 ExpectedURLs expected_urls; |
831 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( | 841 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( |
832 expected_url, true)); | 842 expected_url, true)); |
833 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(" echo")); | 843 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(" echo")); |
(...skipping 10 matching lines...) Expand all Loading... |
844 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); | 854 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); |
845 content::NotificationService::current()->Notify( | 855 content::NotificationService::current()->Notify( |
846 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 856 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
847 content::Source<Profile>(&profile_), | 857 content::Source<Profile>(&profile_), |
848 content::Details<extensions::UnloadedExtensionInfo>(&details)); | 858 content::Details<extensions::UnloadedExtensionInfo>(&details)); |
849 | 859 |
850 // Now the URL should have disappeared. | 860 // Now the URL should have disappeared. |
851 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); | 861 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); |
852 } | 862 } |
853 #endif | 863 #endif |
OLD | NEW |