| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extensions/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 ValidateIntegerPref(good2, "location", Manifest::INTERNAL); | 860 ValidateIntegerPref(good2, "location", Manifest::INTERNAL); |
| 861 | 861 |
| 862 URLPatternSet expected_patterns; | 862 URLPatternSet expected_patterns; |
| 863 AddPattern(&expected_patterns, "file:///*"); | 863 AddPattern(&expected_patterns, "file:///*"); |
| 864 AddPattern(&expected_patterns, "http://*.google.com/*"); | 864 AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 865 AddPattern(&expected_patterns, "https://*.google.com/*"); | 865 AddPattern(&expected_patterns, "https://*.google.com/*"); |
| 866 const Extension* extension = loaded_[0].get(); | 866 const Extension* extension = loaded_[0].get(); |
| 867 const extensions::UserScriptList& scripts = | 867 const extensions::UserScriptList& scripts = |
| 868 extensions::ContentScriptsInfo::GetContentScripts(extension); | 868 extensions::ContentScriptsInfo::GetContentScripts(extension); |
| 869 ASSERT_EQ(2u, scripts.size()); | 869 ASSERT_EQ(2u, scripts.size()); |
| 870 EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); | 870 EXPECT_EQ(expected_patterns, scripts[0]->url_patterns()); |
| 871 EXPECT_EQ(2u, scripts[0].js_scripts().size()); | 871 EXPECT_EQ(2u, scripts[0]->js_scripts().size()); |
| 872 ExtensionResource resource00(extension->id(), | 872 ExtensionResource resource00(extension->id(), |
| 873 scripts[0].js_scripts()[0].extension_root(), | 873 scripts[0]->js_scripts()[0]->extension_root(), |
| 874 scripts[0].js_scripts()[0].relative_path()); | 874 scripts[0]->js_scripts()[0]->relative_path()); |
| 875 base::FilePath expected_path = | 875 base::FilePath expected_path = |
| 876 base::MakeAbsoluteFilePath(extension->path().AppendASCII("script1.js")); | 876 base::MakeAbsoluteFilePath(extension->path().AppendASCII("script1.js")); |
| 877 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); | 877 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); |
| 878 ExtensionResource resource01(extension->id(), | 878 ExtensionResource resource01(extension->id(), |
| 879 scripts[0].js_scripts()[1].extension_root(), | 879 scripts[0]->js_scripts()[1]->extension_root(), |
| 880 scripts[0].js_scripts()[1].relative_path()); | 880 scripts[0]->js_scripts()[1]->relative_path()); |
| 881 expected_path = | 881 expected_path = |
| 882 base::MakeAbsoluteFilePath(extension->path().AppendASCII("script2.js")); | 882 base::MakeAbsoluteFilePath(extension->path().AppendASCII("script2.js")); |
| 883 EXPECT_TRUE(resource01.ComparePathWithDefault(expected_path)); | 883 EXPECT_TRUE(resource01.ComparePathWithDefault(expected_path)); |
| 884 EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(extension)); | 884 EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(extension)); |
| 885 EXPECT_EQ(1u, scripts[1].url_patterns().patterns().size()); | 885 EXPECT_EQ(1u, scripts[1]->url_patterns().patterns().size()); |
| 886 EXPECT_EQ("http://*.news.com/*", | 886 EXPECT_EQ("http://*.news.com/*", |
| 887 scripts[1].url_patterns().begin()->GetAsString()); | 887 scripts[1]->url_patterns().begin()->GetAsString()); |
| 888 ExtensionResource resource10(extension->id(), | 888 ExtensionResource resource10(extension->id(), |
| 889 scripts[1].js_scripts()[0].extension_root(), | 889 scripts[1]->js_scripts()[0]->extension_root(), |
| 890 scripts[1].js_scripts()[0].relative_path()); | 890 scripts[1]->js_scripts()[0]->relative_path()); |
| 891 expected_path = | 891 expected_path = |
| 892 extension->path().AppendASCII("js_files").AppendASCII("script3.js"); | 892 extension->path().AppendASCII("js_files").AppendASCII("script3.js"); |
| 893 expected_path = base::MakeAbsoluteFilePath(expected_path); | 893 expected_path = base::MakeAbsoluteFilePath(expected_path); |
| 894 EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); | 894 EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); |
| 895 | 895 |
| 896 expected_patterns.ClearPatterns(); | 896 expected_patterns.ClearPatterns(); |
| 897 AddPattern(&expected_patterns, "http://*.google.com/*"); | 897 AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 898 AddPattern(&expected_patterns, "https://*.google.com/*"); | 898 AddPattern(&expected_patterns, "https://*.google.com/*"); |
| 899 EXPECT_EQ( | 899 EXPECT_EQ( |
| 900 expected_patterns, | 900 expected_patterns, |
| 901 extension->permissions_data()->active_permissions().explicit_hosts()); | 901 extension->permissions_data()->active_permissions().explicit_hosts()); |
| 902 | 902 |
| 903 EXPECT_EQ(std::string(good1), loaded_[1]->id()); | 903 EXPECT_EQ(std::string(good1), loaded_[1]->id()); |
| 904 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); | 904 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); |
| 905 EXPECT_EQ(std::string(), loaded_[1]->description()); | 905 EXPECT_EQ(std::string(), loaded_[1]->description()); |
| 906 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), | 906 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), |
| 907 extensions::BackgroundInfo::GetBackgroundURL(loaded_[1].get())); | 907 extensions::BackgroundInfo::GetBackgroundURL(loaded_[1].get())); |
| 908 EXPECT_EQ(0u, | 908 EXPECT_TRUE( |
| 909 extensions::ContentScriptsInfo::GetContentScripts(loaded_[1].get()) | 909 extensions::ContentScriptsInfo::GetContentScripts(loaded_[1].get()) |
| 910 .size()); | 910 .empty()); |
| 911 | 911 |
| 912 // We don't parse the plugins section on Chrome OS. | 912 // We don't parse the plugins section on Chrome OS. |
| 913 #if defined(OS_CHROMEOS) | 913 #if defined(OS_CHROMEOS) |
| 914 EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(loaded_[1].get())); | 914 EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(loaded_[1].get())); |
| 915 #else | 915 #else |
| 916 ASSERT_TRUE(extensions::PluginInfo::HasPlugins(loaded_[1].get())); | 916 ASSERT_TRUE(extensions::PluginInfo::HasPlugins(loaded_[1].get())); |
| 917 const std::vector<extensions::PluginInfo>* plugins = | 917 const std::vector<extensions::PluginInfo>* plugins = |
| 918 extensions::PluginInfo::GetPlugins(loaded_[1].get()); | 918 extensions::PluginInfo::GetPlugins(loaded_[1].get()); |
| 919 ASSERT_TRUE(plugins); | 919 ASSERT_TRUE(plugins); |
| 920 ASSERT_EQ(2u, plugins->size()); | 920 ASSERT_EQ(2u, plugins->size()); |
| 921 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), | 921 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), |
| 922 plugins->at(0).path.value()); | 922 plugins->at(0).path.value()); |
| 923 EXPECT_TRUE(plugins->at(0).is_public); | 923 EXPECT_TRUE(plugins->at(0).is_public); |
| 924 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), | 924 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), |
| 925 plugins->at(1).path.value()); | 925 plugins->at(1).path.value()); |
| 926 EXPECT_FALSE(plugins->at(1).is_public); | 926 EXPECT_FALSE(plugins->at(1).is_public); |
| 927 #endif | 927 #endif |
| 928 | 928 |
| 929 EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location()); | 929 EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location()); |
| 930 | 930 |
| 931 int index = expected_num_extensions - 1; | 931 int index = expected_num_extensions - 1; |
| 932 EXPECT_EQ(std::string(good2), loaded_[index]->id()); | 932 EXPECT_EQ(std::string(good2), loaded_[index]->id()); |
| 933 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); | 933 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); |
| 934 EXPECT_EQ(std::string(), loaded_[index]->description()); | 934 EXPECT_EQ(std::string(), loaded_[index]->description()); |
| 935 EXPECT_EQ(0u, | 935 EXPECT_TRUE( |
| 936 extensions::ContentScriptsInfo::GetContentScripts( | 936 extensions::ContentScriptsInfo::GetContentScripts(loaded_[index].get()) |
| 937 loaded_[index].get()).size()); | 937 .empty()); |
| 938 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); | 938 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); |
| 939 } | 939 } |
| 940 | 940 |
| 941 // Test loading bad extensions from the profile directory. | 941 // Test loading bad extensions from the profile directory. |
| 942 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { | 942 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { |
| 943 // Initialize the test dir with a bad Preferences/extensions. | 943 // Initialize the test dir with a bad Preferences/extensions. |
| 944 base::FilePath source_install_dir = | 944 base::FilePath source_install_dir = |
| 945 data_dir().AppendASCII("bad").AppendASCII("Extensions"); | 945 data_dir().AppendASCII("bad").AppendASCII("Extensions"); |
| 946 base::FilePath pref_path = | 946 base::FilePath pref_path = |
| 947 source_install_dir.DirName().Append(chrome::kPreferencesFilename); | 947 source_install_dir.DirName().Append(chrome::kPreferencesFilename); |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2084 | 2084 |
| 2085 // A theme with extension elements. Themes cannot have extension elements, | 2085 // A theme with extension elements. Themes cannot have extension elements, |
| 2086 // so any such elements (like content scripts) should be ignored. | 2086 // so any such elements (like content scripts) should be ignored. |
| 2087 service()->set_extensions_enabled(true); | 2087 service()->set_extensions_enabled(true); |
| 2088 { | 2088 { |
| 2089 path = data_dir().AppendASCII("theme_with_extension.crx"); | 2089 path = data_dir().AppendASCII("theme_with_extension.crx"); |
| 2090 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 2090 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2091 ValidatePrefKeyCount(++pref_count); | 2091 ValidatePrefKeyCount(++pref_count); |
| 2092 ASSERT_TRUE(extension); | 2092 ASSERT_TRUE(extension); |
| 2093 EXPECT_TRUE(extension->is_theme()); | 2093 EXPECT_TRUE(extension->is_theme()); |
| 2094 EXPECT_EQ( | 2094 EXPECT_TRUE( |
| 2095 0u, | 2095 extensions::ContentScriptsInfo::GetContentScripts(extension).empty()); |
| 2096 extensions::ContentScriptsInfo::GetContentScripts(extension).size()); | |
| 2097 } | 2096 } |
| 2098 | 2097 |
| 2099 // A theme with image resources missing (misspelt path). | 2098 // A theme with image resources missing (misspelt path). |
| 2100 path = data_dir().AppendASCII("theme_missing_image.crx"); | 2099 path = data_dir().AppendASCII("theme_missing_image.crx"); |
| 2101 InstallCRX(path, INSTALL_FAILED); | 2100 InstallCRX(path, INSTALL_FAILED); |
| 2102 ValidatePrefKeyCount(pref_count); | 2101 ValidatePrefKeyCount(pref_count); |
| 2103 } | 2102 } |
| 2104 | 2103 |
| 2105 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { | 2104 TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { |
| 2106 // Load. | 2105 // Load. |
| (...skipping 4803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6910 | 6909 |
| 6911 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 6910 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 6912 content::Source<Profile>(profile()), | 6911 content::Source<Profile>(profile()), |
| 6913 content::NotificationService::NoDetails()); | 6912 content::NotificationService::NoDetails()); |
| 6914 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 6913 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
| 6915 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 6914 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 6916 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 6915 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 6917 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 6916 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 6918 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 6917 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
| 6919 } | 6918 } |
| OLD | NEW |