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

Side by Side Diff: chrome/test/functional/gtalk/test_basic.py

Issue 9317067: Pyauto test for Quasar(Google Talk Extension) (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 8 years, 10 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 | Annotate | Revision Log
Property Changes:
Added: svn:executable
+ *
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 """Basic sanity tests for the GTalk extension
Nirnimesh 2012/02/10 01:36:51 End with .
jqian1 2012/02/15 18:41:27 Done.
7
8 This module contains the basic set of sanity tests run on the
9 GTalk extension.
10 """
11
12 import logging
13 import sys
14 import time
15 import traceback
16 import urllib2
17
18 import gtalk_base_test
19 import pyauto_gtalk # must preceed pyauto
20 import pyauto
21
22
23 class BasicTest(gtalk_base_test.GTalkBaseTest):
24 """Test for Google Talk Chrome Extension."""
25
26 def Prompt(self, text):
frankf 2012/02/10 03:09:36 Isn't this identical to the base class's?
jqian1 2012/02/15 18:41:27 Yes, thanks for pointing this out. I removed it fr
27 """Pause execution with debug output.
28
29 Args:
30 text: The debug output.
31 """
32 text = str(text)
33 raw_input('--------------------> ' + text.encode('utf-8'))
34
35 def _OpenRoster(self):
36 """Download Talk extension and open the roster."""
37
38 self.InstallGTalkExtension()
39
40 # Wait for the background view to load.
41 extension = self.GetGTalkExtensionInfo()
42 background_view = self.WaitUntilExtensionViewLoaded(
43 extension_id=extension['id'],
44 view_type='EXTENSION_BACKGROUND_PAGE')
45 self.assertTrue(background_view,
46 msg='Failed to get background view: views = %s.' %
47 self.GetBrowserInfo()['extension_views'])
48
49 # Click browser action icon
50 self.TriggerBrowserActionById(extension['id'])
51
52 # Wait for viewer window to open.
53 self.assertTrue(self.WaitUntil(self.GetViewerInfo),
54 msg='Timed out waiting for viewer.html to open.')
55
56 # Wait for all iframes to load.
57 self.WaitUntilResult(True,
58 lambda: self.RunInViewer(
59 'window.document.getElementsByTagName("iframe") != null'),
60 msg='Timed out waiting for iframes to load.')
frankf 2012/02/10 03:09:36 msg should be aligned with 'window..
jqian1 2012/02/15 18:41:27 Done.
61
62 # Wait for viewer window to load the sign-in page.
63 self.WaitUntilCondition(
64 lambda: self.RunInViewer('window.location.href',
65 '//iframe[1]'),
66 lambda url: url and '/qsignin' in url,
67 msg='Timed out waiting for /qsignin page.')
68
69 def _SignIn(self):
70 """Download the extension, open the roster, and sign in"""
71 # Open the roster.
72 self._OpenRoster()
73
74 # Wait for /qsignin's BODY.
75 self.WaitUntilResult(True,
76 lambda: self.RunInViewer(
77 'Boolean($BODY())', '//iframe[1]'),
78 msg='Timed out waiting for document.body in /qsignin page.')
79
80 # Wait for the "Sign In" link.
81 self.WaitUntilResult(True,
82 lambda: self.RunInViewer(
83 'Boolean($FindByText($BODY(), "Sign In"))', '//iframe[1]'),
84 msg='Timed out waiting for "Sign In" link in DOM.')
85
86 # Click the "Sign In" link.
87 self.assertTrue(self.RunInViewer(
88 '$Click($FindByText($BODY(), "Sign In"))', '//iframe[1]'))
frankf 2012/02/10 03:09:36 optional: define '//iframe...' as constant once.
89
90 # Wait for the login page to open.
91 self.assertTrue(self.WaitUntil(self.GetLoginPageInfo),
92 msg='Timed out waiting for login page to open.')
93
94 # Wait for the login page's form element.
95 self.WaitUntilResult(True,
96 lambda: self.RunInLoginPage('Boolean(document.forms[0])'),
97 msg='Timed out waiting for document.forms[0].')
98
99 # Fill and submit the login form.
100 self.RunInLoginPage(
101 'document.forms[0].Email.value="quasar.test.1@gmail.com"')
Nirnimesh 2012/02/10 01:36:51 Add a TODO to move it to a private file.
jqian1 2012/02/15 18:41:27 I have moved the userid/password to a private file
102 self.RunInLoginPage('document.forms[0].Passwd.value="stablechat"')
103 self.RunInLoginPage('document.forms[0].submit() || true')
104
105 def RunBasicFunctionalityTest(self):
106 """Run tests for basic functionality in GTalk."""
107
108 # Install the extension, open the viewer, and sign in.
109 self._SignIn()
110
111 # Wait for the roster container iframe.
112 self.WaitUntilResult(True,
113 lambda: self.RunInViewer(
114 'window.document.getElementById("popoutRoster") != null'),
115 msg='Timed out waiting for roster container iframe.')
116
117 self.WaitUntilResult(True,
118 lambda: self.RunInViewer('Boolean(window.frames[0])', '//iframe[1]'),
119 msg='Timed out waiting for roster iframe.')
120
121 # Wait for the roster iframe to load.
122 self.WaitUntilCondition(
123 lambda: self.RunInRoster('window.location.href'),
124 lambda url: url and '/proster' in url,
125 msg='Timed out waiting for /proster url.')
126
127 self.WaitUntilResult(True,
128 lambda: self.RunInRoster(
129 'window.document.getElementById(":rf") != null'),
130 msg='Timed out waiting for send message to label in roster DOM.')
131
132 # Wait for "chatpinger@appspot.com" to appear in the roster.
133 self.WaitUntilResult(True,
134 lambda: self.RunInRoster(
135 'Boolean($FindByText($BODY(), "chatpinger@appspot.com"))'),
136 msg='Timed out waiting for chatpinger@appspot.com in roster DOM.')
137
138 # Works around for issue where mole doesn't open when clicked too quickly.
139 time.sleep(1)
140
141 # Click "chatpinger@appspot.com" to open a chat mole.
142 self.RunInRoster('$Click($FindByText($BODY(), "chatpinger@appspot.com"))')
143
144 # Wait for chat mole to open.
145 self.assertTrue(self.WaitUntil(self.GetMoleInfo),
146 msg='Timed out waiting for mole window to open.')
147
148 self.WaitUntilResult(True,
149 lambda: self.RunInViewer(
150 'window.document.getElementsByTagName("iframe") != null'),
151 msg='Timed out waiting for iframes to load.')
152
153 # Wait for chat mole to load.
154 self.WaitUntilResult(True,
155 lambda: self.RunInMole('Boolean(window.location.href)'),
156 msg='Timed out waiting for mole window location.')
157
158 # Wait for the chat mole's input textarea to load.
159 self.WaitUntilResult(True,
160 lambda: self.RunInMole(
161 'Boolean($FindByTagName($BODY(), "textarea", 0))'),
162 msg='Timed out waiting for mole textarea.')
163
164 # Type /ping in the mole's input widget.
165 self.assertTrue(self.RunInMole(
166 '$Type($FindByTagName($BODY(), "textarea", 0), "/ping")'),
167 msg='Error typing in mole textarea.')
168
169 # Type ENTER in the mole's input widget.
170 self.assertTrue(self.RunInMole(
171 '$Press($FindByTagName($BODY(),"textarea",0), $KEYS.ENTER)'),
172 msg='Error sending ENTER in mole textarea.')
173
174 # Wait for chat input to clear.
175 self.WaitUntilResult(True,
176 lambda: self.RunInMole(
177 'Boolean($FindByTagName($BODY(),"textarea",0).value=="")'),
178 msg='Timed out waiting for textarea to clear after ENTER.')
179
180 # Wait for /ping to appear in the chat history.
181 self.WaitUntilCondition(
182 lambda: self.RunInMole('window.document.body.innerHTML'),
183 lambda html: html and '/ping' in html,
184 msg='Timed out waiting for /ping to appear in mole DOM.')
185
186 # Wait for the echo "Ping!" to appear in the chat history.
187 self.WaitUntilCondition(
188 lambda: self.RunInMole('window.document.body.innerHTML'),
189 lambda html: html and 'Ping!' in html,
190 msg='Timed out waiting for "Ping!" reply to appear in mole DOM.')
191
192 # Request a ping in 7 seconds.
193 self.assertTrue(self.RunInMole(
194 '$Type($FindByTagName($BODY(),"textarea",0), "/ping 7")'),
195 msg='Error typing "ping /7" in mole textarea.')
196
197 # Press Enter in chat input.
198 self.assertTrue(self.RunInMole(
199 '$Press($FindByTagName($BODY(),"textarea",0), $KEYS.ENTER)'),
200 msg='Error sending ENTER after "ping /7" in mole textarea.')
201
202 # Briefly show mole for visual examination.
203 # Also works around issue where extension may show the first
204 # Ping! notification before closing the mole.
205 time.sleep(2)
206
207 # Press escape to close the mole.
208 self.assertTrue(self.RunInMole(
209 '$Press($FindByTagName($BODY(),"textarea",0), $KEYS.ESC)'),
210 msg='Error sending ESC after "ping /7" in mole textarea.')
211
212 # Wait for the mole to close.
213 self.assertTrue(self.WaitUntil(
214 lambda: not(bool(self.GetMoleInfo()))),
215 msg='Timed out waiting for chatpinger mole to close.')
216
217 # Ensure "chatpinger2@appspot.com" is in the roster.
218 self.WaitUntilResult(True,
219 lambda: self.RunInRoster(
220 'Boolean($FindByText($BODY(), "chatpinger2@appspot.com"))'),
221 msg='Timed out waiting for chatpinger2@appspot.com in roster DOM.')
222
223 # Click "chatpinger2@appspot.com" in the roster.
224 self.RunInRoster('$Click($FindByText($BODY(), "chatpinger2@appspot.com"))')
225
226 self.WaitUntilResult(True,
227 lambda: self.RunInViewer(
228 'window.document.getElementsByTagName("iframe") != null'),
229 msg='Timed out waiting for iframes to load.')
230
231 # Wait for a second chat mole to open.
232 self.assertTrue(self.WaitUntil(lambda: bool(self.GetMoleInfo(1))),
233 msg='Timed out waiting for second mole window to open.')
234
235 # Disable the extension.
236 extension = self.GetGTalkExtensionInfo()
237 self.SetExtensionStateById(extension['id'], enable=False,
238 allow_in_incognito=False)
239 extension = self.GetGTalkExtensionInfo()
240 self.assertFalse(extension['is_enabled'])
241
242 # Verify all moles + windows are closed.
243 self.assertTrue(self.WaitUntil(lambda: not(bool(self.GetViewerInfo()))),
244 msg='Timed out waiting for viewer.html to close after disabling.')
245 self.assertTrue(self.WaitUntil(lambda: not(bool(self.GetMoleInfo()))),
246 msg='Timed out waiting for first mole to close after disabling.')
247 self.assertTrue(self.WaitUntil(lambda: not(bool(self.GetMoleInfo(1)))),
248 msg='Timed out waiting for second mole to close after disabling.')
249
250 def testBasicFunctionality(self):
251 """Run tests for basic functionality in GTalk with retries."""
252
253 # Since this test goes against prod servers, we'll retry to mitigate
254 # flakiness due to network issues.
255 tries = 0
frankf 2012/02/10 03:09:36 don't need the initialization.
jqian1 2012/02/15 18:41:27 Done.
256 RETRIES = 5
257 for tries in range(RETRIES):
258 logging.info('Calling RunBasicFunctionalityTest. Try #%s/%s'
259 % (tries + 1, RETRIES))
260 try:
261 self.RunBasicFunctionalityTest()
262 logging.info('RunBasicFunctionalityTest succeeded. Tries: %s'
263 % (tries + 1))
264 break
265 except Exception as e:
266 logging.info("\n*** ERROR in RunBasicFunctionalityTest ***")
267 exc_type, exc_value, exc_traceback = sys.exc_info()
268 traceback.print_exception(exc_type, exc_value, exc_traceback)
269 logging.info("\n")
270 if tries < RETRIES - 1:
271 self.NavigateToURL('http://accounts.google.com/Logout')
272 logging.info('Retrying...')
273 else:
274 raise
275
276
277 if __name__ == '__main__':
278 pyauto_gtalk.Main()
OLDNEW
« chrome/test/functional/gtalk/pyauto_gtalk.py ('K') | « chrome/test/functional/gtalk/pyauto_gtalk.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698