OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import re | 8 import re |
9 | 9 |
10 import pyauto_functional # Must be imported before pyauto | 10 import pyauto_functional # Must be imported before pyauto |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 if 'Shockwave Flash' == plugin_name: | 132 if 'Shockwave Flash' == plugin_name: |
133 continue # cannot reload file:// flash URL - crbug.com/47249 | 133 continue # cannot reload file:// flash URL - crbug.com/47249 |
134 # Enable | 134 # Enable |
135 self._TogglePlugin(plugin_name) | 135 self._TogglePlugin(plugin_name) |
136 self.GetBrowserWindow(0).GetTab(0).Reload() | 136 self.GetBrowserWindow(0).GetTab(0).Reload() |
137 self.assertTrue([x for x in self.GetBrowserInfo()['child_processes'] | 137 self.assertTrue([x for x in self.GetBrowserInfo()['child_processes'] |
138 if x['type'] == 'Plug-in' and | 138 if x['type'] == 'Plug-in' and |
139 re.search(plugin_name, x['name'])]) | 139 re.search(plugin_name, x['name'])]) |
140 self.assertTrue(self._IsEnabled(plugin_name), plugin_name) | 140 self.assertTrue(self._IsEnabled(plugin_name), plugin_name) |
141 | 141 |
| 142 def testBlockAllPlugins(self): |
| 143 """Verify that all the plugins can be blocked. |
| 144 Verifying by checking that flash plugin was blocked. |
| 145 """ |
| 146 flash_url = self.GetFileURLForPath(os.path.join( |
| 147 self.DataDir(), 'plugin', 'flash-clicktoplay.html')) |
| 148 self.NavigateToURL(flash_url) |
| 149 flash_pid = self._GetPluginPID('Shockwave Flash') |
| 150 self.assertTrue(flash_pid, msg='No plugin process for Shockwave Flash') |
| 151 # Killing the flash process as it takes a while before the plugin |
| 152 # process is terminated even though there are no tabs using it. |
| 153 self.Kill(flash_pid) |
| 154 self.assertTrue(self.WaitUntil( |
| 155 lambda: self._GetPluginPID('Shockwave Flash') is None), |
| 156 msg='Expected Shockwave Flash plugin to die after killing') |
| 157 |
| 158 # Set the preference to block all plugins. |
| 159 self.SetPrefs(pyauto.kDefaultContentSettings, {'plugins': 2}) |
| 160 |
| 161 self.GetBrowserWindow(0).GetTab(0).Reload() |
| 162 self.assertFalse(self._GetPluginPID('Shockwave Flash'), |
| 163 msg='Plug-in not blocked.') |
| 164 |
| 165 def testAllowPluginException(self): |
| 166 """Verify that plugins can be allowed on a domain by adding |
| 167 an exception(s).""" |
| 168 # Set the preference to block all plugins. |
| 169 self.SetPrefs(pyauto.kDefaultContentSettings, {'plugins': 2}) |
| 170 |
| 171 flash_url = self.GetFileURLForPath(os.path.join( |
| 172 self.DataDir(), 'plugin', 'flash-clicktoplay.html')) |
| 173 self.NavigateToURL(flash_url) |
| 174 # Check that plugins are blocked. |
| 175 self.assertFalse(self._GetPluginPID('Shockwave Flash'), |
| 176 msg='Plug-in not blocked.') |
| 177 |
| 178 # Add an exception to allow plugins on hulu.com. |
| 179 self.SetPrefs(pyauto.kContentSettingsPatterns, |
| 180 {'[*.]hulu.com': {'plugins': 1}}) |
| 181 self.AppendTab(pyauto.GURL('http://www.hulu.com')) |
| 182 self.assertTrue(self._GetPluginPID('Shockwave Flash'), |
| 183 msg='No plugin process for Shockwave Flash') |
| 184 |
| 185 def testBlockPluginException(self): |
| 186 """Verify that plugins can be blocked on a domain by adding |
| 187 an exception(s).""" |
| 188 # We are using the same live site in order to detect if the web page |
| 189 # is using shockwave flash process |
| 190 self.NavigateToURL('http://www.hulu.com') |
| 191 pid = self._GetPluginPID('Shockwave Flash') |
| 192 self.assertTrue(pid, msg='No plugin process for Shockwave Flash') |
| 193 self.Kill(pid) |
| 194 self.assertTrue(self.WaitUntil( |
| 195 lambda: self._GetPluginPID('Shockwave Flash') is None), |
| 196 msg='Expected Shockwave Flash plugin to die after killing') |
| 197 |
| 198 # Add an exception to block plugins on hulu.com. |
| 199 self.SetPrefs(pyauto.kContentSettingsPatterns, |
| 200 {'[*.]hulu.com': {'plugins': 2}}) |
| 201 self.GetBrowserWindow(0).GetTab(0).Reload() |
| 202 self.assertFalse(self._GetPluginPID('Shockwave Flash'), |
| 203 msg='Plug-in not blocked.') |
| 204 |
142 | 205 |
143 if __name__ == '__main__': | 206 if __name__ == '__main__': |
144 pyauto_functional.Main() | 207 pyauto_functional.Main() |
OLD | NEW |