OLD | NEW |
| (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 import glob | |
7 import logging | |
8 import os | |
9 import time | |
10 | |
11 import pyauto_functional # must be imported before pyauto | |
12 import pyauto | |
13 | |
14 | |
15 class SecureShellTest(pyauto.PyUITest): | |
16 """Tests for Secure Shell app. | |
17 | |
18 Uses app from chrome/test/data/extensions/secure_shell/. | |
19 The test uses stable app by default. | |
20 Set the env var SECURE_SHELL_USE_DEV=1 to make it use the dev one. | |
21 """ | |
22 | |
23 assert pyauto.PyUITest.IsChromeOS(), 'Works on ChromeOS only' | |
24 | |
25 def setUp(self): | |
26 """Install secure shell app at startup.""" | |
27 pyauto.PyUITest.setUp(self) | |
28 | |
29 # Pick app from data dir. | |
30 app_dir = os.path.join(os.path.abspath( | |
31 self.DataDir()), 'extensions', 'secure_shell') | |
32 channel = 'dev' if os.getenv('SECURE_SHELL_USE_DEV') else 'stable' | |
33 files = glob.glob(os.path.join(app_dir, 'SecureShell-%s-*.crx' % channel)) | |
34 assert files, 'Secure Shell %s app missing in %s' % (channel, app_dir) | |
35 app_path = files[0] | |
36 | |
37 # Install app. | |
38 logging.debug('Using Secure shell app %s' % app_path) | |
39 self._app_id = self.InstallExtension(app_path, from_webstore=True) | |
40 | |
41 def testInstall(self): | |
42 """Install Secure Shell.""" | |
43 # Installation already done in setUp. Just verify. | |
44 self.assertTrue(self._app_id) | |
45 ssh_info = [x for x in self.GetExtensionsInfo() | |
46 if x['id'] == self._app_id][0] | |
47 self.assertTrue(ssh_info) | |
48 # Uninstall. | |
49 self.UninstallExtensionById(id=self._app_id) | |
50 self.assertFalse([x for x in self.GetExtensionsInfo() | |
51 if x['id'] == self._app_id], | |
52 msg='Could not uninstall.') | |
53 | |
54 def testLaunch(self): | |
55 """Launch Secure Shell and verify basic connect/exit flow. | |
56 | |
57 This basic flow also verifies that NaCl works since secure shell is based | |
58 on it. | |
59 """ | |
60 self.assertEqual(1, self.GetTabCount()) | |
61 then = time.time() | |
62 self.LaunchApp(self._app_id) | |
63 login_ui_frame = ( | |
64 '/descendant::iframe[contains(@src, "nassh_connect_dialog.html")]') | |
65 # Wait for connection dialog iframe to load. | |
66 self.WaitForDomNode(login_ui_frame, tab_index=1, | |
67 msg='Secure shell login dialog did not show up') | |
68 self.WaitForDomNode('id("field-description")', tab_index=1, | |
69 attribute='placeholder', | |
70 expected_value='username@hostname', # partial match | |
71 frame_xpath=login_ui_frame, | |
72 msg='Did not find secure shell username dialog') | |
73 now = time.time() | |
74 self.assertEqual(2, self.GetTabCount(), msg='Did not launch') | |
75 logging.info('Launched Secure Shell in %.2f secs' % (now - then)) | |
76 | |
77 # Fill in chronos@localhost using webdriver. | |
78 driver = self.NewWebDriver() | |
79 driver.switch_to_window(driver.window_handles[-1]) # last tab | |
80 driver.switch_to_frame(1) | |
81 user = 'chronos@localhost' | |
82 driver.find_element_by_id('field-description').send_keys(user + '\n') | |
83 | |
84 # Verify yes/no prompt | |
85 self.WaitForHtermText('continue connecting \(yes/no\)\?', tab_index=1, | |
86 msg='Did not get the yes/no prompt') | |
87 welcome_text = self.GetHtermRowsText(0, 8, tab_index=1) | |
88 self.assertTrue('Welcome to Secure Shell' in welcome_text, | |
89 msg='Did not get correct welcome message') | |
90 | |
91 # Type 'yes' and enter password | |
92 self.SendKeysToHterm('yes\\n', tab_index=1) | |
93 self.WaitForHtermText('Password:', tab_index=1, | |
94 msg='Did not get password prompt') | |
95 self.SendKeysToHterm('test0000\\n', tab_index=1) | |
96 self.WaitForHtermText('chronos@localhost $', tab_index=1, | |
97 msg='Did not get shell login prompt') | |
98 | |
99 # Type 'exit' and close the tab | |
100 self.SendKeysToHterm('exit\\n', tab_index=1) | |
101 # Check for only 'code 0' since that is what indicates that we exited | |
102 # successfully. Checking for more stringage causes flakes since the exit | |
103 # string does change at times. | |
104 self.WaitForHtermText('code 0', tab_index=1, | |
105 msg='Did not get correct exit message') | |
106 | |
107 | |
108 if __name__ == '__main__': | |
109 pyauto_functional.Main() | |
OLD | NEW |