OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 | 8 |
9 import pyauto_functional # must come before pyauto. | 9 import pyauto_functional # must come before pyauto. |
10 import policy_base | 10 import policy_base |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 | 681 |
682 # With the policy set, the cookie should be gone after a restart. | 682 # With the policy set, the cookie should be gone after a restart. |
683 self.SetUserPolicy({ | 683 self.SetUserPolicy({ |
684 'ClearSiteDataOnExit': True | 684 'ClearSiteDataOnExit': True |
685 }) | 685 }) |
686 self.RestartBrowser(clear_profile=False) | 686 self.RestartBrowser(clear_profile=False) |
687 self.assertFalse( | 687 self.assertFalse( |
688 self.GetCookie(pyauto.GURL(cookie_url)), | 688 self.GetCookie(pyauto.GURL(cookie_url)), |
689 msg='Cookie present on ' + cookie_url + '.'); | 689 msg='Cookie present on ' + cookie_url + '.'); |
690 | 690 |
| 691 def testDisableScreenshotFile(self): |
| 692 """Verify screenshot keyboard shortcut can be disabled by policy.""" |
| 693 if not self.IsChromeOS(): |
| 694 return # Screenshot accelerator available only on ChromeOS |
| 695 |
| 696 download_dir = self.GetDownloadDirectory().value() |
| 697 |
| 698 def FilesCount(): |
| 699 return len(os.listdir(download_dir)) |
| 700 |
| 701 # Make sure screenshots actually go to downloads directory. |
| 702 expected_count = FilesCount() + 1 |
| 703 self.assertTrue(self.ApplyAshAccelerator(pyauto.TAKE_SCREENSHOT)) |
| 704 self.assertTrue(self.WaitUntil(FilesCount, expect_retval=expected_count)) |
| 705 |
| 706 # Real testing here: check if disabling screenshots works. |
| 707 policy = { |
| 708 'DisableScreenshots': True |
| 709 } |
| 710 self.SetUserPolicy(policy) |
| 711 self.assertTrue(self.ApplyAshAccelerator(TAKE_SCREENSHOT)) |
| 712 self.assertFalse(self.WaitUntil(lambda: files_count() != expected_count, |
| 713 timeout=5, expect_retval=True)) |
| 714 |
| 715 def testDisableScreenshotFeedback(self): |
| 716 """Verify screenshot in feedback form can be disabled by policy.""" |
| 717 |
| 718 def SafeWaitUntilNavigationCompletes(tab_index): |
| 719 self.assertTrue(self.WaitUntil(lambda: self.GetTabCount() > tab_index, |
| 720 expect_retval=True)) |
| 721 self.WaitUntilNavigationCompletes(tab_index=tab_index) |
| 722 |
| 723 # Make sure screenshot is normally displayed in feedback form. |
| 724 self.assertTrue(self.ApplyAccelerator(pyauto.IDC_FEEDBACK)) |
| 725 SafeWaitUntilNavigationCompletes(1) |
| 726 self.WaitForDomNode('//img[starts-with(@id, "current-screenshots")]', |
| 727 tab_index=1) |
| 728 |
| 729 # The feedback tab is a singleton tab, so close it first before trying to |
| 730 # reopen. Otherwise it might not reload. |
| 731 self.GetBrowserWindow(0).GetTab(1).Close(True) |
| 732 |
| 733 # Real testing here: check if disabling screenshots works. |
| 734 policy = { |
| 735 'DisableScreenshots': True |
| 736 } |
| 737 self.SetUserPolicy(policy) |
| 738 self.assertTrue(self.ApplyAccelerator(pyauto.IDC_FEEDBACK)) |
| 739 SafeWaitUntilNavigationCompletes(1) |
| 740 self.assertRaises(pyauto.JSONInterfaceError, lambda: self.WaitForDomNode( |
| 741 '//img[starts-with(@id, "current-screenshots")]', tab_index=1, |
| 742 timeout=3)) |
| 743 |
691 | 744 |
692 if __name__ == '__main__': | 745 if __name__ == '__main__': |
693 pyauto_functional.Main() | 746 pyauto_functional.Main() |
OLD | NEW |