blob: 3090c15b414b8c1ea3069fc86810bb4b238d03b8 [file] [log] [blame]
# Copyright 2012 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.
"""Test display functionailty.
This test check basic display functionality by showing colors or images on
display, and ask operator to judge if the output looks correct.
The test can also be used to show an image for ``idle_timeout`` seconds, and
automatically pass itself after timeout is reached.
Test Procedure
If ``idle_timeout`` is set:
1. An image is shown on the display.
2. If the image looks incorrect, operator can press escape key or touch the
display to fail the test.
3. The test pass itself after ``idle_timeout`` seconds.
If ``idle_timeout`` is not set:
1. A table of images to be tested is shown.
2. Operator press space key to show the image.
3. For each image, if it looks correct, operator press enter key to mark the
item as passed, otherwise, operator press escape key to mark the item as
failed. Operator can also press space key or touch the display to return
to the table view.
4. The next image would be shown after the previous one is judged.
5. The test is passed if all items are judged as passed, and fail if any item
is judged as failed.
If ``items`` contains item with prefix ``image-``, external program ``bz2`` to
extract the compressed images.
To test display functionality, add this into test list::
"pytest_name": "display"
To test display functionality, show gray image, idle for an hour and pass, add
this into test list::
"pytest_name": "display",
"args": {
"items": ["solid-gray-127"],
"idle_timeout": 3600
To test display functionality, and show some more images, add this into test
"pytest_name": "display",
"args": {
"items": [
import os
import factory_common # pylint: disable=unused-import
from cros.factory.test.i18n import _
from cros.factory.test.i18n import translation
from cros.factory.test import test_case
from cros.factory.test import test_ui
from cros.factory.utils.arg_utils import Arg
from cros.factory.utils import file_utils
# The _() is necessary for pygettext to get translatable strings correctly.
_ALL_ITEMS = [x[translation.DEFAULT_LOCALE] for x in _ALL_ITEMS]
_IMAGE_PREFIX = 'image-'
class DisplayTest(test_case.TestCase):
"""Tests the function of display.
ui: test ui.
checked: user has check the display of current subtest.
fullscreen: the test ui is in fullscreen or not.
static_dir: string of static file directory.
ARGS = [
Arg('items', list,
'Set items to be shown on screen. Available items are:\n%s\n' %
'\n'.join(' * ``"%s"``' % x for x in _ALL_ITEMS),
default=['solid-gray-170', 'solid-gray-127', 'solid-gray-63',
'solid-red', 'solid-green', 'solid-blue']),
'If given, the test would be start automatically, run for '
'idle_timeout seconds, and pass itself. '
'Note that items should contain exactly one item in this mode.',
def setUp(self):
"""Initializes frontend presentation and properties."""
self.static_dir = self.ui.GetStaticDirectoryPath()
self.idle_timeout = self.args.idle_timeout
if self.idle_timeout is not None and len(self.args.items) != 1:
raise ValueError('items should have exactly one item in idle mode.')
unknown_items = set(self.args.items) - set(_ALL_ITEMS)
if unknown_items:
raise ValueError('Unknown item %r in items.' % list(unknown_items))
self.items = self.args.items
self.images = [
'%s.bmp' % item[len(_IMAGE_PREFIX):] for item in self.items
if item.startswith(_IMAGE_PREFIX)
if self.images:
self.frontend_proxy = self.ui.InitJSTestObject('DisplayTest', self.items)
self.checked = False
self.fullscreen = False
def tearDown(self):
def runTest(self):
"""Sets the callback function of keys."""
if self.idle_timeout is None:
self.ui.BindKey(test_ui.SPACE_KEY, self.OnSpacePressed)
self.ui.BindKey(test_ui.ENTER_KEY, self.OnEnterPressed)
# Automatically enter fullscreen mode in idle mode.
self.event_loop.AddEventHandler('onFullscreenClicked', self.OnFailPressed)
self.ui.StartCountdownTimer(self.idle_timeout, self.PassTask)
self.ui.BindKey(test_ui.ESCAPE_KEY, self.OnFailPressed)
def ExtractTestImages(self):
"""Extracts selected test images from test_images.tar.bz2."""
file_utils.ExtractFile(os.path.join(self.static_dir, 'test_images.tar.bz2'),
self.static_dir, only_extracts=self.images)
def RemoveTestImages(self):
"""Removes extracted image files after test finished."""
for image in self.images:
file_utils.TryUnlink(os.path.join(self.static_dir, image))
def OnSpacePressed(self, event):
"""Sets self.checked to True. Calls JS function to switch display on/off."""
del event # Unused.
def ToggleFullscreen(self):
self.checked = True
self.fullscreen = not self.fullscreen
def OnEnterPressed(self, event):
"""Passes the subtest only if self.checked is True."""
del event # Unused.
if self.checked:
# If the next subtest will be in fullscreen mode, checked should be True
self.checked = self.fullscreen
def OnFailPressed(self, event):
"""Fails the subtest only if self.checked is True."""
del event # Unused.
if self.checked:
# If the next subtest will be in fullscreen mode, checked should be True
self.checked = self.fullscreen