| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "chrome/browser/extensions/extension_browsertest.h" | 7 #include "chrome/browser/extensions/extension_browsertest.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_commands.h" | 11 #include "chrome/browser/ui/browser_commands.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/test/base/test_switches.h" | 14 #include "chrome/test/base/test_switches.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "components/content_settings/core/browser/host_content_settings_map.h" | 16 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/plugin_service.h" | 18 #include "content/public/browser/plugin_service.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 21 #include "extensions/browser/extension_registry.h" |
| 21 #include "extensions/browser/extension_system.h" | 22 #include "extensions/browser/extension_system.h" |
| 22 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
| 23 #include "net/base/filename_util.h" | 24 #include "net/base/filename_util.h" |
| 24 | 25 |
| 25 using content::NavigationController; | 26 using content::NavigationController; |
| 26 using content::WebContents; | 27 using content::WebContents; |
| 27 using extensions::Extension; | 28 using extensions::Extension; |
| 28 | 29 |
| 29 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 30 // http://crbug.com/123851 : test flakily fails on win. | 31 // http://crbug.com/123851 : test flakily fails on win. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 56 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 57 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 57 | 58 |
| 58 // With no extensions, the plugin should not be loaded. | 59 // With no extensions, the plugin should not be loaded. |
| 59 bool result = false; | 60 bool result = false; |
| 60 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 61 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 61 tab, "testPluginWorks()", &result)); | 62 tab, "testPluginWorks()", &result)); |
| 62 EXPECT_FALSE(result); | 63 EXPECT_FALSE(result); |
| 63 | 64 |
| 64 ExtensionService* service = extensions::ExtensionSystem::Get( | 65 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 65 browser()->profile())->extension_service(); | 66 browser()->profile())->extension_service(); |
| 67 extensions::ExtensionRegistry* registry = |
| 68 extensions::ExtensionRegistry::Get(browser()->profile()); |
| 66 service->set_show_extensions_prompts(false); | 69 service->set_show_extensions_prompts(false); |
| 67 const size_t size_before = service->extensions()->size(); | 70 const size_t size_before = registry->enabled_extensions().size(); |
| 68 const Extension* extension = LoadExtension(extension_dir); | 71 const Extension* extension = LoadExtension(extension_dir); |
| 69 ASSERT_TRUE(extension); | 72 ASSERT_TRUE(extension); |
| 70 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 73 EXPECT_EQ(size_before + 1, registry->enabled_extensions().size()); |
| 71 // Now the plugin should be in the cache. | 74 // Now the plugin should be in the cache. |
| 72 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 75 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 73 tab, "testPluginWorks()", &result)); | 76 tab, "testPluginWorks()", &result)); |
| 74 // We don't allow extension plugins to run on ChromeOS. | 77 // We don't allow extension plugins to run on ChromeOS. |
| 75 #if defined(OS_CHROMEOS) | 78 #if defined(OS_CHROMEOS) |
| 76 EXPECT_FALSE(result); | 79 EXPECT_FALSE(result); |
| 77 #else | 80 #else |
| 78 EXPECT_TRUE(result); | 81 EXPECT_TRUE(result); |
| 79 #endif | 82 #endif |
| 80 | 83 |
| 81 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 84 EXPECT_EQ(size_before + 1, registry->enabled_extensions().size()); |
| 82 UnloadExtension(extension->id()); | 85 UnloadExtension(extension->id()); |
| 83 EXPECT_EQ(size_before, service->extensions()->size()); | 86 EXPECT_EQ(size_before, registry->enabled_extensions().size()); |
| 84 | 87 |
| 85 // Now the plugin should be unloaded, and the page should be broken. | 88 // Now the plugin should be unloaded, and the page should be broken. |
| 86 | 89 |
| 87 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 90 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 88 tab, "testPluginWorks()", &result)); | 91 tab, "testPluginWorks()", &result)); |
| 89 EXPECT_FALSE(result); | 92 EXPECT_FALSE(result); |
| 90 | 93 |
| 91 // If we reload the extension and page, it should work again. | 94 // If we reload the extension and page, it should work again. |
| 92 | 95 |
| 93 ASSERT_TRUE(LoadExtension(extension_dir)); | 96 ASSERT_TRUE(LoadExtension(extension_dir)); |
| 94 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 97 EXPECT_EQ(size_before + 1, registry->enabled_extensions().size()); |
| 95 { | 98 { |
| 96 content::WindowedNotificationObserver observer( | 99 content::WindowedNotificationObserver observer( |
| 97 content::NOTIFICATION_LOAD_STOP, | 100 content::NOTIFICATION_LOAD_STOP, |
| 98 content::Source<NavigationController>( | 101 content::Source<NavigationController>( |
| 99 &browser()->tab_strip_model()->GetActiveWebContents()-> | 102 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 100 GetController())); | 103 GetController())); |
| 101 chrome::Reload(browser(), CURRENT_TAB); | 104 chrome::Reload(browser(), CURRENT_TAB); |
| 102 observer.Wait(); | 105 observer.Wait(); |
| 103 } | 106 } |
| 104 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 107 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return; | 139 return; |
| 137 | 140 |
| 138 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize, | 141 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize, |
| 139 true); | 142 true); |
| 140 | 143 |
| 141 base::FilePath extension_dir = | 144 base::FilePath extension_dir = |
| 142 test_data_dir_.AppendASCII("uitest").AppendASCII("plugins_private"); | 145 test_data_dir_.AppendASCII("uitest").AppendASCII("plugins_private"); |
| 143 | 146 |
| 144 ExtensionService* service = extensions::ExtensionSystem::Get( | 147 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 145 browser()->profile())->extension_service(); | 148 browser()->profile())->extension_service(); |
| 149 extensions::ExtensionRegistry* registry = |
| 150 extensions::ExtensionRegistry::Get(browser()->profile()); |
| 146 service->set_show_extensions_prompts(false); | 151 service->set_show_extensions_prompts(false); |
| 147 const size_t size_before = service->extensions()->size(); | 152 const size_t size_before = registry->enabled_extensions().size(); |
| 148 const Extension* extension = LoadExtension(extension_dir); | 153 const Extension* extension = LoadExtension(extension_dir); |
| 149 ASSERT_TRUE(extension); | 154 ASSERT_TRUE(extension); |
| 150 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 155 EXPECT_EQ(size_before + 1, registry->enabled_extensions().size()); |
| 151 | 156 |
| 152 // Load the test page through the extension URL, and the plugin should work. | 157 // Load the test page through the extension URL, and the plugin should work. |
| 153 ui_test_utils::NavigateToURL(browser(), | 158 ui_test_utils::NavigateToURL(browser(), |
| 154 extension->GetResourceURL("test.html")); | 159 extension->GetResourceURL("test.html")); |
| 155 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 160 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 156 bool result = false; | 161 bool result = false; |
| 157 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 162 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 158 tab, "testPluginWorks()", &result)); | 163 tab, "testPluginWorks()", &result)); |
| 159 // We don't allow extension plugins to run on ChromeOS. | 164 // We don't allow extension plugins to run on ChromeOS. |
| 160 #if defined(OS_CHROMEOS) | 165 #if defined(OS_CHROMEOS) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 180 EXPECT_TRUE(result); | 185 EXPECT_TRUE(result); |
| 181 #endif | 186 #endif |
| 182 | 187 |
| 183 // Now load it through a file URL. The plugin should not load. | 188 // Now load it through a file URL. The plugin should not load. |
| 184 ui_test_utils::NavigateToURL(browser(), | 189 ui_test_utils::NavigateToURL(browser(), |
| 185 net::FilePathToFileURL(extension_dir.AppendASCII("test.html"))); | 190 net::FilePathToFileURL(extension_dir.AppendASCII("test.html"))); |
| 186 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 191 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 187 tab, "testPluginWorks()", &result)); | 192 tab, "testPluginWorks()", &result)); |
| 188 EXPECT_FALSE(result); | 193 EXPECT_FALSE(result); |
| 189 } | 194 } |
| OLD | NEW |