Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/test/pyautolib/pyauto.py

Issue 3026016: New pyauto hook for the translate feature. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Small changes Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/functional/translate.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 Returns: 639 Returns:
640 an instance of history_info.HistoryInfo 640 an instance of history_info.HistoryInfo
641 """ 641 """
642 cmd_dict = { # Prepare command for the json interface 642 cmd_dict = { # Prepare command for the json interface
643 'command': 'GetHistoryInfo', 643 'command': 'GetHistoryInfo',
644 'search_text': search_text, 644 'search_text': search_text,
645 } 645 }
646 return history_info.HistoryInfo( 646 return history_info.HistoryInfo(
647 self._SendJSONRequest(0, json.dumps(cmd_dict))) 647 self._SendJSONRequest(0, json.dumps(cmd_dict)))
648 648
649 def GetTranslateInfo(self, tab_index=0, window_index=0):
650 """Returns info about translate for the given page.
651
652 If the translate bar is showing, also returns information about the bar.
653
654 Args:
655 tab_index: The tab index, default is 0.
656 window_index: The window index, default is 0.
657
658 Returns:
659 A dictionary of information about translate for the page. Example:
660 { u'can_translate_page': True,
661 u'original_language': u'es',
662 u'page_translated': False,
663 # The below will only appear if the translate bar is showing.
664 u'translate_bar': { u'bar_state': u'BEFORE_TRANSLATE',
665 u'original_lang_code': u'es',
666 u'target_lang_code': u'en'}}
667 """
668 cmd_dict = { # Prepare command for the json interface
669 'command': 'GetTranslateInfo',
670 'tab_index': tab_index
671 }
672 return self._GetResultFromJSONRequest(cmd_dict, windex=window_index)
673
674 def ClickTranslateBarTranslate(self, tab_index=0, window_index=0):
675 """If the translate bar is showing, clicks the 'Translate' button on the
676 bar. This will show the 'this page has been translated...' infobar.
677
678 Args:
679 tab_index: The index of the tab, default is 0.
680 window_index: The index of the window, default is 0.
681
682 Returns:
683 True if the translation was successful or false if there was an error.
684 Note that an error shouldn't neccessarily mean a failed test - retry the
685 call on error.
686
687 Raises:
688 pyauto_errors.JSONInterfaceError if the automation returns an error.
689 """
690 cmd_dict = { # Prepare command for the json interface
691 'command': 'SelectTranslateOption',
692 'tab_index': tab_index,
693 'option': 'translate_page'
694 }
695 return self._GetResultFromJSONRequest(
696 cmd_dict, windex=window_index)['translation_success']
697
698 def RevertPageTranslation(self, tab_index=0, window_index=0):
699 """Select the 'Show original' button on the 'this page has been
700 translated...' infobar. This will remove the infobar and revert the
701 page translation.
702
703 Args:
704 tab_index: The index of the tab, default is 0.
705 window_index: The index of the window, default is 0.
706 """
707 cmd_dict = { # Prepare command for the json interface
708 'command': 'SelectTranslateOption',
709 'tab_index': tab_index,
710 'option': 'revert_translation'
711 }
712 self._GetResultFromJSONRequest(cmd_dict, windex=window_index)
713
714 def SelectTranslateOption(self, option, tab_index=0, window_index=0):
715 """Selects one of the options in the drop-down menu for the translate bar.
716
717 Args:
718 option: One of 'never_translate_language', 'never_translate_site', or
719 'toggle_always_translate'. See notes on each below.
720 tab_index: The index of the tab, default is 0.
721 window_index: The index of the window, default is 0.
722
723 *Notes*
724 never translate language: Selecting this means that no sites in this
725 language will be translated. This dismisses the infobar.
726 never translate site: Selecting this means that this site will never be
727 translated, regardless of the language. This dismisses the infobar.
728 toggle always translate: This does not dismiss the infobar or translate the
729 page. See ClickTranslateBarTranslate and PerformActioOnInfobar to do those .
730 If a language is selected to be always translated, then whenver the user
731 visits a page with that language, the infobar will show the 'This page has
732 been translated...' message.
733
734 Raises:
735 pyauto_errors.JSONInterfaceError if the automation returns an error.
736 """
737 cmd_dict = { # Prepare command for the json interface
738 'command': 'SelectTranslateOption',
739 'option': option,
740 'tab_index': tab_index
741 }
742 self._GetResultFromJSONRequest(cmd_dict, windex=window_index)
743
649 def FillAutoFillProfile(self, profiles=None, credit_cards=None, 744 def FillAutoFillProfile(self, profiles=None, credit_cards=None,
650 tab_index=0, window_index=0): 745 tab_index=0, window_index=0):
651 """Set the autofill profile to contain the given profiles and credit cards. 746 """Set the autofill profile to contain the given profiles and credit cards.
652 747
653 If profiles or credit_cards are specified, they will overwrite existing 748 If profiles or credit_cards are specified, they will overwrite existing
654 profiles and credit cards. To update profiles and credit cards, get the 749 profiles and credit cards. To update profiles and credit cards, get the
655 existing ones with the GetAutoFillProfile function and then append new 750 existing ones with the GetAutoFillProfile function and then append new
656 profiles to the list and call this function. 751 profiles to the list and call this function.
657 752
658 Args: 753 Args:
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 if self._options.verbose: 1319 if self._options.verbose:
1225 verbosity = 2 1320 verbosity = 2
1226 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) 1321 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite)
1227 del loaded_tests # Need to destroy test cases before the suite 1322 del loaded_tests # Need to destroy test cases before the suite
1228 del pyauto_suite 1323 del pyauto_suite
1229 sys.exit(not result.wasSuccessful()) 1324 sys.exit(not result.wasSuccessful())
1230 1325
1231 1326
1232 if __name__ == '__main__': 1327 if __name__ == '__main__':
1233 Main() 1328 Main()
OLDNEW
« no previous file with comments | « chrome/test/functional/translate.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698