summaryrefslogtreecommitdiffstats
path: root/chrome/test/functional/chromeos_crosh.py
blob: 690c1ef5359ea403aeef96cba742fe34694f3123 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/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 os

import pyauto_functional  # must be imported before pyauto
import pyauto
import test_utils


class CroshTest(pyauto.PyUITest):
  """Tests for crosh."""

  def setUp(self):
    """Close all windows at startup."""
    pyauto.PyUITest.setUp(self)
    for _ in range(self.GetBrowserWindowCount()):
      self.CloseBrowserWindow(0)

  def testBasic(self):
    """Verify crosh basic flow."""
    test_utils.OpenCroshVerification(self)

    # Verify crosh prompt.
    self.WaitForHtermText(text='crosh> ',
        msg='Could not find "crosh> " prompt')
    self.assertTrue(
        self.GetHtermRowsText(start=0, end=2).endswith('crosh> '),
        msg='Could not find "crosh> " prompt')

    # Run a crosh command.
    self.SendKeysToHterm('help\\n')
    self.WaitForHtermText(text='help_advanced',
        msg='Could not find "help_advanced" in help output.')

    # Exit crosh and close tab.
    self.SendKeysToHterm('exit\\n')
    self.WaitForHtermText(text='command crosh completed with exit code 0',
        msg='Could not exit crosh.')

  def testAddBookmark(self):
    """Test crosh URL can be bookmarked"""
    test_utils.OpenCroshVerification(self)

    # Add bookmark.
    bookmarks = self.GetBookmarkModel()
    bar_id = bookmarks.BookmarkBar()['id']
    name = 'crosh'
    url = self.GetActiveTabURL()
    count = bookmarks.NodeCount()
    self.AddBookmarkURL(bar_id, 0, name, url.spec())
    bookmarks = self.GetBookmarkModel()
    node = bookmarks.BookmarkBar()['children'][0]
    self.assertEqual(count + 1, bookmarks.NodeCount())
    self.assertEqual(node['type'], 'url')
    self.assertEqual(node['name'], name)
    self.assertEqual(url.spec(), node['url'])

  def testMultipleWindowCrosh(self):
    """Test that crosh can be opened in multiple windows."""
    test_utils.OpenCroshVerification(self)

    for windex in range (1, 4):  # 3 new windows
      self.OpenNewBrowserWindow(True)
      self.OpenCrosh()
      self.assertEqual('crosh', self.GetActiveTabTitle())

      # Verify crosh prompt.
      self.WaitForHtermText(text='crosh> ', tab_index=1, windex=windex,
          msg='Could not find "crosh> " prompt')
      self.assertTrue(
        self.GetHtermRowsText(start=0, end=2, tab_index=1,
                              windex=windex).endswith('crosh> '),
        msg='Could not find "crosh> " prompt')

      # Exit crosh.
      self.SendKeysToHterm('exit\\n', tab_index=1, windex=windex)
      self.WaitForHtermText(text='command crosh completed with exit code 0',
          tab_index=1, windex=windex,
          msg='Could not exit crosh.')

  def testShell(self):
    """Test shell can be opened in crosh."""
    test_utils.OpenCroshVerification(self)

    # Verify crosh prompt.
    self.WaitForHtermText(text='crosh> ',
        msg='Could not find "crosh> " prompt')
    self.assertTrue(
        self.GetHtermRowsText(start=0, end=2).endswith('crosh> '),
        msg='Could not find "crosh> " prompt')

    # Run a shell command.
    self.SendKeysToHterm(r'shell\n')
    self.WaitForHtermText(text='chronos@localhost',
        msg='Could not find "chronos@localhost" in shell output.')

  def testConnectToAnotherhost(self):
    """Test ssh to another host."""
    test_utils.OpenCroshVerification(self)

    # Verify crosh prompt.
    self.WaitForHtermText(text='crosh> ',
        msg='Could not find "crosh> " prompt')
    self.assertTrue(
        self.GetHtermRowsText(start=0, end=2).endswith('crosh> '),
        msg='Could not find "crosh> " prompt')

    # Ssh to another host: chronos@localhost.
    self.SendKeysToHterm(r'ssh chronos@localhost\n')
    self.WaitForHtermText(text='Password',
        msg='Could not find "Password" in shell output.')
    self.SendKeysToHterm(r'test0000\n')
    self.WaitForHtermText(text='chronos@localhost',
        msg='Could not find "chronos@localhost" in shell output.')

  def testTabSwitching(self):
    """Test tab can be switched in crosh."""
    test_utils.OpenCroshVerification(self)

    # Open 6 tabs
    for x in xrange(3):
      self.AppendTab(self.GetHttpURLForDataPath('title2.html'))
      self.assertEqual('Title Of Awesomeness', self.GetActiveTabTitle(),
                       msg='Unable to navigate to title2.html and '
                           'verify tab title.')
      self.OpenCrosh()
    self.assertEqual(7, len(self.GetBrowserInfo()['windows'][0]['tabs']))

    # Select tab 5
    self.ApplyAccelerator(pyauto.IDC_SELECT_TAB_4)
    self.assertEqual('crosh', self.GetActiveTabTitle(),
                     msg='Unable to naviage to crosh.')

    # Run a crosh command.
    self.SendKeysToHterm('help\\n', tab_index=4, windex=0)
    self.WaitForHtermText(text='help_advanced', tab_index=4, windex=0,
        msg='Could not find "help_advanced" in help output.')

  def testLargefileCrosh(self):
    """Test large file is displayed in crosh."""
    test_utils.OpenCroshVerification(self)

    # Verify crosh prompt.
    self.WaitForHtermText(text='crosh> ',
        msg='Could not find "crosh> " prompt')
    self.assertTrue(
        self.GetHtermRowsText(start=0, end=2).endswith('crosh> '),
        msg='Could not find "crosh> " prompt')

    # Login to localhost.
    self.SendKeysToHterm(r'ssh chronos@localhost\n')
    self.WaitForHtermText(text='Password',
        msg='Could not find "Password" in shell output.')
    self.SendKeysToHterm(r'test0000\n')
    self.WaitForHtermText(text='chronos@localhost',
        msg='Could not find "chronos@localhost" in shell output.')

    # Create a file with 140 characters per line, 50000 lines.
    bigfn = '/tmp/bigfile.txt'
    with open(bigfn, 'w') as file:
        file.write(('0' * 140 + '\n') * 50000 + 'complete\n')

    # Cat a large file.
    self.SendKeysToHterm(r'cat %s\n' % bigfn)
    self.WaitForHtermText(text='complete',
        msg='Could not find "complete" in shell output.')
    os.remove(bigfn)


if __name__ == '__main__':
  pyauto_functional.Main()