OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/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 import os |
8 import subprocess | 8 import subprocess |
9 import re | 9 import re |
10 | 10 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 | 300 |
301 def testDisableBrowsingHistory(self): | 301 def testDisableBrowsingHistory(self): |
302 """Verify that browsing history is not being saved.""" | 302 """Verify that browsing history is not being saved.""" |
303 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | 303 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': |
304 return | 304 return |
305 url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'empty.html')) | 305 url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'empty.html')) |
306 self.NavigateToURL(url) | 306 self.NavigateToURL(url) |
307 self.assertFalse(self.GetHistoryInfo().History(), | 307 self.assertFalse(self.GetHistoryInfo().History(), |
308 msg='History is being saved.') | 308 msg='History is being saved.') |
309 | 309 |
310 class EnterpriseTestSetTwo(pyauto.PyUITest): | |
Nirnimesh
2011/08/05 19:05:23
'SetTwo' is not informative enough.
In the docstr
aocampo
2011/08/05 23:04:32
Done.
| |
311 """Test for Enterprise features. | |
312 | |
313 Browser preferences will be managed using policies. These managed preferences | |
314 cannot be modified by user. This works only for Google Chrome, not Chromium. | |
315 | |
316 On Linux, assume that 'suid-python' (a python binary setuid root) is | |
317 available on the machine under /usr/local/bin directory. | |
318 """ | |
319 assert pyauto.PyUITest.IsWin() or pyauto.PyUITest.IsLinux(), \ | |
320 'Only runs on Win or Linux' | |
321 | |
322 def Debug(self): | |
323 """Test method for experimentation. | |
324 | |
325 This method will not run automatically. | |
326 """ | |
327 import pprint | |
328 pp = pprint.PrettyPrinter(indent=2) | |
329 while True: | |
330 raw_input('Interact with the browser and hit <enter> to dump prefs... ') | |
331 pp.pprint(self.GetPrefsInfo().Prefs()) | |
332 | |
333 @staticmethod | |
334 def _Cleanup(): | |
335 """Removes the registry key and its subkeys(if they exist). | |
336 | |
337 Win: Registry Key being deleted: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google | |
338 Linux: Removes the chrome directory from /etc/opt | |
339 """ | |
340 if pyauto.PyUITest.IsWin(): | |
341 if subprocess.call( | |
342 r'reg query HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google') == 0: | |
343 logging.debug(r'Removing HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google') | |
344 subprocess.call(r'reg delete HKLM\Software\Policies\Google /f') | |
345 elif pyauto.PyUITest.IsLinux(): | |
346 sudo_cmd_file = os.path.join(os.path.dirname(__file__), | |
347 'enterprise_helper_linux.py') | |
348 if os.path.isdir ('/etc/opt/chrome'): | |
349 logging.debug('Removing directory /etc/opt/chrome/') | |
350 subprocess.call(['suid-python', sudo_cmd_file, | |
351 'remove_dir', '/etc/opt/chrome']) | |
352 | |
353 @staticmethod | |
354 def _SetUp(): | |
355 """Win: Add the registry keys from the .reg file. | |
356 | |
357 Removes the registry key and its subkeys if they exist. | |
358 Adding HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google. | |
359 | |
360 Linux: Copy the chrome.json file to the managed directory. | |
361 Remove /etc/opt/chrome directory if it exists. | |
362 """ | |
363 EnterpriseTestSetTwo._Cleanup() | |
364 if pyauto.PyUITest.IsWin(): | |
365 registry_location = os.path.join(EnterpriseTestSetTwo.DataDir(), 'enterpri se', | |
Nirnimesh
2011/08/05 19:05:23
>80 chars
| |
366 'chrome-add-reverse.reg') | |
367 # Add the registry keys | |
368 subprocess.call('reg import %s' % registry_location) | |
369 elif pyauto.PyUITest.IsLinux(): | |
370 chrome_json = os.path.join(EnterpriseTestSetTwo.DataDir(), | |
371 'enterprise', 'chrome-reverse.json') | |
372 sudo_cmd_file = os.path.join(os.path.dirname(__file__), | |
373 'enterprise_helper_linux.py') | |
374 policies_location = '/etc/opt/chrome/policies/managed' | |
375 subprocess.call(['suid-python', sudo_cmd_file, | |
376 'setup_dir', policies_location]) | |
377 # Copy chrome.json file to the managed directory | |
378 subprocess.call(['suid-python', sudo_cmd_file, | |
379 'copy', chrome_json, policies_location]) | |
380 | |
381 def setUp(self): | |
382 # Add policies through registry or json file. | |
383 self._SetUp() | |
384 # Check if registries are created in Win. | |
385 if pyauto.PyUITest.IsWin(): | |
386 registry_query_code = subprocess.call( | |
387 r'reg query HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google') | |
388 assert registry_query_code == 0, 'Could not create registries.' | |
389 # Check if json file is copied under correct location in Linux. | |
390 elif pyauto.PyUITest.IsLinux(): | |
391 policy_file_check = os.path.isfile( | |
392 '/etc/opt/chrome/policies/managed/chrome-reverse.jso n') | |
Nirnimesh
2011/08/05 19:05:23
>80 chars
aocampo
2011/08/05 23:04:32
Done.
| |
393 assert policy_file_check, 'Policy file(s) not set up.' | |
394 pyauto.PyUITest.setUp(self) | |
395 | |
396 def tearDown(self): | |
397 pyauto.PyUITest.tearDown(self) | |
398 EnterpriseTestSetTwo._Cleanup() | |
399 | |
400 def _CheckIfPrefCanBeModified(self, key, defaultval, newval): | |
401 """Check if the managed preferences can be modified. | |
402 | |
403 Args: | |
404 key: The preference key that you want to modify | |
405 defaultval: Default value of the preference that we are trying to modify | |
406 newval: New value that we are trying to set | |
407 """ | |
408 # Check if the default value of the preference is set as expected. | |
409 self.assertEqual(self.GetPrefsInfo().Prefs(key), defaultval, | |
410 msg='Default value of the preference is wrong.') | |
411 self.assertRaises(pyauto.JSONInterfaceError, | |
412 lambda: self.SetPrefs(key, newval)) | |
413 | |
414 def _GetPluginPID(self, plugin_name): | |
415 """Fetch the pid of the plugin process with name |plugin_name|.""" | |
416 child_processes = self.GetBrowserInfo()['child_processes'] | |
417 plugin_type = 'Plug-in' | |
418 for x in child_processes: | |
419 if x['type'] == plugin_type and re.search(plugin_name, x['name']): | |
420 return x['pid'] | |
421 return None | |
422 | |
423 # Tests for options in Basics | |
424 def testStartupPages(self): | |
425 """Verify that user cannot modify the startup page options.""" | |
426 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
427 return | |
428 # Verify startup option | |
429 self.assertEquals(0, self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup)) | |
430 self.assertRaises(pyauto.JSONInterfaceError, | |
431 lambda: self.SetPrefs(pyauto.kRestoreOnStartup, 1)) | |
432 | |
433 def testHomePageOptions(self): | |
434 """Verify that we cannot modify Homepage settings.""" | |
435 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
436 return | |
437 # Try to configure home page URL | |
438 self.assertEquals('http://chromium.org', | |
439 self.GetPrefsInfo().Prefs('homepage')) | |
440 self.assertRaises(pyauto.JSONInterfaceError, | |
441 lambda: self.SetPrefs('homepage', 'http://www.google.com')) | |
442 | |
443 # Try to reconfigure NTP as home page | |
444 self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kHomePageIsNewTabPage)) | |
445 self.assertRaises(pyauto.JSONInterfaceError, | |
446 lambda: self.SetPrefs(pyauto.kHomePageIsNewTabPage, True)) | |
447 | |
448 def testShowHomeButton(self): | |
449 """Verify that home button option cannot be modified when it's managed.""" | |
450 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
451 return | |
452 self._CheckIfPrefCanBeModified(pyauto.kShowHomeButton, False, True) | |
453 | |
454 def testInstant(self): | |
455 """Verify that Instant option cannot be modified.""" | |
456 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
457 return | |
458 self._CheckIfPrefCanBeModified(pyauto.kInstantEnabled, False, True) | |
459 | |
460 # Tests for options in Personal Stuff | |
461 def testPasswordManagerEnabled(self): | |
462 """Verify that password manager preference cannot be modified.""" | |
463 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
464 return | |
465 self._CheckIfPrefCanBeModified(pyauto.kPasswordManagerEnabled, False, True) | |
466 | |
467 # Tests for options in Under the Hood | |
468 def testPrivacyPrefs(self): | |
469 """Verify that the managed preferences cannot be modified.""" | |
470 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
471 return | |
472 prefs_list = [ | |
473 # (preference key, default value, new value) | |
474 (pyauto.kAlternateErrorPagesEnabled, False, True), | |
475 (pyauto.kNetworkPredictionEnabled, False, True), | |
476 (pyauto.kSafeBrowsingEnabled, False, True), | |
477 (pyauto.kSearchSuggestEnabled, False, True), | |
478 ] | |
479 # Check if the policies got applied by trying to modify | |
480 for key, defaultval, newval in prefs_list: | |
481 logging.info('Checking pref %s', key) | |
482 self._CheckIfPrefCanBeModified(key, defaultval, newval) | |
483 | |
484 def testNotClearSiteDataOnExit(self): | |
485 """Verify that clear data on exit preference cannot be modified.""" | |
486 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
487 return | |
488 self._CheckIfPrefCanBeModified(pyauto.kClearSiteDataOnExit, False, True) | |
489 | |
490 def testUnblockThirdPartyCookies(self): | |
491 """Verify that block third party cookies preference cannot be modified.""" | |
492 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
493 return | |
494 self._CheckIfPrefCanBeModified(pyauto.kBlockThirdPartyCookies, False, True) | |
495 | |
496 def testEnableDevTools(self): | |
497 """Verify that devtools window can be launched.""" | |
498 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
499 return | |
500 # DevTools process can be seen by PyAuto only when it's undocked. | |
501 self.SetPrefs(pyauto.kDevToolsOpenDocked, False) | |
502 self.ApplyAccelerator(pyauto.IDC_DEV_TOOLS) | |
503 self.assertEquals(2, len(self.GetBrowserInfo()['windows']), | |
504 msg='Devtools window not launched.') | |
505 | |
506 def testEnableSPDY(self): | |
507 """Verify that SPDY is enabled.""" | |
508 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
509 return | |
510 self.NavigateToURL('chrome://net-internals/#spdy') | |
511 self.assertEquals(0, | |
512 self.FindInPage('encrypted.google.com')['match_count']) | |
513 self.AppendTab(pyauto.GURL('https://encrypted.google.com')) | |
514 self.assertEquals('Google', self.GetActiveTabTitle()) | |
515 self.GetBrowserWindow(0).GetTab(0).Reload() | |
516 self.assertEquals(1, | |
517 self.FindInPage('encrypted.google.com', tab_index=0)['match_count'], | |
518 msg='SPDY is not enabled.') | |
519 | |
520 def testSetDownloadDirectory(self): | |
521 """Verify that the downloads directory and prompt for download preferences | |
522 can be modified. | |
523 """ | |
524 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
525 return | |
526 if self.IsWin(): | |
527 download_default_dir = os.path.join(os.getenv('USERPROFILE'),'Downloads') | |
528 self.assertEqual(download_default_dir, | |
529 self.GetPrefsInfo().Prefs()['download']['default_directory'], | |
530 msg='Downloads directory is not set correctly.') | |
531 # Check for changing the download directory location | |
532 self.SetPrefs(pyauto.kDownloadDefaultDirectory, | |
533 os.getenv('USERPROFILE')) | |
534 elif self.IsLinux(): | |
535 download_default_dir = os.path.join(os.getenv('HOME'), 'Downloads') | |
536 self.assertEqual(download_default_dir, | |
537 self.GetPrefsInfo().Prefs()['download']['default_directory'], | |
538 msg='Downloads directory is not set correctly.') | |
539 self.SetPrefs(pyauto.kDownloadDefaultDirectory, | |
540 os.getenv('HOME')) | |
541 # Check for changing the option 'Ask for each download' | |
542 self.SetPrefs(pyauto.kPromptForDownload, False) | |
543 | |
544 def testIncognitoDisabled(self): | |
545 """Verify that incognito window can be launched.""" | |
546 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
547 return | |
548 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | |
549 self.assertEquals(1, self.GetBrowserWindowCount()) | |
550 | |
551 def testEnableBrowsingHistory(self): | |
552 """Verify that browsing history is being saved.""" | |
553 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
554 return | |
555 url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'empty.html')) | |
556 self.NavigateToURL(url) | |
557 self.assertTrue(self.GetHistoryInfo().History(), | |
558 msg='History not is being saved.') | |
559 | |
560 def testAlwaysAuthorizePluginsDisabled(self): | |
561 """Verify plugins are always not allowed to run when policy is set.""" | |
562 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
563 return | |
564 url = self.GetFileURLForDataPath('plugin', 'java_new.html') | |
565 self.NavigateToURL(url) | |
566 self.assertTrue(self.WaitForInfobarCount(1)) | |
567 pid = self._GetPluginPID('Java') | |
568 self.assertFalse(pid, 'There is a plugin process for java') | |
310 | 569 |
Nirnimesh
2011/08/05 19:05:23
leave another blank line here
| |
311 if __name__ == '__main__': | 570 if __name__ == '__main__': |
312 pyauto_functional.Main() | 571 pyauto_functional.Main() |
OLD | NEW |