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 import email | 7 import email |
8 import os | 8 import os |
9 import smtplib | 9 import smtplib |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 Arg: | 37 Arg: |
38 test: derived from pyauto.PyUITest - base class for UI test cases | 38 test: derived from pyauto.PyUITest - base class for UI test cases |
39 file_name: name of file to remove | 39 file_name: name of file to remove |
40 """ | 40 """ |
41 downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), | 41 downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(), |
42 file_name) | 42 file_name) |
43 pyauto_utils.RemovePath(downloaded_pkg) | 43 pyauto_utils.RemovePath(downloaded_pkg) |
44 pyauto_utils.RemovePath(downloaded_pkg + '.crdownload') | 44 pyauto_utils.RemovePath(downloaded_pkg + '.crdownload') |
45 | 45 |
46 | 46 |
47 def GoogleAccountsLogin(test, url, username, password): | 47 def GoogleAccountsLogin(test, username, password, tab_index=0, windex=0): |
48 """Log into Google Accounts. | 48 """Log into Google Accounts. |
49 | 49 |
50 Attempts to login to Google by entering the username/password into the google | 50 Attempts to login to Google by entering the username/password into the google |
51 login page and click submit button. | 51 login page and click submit button. |
52 | 52 |
53 Args: | 53 Args: |
54 test: derived from pyauto.PyUITest - base class for UI test cases. | 54 test: derived from pyauto.PyUITest - base class for UI test cases. |
55 username: users login input. | 55 username: users login input. |
56 password: users login password input. | 56 password: users login password input. |
| 57 tab_index: The tab index, default is 0. |
| 58 windex: The window index, default is 0. |
57 """ | 59 """ |
58 test.NavigateToURL('https://www.google.com/accounts/') | 60 test.NavigateToURL('https://www.google.com/accounts/', windex, tab_index) |
59 email_id = 'document.getElementById("Email").value = \"%s\"; ' \ | 61 email_id = 'document.getElementById("Email").value = "%s"; ' \ |
60 'window.domAutomationController.send("done")' % username | 62 'window.domAutomationController.send("done")' % username |
61 password = 'document.getElementById("Passwd").value = \"%s\"; ' \ | 63 password = 'document.getElementById("Passwd").value = "%s"; ' \ |
62 'window.domAutomationController.send("done")' % password | 64 'window.domAutomationController.send("done")' % password |
63 test.ExecuteJavascript(email_id); | 65 test.ExecuteJavascript(email_id, windex, tab_index); |
64 test.ExecuteJavascript(password); | 66 test.ExecuteJavascript(password, windex, tab_index); |
65 test.ExecuteJavascript('document.getElementById("gaia_loginform").submit();' | 67 test.ExecuteJavascript('document.getElementById("gaia_loginform").submit();' |
66 'window.domAutomationController.send("done")') | 68 'window.domAutomationController.send("done")', |
| 69 windex, tab_index) |
67 | 70 |
68 | 71 |
69 def VerifyGoogleAccountCredsFilled(test, username, password): | 72 def VerifyGoogleAccountCredsFilled(test, username, password, tab_index=0, |
| 73 windex=0): |
70 """Verify stored/saved user and password values to the values in the field. | 74 """Verify stored/saved user and password values to the values in the field. |
71 | 75 |
72 Args: | 76 Args: |
73 test: derived from pyauto.PyUITest - base class for UI test cases. | 77 test: derived from pyauto.PyUITest - base class for UI test cases. |
74 username: user log in input. | 78 username: user log in input. |
75 password: user log in password input. | 79 password: user log in password input. |
| 80 tab_index: The tab index, default is 0. |
| 81 windex: The window index, default is 0. |
76 """ | 82 """ |
77 email_value = test.GetDOMValue('document.getElementById("Email").value') | 83 email_value = test.GetDOMValue('document.getElementById("Email").value', |
78 passwd_value = test.GetDOMValue('document.getElementById("Passwd").value') | 84 windex, tab_index) |
| 85 passwd_value = test.GetDOMValue('document.getElementById("Passwd").value', |
| 86 windex, tab_index) |
79 test.assertEqual(email_value, username) | 87 test.assertEqual(email_value, username) |
80 test.assertEqual(passwd_value, password) | 88 test.assertEqual(passwd_value, password) |
81 | 89 |
82 | 90 |
83 def ClearPasswords(test): | 91 def ClearPasswords(test): |
84 """Clear saved passwords.""" | 92 """Clear saved passwords.""" |
85 test.ClearBrowsingData(['PASSWORDS'], 'EVERYTHING') | 93 test.ClearBrowsingData(['PASSWORDS'], 'EVERYTHING') |
86 | 94 |
87 | 95 |
88 def Shell2(cmd_string, bg=False): | 96 def Shell2(cmd_string, bg=False): |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 if file_to_send is not None: | 138 if file_to_send is not None: |
131 part.set_payload(open(file_to_send,'rb').read()) | 139 part.set_payload(open(file_to_send,'rb').read()) |
132 email.Encoders.encode_base64(part) | 140 email.Encoders.encode_base64(part) |
133 part.add_header('Content-Disposition', | 141 part.add_header('Content-Disposition', |
134 'attachment; filename="%s"' | 142 'attachment; filename="%s"' |
135 % os.path.basename(file_to_send)) | 143 % os.path.basename(file_to_send)) |
136 msg.attach(part) | 144 msg.attach(part) |
137 smtp_obj = smtplib.SMTP(smtp) | 145 smtp_obj = smtplib.SMTP(smtp) |
138 smtp_obj.sendmail(send_from, send_to, msg.as_string()) | 146 smtp_obj.sendmail(send_from, send_to, msg.as_string()) |
139 smtp_obj.close() | 147 smtp_obj.close() |
140 | |
OLD | NEW |