diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-03 21:55:35 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-03 21:55:35 +0000 |
commit | 96e5f8f350fba74fddfddc1017cd7a8cab963b8d (patch) | |
tree | 8a0424dcaa3562e41d3f28fb319957fa50da74cc /chrome/test/functional/secure_shell.py | |
parent | 275cb76096b0f9493e2bf82b9d2afc703a28a5cb (diff) | |
download | chromium_src-96e5f8f350fba74fddfddc1017cd7a8cab963b8d.zip chromium_src-96e5f8f350fba74fddfddc1017cd7a8cab963b8d.tar.gz chromium_src-96e5f8f350fba74fddfddc1017cd7a8cab963b8d.tar.bz2 |
Add automated test for secure shell
Add a test to install, and another to verify a connect session.
Includes extension as data files. Uses the stable extension by default but
can be overridden through an env var to use the dev one.
R=rginda@chromium.org
BUG=chromium-os:29472
TEST=secure_shell.py
Review URL: https://chromiumcodereview.appspot.com/10683012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145388 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/functional/secure_shell.py')
-rwxr-xr-x | chrome/test/functional/secure_shell.py | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/chrome/test/functional/secure_shell.py b/chrome/test/functional/secure_shell.py new file mode 100755 index 0000000..bd2d437 --- /dev/null +++ b/chrome/test/functional/secure_shell.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import glob +import logging +import os +import time + +import pyauto_functional # must be imported before pyauto +import pyauto + + +class SecureShellTest(pyauto.PyUITest): + """Tests for Secure Shell app. + + Uses app from chrome/test/data/extensions/secure_shell/. + The test uses stable app by default. + Set the env var SECURE_SHELL_USE_DEV=1 to make it use the dev one. + """ + + assert pyauto.PyUITest.IsChromeOS(), 'Works on ChromeOS only' + + def setUp(self): + """Install secure shell app at startup.""" + pyauto.PyUITest.setUp(self) + + # Pick app from data dir. + app_dir = os.path.join(os.path.abspath( + self.DataDir()), 'extensions', 'secure_shell') + channel = 'dev' if os.getenv('SECURE_SHELL_USE_DEV') else 'stable' + files = glob.glob(os.path.join(app_dir, 'SecureShell-%s-*.crx' % channel)) + assert files, 'Secure Shell %s app missing in %s' % (channel, app_dir) + app_path = files[0] + + # Install app. + logging.debug('Using Secure shell app %s' % app_path) + self._app_id = self.InstallExtension(app_path, from_webstore=True) + + def testInstall(self): + """Install Secure Shell.""" + # Installation already done in setUp. Just verify. + self.assertTrue(self._app_id) + ssh_info = [x for x in self.GetExtensionsInfo() + if x['id'] == self._app_id][0] + self.assertTrue(ssh_info) + # Uninstall. + self.UninstallExtensionById(id=self._app_id) + self.assertFalse([x for x in self.GetExtensionsInfo() + if x['id'] == self._app_id], + msg='Could not uninstall.') + + def testLaunch(self): + """Launch Secure Shell and verify basic connect/exit flow. + + This basic flow also verifies that NaCl works since secure shell is based + on it. + """ + self.assertEqual(1, self.GetTabCount()) + then = time.time() + self.LaunchApp(self._app_id) + login_ui_frame = ( + '/descendant::iframe[contains(@src, "nassh_connect_dialog.html")]') + # Wait for connection dialog iframe to load. + self.WaitForDomNode(login_ui_frame, tab_index=1, + msg='Secure shell login dialog did not show up') + self.WaitForDomNode('id("field-description")', tab_index=1, + attribute='placeholder', + expected_value='username@hostname', # partial match + frame_xpath=login_ui_frame, + msg='Did not find secure shell username dialog') + now = time.time() + self.assertEqual(2, self.GetTabCount(), msg='Did not launch') + logging.info('Launched Secure Shell in %.2f secs' % (now - then)) + + # Fill in chronos@localhost using webdriver. + driver = self.NewWebDriver() + driver.switch_to_window(driver.window_handles[-1]) # last tab + driver.switch_to_frame(1) + user = 'chronos@localhost' + driver.find_element_by_id('field-description').send_keys(user + '\n') + + # Verify yes/no prompt + self.WaitForHtermText('continue connecting \(yes/no\)\?', tab_index=1, + msg='Did not get the yes/no prompt') + welcome_text = self.GetHtermRowsText(0, 8, tab_index=1) + self.assertTrue('Welcome to Secure Shell' in welcome_text, + msg='Did not get correct welcome message') + + # Type 'yes' and enter password + self.SendKeysToHterm('yes\\n', tab_index=1) + self.WaitForHtermText('Password:', tab_index=1, + msg='Did not get password prompt') + self.SendKeysToHterm('test0000\\n', tab_index=1) + self.WaitForHtermText('chronos@localhost $', tab_index=1, + msg='Did not get shell login prompt') + + # Type 'exit' and close the tab + self.SendKeysToHterm('exit\\n', tab_index=1) + self.WaitForHtermText('completed with exit code 0', tab_index=1, + msg='Did not get correct exit message') + + +if __name__ == '__main__': + pyauto_functional.Main() |