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 sys
      8 
      9 import pyauto_functional  # Must be imported before pyauto
     10 import pyauto
     11 
     12 sys.path.append('/usr/local')  # To make autotest libs importable.
     13 from autotest.cros import cros_ui
     14 from autotest.cros import ownership
     15 
     16 
     17 class ChromeosTime(pyauto.PyUITest):
     18   """Tests for the ChromeOS status area clock and timezone settings."""
     19 
     20   def setUp(self):
     21     cros_ui.fake_ownership()
     22     pyauto.PyUITest.setUp(self)
     23     self._initial_timezone = self.GetTimeInfo()['timezone']
     24 
     25   def tearDown(self):
     26     self.SetTimezone(self._initial_timezone)
     27     pyauto.PyUITest.tearDown(self)
     28     ownership.clear_ownership()
     29 
     30   def testTimeInfo(self):
     31     """Print the the display time, date, and timezone."""
     32     logging.debug(self.GetTimeInfo())
     33 
     34   def testSetTimezone(self):
     35     """Sanity test to make sure setting the timezone works."""
     36     self.SetTimezone('America/Los_Angeles')
     37     pacific_time = self.GetTimeInfo()['display_time']
     38     self.SetTimezone('America/New_York')
     39     eastern_time = self.GetTimeInfo()['display_time']
     40 
     41     self.assertNotEqual(pacific_time, eastern_time,
     42                         'Time zone changed but display time did not.')
     43 
     44   def _IsTimezoneEditable(self):
     45     """Check if the timezone is editable.
     46 
     47     It will navigate to the system settings page and verify that the
     48     timezone settings drop down is not disabled.
     49 
     50     Returns:
     51       True, if timezone dropdown is enabled
     52       False, otherwise
     53     """
     54     self.NavigateToURL('chrome://settings-frame')
     55     ret = self.ExecuteJavascript("""
     56         var disabled = true;
     57         var timezone = document.getElementById('timezone-select');
     58         if (timezone)
     59           disabled = timezone.disabled;
     60         domAutomationController.send(disabled.toString());
     61     """)
     62     return ret == 'false'
     63 
     64   def testTimezoneIsEditable(self):
     65     """Test that the timezone is always editable."""
     66     # This test only makes sense if we are not running as the owner.
     67     self.assertFalse(self.GetLoginInfo()['is_owner'])
     68     editable = self._IsTimezoneEditable()
     69     self.assertTrue(editable, msg='Timezone is not editable when not owner.')
     70 
     71   def _SetTimezoneInUI(self, timezone):
     72     self.NavigateToURL('chrome://settings-frame/settings')
     73     self.ExecuteJavascript("""
     74         var selectElement = document.getElementById('timezone-select');
     75         selectElement.value = "%s";
     76         var event = document.createEvent("HTMLEvents");
     77         event.initEvent("change", true, true);
     78         selectElement.dispatchEvent(event);
     79         domAutomationController.send("");
     80     """ % timezone)
     81 
     82   def testSetTimezoneUI(self):
     83     """Test that the timezone UI changes internal settings.
     84 
     85     Set the Timezone on the settings page. Check the internal timezone
     86     afterwards. Timezones should be always editable."""
     87 
     88     for timezone in ['America/Barbados', 'Europe/Helsinki']:
     89       self._SetTimezoneInUI(timezone)
     90       self.assertTrue(self.WaitUntil(lambda: self.GetTimeInfo()['timezone'],
     91                                      expect_retval=timezone),
     92                       'Timezone not changed as expected.');
     93 
     94 if __name__ == '__main__':
     95   pyauto_functional.Main()
     96