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.
8 import pyauto_functional # must be imported before pyauto
13 class CroshTest(pyauto.PyUITest):
14 """Tests for crosh."""
17 """Close all windows at startup."""
18 pyauto.PyUITest.setUp(self)
19 for _ in range(self.GetBrowserWindowCount()):
20 self.CloseBrowserWindow(0)
23 """Verify crosh basic flow."""
24 test_utils.OpenCroshVerification(self)
26 # Verify crosh prompt.
27 self.WaitForHtermText(text='crosh> ',
28 msg='Could not find "crosh> " prompt')
30 self.GetHtermRowsText(start=0, end=2).endswith('crosh> '),
31 msg='Could not find "crosh> " prompt')
33 # Run a crosh command.
34 self.SendKeysToHterm('help\\n')
35 self.WaitForHtermText(text='help_advanced',
36 msg='Could not find "help_advanced" in help output.')
38 # Exit crosh and close tab.
39 self.SendKeysToHterm('exit\\n')
40 self.WaitForHtermText(text='command crosh completed with exit code 0',
41 msg='Could not exit crosh.')
43 def testAddBookmark(self):
44 """Test crosh URL can be bookmarked"""
45 test_utils.OpenCroshVerification(self)
48 bookmarks = self.GetBookmarkModel()
49 bar_id = bookmarks.BookmarkBar()['id']
51 url = self.GetActiveTabURL()
52 count = bookmarks.NodeCount()
53 self.AddBookmarkURL(bar_id, 0, name, url.spec())
54 bookmarks = self.GetBookmarkModel()
55 node = bookmarks.BookmarkBar()['children'][0]
56 self.assertEqual(count + 1, bookmarks.NodeCount())
57 self.assertEqual(node['type'], 'url')
58 self.assertEqual(node['name'], name)
59 self.assertEqual(url.spec(), node['url'])
61 def testMultipleWindowCrosh(self):
62 """Test that crosh can be opened in multiple windows."""
63 test_utils.OpenCroshVerification(self)
65 for windex in range (1, 4): # 3 new windows
66 self.OpenNewBrowserWindow(True)
68 self.assertEqual('crosh', self.GetActiveTabTitle())
70 # Verify crosh prompt.
71 self.WaitForHtermText(text='crosh> ', tab_index=1, windex=windex,
72 msg='Could not find "crosh> " prompt')
74 self.GetHtermRowsText(start=0, end=2, tab_index=1,
75 windex=windex).endswith('crosh> '),
76 msg='Could not find "crosh> " prompt')
79 self.SendKeysToHterm('exit\\n', tab_index=1, windex=windex)
80 self.WaitForHtermText(text='command crosh completed with exit code 0',
81 tab_index=1, windex=windex,
82 msg='Could not exit crosh.')
85 """Test shell can be opened in crosh."""
86 test_utils.OpenCroshVerification(self)
88 # Verify crosh prompt.
89 self.WaitForHtermText(text='crosh> ',
90 msg='Could not find "crosh> " prompt')
92 self.GetHtermRowsText(start=0, end=2).endswith('crosh> '),
93 msg='Could not find "crosh> " prompt')
95 # Run a shell command.
96 self.SendKeysToHterm(r'shell\n')
97 self.WaitForHtermText(text='chronos@localhost',
98 msg='Could not find "chronos@localhost" in shell output.')
100 def testConnectToAnotherhost(self):
101 """Test ssh to another host."""
102 test_utils.OpenCroshVerification(self)
104 # Verify crosh prompt.
105 self.WaitForHtermText(text='crosh> ',
106 msg='Could not find "crosh> " prompt')
108 self.GetHtermRowsText(start=0, end=2).endswith('crosh> '),
109 msg='Could not find "crosh> " prompt')
111 # Ssh to another host: chronos@localhost.
112 self.SendKeysToHterm(r'ssh chronos@localhost\n')
113 self.WaitForHtermText(text='Password',
114 msg='Could not find "Password" in shell output.')
115 self.SendKeysToHterm(r'test0000\n')
116 self.WaitForHtermText(text='chronos@localhost',
117 msg='Could not find "chronos@localhost" in shell output.')
119 def testTabSwitching(self):
120 """Test tab can be switched in crosh."""
121 test_utils.OpenCroshVerification(self)
125 self.AppendTab(self.GetHttpURLForDataPath('title2.html'))
126 self.assertEqual('Title Of Awesomeness', self.GetActiveTabTitle(),
127 msg='Unable to navigate to title2.html and '
130 self.assertEqual(7, len(self.GetBrowserInfo()['windows'][0]['tabs']))
133 self.ApplyAccelerator(pyauto.IDC_SELECT_TAB_4)
134 self.assertEqual('crosh', self.GetActiveTabTitle(),
135 msg='Unable to naviage to crosh.')
137 # Run a crosh command.
138 self.SendKeysToHterm('help\\n', tab_index=4, windex=0)
139 self.WaitForHtermText(text='help_advanced', tab_index=4, windex=0,
140 msg='Could not find "help_advanced" in help output.')
142 def testLargefileCrosh(self):
143 """Test large file is displayed in crosh."""
144 test_utils.OpenCroshVerification(self)
146 # Verify crosh prompt.
147 self.WaitForHtermText(text='crosh> ',
148 msg='Could not find "crosh> " prompt')
150 self.GetHtermRowsText(start=0, end=2).endswith('crosh> '),
151 msg='Could not find "crosh> " prompt')
153 # Login to localhost.
154 self.SendKeysToHterm(r'ssh chronos@localhost\n')
155 self.WaitForHtermText(text='Password',
156 msg='Could not find "Password" in shell output.')
157 self.SendKeysToHterm(r'test0000\n')
158 self.WaitForHtermText(text='chronos@localhost',
159 msg='Could not find "chronos@localhost" in shell output.')
161 # Create a file with 140 characters per line, 50000 lines.
162 bigfn = '/tmp/bigfile.txt'
163 with open(bigfn, 'w') as file:
164 file.write(('0' * 140 + '\n') * 50000 + 'complete\n')
167 self.SendKeysToHterm(r'cat %s\n' % bigfn)
168 self.WaitForHtermText(text='complete',
169 msg='Could not find "complete" in shell output.')
173 if __name__ == '__main__':
174 pyauto_functional.Main()