• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# Copyright (c) 2013 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.
5
6import os
7import shutil
8import time
9
10from autotest_lib.client.bin import test, utils
11from autotest_lib.client.common_lib import error
12from autotest_lib.client.common_lib.cros import chrome
13from autotest_lib.client.cros import upstart
14from autotest_lib.client.cros.power import power_utils
15
16class power_VideoDetector(test.test):
17    """
18    Verify the backlight does not get dimmed while playing video.
19    """
20
21    version = 1
22    tmp_path = '/tmp'
23
24    def run_once(self, run_time_sec=60):
25        """
26        @param run_time_sec: time to run the test
27        """
28        if run_time_sec < 30:
29            raise error.TestError('Must run for at least 30 seconds')
30
31
32        # https://crbug.com/1288417, b/215442780
33        # Copy file to tmpdir to avoid the need of setting up local http server.
34        file_path = os.path.join(self.bindir, 'fade.html')
35        self.dest_path = os.path.join(self.tmp_path, 'fade.html')
36        shutil.copy(file_path, self.dest_path)
37        http_path = 'file://' + self.dest_path
38
39        with chrome.Chrome(init_network_controller=True) as cr:
40            # Start powerd if not started.  Set timeouts for quick idle events.
41            run_time_ms = run_time_sec * 1000
42            # At the time of writing this test, the video detector gets a status
43            # update from Chrome every ten seconds.
44            dim_ms = 10000
45            off_ms = max(3600000, run_time_ms * 10)
46            prefs = { 'has_ambient_light_sensor' : 0,
47                      'ignore_external_policy'   : 1,
48                      'plugged_dim_ms'           : dim_ms,
49                      'plugged_off_ms'           : off_ms,
50                      'unplugged_dim_ms'         : dim_ms,
51                      'unplugged_off_ms'         : off_ms, }
52            self._pref_change = power_utils.PowerPrefChanger(prefs)
53
54            keyvals = {}
55
56            # Start with max brightness, so we can easily detect dimming.
57            power_utils.BacklightController().set_brightness_to_max()
58            backlight = power_utils.Backlight()
59            initial_brightness = \
60                utils.wait_for_value(backlight.get_max_level)
61
62            # Open a tab to play video.
63            tab = cr.browser.tabs[0]
64            tab.Navigate(http_path)
65            tab.WaitForDocumentReadyStateToBeComplete()
66
67
68            # Sleep until the runtime is up.
69            time.sleep(run_time_sec)
70
71            # Stop powerd to avoid dimming when the video stops.
72            utils.system_output('stop powerd')
73
74            final_brightness = backlight.get_level()
75
76            # Check that the backlight stayed the same.
77            if initial_brightness != final_brightness:
78                raise error.TestFail(
79                    ('Backlight level changed from %d to %d when it should ' + \
80                     'have stayed the same.') %
81                    (initial_brightness, final_brightness))
82
83            keyvals['initial_brightness'] = initial_brightness
84            keyvals['final_brightness'] = final_brightness
85            self.write_perf_keyval(keyvals)
86
87
88    def cleanup(self):
89        """
90        Cleanup powerd after test.
91        """
92        if hasattr(self, 'dest_path'):
93            os.remove(self.dest_path)
94        upstart.restart_job('powerd')
95