def testGuestCrosh(self): """Verify we can use crosh in guest mode.""" self.LoginAsGuest() login_info = self.GetLoginInfo() self.assertTrue(login_info['is_logged_in'], msg='Not logged in at all.') self.assertTrue(login_info['is_guest'], msg='Not logged in as guest.') for _ in range(self.GetBrowserWindowCount()): self.CloseBrowserWindow(0) 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 testCroshPreservedBetweenLogins(self): """Verify user can continue after re-login.""" self.testGoodLogin() self.CloseBrowserWindow(0) 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') # Open 2 other tabs. self.AppendTab(self.GetHttpURLForDataPath('title2.html')) self.assertEqual('Title Of Awesomeness', self.GetActiveTabTitle(), msg='Unable to naviage to title2.html and ' 'verify tab title.') self.AppendTab( self.GetHttpURLForDataPath('settings', 'image_page.html')) self.assertEqual('Show an image', self.GetActiveTabTitle(), msg='Unable to navigate to image_page and ' 'verify tab title.') self.Logout() self.testGoodLogin() # Re-Login with same account. # Verify 3 tabs are still open after re-login. self.assertEqual(3, len(self.GetBrowserInfo()['windows'][0]['tabs']))
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 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)
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 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 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 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 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.')