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

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
« no previous file with comments | « chrome/test/functional/gtalk/pyauto_gtalk.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
(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.
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 _OpenRoster(self):
27 """Download Talk extension and open the roster."""
28
29 self.InstallGTalkExtension()
30
31 # Wait for the background view to load.
32 extension = self.GetGTalkExtensionInfo()
33 background_view = self.WaitUntilExtensionViewLoaded(
34 extension_id=extension['id'],
35 view_type='EXTENSION_BACKGROUND_PAGE')
36 self.assertTrue(background_view,
37 msg='Failed to get background view: views = %s.' %
38 self.GetBrowserInfo()['extension_views'])
39
40 # Click browser action icon
41 self.TriggerBrowserActionById(extension['id'])
42
43 # Wait for viewer window to open.
44 self.assertTrue(
45 self.WaitUntil(self.GetViewerInfo),
46 msg='Timed out waiting for viewer.html to open.')
47
48 # Wait for all iframes to load.
49 self.WaitUntilResult(True,
50 lambda: self.RunInViewer(
51 'window.document.getElementsByTagName("iframe") != null'),
52 msg='Timed out waiting for iframes to load.')
53
54 # Wait for viewer window to load the sign-in page.
55 self.WaitUntilCondition(
56 lambda: self.RunInViewer('window.location.href',
57 '//iframe[1]'),
58 lambda url: url and '/qsignin' in url,
59 msg='Timed out waiting for /qsignin page.')
60
61 def _SignIn(self):
62 """Download the extension, open the roster, and sign in"""
63 # Open the roster.
64 self._OpenRoster()
65
66 # Wait for /qsignin's BODY.
67 self.WaitUntilResult(True,
68 lambda: self.RunInViewer(
69 'Boolean($BODY())', '//iframe[1]'),
70 msg='Timed out waiting for document.body in /qsignin page.')
71
72 # Wait for the "Sign In" link.
73 self.WaitUntilResult(True,
74 lambda: self.RunInViewer(
75 'Boolean($FindByText($BODY(), "Sign In"))', '//iframe[1]'),
76 msg='Timed out waiting for "Sign In" link in DOM.')
77
78 # Click the "Sign In" link.
79 self.assertTrue(self.RunInViewer(
80 '$Click($FindByText($BODY(), "Sign In"))', '//iframe[1]'))
81
82 # Wait for the login page to open.
83 self.assertTrue(self.WaitUntil(self.GetLoginPageInfo),
84 msg='Timed out waiting for login page to open.')
85
86 # Wait for the login page's form element.
87 self.WaitUntilResult(True,
88 lambda: self.RunInLoginPage('Boolean(document.forms[0])'),
89 msg='Timed out waiting for document.forms[0].')
90
91 # Fill and submit the login form.
92 credentials = self.GetPrivateInfo()['test_quasar']
93
94 self.RunInLoginPage(
95 'document.forms[0].Email.value="' + credentials['username'] + '"')
96 self.RunInLoginPage(
97 'document.forms[0].Passwd.value="' + credentials['password'] + '"')
98 self.RunInLoginPage('document.forms[0].submit() || true')
99
100 def RunBasicFunctionalityTest(self):
101 """Run tests for basic functionality in GTalk."""
102
103 # Install the extension, open the viewer, and sign in.
104 self._SignIn()
105
106 # Wait for the roster container iframe.
107 self.WaitUntilResult(True,
108 lambda: self.RunInViewer(
109 'window.document.getElementById("popoutRoster") != null'),
110 msg='Timed out waiting for roster container iframe.')
111
112 self.WaitUntilResult(True,
113 lambda: self.RunInViewer('Boolean(window.frames[0])', '//iframe[1]'),
114 msg='Timed out waiting for roster iframe.')
115
116 # Wait for the roster iframe to load.
117 self.WaitUntilCondition(
118 lambda: self.RunInRoster('window.location.href'),
119 lambda url: url and '/proster' in url,
120 msg='Timed out waiting for /proster url.')
121
122 self.WaitUntilResult(True,
123 lambda: self.RunInRoster(
124 'window.document.getElementById(":rf") != null'),
125 msg='Timed out waiting for send message to label in roster DOM.')
126
127 # Wait for "chatpinger@appspot.com" to appear in the roster.
128 self.WaitUntilResult(True,
129 lambda: self.RunInRoster(
130 'Boolean($FindByText($BODY(), "chatpinger@appspot.com"))'),
131 msg='Timed out waiting for chatpinger@appspot.com in roster DOM.')
132
133 # Works around for issue where mole doesn't open when clicked too quickly.
134 time.sleep(1)
135
136 # Click "chatpinger@appspot.com" to open a chat mole.
137 self.RunInRoster('$Click($FindByText($BODY(), "chatpinger@appspot.com"))')
138
139 # Wait for chat mole to open.
140 self.assertTrue(self.WaitUntil(self.GetMoleInfo),
141 msg='Timed out waiting for mole window to open.')
142
143 self.WaitUntilResult(True,
144 lambda: self.RunInViewer(
145 'window.document.getElementsByTagName("iframe") != null'),
146 msg='Timed out waiting for iframes to load.')
147
148 # Wait for chat mole to load.
149 self.WaitUntilResult(True,
150 lambda: self.RunInMole('Boolean(window.location.href)'),
151 msg='Timed out waiting for mole window location.')
152
153 # Wait for the chat mole's input textarea to load.
154 self.WaitUntilResult(True,
155 lambda: self.RunInMole(
156 'Boolean($FindByTagName($BODY(), "textarea", 0))'),
157 msg='Timed out waiting for mole textarea.')
158
159 # Type /ping in the mole's input widget.
160 self.assertTrue(self.RunInMole(
161 '$Type($FindByTagName($BODY(), "textarea", 0), "/ping")'),
162 msg='Error typing in mole textarea.')
163
164 # Type ENTER in the mole's input widget.
165 self.assertTrue(self.RunInMole(
166 '$Press($FindByTagName($BODY(),"textarea",0), $KEYS.ENTER)'),
167 msg='Error sending ENTER in mole textarea.')
168
169 # Wait for chat input to clear.
170 self.WaitUntilResult(True,
171 lambda: self.RunInMole(
172 'Boolean($FindByTagName($BODY(),"textarea",0).value=="")'),
173 msg='Timed out waiting for textarea to clear after ENTER.')
174
175 # Wait for /ping to appear in the chat history.
176 self.WaitUntilCondition(
177 lambda: self.RunInMole('window.document.body.innerHTML'),
178 lambda html: html and '/ping' in html,
179 msg='Timed out waiting for /ping to appear in mole DOM.')
180
181 # Wait for the echo "Ping!" to appear in the chat history.
182 self.WaitUntilCondition(
183 lambda: self.RunInMole('window.document.body.innerHTML'),
184 lambda html: html and 'Ping!' in html,
185 msg='Timed out waiting for "Ping!" reply to appear in mole DOM.')
186
187 # Request a ping in 7 seconds.
188 self.assertTrue(self.RunInMole(
189 '$Type($FindByTagName($BODY(),"textarea",0), "/ping 7")'),
190 msg='Error typing "ping /7" in mole textarea.')
191
192 # Press Enter in chat input.
193 self.assertTrue(self.RunInMole(
194 '$Press($FindByTagName($BODY(),"textarea",0), $KEYS.ENTER)'),
195 msg='Error sending ENTER after "ping /7" in mole textarea.')
196
197 # Briefly show mole for visual examination.
198 # Also works around issue where extension may show the first
199 # Ping! notification before closing the mole.
200 time.sleep(2)
201
202 # Press escape to close the mole.
203 self.assertTrue(self.RunInMole(
204 '$Press($FindByTagName($BODY(),"textarea",0), $KEYS.ESC)'),
205 msg='Error sending ESC after "ping /7" in mole textarea.')
206
207 # Wait for the mole to close.
208 self.assertTrue(self.WaitUntil(
209 lambda: not(bool(self.GetMoleInfo()))),
210 msg='Timed out waiting for chatpinger mole to close.')
211
212 # Ensure "chatpinger2@appspot.com" is in the roster.
213 self.WaitUntilResult(True,
214 lambda: self.RunInRoster(
215 'Boolean($FindByText($BODY(), "chatpinger2@appspot.com"))'),
216 msg='Timed out waiting for chatpinger2@appspot.com in roster DOM.')
217
218 # Click "chatpinger2@appspot.com" in the roster.
219 self.RunInRoster('$Click($FindByText($BODY(), "chatpinger2@appspot.com"))')
220
221 self.WaitUntilResult(True,
222 lambda: self.RunInViewer(
223 'window.document.getElementsByTagName("iframe") != null'),
224 msg='Timed out waiting for iframes to load.')
225
226 # Wait for a second chat mole to open.
227 time.sleep(1)
228 self.assertTrue(self.WaitUntil(lambda: bool(self.GetMoleInfo(1))),
229 msg='Timed out waiting for second mole window to open.')
230
231 # Disable the extension.
232 extension = self.GetGTalkExtensionInfo()
233 self.SetExtensionStateById(extension['id'], enable=False,
234 allow_in_incognito=False)
235 extension = self.GetGTalkExtensionInfo()
236 self.assertFalse(extension['is_enabled'])
237
238 # Verify all moles + windows are closed.
239 self.assertTrue(self.WaitUntil(lambda: not(bool(self.GetViewerInfo()))),
240 msg='Timed out waiting for viewer.html to close after disabling.')
241 self.assertTrue(self.WaitUntil(lambda: not(bool(self.GetMoleInfo()))),
242 msg='Timed out waiting for first mole to close after disabling.')
243 self.assertTrue(self.WaitUntil(lambda: not(bool(self.GetMoleInfo(1)))),
244 msg='Timed out waiting for second mole to close after disabling.')
245
246 def testBasicFunctionality(self):
247 """Run tests for basic functionality in GTalk with retries."""
248
249 # Since this test goes against prod servers, we'll retry to mitigate
250 # flakiness due to network issues.
251 RETRIES = 5
252 for tries in range(RETRIES):
253 logging.info('Calling RunBasicFunctionalityTest. Try #%s/%s'
254 % (tries + 1, RETRIES))
255 try:
256 self.RunBasicFunctionalityTest()
257 logging.info('RunBasicFunctionalityTest succeeded. Tries: %s'
258 % (tries + 1))
259 break
260 except Exception as e:
261 logging.info("\n*** ERROR in RunBasicFunctionalityTest ***")
262 exc_type, exc_value, exc_traceback = sys.exc_info()
263 traceback.print_exception(exc_type, exc_value, exc_traceback)
264 logging.info("\n")
265 if tries < RETRIES - 1:
266 self.NavigateToURL('http://accounts.google.com/Logout')
267 logging.info('Retrying...')
268 else:
269 raise
270
271
272 if __name__ == '__main__':
273 pyauto_gtalk.Main()
OLDNEW
« no previous file with comments | « 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