#!/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 logging

import pyauto_functional  # Must be imported before pyauto
import pyauto

class ChromeosTime(pyauto.PyUITest):
  """Tests for the ChromeOS status area clock and timezone settings."""

  def setUp(self):
    pyauto.PyUITest.setUp(self)
    self._initial_timezone = self.GetTimeInfo()['timezone']

  def tearDown(self):
    self.SetTimezone(self._initial_timezone)
    pyauto.PyUITest.tearDown(self)

  def testTimeInfo(self):
    """Print the the display time, date, and timezone."""
    logging.debug(self.GetTimeInfo())

  def testSetTimezone(self):
    """Sanity test to make sure setting the timezone works."""
    self.SetTimezone('America/Los_Angeles')
    pacific_time = self.GetTimeInfo()['display_time']
    self.SetTimezone('America/New_York')
    eastern_time = self.GetTimeInfo()['display_time']

    self.assertNotEqual(pacific_time, eastern_time,
                        'Time zone changed but display time did not.')

  def _IsTimezoneEditable(self):
    """Check if the timezone is editable.

    It will navigate to the system settings page and verify that the
    timezone settings drop down is not disabled.

    Returns:
      True, if timezone dropdown is enabled
      False, otherwise
    """
    self.NavigateToURL('chrome://settings/system')
    ret = self.ExecuteJavascript("""
        var enabled = false;
        var timezone = document.getElementById('timezone-select');
        if (timezone)
          enabled = banner.enabled;
        domAutomationController.send(enabled.toString());
    """)
    return ret == 'true'

  def testTimezoneIsEditable(self):
    """Test that the timezone is always editable."""
    # This test only makes sense if we are not running as the owner.
    self.assertFalse(self.GetLoginInfo()['is_owner'])
    enabled = _IsTimezoneEditable()
    self.assertTrue(enabled, msg='Timezone is not editable when not owner.')


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

#!/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 logging

import pyauto_functional  # Must be imported before pyauto
import pyauto

class ChromeosTime(pyauto.PyUITest):
  """Tests for the ChromeOS status area clock and timezone settings."""

  def setUp(self):
    pyauto.PyUITest.setUp(self)
    self._initial_timezone = self.GetTimeInfo()['timezone']

  def tearDown(self):
    self.SetTimezone(self._initial_timezone)
    pyauto.PyUITest.tearDown(self)

  def testTimeInfo(self):
    """Print the the display time, date, and timezone."""
    logging.debug(self.GetTimeInfo())

  def testSetTimezone(self):
    """Sanity test to make sure setting the timezone works."""
    self.SetTimezone('America/Los_Angeles')
    pacific_time = self.GetTimeInfo()['display_time']
    self.SetTimezone('America/New_York')
    eastern_time = self.GetTimeInfo()['display_time']

    self.assertNotEqual(pacific_time, eastern_time,
                        'Time zone changed but display time did not.')

  def _IsTimezoneEditable(self):
    """Check if the timezone is editable.

    It will navigate to the system settings page and verify that the
    timezone settings drop down is not disabled.

    Returns:
      True, if timezone dropdown is enabled
      False, otherwise
    """
    self.NavigateToURL('chrome://settings/system')
    ret = self.ExecuteJavascript("""
        var disabled = true;
        var timezone = document.getElementById('timezone-select');
        if (timezone)
          disabled = timezone.disabled;
        domAutomationController.send(disabled.toString());
    """)
    return ret == 'false'

  def testTimezoneIsEditable(self):
    """Test that the timezone is always editable."""
    # This test only makes sense if we are not running as the owner.
    self.assertFalse(self.GetLoginInfo()['is_owner'])
    editable = self._IsTimezoneEditable()
    self.assertTrue(editable, msg='Timezone is not editable when not owner.')


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

Fix testTimezoneIsEditable