Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: chrome/test/functional/policy.py

Issue 9585034: Add extension policy tests (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 8
8 import pyauto_functional # must come before pyauto. 9 import pyauto_functional # must come before pyauto.
9 import policy_base 10 import policy_base
10 import pyauto 11 import pyauto
11 from pyauto_errors import JSONInterfaceError 12 from pyauto_errors import JSONInterfaceError
12 13
13 14
14 class PolicyTest(policy_base.PolicyTestBase): 15 class PolicyTest(policy_base.PolicyTestBase):
15 """Tests that the effects of policies are being enforced as expected.""" 16 """Tests that the effects of policies are being enforced as expected."""
16 17
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 self.SetPolicies(policy) 179 self.SetPolicies(policy)
179 self.NavigateToURL('about:blank') 180 self.NavigateToURL('about:blank')
180 self.assertTrue(self.IsJavascriptEnabled()) 181 self.assertTrue(self.IsJavascriptEnabled())
181 182
182 def testDisable3DAPIs(self): 183 def testDisable3DAPIs(self):
183 """Tests the policy that disables the 3D APIs.""" 184 """Tests the policy that disables the 3D APIs."""
184 self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kDisable3DAPIs)) 185 self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kDisable3DAPIs))
185 self.assertTrue(self.IsWebGLEnabled()) 186 self.assertTrue(self.IsWebGLEnabled())
186 187
187 self.SetPolicies({ 188 self.SetPolicies({
188 'Disable3DAPIs': True 189 'Disable3DAPIs': True
189 }) 190 })
190 self.assertTrue(self.GetPrefsInfo().Prefs(pyauto.kDisable3DAPIs)) 191 self.assertTrue(self.GetPrefsInfo().Prefs(pyauto.kDisable3DAPIs))
191 # The Disable3DAPIs policy only applies updated values to new renderers. 192 # The Disable3DAPIs policy only applies updated values to new renderers.
192 self.RestartRenderer() 193 self.RestartRenderer()
193 self.assertFalse(self.IsWebGLEnabled()) 194 self.assertFalse(self.IsWebGLEnabled())
194 195
196 # Needed for extension tests
197 GOOD_CRX_ID = 'ldnnhddmnhbkjipkidpdiheffobcpfmf'
198 ADBLOCK_CRX_ID = 'dojnnbeimaimaojcialkkgajdnefpgcn'
199 SCREEN_CAPTURE_CRX_ID = 'cpngackimfmofbokmjmljamhdncknpmg'
frankf 2012/03/14 01:41:39 _GOOD_CRX_ID
200
201 def _BuildCRXPath(self, crx_file_name):
202 """Returns the complete path to a crx_file in the data directory.
203
204 Args:
205 crx_file_name: The file name of the extension
206
207 Returns:
208 The full path to the crx in the data directory
209 """
210 return os.path.abspath(os.path.join(self.DataDir(), 'extensions',
211 crx_file_name))
212
213 def _AttemptExtensionInstallThatShouldFail(self, crx_file_name):
214 """Attempts to install an extension, raises an exception if installed.
215
216 Args:
217 crx_file_name: The file name of the extension
218 """
219 install_failed = True
220 try:
221 self.InstallExtension(self._BuildCRXPath(crx_file_name))
222 install_failed = False
223 except pyauto_errors.JSONInterfaceError as e:
224 self.assertEqual(e[0], 'Extension could not be installed',
225 msg='The extension failed to install which is expected. '
226 ' However it failed due to an unexpected reason: %s'
227 % e[0])
228 self.assertTrue(install_failed, msg='The extension %s did not throw an '
229 'exception when installation was attempted. This most '
230 'likely means it succeeded, which it should not.')
231
232 def _AttemptExtensionInstallThatShouldPass(self, crx_file_name):
233 """Attempts to install an extension, raises an exception if not installed.
234
235 Args:
236 crx_file_name: The file name of the extension
237 """
238 ext_id = self.InstallExtension(self._BuildCRXPath(crx_file_name))
239 self.assertTrue(self._CheckForExtensionByID(ext_id),
240 msg='The %s extension was not install even though '
241 'it should have been.' % crx_file_name)
242
243 def _CheckForExtensionByID(self, extension_id):
244 """Returns if an extension is installed.
245
246 Args:
247 extension_id: The id of the extension
248
249 Returns:
250 True if the extension is installed; False otherwise
251 """
252 all_extensions = [extension['id'] for extension in self.GetExtensionsInfo()]
253 return extension_id in all_extensions
254
255 def _RemoveTestingExtensions(self):
256 """Temporary method that cleans state for extension test.
257
258 Currently the tear down method for policy_base does not clear the user
259 state. See crosbug.com/27227.
260 """
261 if self._CheckForExtensionByID(PolicyTest.SCREEN_CAPTURE_CRX_ID):
frankf 2012/03/14 01:41:39 self._SCREEN_CAPTURE_CRX_ID
262 self.UninstallExtensionById(PolicyTest.SCREEN_CAPTURE_CRX_ID)
263 if self._CheckForExtensionByID(PolicyTest.GOOD_CRX_ID):
264 self.UninstallExtensionById(PolicyTest.GOOD_CRX_ID)
265 self.NavigateToURL('chrome:extensions')
266 if self._CheckForExtensionByID(PolicyTest.ADBLOCK_CRX_ID):
267 self.UninstallExtensionById(PolicyTest.ADBLOCK_CRX_ID)
268 # There is an issue where if you uninstall and reinstall and extension
269 # quickly with self.InstallExtension, the reinstall fails. This is a hack
270 # to fix it. Bug coming soon.
271 self.NavigateToURL('chrome:extensions')
272
273 def testExtensionInstallPopulatedBlacklist(self):
274 """Verify blacklisted extensions cannot be installed."""
275 # TODO(krisr): Remove this when crosbug.com/27227 is fixed.
276 self._RemoveTestingExtensions()
277 # Blacklist good.crx
278 self.SetPolicies({
279 'ExtensionInstallBlacklist': [PolicyTest.GOOD_CRX_ID]
280 })
281 self._AttemptExtensionInstallThatShouldFail('good.crx')
282 # Check adblock is installed.
283 self._AttemptExtensionInstallThatShouldPass('adblock.crx')
284
285 def testExtensionInstallFailWithGlobalBlacklist(self):
286 """Verify no extensions can be installed when all are blacklisted."""
287 # TODO(krisr): Remove this when crosbug.com/27227 is fixed.
288 self._RemoveTestingExtensions()
289 # Block installs of all extensions
290 self.SetPolicies({
291 'ExtensionInstallBlacklist': ['*']
292 })
293 self._AttemptExtensionInstallThatShouldFail('good.crx')
294 self._AttemptExtensionInstallThatShouldFail('adblock.crx')
295
296 def testExtensionInstallWithGlobalBlacklistAndWhitelistedExtension(self):
297 """Verify whitelisted extension is installed when all are blacklisted."""
298 # TODO(krisr): Remove this when crosbug.com/27227 is fixed.
299 self._RemoveTestingExtensions()
300 # Block installs of all extensions, but whitelist adblock.crx
301 self.SetPolicies({
302 'ExtensionInstallBlacklist': ['*'],
303 'ExtensionInstallWhitelist': [PolicyTest.ADBLOCK_CRX_ID]
304 })
305 self._AttemptExtensionInstallThatShouldFail('good.crx')
306 self._AttemptExtensionInstallThatShouldPass('adblock.crx')
307
308 # TODO(krisr): Enable this test once we figure out why it isn't downloading
309 # the extension.
310 def testExtensionInstallFromForceList(self):
311 """Verify force install extensions are installed."""
312 # TODO(krisr): Remove this when crosbug.com/27227 is fixed.
313 self._RemoveTestingExtensions()
314 # Force an extension download from the webstore.
315 self.SetPolicies({
316 'ExtensionInstallForcelist': [PolicyTest.SCREEN_CAPTURE_CRX_ID],
317 })
318 # Give the system 30 seconds to go get this extension. We are not sure how
319 # long it will take the policy to take affect and download the extension.
320 self.assertTrue(self.WaitUntil(lambda:
321 self._CheckForExtensionByID(PolicyTest.SCREEN_CAPTURE_CRX_ID),
322 expect_retval=True),
323 msg='The force install extension was never installed.')
324
195 325
196 if __name__ == '__main__': 326 if __name__ == '__main__':
197 pyauto_functional.Main() 327 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698