• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5from autotest_lib.client.bin import test
6from autotest_lib.client.bin import utils
7from autotest_lib.client.common_lib import error
8from autotest_lib.client.common_lib.cros import chrome
9from autotest_lib.client.cros.graphics import graphics_utils
10from autotest_lib.client.cros.input_playback import input_playback
11
12
13class platform_InputBrightness(test.test):
14    """Tests if device suspends using shortcut keys."""
15    version = 1
16    BRIGHTNESS_CMD = "backlight_tool --get_brightness_percent"
17    RESET_BRIGHTNESS_CMD = "backlight_tool --set_brightness_percent=70.0"
18
19    def warmup(self):
20        """Test setup."""
21        # Emulate keyboard.
22        # See input_playback. The keyboard is used to play back shortcuts.
23        self._player = input_playback.InputPlayback()
24        self._player.emulate(input_type='keyboard')
25        self._player.find_connected_inputs()
26
27    def test_brightness_down(self):
28        """
29        Use keyboard shortcut to test brightness Down (F6) key.
30
31        @raises: error.TestFail if system brightness did not decrease.
32
33        """
34        sys_brightness = self.get_system_brightness()
35        if not sys_brightness:
36            utils.system_output(self.RESET_BRIGHTNESS_CMD)
37            sys_brightness = self.get_system_brightness()
38        self._player.blocking_playback_of_default_file(
39            input_type='keyboard', filename='keyboard_f6')
40        if not sys_brightness > self.get_system_brightness():
41            raise error.TestFail("Brightness did not decrease from: %s" % sys_brightness)
42
43    def test_brightness_up(self):
44        """
45        Use keyboard shortcut to test brightness Up (F7) key.
46
47        @raises: error.TestFail if system brightness did not increase.
48
49        """
50        sys_brightness = self.get_system_brightness()
51        if sys_brightness == 100:
52            utils.system_output(self.RESET_BRIGHTNESS_CMD)
53            sys_brightness = self.get_system_brightness()
54        self._player.blocking_playback_of_default_file(
55            input_type='keyboard', filename='keyboard_f7')
56        if not sys_brightness < self.get_system_brightness():
57            raise error.TestFail("Brightness did not increase from: %s" % sys_brightness)
58
59
60    def get_system_brightness(self):
61        """
62        Get current system brightness percent (0.0-100.0).
63
64        @returns: current system brightness.
65        """
66        sys_brightness = utils.system_output(self.BRIGHTNESS_CMD)
67        return float(sys_brightness)
68
69
70    def run_once(self):
71        """
72        Open browser, and affect brightness using  up and down functions.
73
74        @raises: error.TestFail if brightness keys (F6/F7) did not work.
75
76        """
77        # Check for internal_display
78        if not graphics_utils.has_internal_display():
79            raise error.TestNAError('Test can not proceed on '
80                                    'devices without internal display.')
81        with chrome.Chrome():
82            self.test_brightness_up()
83            self.test_brightness_down()
84
85
86    def cleanup(self):
87        """Test cleanup."""
88        self._player.close()
89        utils.system_output(self.RESET_BRIGHTNESS_CMD)
90