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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/functional/policy.py
===================================================================
--- chrome/test/functional/policy.py (revision 124003)
+++ chrome/test/functional/policy.py (working copy)
@@ -4,6 +4,7 @@
# found in the LICENSE file.
import logging
+import os
import pyauto_functional # must come before pyauto.
import policy_base
@@ -192,6 +193,139 @@
self.RestartRenderer()
self.assertFalse(self.IsWebGLEnabled())
+ # Needed for extension tests
+ _good_crx_id = 'ldnnhddmnhbkjipkidpdiheffobcpfmf'
+ _adblock_crx_id = 'dojnnbeimaimaojcialkkgajdnefpgcn'
+ _screen_capture_crx_id = 'cpngackimfmofbokmjmljamhdncknpmg'
frankf 2012/03/06 22:54:41 constants should be capital.
+ def _buildCRXPath(self, crx_file_name):
frankf 2012/03/06 22:54:41 capitalize first letter. Also other places.
+ """ Returns the complete path to a crx_file in the data directory
frankf 2012/03/06 22:54:41 no space after quotation.
+
+ Args:
+ crx_file_name: The file name of the extension
+
+ Returns:
+ The full path to the crx in the data directory
+ """
+ return os.path.abspath(os.path.join(self.DataDir(), 'extensions',
+ crx_file_name))
+
+ def _attemptExtensionInstallThatShouldFail(self, crx_file_name):
+ """ Attempts to install an extension, throws an exception if it is installed
+
+ Args:
+ crx_file_name: The file name of the extension
+ """
+ install_successful = True
+ try:
+ ext_id = self.InstallExtension(self._buildCRXPath(crx_file_name))
+ install_successful = False
frankf 2012/03/06 22:54:41 this variable has the opposite meaning of what it
+ except JSONInterfaceError, e:
+ self.assertEqual(e[0], u'Extension could not be installed',
frankf 2012/03/06 22:54:41 do you need unicode for this to work?
+ msg='The extension failed to install which is expected. '
+ ' However it failed due to an unexpected reason: %s'
+ % e[0])
+ self.assertTrue(install_successful, msg='The extension %s did not throw an '
+ 'exception when installation was attempted. This most '
+ 'likely means it succeeded, which it should not.')
+
+ def _checkForExtensionByID(self, extension_id):
+ """ Returns if an extension is installed
+
+ Args:
+ extension_id: The id of the extension
+
+ Returns:
+ True if the extension is installed; False otherwise
+ """
+ all_extensions = [extension['id'] for extension in self.GetExtensionsInfo()]
+ return extension_id in all_extensions
+
+ def _removeTestingExtensions(self):
+ """ Temporary method that cleans state for extension test.
+
+ Currently the tear down method for policy_base does not clear the user
+ state. See crosbug.com/27227.
+ """
+ if self._checkForExtensionByID(PolicyTest._screen_capture_crx_id):
+ self.UninstallExtensionById(PolicyTest._screen_capture_crx_id)
+ if self._checkForExtensionByID(PolicyTest._good_crx_id):
+ self.UninstallExtensionById(PolicyTest._good_crx_id)
+ if self._checkForExtensionByID(PolicyTest._adblock_crx_id):
+ self.UninstallExtensionById(PolicyTest._adblock_crx_id)
+
+
+ def testExtensionInstallPopulatedBlacklist(self):
+ # TODO: Remove this when crosbug.com/27227 is fixed.
+ self._removeTestingExtensions()
+ # Blacklist good.crx
+ self.SetPolicies({
+ 'ExtensionInstallBlacklist': [PolicyTest._good_crx_id]
+ })
+ self._attemptExtensionInstallThatShouldFail('good.crx')
+ ext_id = self.InstallExtension(self._buildCRXPath('adblock.crx'))
+ # Check good.crx is not installed
+ self.assertFalse(self._checkForExtensionByID(PolicyTest._good_crx_id),
frankf 2012/03/06 22:54:41 Don't you already this verification in attemptExte
+ msg='The good.crx extension was installed even though it '
+ 'is on the Blacklist.')
+ # Check adblock is installed
frankf 2012/03/06 22:54:41 Period at the end.
+ self.assertTrue(self._checkForExtensionByID(ext_id),
+ msg='The adblock.crx extension was not install even though '
+ 'it is not on the Blacklist.')
+
+ def testExtensionInstallFailWithGlobalBlacklist(self):
+ # TODO: Remove this when crosbug.com/27227 is fixed.
frankf 2012/03/06 22:54:41 This should be fixed now, give a try.
+ self._removeTestingExtensions()
+ # Block installs of all extensions
+ self.SetPolicies({
+ 'ExtensionInstallBlacklist': ['*']
+ })
+ self._attemptExtensionInstallThatShouldFail('good.crx')
+ self._attemptExtensionInstallThatShouldFail('adblock.crx')
+ # Check good.crx is not installed
+ self.assertFalse(self._checkForExtensionByID(PolicyTest._good_crx_id),
+ msg='The good.crx extension was installed even though no '
+ 'extension installs are permitted.')
+ # Check adblock.crx is not installed
+ self.assertFalse(self._checkForExtensionByID(PolicyTest._adblock_crx_id),
+ msg='The adblock.crx extension was installed even though '
+ 'no extension installs are permitted.')
+
+ def testExtensionInstallWithGlobalBlacklistAndWhitelistedExtension(self):
+ # TODO: Remove this when crosbug.com/27227 is fixed.
+ self._removeTestingExtensions()
+ # Block installs of all extensions, but whitelist adblock.crx
+ self.SetPolicies({
+ 'ExtensionInstallBlacklist': ['*'],
+ 'ExtensionInstallWhitelist': [PolicyTest._adblock_crx_id]
+ })
+ self._attemptExtensionInstallThatShouldFail('good.crx')
+ ext_id = self.InstallExtension(self._buildCRXPath('adblock.crx'))
+ # Check good.crx is not installed
+ self.assertFalse(self._checkForExtensionByID(PolicyTest._good_crx_id),
+ msg='The good.crx extension was installed even though no '
+ 'extension installs are permitted except whitelisted ones,'
+ ' which this is not.')
+ # Check adblock is installed
+ self.assertTrue(self._checkForExtensionByID(ext_id),
+ msg='The adblock.crx extension was not install even though'
+ ' it is on the whitelist.')
+
+ # TODO: Enable this test once we figure out why it isn't downloading the
+ # extension
+ def testExtensionInstallFromForceList(self):
+ # TODO: Remove this when crosbug.com/27227 is fixed.
+ self._removeTestingExtensions()
+ # Force an extension download from the webstore.
+ self.SetPolicies({
+ 'ExtensionInstallForcelist': [PolicyTest._screen_capture_crx_id],
+ })
+ # Give the system 30 seconds to go get this extension.
+ self.assertTrue(self.WaitUntil(lambda:
+ self._checkForExtensionByID(PolicyTest._screen_capture_crx_id),
+ expect_retval=True),
+ msg='The force install extension was never installed.')
+
+
xot 2012/03/14 15:00:14 Other test cases to cover: 1) Ext on Forcelist can
xot 2012/03/14 15:00:14 InstallExtension() method says that Ext must not b
if __name__ == '__main__':
pyauto_functional.Main()
« 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