| # Copyright 2013 The ChromiumOS Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| """A factory test to test the function of display panel using some points. |
| |
| Description |
| ----------- |
| Show some points on the display. The test is designed to catch display with |
| dark dots. |
| |
| Test Procedure |
| -------------- |
| 1. Display white/black screen with a random number of black/white dots at random |
| generated positions. |
| 2. Operator reports the number of dots. |
| 3. Fails if the numbers don't match. |
| 4. Display the other color in step 1 and generate the dots again. |
| 5. Operator reports the number of dots. |
| 6. Fails if the numbers don't match. |
| |
| Dependency |
| ---------- |
| - A browser to run display_point.js. |
| |
| Examples |
| -------- |
| Sample test_list entry: |
| |
| .. test_list:: |
| |
| generic_display_panel_examples:DisplayPoint |
| |
| """ |
| |
| import collections |
| import logging |
| import random |
| |
| from cros.factory.test import test_case |
| from cros.factory.test import test_ui |
| from cros.factory.utils.arg_utils import Arg |
| |
| |
| # yapf: disable |
| _TestItem = collections.namedtuple('TestItem', 'num_point bg_color point_color') # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| |
| |
| class DisplayPointTest(test_case.TestCase): |
| """Tests the function of display panel using some points. |
| |
| There are two subtests in this test. The first one is black points on white |
| background. The second one is white points on black background. |
| There will be random number of points(1 to 3) in random places in |
| each subtest. |
| |
| Attributes: |
| list_number_point: a list of the number of points in each subtest. |
| """ |
| related_components = (test_case.TestCategory.LCD, ) |
| ARGS = [ |
| Arg('point_size', (float, int), 'width and height of testing point in px', |
| default=3.0), |
| Arg('max_point_count', int, 'maximum number of points in each subtest', |
| default=3) |
| ] |
| |
| def setUp(self): |
| """Initializes frontend presentation and properties.""" |
| # yapf: disable |
| if self.args.max_point_count >= 10: # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| raise ValueError('>= 10 points is not supported') |
| |
| self.items = [ |
| _TestItem( |
| # yapf: disable |
| random.randint(1, self.args.max_point_count), # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| 'white', |
| 'black'), # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| _TestItem( |
| # yapf: disable |
| random.randint(1, self.args.max_point_count), # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| 'black', |
| 'white') # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| ] |
| logging.info('testing point: %s', |
| ', '.join(str(item.num_point) for item in self.items)) |
| # yapf: disable |
| self._frontend_proxy = self.ui.InitJSTestObject( # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| # yapf: disable |
| 'DisplayPointTest', self.args.point_size) # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| # yapf: disable |
| self.event_loop.AddEventHandler( # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| 'toggle-display', lambda unused_event: self.ToggleDisplay()) |
| self.display = False |
| self.checked = False |
| |
| def runTest(self): |
| """Sets the callback function of keys and run the test.""" |
| all_keys = [test_ui.SPACE_KEY, test_ui.ESCAPE_KEY] |
| # yapf: disable |
| all_keys.extend(str(k) for k in range(1, self.args.max_point_count + 1)) # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| for idx, item in enumerate(self.items): |
| self._frontend_proxy.SetupPoints(item.num_point, item.bg_color, |
| item.point_color) |
| if idx > 0 and not self.display: |
| self.ToggleDisplay() |
| |
| while True: |
| # yapf: disable |
| key = self.ui.WaitKeysOnce(all_keys) # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| if key == test_ui.SPACE_KEY: |
| self.ToggleDisplay() |
| elif key == test_ui.ESCAPE_KEY: |
| self.FailTask( |
| f'DisplayPoint test failed at item {int(idx)}: Mark failed by ' |
| f'operator.') |
| else: |
| if not self.checked: |
| continue |
| input_num = int(key) |
| if input_num == item.num_point: |
| break |
| self.FailTask( |
| f'DisplayPoint test failed at item {int(idx)}: Correct number: ' |
| f'{int(item.num_point)}, Input number: {int(input_num)}') |
| |
| def ToggleDisplay(self): |
| if self.display: |
| self._frontend_proxy.SwitchDisplayOff() |
| else: |
| self._frontend_proxy.SwitchDisplayOn() |
| self.checked = True |
| self.display = not self.display |