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.
9 import pyauto_functional
# Must be imported before pyauto
12 sys
.path
.append('/usr/local') # To make autotest libs importable.
13 from autotest
.cros
import cros_ui
14 from autotest
.cros
import ownership
17 class ChromeosTime(pyauto
.PyUITest
):
18 """Tests for the ChromeOS status area clock and timezone settings."""
21 cros_ui
.fake_ownership()
22 pyauto
.PyUITest
.setUp(self
)
23 self
._initial
_timezone
= self
.GetTimeInfo()['timezone']
26 self
.SetTimezone(self
._initial
_timezone
)
27 pyauto
.PyUITest
.tearDown(self
)
28 ownership
.clear_ownership()
30 def testTimeInfo(self
):
31 """Print the the display time, date, and timezone."""
32 logging
.debug(self
.GetTimeInfo())
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']
41 self
.assertNotEqual(pacific_time
, eastern_time
,
42 'Time zone changed but display time did not.')
44 def _IsTimezoneEditable(self
):
45 """Check if the timezone is editable.
47 It will navigate to the system settings page and verify that the
48 timezone settings drop down is not disabled.
51 True, if timezone dropdown is enabled
54 self
.NavigateToURL('chrome://settings-frame')
55 ret
= self
.ExecuteJavascript("""
57 var timezone = document.getElementById('timezone-select');
59 disabled = timezone.disabled;
60 domAutomationController.send(disabled.toString());
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.')
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("");
82 def testSetTimezoneUI(self
):
83 """Test that the timezone UI changes internal settings.
85 Set the Timezone on the settings page. Check the internal timezone
86 afterwards. Timezones should be always editable."""
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.');
94 if __name__
== '__main__':
95 pyauto_functional
.Main()