blob: 443b93caa0a2c07fd68f3213ca400faabd5fa0db [file] [log] [blame]
# Copyright 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Verifies physical developer switch can be toggled and end in right state."""
import unittest
import factory_common # pylint: disable=unused-import
from cros.factory.test.i18n import test_ui as i18n_test_ui
from cros.factory.test import test_ui
from cros.factory.test import ui_templates
from cros.factory.utils.arg_utils import Arg
from cros.factory.utils import process_utils
from cros.factory.utils import sync_utils
_MSG_TURN_ON = i18n_test_ui.MakeI18nLabel(
'Please turn <b class="on">ON</b> Developer Switch.')
_MSG_TURN_OFF = i18n_test_ui.MakeI18nLabel(
'Please turn <b class="off">OFF</b> Developer Switch.')
_MSG_SW_ON = i18n_test_ui.MakeI18nLabel(
'Develop switch is currently <b class="on">ON</b>.')
_MSG_SW_OFF = i18n_test_ui.MakeI18nLabel(
'Develop switch is currently <b class="off">OFF</b>.')
_TEST_PAGE_CSS = """
.on {
color: green;
}
.off {
color: red;
}
"""
class DeveloperSwitchTest(unittest.TestCase):
ARGS = [
Arg('end_state', bool,
'The state when leaving test. True as enabled and False as disabled.',
default=True),
Arg('timeout_secs', int, 'Time out value in seconds.',
default=(60 * 60))
]
def setUp(self):
self._ui = test_ui.UI()
self._template = ui_templates.TwoSections(self._ui)
self._ui.AppendCSS(_TEST_PAGE_CSS)
def runTest(self):
self._ui.RunInBackground(self._runTest)
self._ui.Run()
def _runTest(self):
def GetState():
# This will be called so many times so we don't want to be logged.
return int(process_utils.SpawnOutput(
['crossystem', 'devsw_cur'], log=False, check_output=True))
def UpdateUI(state):
if state:
self._template.SetState(_MSG_TURN_OFF)
self._template.SetInstruction(_MSG_SW_ON)
else:
self._template.SetState(_MSG_TURN_ON)
self._template.SetInstruction(_MSG_SW_OFF)
initial_state = GetState()
timeout_secs = self.args.timeout_secs
UpdateUI(initial_state)
sync_utils.WaitFor(lambda: GetState() != initial_state, timeout_secs)
UpdateUI(not initial_state)
sync_utils.WaitFor(lambda: GetState() == initial_state, timeout_secs)
UpdateUI(initial_state)
# Flip again if state is not end_state
sync_utils.WaitFor(lambda: GetState() != int(self.args.end_state),
timeout_secs)