OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 self.assertTrue(self.WaitForInfobarCount(1)) | 112 self.assertTrue(self.WaitForInfobarCount(1)) |
113 self.PerformActionOnInfobar('accept', 0) | 113 self.PerformActionOnInfobar('accept', 0) |
114 self.WaitUntil( | 114 self.WaitUntil( |
115 lambda: self._GetPluginPID(plugin_name) is not None ) | 115 lambda: self._GetPluginPID(plugin_name) is not None ) |
116 pid = self._GetPluginPID(plugin_name) | 116 pid = self._GetPluginPID(plugin_name) |
117 self.assertTrue(pid, 'No plugin process for %s' % plugin_name) | 117 self.assertTrue(pid, 'No plugin process for %s' % plugin_name) |
118 self.Kill(pid) | 118 self.Kill(pid) |
119 self.assertTrue(self.WaitUntil( | 119 self.assertTrue(self.WaitUntil( |
120 lambda: self._GetPluginPID(plugin_name) is None), | 120 lambda: self._GetPluginPID(plugin_name) is None), |
121 msg='Expected %s plugin to die after killing' % plugin_name) | 121 msg='Expected %s plugin to die after killing' % plugin_name) |
122 self.GetBrowserWindow(0).GetTab(0).Reload() | 122 self.ReloadTab() |
123 self.assertTrue(self.WaitUntil( | 123 self.assertTrue(self.WaitUntil( |
124 lambda: self._GetPluginPID(plugin_name)), | 124 lambda: self._GetPluginPID(plugin_name)), |
125 msg='No plugin process for %s after reloading' % plugin_name) | 125 msg='No plugin process for %s after reloading' % plugin_name) |
126 # Verify that it's in fact a new process. | 126 # Verify that it's in fact a new process. |
127 self.assertNotEqual(pid, self._GetPluginPID(plugin_name), | 127 self.assertNotEqual(pid, self._GetPluginPID(plugin_name), |
128 'Did not get new pid for %s after reloading' % | 128 'Did not get new pid for %s after reloading' % |
129 plugin_name) | 129 plugin_name) |
130 | 130 |
131 def testDisableEnableAllPlugins(self): | 131 def testDisableEnableAllPlugins(self): |
132 """Verify if all the plugins can be disabled and enabled. | 132 """Verify if all the plugins can be disabled and enabled. |
(...skipping 21 matching lines...) Expand all Loading... |
154 self.NavigateToURL(url) | 154 self.NavigateToURL(url) |
155 self.assertTrue(self.WaitUntil( | 155 self.assertTrue(self.WaitUntil( |
156 lambda: self._GetPluginPID(plugin_name) is None )) | 156 lambda: self._GetPluginPID(plugin_name) is None )) |
157 self.assertFalse(self._GetPluginPID(plugin_name=plugin_name)) | 157 self.assertFalse(self._GetPluginPID(plugin_name=plugin_name)) |
158 if plugin_name == 'Shockwave Flash': | 158 if plugin_name == 'Shockwave Flash': |
159 continue # cannot reload file:// flash URL - crbug.com/47249 | 159 continue # cannot reload file:// flash URL - crbug.com/47249 |
160 if plugin_name == 'Java': | 160 if plugin_name == 'Java': |
161 continue # crbug.com/71223 | 161 continue # crbug.com/71223 |
162 # Enable | 162 # Enable |
163 self._TogglePlugin(plugin_name) | 163 self._TogglePlugin(plugin_name) |
164 self.GetBrowserWindow(0).GetTab(0).Reload() | 164 self.ReloadTab() |
165 if self._PluginNeedsAuthorization(plugin_name): | 165 if self._PluginNeedsAuthorization(plugin_name): |
166 self.assertTrue(self.WaitForInfobarCount(1)) | 166 self.assertTrue(self.WaitForInfobarCount(1)) |
167 self.PerformActionOnInfobar('accept', 0) | 167 self.PerformActionOnInfobar('accept', 0) |
168 self.assertTrue(self.WaitUntil( | 168 self.assertTrue(self.WaitUntil( |
169 lambda: self._GetPluginPID(plugin_name=plugin_name))) | 169 lambda: self._GetPluginPID(plugin_name=plugin_name))) |
170 self.assertTrue(self._IsEnabled(plugin_name), plugin_name) | 170 self.assertTrue(self._IsEnabled(plugin_name), plugin_name) |
171 | 171 |
172 def testBlockAllPlugins(self): | 172 def testBlockAllPlugins(self): |
173 """Verify that all the plugins can be blocked. | 173 """Verify that all the plugins can be blocked. |
174 Verifying by checking that flash plugin was blocked. | 174 Verifying by checking that flash plugin was blocked. |
175 """ | 175 """ |
176 flash_url = self.GetFileURLForContentDataPath( | 176 flash_url = self.GetFileURLForContentDataPath( |
177 'plugin', 'flash-clicktoplay.html') | 177 'plugin', 'flash-clicktoplay.html') |
178 self.NavigateToURL(flash_url) | 178 self.NavigateToURL(flash_url) |
179 flash_pid = self._GetPluginPID('Shockwave Flash') | 179 flash_pid = self._GetPluginPID('Shockwave Flash') |
180 self.assertTrue(flash_pid, msg='No plugin process for Shockwave Flash') | 180 self.assertTrue(flash_pid, msg='No plugin process for Shockwave Flash') |
181 # Killing the flash process as it takes a while before the plugin | 181 # Killing the flash process as it takes a while before the plugin |
182 # process is terminated even though there are no tabs using it. | 182 # process is terminated even though there are no tabs using it. |
183 self.Kill(flash_pid) | 183 self.Kill(flash_pid) |
184 self.assertTrue(self.WaitUntil( | 184 self.assertTrue(self.WaitUntil( |
185 lambda: self._GetPluginPID('Shockwave Flash') is None), | 185 lambda: self._GetPluginPID('Shockwave Flash') is None), |
186 msg='Expected Shockwave Flash plugin to die after killing') | 186 msg='Expected Shockwave Flash plugin to die after killing') |
187 | 187 |
188 # Set the preference to block all plugins. | 188 # Set the preference to block all plugins. |
189 self.SetPrefs(pyauto.kDefaultContentSettings, {'plugins': 2}) | 189 self.SetPrefs(pyauto.kDefaultContentSettings, {'plugins': 2}) |
190 | 190 |
191 self.GetBrowserWindow(0).GetTab(0).Reload() | 191 self.ReloadTab() |
192 self.assertFalse(self._GetPluginPID('Shockwave Flash'), | 192 self.assertFalse(self._GetPluginPID('Shockwave Flash'), |
193 msg='Plug-in not blocked.') | 193 msg='Plug-in not blocked.') |
194 | 194 |
195 def testAllowPluginException(self): | 195 def testAllowPluginException(self): |
196 """Verify that plugins can be allowed on a domain by adding | 196 """Verify that plugins can be allowed on a domain by adding |
197 an exception(s).""" | 197 an exception(s).""" |
198 # Set the preference to block all plugins. | 198 # Set the preference to block all plugins. |
199 self.SetPrefs(pyauto.kDefaultContentSettings, {'plugins': 2}) | 199 self.SetPrefs(pyauto.kDefaultContentSettings, {'plugins': 2}) |
200 | 200 |
201 flash_url = self.GetFileURLForPath(os.path.join( | 201 flash_url = self.GetFileURLForPath(os.path.join( |
(...skipping 20 matching lines...) Expand all Loading... |
222 lambda: self._GetPluginPID('Shockwave Flash') is not None), | 222 lambda: self._GetPluginPID('Shockwave Flash') is not None), |
223 msg='No plugin process for Shockwave Flash') | 223 msg='No plugin process for Shockwave Flash') |
224 self.Kill(self._GetPluginPID('Shockwave Flash')) | 224 self.Kill(self._GetPluginPID('Shockwave Flash')) |
225 self.assertTrue(self.WaitUntil( | 225 self.assertTrue(self.WaitUntil( |
226 lambda: self._GetPluginPID('Shockwave Flash') is None), | 226 lambda: self._GetPluginPID('Shockwave Flash') is None), |
227 msg='Expected Shockwave Flash plugin to die after killing') | 227 msg='Expected Shockwave Flash plugin to die after killing') |
228 | 228 |
229 # Add an exception to block plugins on localhost. | 229 # Add an exception to block plugins on localhost. |
230 self.SetPrefs(pyauto.kContentSettingsPatternPairs, | 230 self.SetPrefs(pyauto.kContentSettingsPatternPairs, |
231 {'[*.]hulu.com,*': {'plugins': 2}}) | 231 {'[*.]hulu.com,*': {'plugins': 2}}) |
232 self.GetBrowserWindow(0).GetTab(0).Reload() | 232 self.ReloadTab() |
233 self.assertFalse(self._GetPluginPID('Shockwave Flash'), | 233 self.assertFalse(self._GetPluginPID('Shockwave Flash'), |
234 msg='Shockwave Flash Plug-in not blocked.') | 234 msg='Shockwave Flash Plug-in not blocked.') |
235 | 235 |
236 | 236 |
237 if __name__ == '__main__': | 237 if __name__ == '__main__': |
238 pyauto_functional.Main() | 238 pyauto_functional.Main() |
OLD | NEW |