Chromium Code Reviews| 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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 | 688 |
| 689 # With the policy set, the cookie should be gone after a restart. | 689 # With the policy set, the cookie should be gone after a restart. |
| 690 self.SetUserPolicy({ | 690 self.SetUserPolicy({ |
| 691 'ClearSiteDataOnExit': True | 691 'ClearSiteDataOnExit': True |
| 692 }) | 692 }) |
| 693 self.RestartBrowser(clear_profile=False) | 693 self.RestartBrowser(clear_profile=False) |
| 694 self.assertFalse( | 694 self.assertFalse( |
| 695 self.GetCookie(pyauto.GURL(cookie_url)), | 695 self.GetCookie(pyauto.GURL(cookie_url)), |
| 696 msg='Cookie present on ' + cookie_url + '.'); | 696 msg='Cookie present on ' + cookie_url + '.'); |
| 697 | 697 |
| 698 def testDisableScreenshotFile(self): | |
| 699 """Verify screenshot keyboard shortcut can be disabled by policy.""" | |
| 700 if not self.IsChromeOS(): | |
| 701 return # Screenshot accelerator available only on ChromeOS | |
| 702 | |
| 703 download_dir = self.GetDownloadDirectory().value() | |
| 704 | |
| 705 def FilesCount(): | |
|
xot
2012/08/03 15:40:36
Can you make FilesCount() only count files that be
qfel
2012/08/07 09:23:15
Done.
| |
| 706 return len(os.listdir(download_dir)) | |
| 707 | |
| 708 # Make sure screenshots actually go to downloads directory. | |
| 709 expected_count = FilesCount() + 1 | |
| 710 self.assertTrue(self.RunAshCommand(pyauto.TAKE_SCREENSHOT)) | |
|
xot
2012/08/03 15:40:36
Shouldn't you first make sure that DisableScreensh
qfel
2012/08/07 09:23:15
I assumed it's not set = false by default, but I s
| |
| 711 self.assertTrue(self.WaitUntil(FilesCount, expect_retval=expected_count)) | |
| 712 | |
| 713 # Real testing here: check if disabling screenshots works. | |
| 714 policy = { | |
| 715 'DisableScreenshots': True | |
| 716 } | |
| 717 self.SetUserPolicy(policy) | |
| 718 self.assertTrue(self.RunAshCommand(pyauto.TAKE_SCREENSHOT)) | |
| 719 self.assertFalse(self.WaitUntil(lambda: FilesCount() != expected_count, | |
| 720 timeout=5, expect_retval=True)) | |
| 721 | |
| 722 def testDisableScreenshotFeedback(self): | |
| 723 """Verify screenshot in feedback form can be disabled by policy.""" | |
| 724 | |
| 725 def SafeWaitUntilNavigationCompletes(tab_index): | |
| 726 self.assertTrue(self.WaitUntil(lambda: self.GetTabCount() > tab_index, | |
| 727 expect_retval=True)) | |
| 728 self.WaitUntilNavigationCompletes(tab_index=tab_index) | |
| 729 | |
| 730 # Make sure screenshot is normally displayed in feedback form. | |
| 731 self.assertTrue(self.ApplyAccelerator(pyauto.IDC_FEEDBACK)) | |
| 732 SafeWaitUntilNavigationCompletes(1) | |
| 733 self.WaitForDomNode('//img[starts-with(@id, "current-screenshots")]', | |
| 734 tab_index=1) | |
| 735 | |
| 736 # The feedback tab is a singleton tab, so close it first before trying to | |
| 737 # reopen. Otherwise it might not reload. | |
| 738 self.GetBrowserWindow(0).GetTab(1).Close(True) | |
| 739 | |
| 740 # Real testing here: check if disabling screenshots works. | |
| 741 policy = { | |
| 742 'DisableScreenshots': True | |
| 743 } | |
| 744 self.SetUserPolicy(policy) | |
| 745 self.assertTrue(self.ApplyAccelerator(pyauto.IDC_FEEDBACK)) | |
| 746 SafeWaitUntilNavigationCompletes(1) | |
| 747 self.assertRaises(pyauto.JSONInterfaceError, lambda: self.WaitForDomNode( | |
| 748 '//img[starts-with(@id, "current-screenshots")]', tab_index=1, | |
| 749 timeout=3)) | |
| 750 | |
| 698 | 751 |
| 699 if __name__ == '__main__': | 752 if __name__ == '__main__': |
| 700 pyauto_functional.Main() | 753 pyauto_functional.Main() |
| OLD | NEW |