| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stddef.h> | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "build/build_config.h" | |
| 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | |
| 10 #include "chrome/browser/extensions/extension_browsertest.h" | |
| 11 #include "chrome/browser/extensions/extension_service.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "chrome/browser/ui/browser.h" | |
| 14 #include "chrome/browser/ui/browser_commands.h" | |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 16 #include "chrome/common/pref_names.h" | |
| 17 #include "chrome/test/base/test_switches.h" | |
| 18 #include "chrome/test/base/ui_test_utils.h" | |
| 19 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
| 20 #include "components/prefs/pref_service.h" | |
| 21 #include "content/public/browser/navigation_controller.h" | |
| 22 #include "content/public/browser/plugin_service.h" | |
| 23 #include "content/public/browser/web_contents.h" | |
| 24 #include "content/public/test/browser_test_utils.h" | |
| 25 #include "extensions/browser/extension_registry.h" | |
| 26 #include "extensions/browser/extension_system.h" | |
| 27 #include "extensions/common/extension.h" | |
| 28 #include "net/base/filename_util.h" | |
| 29 | |
| 30 using content::NavigationController; | |
| 31 using content::WebContents; | |
| 32 using extensions::Extension; | |
| 33 | |
| 34 #if defined(OS_WIN) | |
| 35 // http://crbug.com/123851 : test flakily fails on win. | |
| 36 #define MAYBE_PluginLoadUnload DISABLED_PluginLoadUnload | |
| 37 #elif defined(OS_MACOSX) && defined(ADDRESS_SANITIZER) | |
| 38 // ExtensionBrowserTest.PluginLoadUnload started failing after the switch to | |
| 39 // dynamic ASan runtime library on Mac. See http://crbug.com/234591. | |
| 40 #define MAYBE_PluginLoadUnload DISABLED_PluginLoadUnload | |
| 41 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | |
| 42 // Timing out on ARM linux http://crbug.com/238460 | |
| 43 #define MAYBE_PluginLoadUnload DISABLED_PluginLoadUnload | |
| 44 #else | |
| 45 #define MAYBE_PluginLoadUnload PluginLoadUnload | |
| 46 #endif | |
| 47 | |
| 48 // Tests that a renderer's plugin list is properly updated when we load and | |
| 49 // unload an extension that contains a plugin. | |
| 50 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginLoadUnload) { | |
| 51 if (!content::PluginService::GetInstance()->NPAPIPluginsSupported()) | |
| 52 return; | |
| 53 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize, | |
| 54 true); | |
| 55 | |
| 56 base::FilePath extension_dir = | |
| 57 test_data_dir_.AppendASCII("uitest").AppendASCII("plugins"); | |
| 58 | |
| 59 ui_test_utils::NavigateToURL(browser(), | |
| 60 net::FilePathToFileURL(extension_dir.AppendASCII("test.html"))); | |
| 61 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 62 | |
| 63 // With no extensions, the plugin should not be loaded. | |
| 64 bool result = false; | |
| 65 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 66 tab, "testPluginWorks()", &result)); | |
| 67 EXPECT_FALSE(result); | |
| 68 | |
| 69 ExtensionService* service = extensions::ExtensionSystem::Get( | |
| 70 browser()->profile())->extension_service(); | |
| 71 extensions::ExtensionRegistry* registry = | |
| 72 extensions::ExtensionRegistry::Get(browser()->profile()); | |
| 73 service->set_show_extensions_prompts(false); | |
| 74 const size_t size_before = registry->enabled_extensions().size(); | |
| 75 const Extension* extension = LoadExtension(extension_dir); | |
| 76 ASSERT_TRUE(extension); | |
| 77 EXPECT_EQ(size_before + 1, registry->enabled_extensions().size()); | |
| 78 // Now the plugin should be in the cache. | |
| 79 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 80 tab, "testPluginWorks()", &result)); | |
| 81 // We don't allow extension plugins to run on ChromeOS. | |
| 82 #if defined(OS_CHROMEOS) | |
| 83 EXPECT_FALSE(result); | |
| 84 #else | |
| 85 EXPECT_TRUE(result); | |
| 86 #endif | |
| 87 | |
| 88 EXPECT_EQ(size_before + 1, registry->enabled_extensions().size()); | |
| 89 UnloadExtension(extension->id()); | |
| 90 EXPECT_EQ(size_before, registry->enabled_extensions().size()); | |
| 91 | |
| 92 // Now the plugin should be unloaded, and the page should be broken. | |
| 93 | |
| 94 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 95 tab, "testPluginWorks()", &result)); | |
| 96 EXPECT_FALSE(result); | |
| 97 | |
| 98 // If we reload the extension and page, it should work again. | |
| 99 | |
| 100 ASSERT_TRUE(LoadExtension(extension_dir)); | |
| 101 EXPECT_EQ(size_before + 1, registry->enabled_extensions().size()); | |
| 102 { | |
| 103 content::WindowedNotificationObserver observer( | |
| 104 content::NOTIFICATION_LOAD_STOP, | |
| 105 content::Source<NavigationController>( | |
| 106 &browser()->tab_strip_model()->GetActiveWebContents()-> | |
| 107 GetController())); | |
| 108 chrome::Reload(browser(), CURRENT_TAB); | |
| 109 observer.Wait(); | |
| 110 } | |
| 111 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 112 tab, "testPluginWorks()", &result)); | |
| 113 // We don't allow extension plugins to run on ChromeOS. | |
| 114 #if defined(OS_CHROMEOS) | |
| 115 EXPECT_FALSE(result); | |
| 116 #else | |
| 117 EXPECT_TRUE(result); | |
| 118 #endif | |
| 119 } | |
| 120 | |
| 121 #if defined(OS_MACOSX) && defined(ADDRESS_SANITIZER) | |
| 122 // ExtensionBrowserTest.PluginPrivate started failing after the switch to | |
| 123 // dynamic ASan runtime library on Mac. See http://crbug.com/234591. | |
| 124 #define MAYBE_PluginPrivate DISABLED_PluginPrivate | |
| 125 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | |
| 126 // Timing out on ARM linux http://crbug.com/238467 | |
| 127 #define MAYBE_PluginPrivate DISABLED_PluginPrivate | |
| 128 #elif defined(OS_WIN) && defined(ARCH_CPU_X86_64) | |
| 129 // TODO(jschuh): Failing plugin tests. crbug.com/244653 | |
| 130 #define MAYBE_PluginPrivate DISABLED_PluginPrivate | |
| 131 #else | |
| 132 #define MAYBE_PluginPrivate PluginPrivate | |
| 133 #endif | |
| 134 // Tests that private extension plugins are only visible to the extension. | |
| 135 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginPrivate) { | |
| 136 #if defined(OS_WIN) && defined(USE_ASH) | |
| 137 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | |
| 138 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 139 switches::kAshBrowserTests)) | |
| 140 return; | |
| 141 #endif | |
| 142 | |
| 143 if (!content::PluginService::GetInstance()->NPAPIPluginsSupported()) | |
| 144 return; | |
| 145 | |
| 146 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize, | |
| 147 true); | |
| 148 | |
| 149 base::FilePath extension_dir = | |
| 150 test_data_dir_.AppendASCII("uitest").AppendASCII("plugins_private"); | |
| 151 | |
| 152 ExtensionService* service = extensions::ExtensionSystem::Get( | |
| 153 browser()->profile())->extension_service(); | |
| 154 extensions::ExtensionRegistry* registry = | |
| 155 extensions::ExtensionRegistry::Get(browser()->profile()); | |
| 156 service->set_show_extensions_prompts(false); | |
| 157 const size_t size_before = registry->enabled_extensions().size(); | |
| 158 const Extension* extension = LoadExtension(extension_dir); | |
| 159 ASSERT_TRUE(extension); | |
| 160 EXPECT_EQ(size_before + 1, registry->enabled_extensions().size()); | |
| 161 | |
| 162 // Load the test page through the extension URL, and the plugin should work. | |
| 163 ui_test_utils::NavigateToURL(browser(), | |
| 164 extension->GetResourceURL("test.html")); | |
| 165 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 166 bool result = false; | |
| 167 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 168 tab, "testPluginWorks()", &result)); | |
| 169 // We don't allow extension plugins to run on ChromeOS. | |
| 170 #if defined(OS_CHROMEOS) | |
| 171 EXPECT_FALSE(result); | |
| 172 #else | |
| 173 // TODO(bauerb): This might wrongly fail if the plugin takes too long | |
| 174 // to load. Extension-private plugins don't appear in navigator.plugins, so | |
| 175 // we can't check for the plugin in Javascript. | |
| 176 EXPECT_TRUE(result); | |
| 177 #endif | |
| 178 | |
| 179 // Regression test for http://crbug.com/131811: The plugin should be | |
| 180 // whitelisted for the extension (and only for the extension), so it should be | |
| 181 // loaded even if content settings are set to block plugins. | |
| 182 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | |
| 183 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 184 CONTENT_SETTING_BLOCK); | |
| 185 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 186 tab, "testPluginWorks()", &result)); | |
| 187 // We don't allow extension plugins to run on ChromeOS. | |
| 188 #if defined(OS_CHROMEOS) | |
| 189 EXPECT_FALSE(result); | |
| 190 #else | |
| 191 EXPECT_TRUE(result); | |
| 192 #endif | |
| 193 | |
| 194 // Now load it through a file URL. The plugin should not load. | |
| 195 ui_test_utils::NavigateToURL(browser(), | |
| 196 net::FilePathToFileURL(extension_dir.AppendASCII("test.html"))); | |
| 197 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 198 tab, "testPluginWorks()", &result)); | |
| 199 EXPECT_FALSE(result); | |
| 200 } | |
| OLD | NEW |