OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """PyAuto: Python Interface to Chromium's Automation Proxy. | 7 """PyAuto: Python Interface to Chromium's Automation Proxy. |
8 | 8 |
9 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 9 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
10 For complete documentation on the functionality available, | 10 For complete documentation on the functionality available, |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 if ret_dict.has_key('error'): | 644 if ret_dict.has_key('error'): |
645 raise JSONInterfaceError(ret_dict['error']) | 645 raise JSONInterfaceError(ret_dict['error']) |
646 try: | 646 try: |
647 f = open(filename) | 647 f = open(filename) |
648 all_data = f.read() | 648 all_data = f.read() |
649 f.close() | 649 f.close() |
650 return all_data | 650 return all_data |
651 finally: | 651 finally: |
652 shutil.rmtree(tempdir) | 652 shutil.rmtree(tempdir) |
653 | 653 |
| 654 def SetTheme(self, crx_file_path): |
| 655 """Installs the given theme synchronously. |
| 656 |
| 657 A theme file is file with .crx suffix, like an extension. |
| 658 This method call waits until theme is installed and will trigger the |
| 659 "theme installed" infobar. |
| 660 |
| 661 Uses InstallExtension(). |
| 662 |
| 663 Returns: |
| 664 True, on success. |
| 665 """ |
| 666 return self.InstallExtension(crx_file_path, True) |
| 667 |
| 668 def ClearTheme(self): |
| 669 """Clear the theme. Resets to default. |
| 670 |
| 671 Has no effect when the theme is already the default one. |
| 672 This is a blocking call. |
| 673 |
| 674 Raises: |
| 675 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 676 """ |
| 677 cmd_dict = { |
| 678 'command': 'ClearTheme', |
| 679 } |
| 680 ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict))) |
| 681 if ret_dict.has_key('error'): |
| 682 raise JSONInterfaceError(ret_dict['error']) |
| 683 return ret_dict |
| 684 |
| 685 def GetThemeInfo(self): |
| 686 """Get info about theme. |
| 687 |
| 688 This includes info about the theme name, its colors, images, etc. |
| 689 |
| 690 Returns: |
| 691 a dictionary containing info about the theme. |
| 692 empty dictionary if no theme has been applied (default theme). |
| 693 SAMPLE: |
| 694 { u'colors': { u'frame': [71, 105, 91], |
| 695 u'ntp_link': [36, 70, 0], |
| 696 u'ntp_section': [207, 221, 192], |
| 697 u'ntp_text': [20, 40, 0], |
| 698 u'toolbar': [207, 221, 192]}, |
| 699 u'images': { u'theme_frame': u'images/theme_frame_camo.png', |
| 700 u'theme_ntp_background': u'images/theme_ntp_background.png', |
| 701 u'theme_toolbar': u'images/theme_toolbar_camo.png'}, |
| 702 u'name': u'camo theme', |
| 703 u'tints': {u'buttons': [0.33000000000000002, 0.5, 0.46999999999999997]}} |
| 704 |
| 705 Raises: |
| 706 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 707 """ |
| 708 cmd_dict = { |
| 709 'command': 'GetThemeInfo', |
| 710 } |
| 711 ret_dict = json.loads(self._SendJSONRequest(0, json.dumps(cmd_dict))) |
| 712 if ret_dict.has_key('error'): |
| 713 raise JSONInterfaceError(ret_dict['error']) |
| 714 return ret_dict |
| 715 |
654 | 716 |
655 class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): | 717 class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): |
656 """Base TestSuite for PyAuto UI tests.""" | 718 """Base TestSuite for PyAuto UI tests.""" |
657 | 719 |
658 def __init__(self, args): | 720 def __init__(self, args): |
659 pyautolib.PyUITestSuiteBase.__init__(self, args) | 721 pyautolib.PyUITestSuiteBase.__init__(self, args) |
660 | 722 |
661 # Figure out path to chromium binaries | 723 # Figure out path to chromium binaries |
662 browser_dir = os.path.normpath(os.path.dirname(pyautolib.__file__)) | 724 browser_dir = os.path.normpath(os.path.dirname(pyautolib.__file__)) |
663 logging.debug('Loading pyauto libs from %s', browser_dir) | 725 logging.debug('Loading pyauto libs from %s', browser_dir) |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 if self._options.verbose: | 949 if self._options.verbose: |
888 verbosity = 2 | 950 verbosity = 2 |
889 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) | 951 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) |
890 del loaded_tests # Need to destroy test cases before the suite | 952 del loaded_tests # Need to destroy test cases before the suite |
891 del pyauto_suite | 953 del pyauto_suite |
892 sys.exit(not result.wasSuccessful()) | 954 sys.exit(not result.wasSuccessful()) |
893 | 955 |
894 | 956 |
895 if __name__ == '__main__': | 957 if __name__ == '__main__': |
896 Main() | 958 Main() |
OLD | NEW |