Chromium Code Reviews
Help | Chromium Project | Sign in
(900)

Side by Side Diff: chrome/test/functional/translate.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 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | chrome/test/pyautolib/pyauto.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import pyauto_functional # Must be imported before pyauto
7 import pyauto
8
9
10 class TranslateTest(pyauto.PyUITest):
11 """Tests that translate works correctly"""
12
13 spanish_google = 'http://www.google.com/webhp?hl=es'
14 spanish = 'es'
15 after_translate = 'AFTER_TRANSLATE'
16 before_translate = 'BEFORE_TRANSLATE'
17 translating = 'TRANSLATING'
18 translation_error = 'TRANSLATION_ERROR'
19
20 def Debug(self):
21 """ Test method for experimentation. """
22 import pprint
23 pp = pprint.PrettyPrinter(indent=2)
24 while True:
25 raw_input('Hit <enter> to dump translate info.. ')
26 pp.pprint(self.GetTranslateInfo())
27
28 def _NavigateAndWaitForBar(self, url):
29 self.NavigateToURL(url)
30 self.WaitForInfobarCount(1)
31
32 def _ClickTranslateUntilSuccess(self):
33 """Since the translate can fail due to server error, continue trying until
34 it is successful or until it has tried too many times."""
35 max_tries = 10
36 curr_try = 0
37 while curr_try < max_tries and not self.ClickTranslateBarTranslate():
38 curr_try = curr_try + 1
39 if curr_try == 10:
40 self.fail('Translation failed more than %d times.' % max_tries)
41
42 def testTranslate(self):
43 """Tests that a page was translated if the user chooses to translate."""
44 self._NavigateAndWaitForBar(self.spanish_google)
45 self._ClickTranslateUntilSuccess()
46 translate_info = self.GetTranslateInfo()
47 self.assertEqual(self.spanish, translate_info['original_language'])
48 self.assertTrue(translate_info['page_translated'])
49 self.assertTrue(translate_info['can_translate_page'])
50 self.assertTrue('translate_bar' in translate_info)
51 self.assertEquals(self.after_translate,
52 translate_info['translate_bar']['bar_state'])
53
54 def testNoTranslate(self):
55 """Tests that a page isn't translated if the user declines translate."""
56 self._NavigateAndWaitForBar(self.spanish_google)
57 self.PerformActionOnInfobar('dismiss', 0)
58 translate_info = self.GetTranslateInfo()
59 self.assertEqual(self.spanish, translate_info['original_language'])
60 self.assertFalse(translate_info['page_translated'])
61 self.assertTrue(translate_info['can_translate_page'])
62 # If the user goes to the site again, the infobar should drop down but
63 # the page should not be automatically translated.
64 self._NavigateAndWaitForBar(self.spanish_google)
65 translate_info = self.GetTranslateInfo()
66 self.assertFalse(translate_info['page_translated'])
67 self.assertTrue(translate_info['can_translate_page'])
68 self.assertTrue('translate_bar' in translate_info)
69 self.assertEquals(self.before_translate,
70 translate_info['translate_bar']['bar_state'])
71
72 def testNeverTranslateLanguage(self):
73 """Tests that blacklisting a language for translate works."""
74 self._NavigateAndWaitForBar(self.spanish_google)
75 self.SelectTranslateOption('never_translate_language')
76 translate_info = self.GetTranslateInfo()
77 self.assertEqual(self.spanish, translate_info['original_language'])
78 self.assertFalse(translate_info['page_translated'])
79 self.assertFalse(translate_info['can_translate_page'])
80 spanish_wikipedia = 'http://es.wikipedia.org/wiki/Wikipedia:Portada'
81 self.NavigateToURL(spanish_wikipedia)
82 translate_info = self.GetTranslateInfo()
83 self.assertEqual(self.spanish, translate_info['original_language'])
84 self.assertFalse(translate_info['page_translated'])
85 self.assertFalse(translate_info['can_translate_page'])
86
87 def testAlwaysTranslateLanguage(self):
88 """Tests that the always translate a language option works."""
89 self._NavigateAndWaitForBar(self.spanish_google)
90 self.SelectTranslateOption('toggle_always_translate')
91 self._ClickTranslateUntilSuccess()
92 translate_info = self.GetTranslateInfo()
93 self.assertEquals(self.spanish, translate_info['original_language'])
94 self.assertTrue(translate_info['page_translated'])
95 self.assertTrue(translate_info['can_translate_page'])
96 self.assertTrue('translate_bar' in translate_info)
97 self.assertEquals(self.after_translate,
98 translate_info['translate_bar']['bar_state'])
99 # Go to another spanish site and verify that it is translated.
100 # Note that the 'This page has been translated..." bar will show up.
101 self._NavigateAndWaitForBar(
102 'http://es.wikipedia.org/wiki/Wikipedia:Portada')
103 translate_info = self.GetTranslateInfo()
104 self.assertTrue('translate_bar' in translate_info)
105 curr_bar_state = translate_info['translate_bar']['bar_state']
106 # We don't care whether the translation has finished, just that it is
107 # trying to translate.
108 self.assertTrue(curr_bar_state is self.after_translate or
109 self.translating or self.translation_error,
110 'Bar state was %s.' % curr_bar_state)
111
112 def testNeverTranslateSite(self):
113 """Tests that blacklisting a site for translate works."""
114 self._NavigateAndWaitForBar(self.spanish_google)
115 self.SelectTranslateOption('never_translate_site')
116 translate_info = self.GetTranslateInfo()
117 self.assertFalse(translate_info['page_translated'])
118 self.assertFalse(translate_info['can_translate_page'])
119 french_google = 'http://www.google.com/webhp?hl=fr'
120 # Go to another page in the same site and verify that the page can't be
121 # translated even though it's in a different language.
122 self.NavigateToURL(french_google)
123 translate_info = self.GetTranslateInfo()
124 self.assertFalse(translate_info['page_translated'])
125 self.assertFalse(translate_info['can_translate_page'])
126
127 def testRevert(self):
128 """Tests that reverting a site to its original language works."""
129 self._NavigateAndWaitForBar(self.spanish_google)
130 self._ClickTranslateUntilSuccess()
131 self.RevertPageTranslation()
132 translate_info = self.GetTranslateInfo()
133 self.assertFalse(translate_info['page_translated'])
134 self.assertTrue(translate_info['can_translate_page'])
135
136
137 if __name__ == '__main__':
138 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | chrome/test/pyautolib/pyauto.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1280:2d3e6564b7b6