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