• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# Copyright 2018 The Chromium OS 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.
5import logging
6import os
7import shutil
8import time
9
10from autotest_lib.client.common_lib import error
11from autotest_lib.client.common_lib.cros import chrome
12from autotest_lib.client.cros.input_playback import keyboard
13from autotest_lib.client.cros.power import power_test
14
15class power_Display(power_test.power_Test):
16    """class for power_Display test.
17    """
18    version = 1
19    tmp_path = '/tmp'
20
21    # TODO(tbroch) find more patterns that typical display vendors use to show
22    # average and worstcase display power.
23    PAGES = ['checker1', 'black', 'white', 'red', 'green', 'blue']
24    def run_once(self, pages=None, secs_per_page=60, brightness=''):
25        """run_once method.
26
27        @param pages: list of pages names that must be in
28            <testdir>/html/<name>.html
29        @param secs_per_page: time in seconds to display page and measure power.
30        @param brightness: flag for brightness setting to use for testing.
31                           possible value are 'max' (100%) and 'all' (all manual
32                           brightness steps in ChromeOS)
33        """
34        if pages is None:
35            pages = self.PAGES
36
37        # https://crbug.com/1288417
38        # Copy file to tmpdir to avoid the need of setting up local http server.
39        file_path = os.path.join(self.bindir, 'html')
40        dest_path = os.path.join(self.tmp_path, 'html')
41        shutil.copytree(file_path, dest_path)
42        http_path = 'file://' + dest_path
43
44        # --disable-sync disables test account info sync, eg. Wi-Fi credentials,
45        # so that each test run does not remember info from last test run.
46        extra_browser_args = ['--disable-sync']
47        # b/228256145 to avoid powerd restart
48        extra_browser_args.append('--disable-features=FirmwareUpdaterApp')
49        with chrome.Chrome(init_network_controller=True,
50                           extra_browser_args=extra_browser_args) as self.cr:
51            tab = self.cr.browser.tabs[0]
52            tab.Activate()
53
54            # Just measure power in full-screen.
55            fullscreen = tab.EvaluateJavaScript('document.webkitIsFullScreen')
56            if not fullscreen:
57                with keyboard.Keyboard() as keys:
58                    keys.press_key('f4')
59
60            # Stop services again as Chrome might have restarted them.
61            self._services.stop_services()
62
63            if brightness not in ['', 'all', 'max']:
64                raise error.TestFail(
65                        'Invalid brightness flag: %s' % (brightness))
66
67            if brightness == 'max':
68                self.backlight.set_percent(100)
69
70            brightnesses = []
71            if brightness == 'all':
72                self.backlight.set_percent(100)
73                for step in range(16, 0, -1):
74                    nonlinear = step * 6.25
75                    linear = self.backlight.nonlinear_to_linear(nonlinear)
76                    brightnesses.append((nonlinear, linear))
77            else:
78                linear = self.backlight.get_percent()
79                nonlinear = self.backlight.linear_to_nonlinear(linear)
80                brightnesses.append((nonlinear, linear))
81
82            self.start_measurements()
83
84            loop = 0
85            for name in pages:
86                url = os.path.join(http_path, name + '.html')
87                logging.info('Navigating to url: %s', url)
88                tab.Navigate(url)
89                tab.WaitForDocumentReadyStateToBeComplete()
90
91                for nonlinear, linear in brightnesses:
92                    self.backlight.set_percent(linear)
93                    tagname = '%s_%s' % (self.tagged_testname, name)
94                    if len(brightnesses) > 1:
95                        tagname += '_%.2f' % (nonlinear)
96                    loop_start = time.time()
97                    self.loop_sleep(loop, secs_per_page)
98                    self.checkpoint_measurements(tagname, loop_start)
99                    loop += 1
100
101        shutil.rmtree(dest_path)
102