OLD | NEW |
---|---|
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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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/06 22:54:41
constants should be capital.
| |
200 | |
201 def _buildCRXPath(self, crx_file_name): | |
frankf
2012/03/06 22:54:41
capitalize first letter. Also other places.
| |
202 """ Returns the complete path to a crx_file in the data directory | |
frankf
2012/03/06 22:54:41
no space after quotation.
| |
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, throws an exception if it is installed | |
215 | |
216 Args: | |
217 crx_file_name: The file name of the extension | |
218 """ | |
219 install_successful = True | |
220 try: | |
221 ext_id = self.InstallExtension(self._buildCRXPath(crx_file_name)) | |
222 install_successful = False | |
frankf
2012/03/06 22:54:41
this variable has the opposite meaning of what it
| |
223 except JSONInterfaceError, e: | |
224 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?
| |
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_successful, 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 _checkForExtensionByID(self, extension_id): | |
233 """ Returns if an extension is installed | |
234 | |
235 Args: | |
236 extension_id: The id of the extension | |
237 | |
238 Returns: | |
239 True if the extension is installed; False otherwise | |
240 """ | |
241 all_extensions = [extension['id'] for extension in self.GetExtensionsInfo()] | |
242 return extension_id in all_extensions | |
243 | |
244 def _removeTestingExtensions(self): | |
245 """ Temporary method that cleans state for extension test. | |
246 | |
247 Currently the tear down method for policy_base does not clear the user | |
248 state. See crosbug.com/27227. | |
249 """ | |
250 if self._checkForExtensionByID(PolicyTest._screen_capture_crx_id): | |
251 self.UninstallExtensionById(PolicyTest._screen_capture_crx_id) | |
252 if self._checkForExtensionByID(PolicyTest._good_crx_id): | |
253 self.UninstallExtensionById(PolicyTest._good_crx_id) | |
254 if self._checkForExtensionByID(PolicyTest._adblock_crx_id): | |
255 self.UninstallExtensionById(PolicyTest._adblock_crx_id) | |
256 | |
257 | |
258 def testExtensionInstallPopulatedBlacklist(self): | |
259 # TODO: Remove this when crosbug.com/27227 is fixed. | |
260 self._removeTestingExtensions() | |
261 # Blacklist good.crx | |
262 self.SetPolicies({ | |
263 'ExtensionInstallBlacklist': [PolicyTest._good_crx_id] | |
264 }) | |
265 self._attemptExtensionInstallThatShouldFail('good.crx') | |
266 ext_id = self.InstallExtension(self._buildCRXPath('adblock.crx')) | |
267 # Check good.crx is not installed | |
268 self.assertFalse(self._checkForExtensionByID(PolicyTest._good_crx_id), | |
frankf
2012/03/06 22:54:41
Don't you already this verification in attemptExte
| |
269 msg='The good.crx extension was installed even though it ' | |
270 'is on the Blacklist.') | |
271 # Check adblock is installed | |
frankf
2012/03/06 22:54:41
Period at the end.
| |
272 self.assertTrue(self._checkForExtensionByID(ext_id), | |
273 msg='The adblock.crx extension was not install even though ' | |
274 'it is not on the Blacklist.') | |
275 | |
276 def testExtensionInstallFailWithGlobalBlacklist(self): | |
277 # TODO: Remove this when crosbug.com/27227 is fixed. | |
frankf
2012/03/06 22:54:41
This should be fixed now, give a try.
| |
278 self._removeTestingExtensions() | |
279 # Block installs of all extensions | |
280 self.SetPolicies({ | |
281 'ExtensionInstallBlacklist': ['*'] | |
282 }) | |
283 self._attemptExtensionInstallThatShouldFail('good.crx') | |
284 self._attemptExtensionInstallThatShouldFail('adblock.crx') | |
285 # Check good.crx is not installed | |
286 self.assertFalse(self._checkForExtensionByID(PolicyTest._good_crx_id), | |
287 msg='The good.crx extension was installed even though no ' | |
288 'extension installs are permitted.') | |
289 # Check adblock.crx is not installed | |
290 self.assertFalse(self._checkForExtensionByID(PolicyTest._adblock_crx_id), | |
291 msg='The adblock.crx extension was installed even though ' | |
292 'no extension installs are permitted.') | |
293 | |
294 def testExtensionInstallWithGlobalBlacklistAndWhitelistedExtension(self): | |
295 # TODO: Remove this when crosbug.com/27227 is fixed. | |
296 self._removeTestingExtensions() | |
297 # Block installs of all extensions, but whitelist adblock.crx | |
298 self.SetPolicies({ | |
299 'ExtensionInstallBlacklist': ['*'], | |
300 'ExtensionInstallWhitelist': [PolicyTest._adblock_crx_id] | |
301 }) | |
302 self._attemptExtensionInstallThatShouldFail('good.crx') | |
303 ext_id = self.InstallExtension(self._buildCRXPath('adblock.crx')) | |
304 # Check good.crx is not installed | |
305 self.assertFalse(self._checkForExtensionByID(PolicyTest._good_crx_id), | |
306 msg='The good.crx extension was installed even though no ' | |
307 'extension installs are permitted except whitelisted ones,' | |
308 ' which this is not.') | |
309 # Check adblock is installed | |
310 self.assertTrue(self._checkForExtensionByID(ext_id), | |
311 msg='The adblock.crx extension was not install even though' | |
312 ' it is on the whitelist.') | |
313 | |
314 # TODO: Enable this test once we figure out why it isn't downloading the | |
315 # extension | |
316 def testExtensionInstallFromForceList(self): | |
317 # TODO: Remove this when crosbug.com/27227 is fixed. | |
318 self._removeTestingExtensions() | |
319 # Force an extension download from the webstore. | |
320 self.SetPolicies({ | |
321 'ExtensionInstallForcelist': [PolicyTest._screen_capture_crx_id], | |
322 }) | |
323 # Give the system 30 seconds to go get this extension. | |
324 self.assertTrue(self.WaitUntil(lambda: | |
325 self._checkForExtensionByID(PolicyTest._screen_capture_crx_id), | |
326 expect_retval=True), | |
327 msg='The force install extension was never installed.') | |
328 | |
195 | 329 |
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
| |
196 if __name__ == '__main__': | 330 if __name__ == '__main__': |
197 pyauto_functional.Main() | 331 pyauto_functional.Main() |
OLD | NEW |