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

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, 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 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 124969)
+++ 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,135 @@
self.RestartRenderer()
self.assertFalse(self.IsWebGLEnabled())
+ # Needed for extension tests
+ GOOD_CRX_ID = 'ldnnhddmnhbkjipkidpdiheffobcpfmf'
+ ADBLOCK_CRX_ID = 'dojnnbeimaimaojcialkkgajdnefpgcn'
+ SCREEN_CAPTURE_CRX_ID = 'cpngackimfmofbokmjmljamhdncknpmg'
+ def _BuildCRXPath(self, crx_file_name):
+ """Returns the complete path to a crx_file in the data directory
frankf 2012/03/14 00:25:25 period.
+
+ Args:
+ crx_file_name: The file name of the extension
frankf 2012/03/14 00:25:25 period everywhere!
+
+ 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
frankf 2012/03/14 00:25:25 Raises section
+ """
+ install_failed = True
+ try:
+ ext_id = self.InstallExtension(self._BuildCRXPath(crx_file_name))
+ install_failed = False
+ except JSONInterfaceError, e:
frankf 2012/03/14 00:25:25 Please rebase your code. You have to do pyauto_err
+ self.assertEqual(e[0], 'Extension could not be installed',
+ msg='The extension failed to install which is expected. '
+ ' However it failed due to an unexpected reason: %s'
+ % e[0])
+ self.assertTrue(install_failed, 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
frankf 2012/03/14 00:25:25 No space before Returns. Also in other places.
+
+ 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):
frankf 2012/03/14 00:25:25 don't need the PolicyTest. prefix
+ self.UninstallExtensionById(PolicyTest.SCREEN_CAPTURE_CRX_ID)
+ if self._CheckForExtensionByID(PolicyTest.GOOD_CRX_ID):
+ self.UninstallExtensionById(PolicyTest.GOOD_CRX_ID)
+ self.NavigateToURL('chrome:extensions')
+ if self._CheckForExtensionByID(PolicyTest.ADBLOCK_CRX_ID):
+ self.UninstallExtensionById(PolicyTest.ADBLOCK_CRX_ID)
+ # There is an issue where if you uninstall and reinstall and extension
+ # quickly with self.InstallExtension, the reinstall fails. This is a hack
+ # to fix it. Bug coming soon.
+ self.NavigateToURL('chrome:extensions')
+
+ def testExtensionInstallPopulatedBlacklist(self):
+ """Verify blacklisted extensions cannot be installed."""
+ # 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'))
frankf 2012/03/14 00:25:25 Please factor this to AttemptExtensionInstallThatS
+ # Check adblock is installed.
+ 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):
+ """Verify no extensions can be installed when all are blacklisted."""
+ # TODO: Remove this when crosbug.com/27227 is fixed.
+ self._RemoveTestingExtensions()
+ # Block installs of all extensions
+ self.SetPolicies({
+ 'ExtensionInstallBlacklist': ['*']
+ })
+ self._AttemptExtensionInstallThatShouldFail('good.crx')
+ self._AttemptExtensionInstallThatShouldFail('adblock.crx')
+
+ def testExtensionInstallWithGlobalBlacklistAndWhitelistedExtension(self):
+ """Verify whitelisted extension is installed when all are blacklisted."""
+ # 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):
+ """Verify force install extensions are installed."""
+ # 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.
frankf 2012/03/14 00:25:25 can you explain the logic for waiting here.
+ self.assertTrue(self.WaitUntil(lambda:
+ self._CheckForExtensionByID(PolicyTest.SCREEN_CAPTURE_CRX_ID),
+ expect_retval=True),
+ msg='The force install extension was never installed.')
+
+
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