Home | History | Annotate | Download | only in functional
      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 logging
      7 import os
      8 import subprocess
      9 import sys
     10 import time
     11 
     12 import pyauto_functional
     13 import pyauto
     14 
     15 sys.path.append('/usr/local')  # To make autotest libs importable.
     16 from autotest.cros import cros_ui
     17 from autotest.cros import cryptohome
     18 
     19 
     20 class AccessibilityTest(pyauto.PyUITest):
     21   """Tests for Accessibility.
     22 
     23   Test various chromeos functionalities while Accessibility is turned on. 
     24   """
     25   find_test_data_dir = 'find_in_page'
     26 
     27   def ShouldAutoLogin(self):
     28     return False
     29 
     30   def setUp(self):
     31     # We want a clean session_manager instance for every run,
     32     # so restart ui now.
     33     cros_ui.stop(allow_fail=True)
     34     cryptohome.remove_all_vaults()
     35     cros_ui.start(wait_for_login_prompt=False)
     36     pyauto.PyUITest.setUp(self)
     37 
     38   def tearDown(self):
     39     self._DisableSpokenFeedback()
     40     pyauto.PyUITest.tearDown(self)
     41 
     42   def _Login(self):
     43     """Perform login."""
     44     credentials = self.GetPrivateInfo()['test_google_account']
     45     self.Login(credentials['username'], credentials['password'])
     46     logging.info('Logging in as %s' % credentials['username'])
     47     login_info = self.GetLoginInfo()
     48     self.assertTrue(login_info['is_logged_in'], msg='Login failed.')
     49 
     50   def _LoginWithSpokenFeedback(self):
     51     self.EnableSpokenFeedback(True)
     52     self._Login()
     53     self.assertTrue(self.IsSpokenFeedbackEnabled(),
     54                     msg='Could not enable spoken feedback accessibility mode.')
     55 
     56   def _EnableSpokenFeedback(self):
     57     self.EnableSpokenFeedback(True)
     58     self.assertTrue(self.IsSpokenFeedbackEnabled(),
     59                     msg='Could not enable spoken feedback accessibility mode.')
     60 
     61   def _DisableSpokenFeedback(self):
     62     self.EnableSpokenFeedback(False)
     63     self.assertFalse(self.IsSpokenFeedbackEnabled(),
     64                     msg='Could not disable spoken feedback accessibility mode.')
     65 
     66   def testCanEnableSpokenFeedback(self):
     67     """Tests that spoken feedback accessibility mode can be enabled."""
     68     self._EnableSpokenFeedback()
     69 
     70   def testLoginAsGuest(self):
     71     """Test that Guest user login is possible when Accessibility is on."""
     72     self._EnableSpokenFeedback()
     73     self.LoginAsGuest()
     74     login_info = self.GetLoginInfo()
     75     self.assertTrue(login_info['is_logged_in'], msg='Not logged in at all.')
     76     self.assertTrue(login_info['is_guest'], msg='Not logged in as guest.')
     77     url = self.GetFileURLForDataPath('title1.html')
     78     self.NavigateToURL(url)
     79     self.assertEqual(1, self.FindInPage('title')['match_count'],
     80         msg='Failed to load the page or find the page contents.')
     81     # crbug.com/129218: adding a volume change functionality to automate this
     82     # issue. Please note that we don't verify any functionality here.
     83     default_volume = self.GetVolumeInfo()
     84     for test_volume in (50.00, 77.00, 85.00, 20.00):
     85       self.SetVolume(test_volume)
     86       time.sleep(1)
     87     self.SetVolume(default_volume.get('volume'))
     88 
     89   def testAccessibilityBeforeLogin(self):
     90     """Test Accessibility before login."""
     91     self._LoginWithSpokenFeedback()
     92     self.Logout()
     93     self.assertFalse(self.GetLoginInfo()['is_logged_in'],
     94                      msg='Still logged in when we should be logged out.')
     95     self.assertTrue(self.IsSpokenFeedbackEnabled(),
     96         msg='Spoken feedback accessibility mode disabled after loggin out.')
     97 
     98   def testAccessibilityAfterLogin(self):
     99     """Test Accessibility after login."""
    100     self._Login()
    101     self._EnableSpokenFeedback()
    102 
    103   def testPagePerformance(self):
    104     """Test Chrome works fine when Accessibility is on."""
    105     self._LoginWithSpokenFeedback()
    106     # Verify that opened tab page behaves normally when Spoken Feedback is
    107     # enabled. crosbug.com/26731
    108     url = self.GetFileURLForDataPath(self.find_test_data_dir, 'largepage.html')
    109     self.NavigateToURL(url)
    110     self.assertEqual(373, self.FindInPage('daughter of Prince')['match_count'],
    111         msg='Failed to load the page or find the page contents.')
    112 
    113 
    114 if __name__ == '__main__':
    115   pyauto_functional.Main()
    116