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 14 matching lines...) Expand all Loading... |
25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
26 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
27 #include "components/history/core/browser/url_database.h" | 27 #include "components/history/core/browser/url_database.h" |
28 #include "components/metrics/proto/omnibox_event.pb.h" | 28 #include "components/metrics/proto/omnibox_event.pb.h" |
29 #include "components/omnibox/autocomplete_input.h" | 29 #include "components/omnibox/autocomplete_input.h" |
30 #include "components/omnibox/autocomplete_match.h" | 30 #include "components/omnibox/autocomplete_match.h" |
31 #include "components/omnibox/autocomplete_provider.h" | 31 #include "components/omnibox/autocomplete_provider.h" |
32 #include "components/omnibox/autocomplete_result.h" | 32 #include "components/omnibox/autocomplete_result.h" |
33 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
34 #include "content/public/test/test_browser_thread.h" | 34 #include "content/public/test/test_browser_thread.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | |
36 | |
37 #if defined(ENABLE_EXTENSIONS) | |
38 #include "extensions/browser/notification_types.h" | 35 #include "extensions/browser/notification_types.h" |
39 #include "extensions/common/extension.h" | 36 #include "extensions/common/extension.h" |
40 #include "extensions/common/extension_builder.h" | 37 #include "extensions/common/extension_builder.h" |
41 #include "extensions/common/value_builder.h" | 38 #include "extensions/common/value_builder.h" |
42 #endif | 39 #include "testing/gtest/include/gtest/gtest.h" |
43 | 40 |
44 using base::ASCIIToUTF16; | 41 using base::ASCIIToUTF16; |
45 | 42 |
46 // TestShortcutInfo ----------------------------------------------------------- | 43 // TestShortcutInfo ----------------------------------------------------------- |
47 | 44 |
48 namespace { | 45 namespace { |
49 | 46 |
50 struct TestShortcutInfo { | 47 struct TestShortcutInfo { |
51 std::string guid; | 48 std::string guid; |
52 std::string text; | 49 std::string text; |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 match.destination_url = GURL(shortcuts_to_test_delete[3].destination_url); | 812 match.destination_url = GURL(shortcuts_to_test_delete[3].destination_url); |
816 match.contents = ASCIIToUTF16(shortcuts_to_test_delete[3].contents); | 813 match.contents = ASCIIToUTF16(shortcuts_to_test_delete[3].contents); |
817 match.description = ASCIIToUTF16(shortcuts_to_test_delete[3].description); | 814 match.description = ASCIIToUTF16(shortcuts_to_test_delete[3].description); |
818 | 815 |
819 provider_->DeleteMatch(match); | 816 provider_->DeleteMatch(match); |
820 EXPECT_EQ(original_shortcuts_count + 1, backend_->shortcuts_map().size()); | 817 EXPECT_EQ(original_shortcuts_count + 1, backend_->shortcuts_map().size()); |
821 EXPECT_TRUE(backend_->shortcuts_map().end() == | 818 EXPECT_TRUE(backend_->shortcuts_map().end() == |
822 backend_->shortcuts_map().find(ASCIIToUTF16("delete"))); | 819 backend_->shortcuts_map().find(ASCIIToUTF16("delete"))); |
823 } | 820 } |
824 | 821 |
825 #if defined(ENABLE_EXTENSIONS) | |
826 TEST_F(ShortcutsProviderTest, Extension) { | 822 TEST_F(ShortcutsProviderTest, Extension) { |
827 // Try an input string that matches an extension URL. | 823 // Try an input string that matches an extension URL. |
828 base::string16 text(ASCIIToUTF16("echo")); | 824 base::string16 text(ASCIIToUTF16("echo")); |
829 std::string expected_url( | 825 std::string expected_url( |
830 "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo"); | 826 "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo"); |
831 ExpectedURLs expected_urls; | 827 ExpectedURLs expected_urls; |
832 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( | 828 expected_urls.push_back(ExpectedURLAndAllowedToBeDefault( |
833 expected_url, true)); | 829 expected_url, true)); |
834 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(" echo")); | 830 RunTest(text, false, expected_urls, expected_url, ASCIIToUTF16(" echo")); |
835 | 831 |
836 // Claim the extension has been unloaded. | 832 // Claim the extension has been unloaded. |
837 scoped_refptr<const extensions::Extension> extension = | 833 scoped_refptr<const extensions::Extension> extension = |
838 extensions::ExtensionBuilder() | 834 extensions::ExtensionBuilder() |
839 .SetManifest(extensions::DictionaryBuilder() | 835 .SetManifest(extensions::DictionaryBuilder() |
840 .Set("name", "Echo") | 836 .Set("name", "Echo") |
841 .Set("version", "1.0")) | 837 .Set("version", "1.0")) |
842 .SetID("cedabbhfglmiikkmdgcpjdkocfcmbkee") | 838 .SetID("cedabbhfglmiikkmdgcpjdkocfcmbkee") |
843 .Build(); | 839 .Build(); |
844 extensions::UnloadedExtensionInfo details( | 840 extensions::UnloadedExtensionInfo details( |
845 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); | 841 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); |
846 content::NotificationService::current()->Notify( | 842 content::NotificationService::current()->Notify( |
847 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 843 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
848 content::Source<Profile>(&profile_), | 844 content::Source<Profile>(&profile_), |
849 content::Details<extensions::UnloadedExtensionInfo>(&details)); | 845 content::Details<extensions::UnloadedExtensionInfo>(&details)); |
850 | 846 |
851 // Now the URL should have disappeared. | 847 // Now the URL should have disappeared. |
852 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); | 848 RunTest(text, false, ExpectedURLs(), std::string(), base::string16()); |
853 } | 849 } |
854 #endif | |
OLD | NEW |