Home | History | Annotate | Download | only in power_VideoDetector
      1 # Copyright (c) 2013 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 
      5 import os
      6 import time
      7 
      8 from autotest_lib.client.bin import test, utils
      9 from autotest_lib.client.common_lib import base_utils, error
     10 from autotest_lib.client.common_lib.cros import chrome
     11 from autotest_lib.client.cros import power_utils
     12 
     13 class power_VideoDetector(test.test):
     14     version = 1
     15 
     16     def run_once(self, run_time_sec=60):
     17         if run_time_sec < 30:
     18             raise error.TestError('Must run for at least 30 seconds')
     19 
     20         with chrome.Chrome() as cr:
     21             # Start powerd if not started.  Set timeouts for quick idle events.
     22             run_time_ms = run_time_sec * 1000
     23             # At the time of writing this test, the video detector gets a status
     24             # update from Chrome every ten seconds.
     25             dim_ms = 10000
     26             off_ms = max(3600000, run_time_ms * 10)
     27             prefs = { 'has_ambient_light_sensor' : 0,
     28                       'ignore_external_policy'   : 1,
     29                       'plugged_dim_ms'           : dim_ms,
     30                       'plugged_off_ms'           : off_ms,
     31                       'unplugged_dim_ms'         : dim_ms,
     32                       'unplugged_off_ms'         : off_ms, }
     33             self._pref_change = power_utils.PowerPrefChanger(prefs)
     34 
     35             keyvals = {}
     36 
     37             # Start with max brightness, so we can easily detect dimming.
     38             power_utils.BacklightController().set_brightness_to_max()
     39             backlight = power_utils.Backlight()
     40             initial_brightness = \
     41                 base_utils.wait_for_value(backlight.get_max_level)
     42 
     43             # Open a tab to play video.
     44             cr.browser.platform.SetHTTPServerDirectories(self.bindir)
     45             tab = cr.browser.tabs[0]
     46             tab.Navigate(cr.browser.platform.http_server.UrlOf(
     47                 os.path.join(self.bindir, 'fade.html')))
     48             tab.WaitForDocumentReadyStateToBeComplete()
     49 
     50             # Sleep until the runtime is up.
     51             time.sleep(run_time_sec)
     52 
     53             # Stop powerd to avoid dimming when the video stops.
     54             utils.system_output('stop powerd')
     55 
     56             final_brightness = backlight.get_level()
     57 
     58             # Check that the backlight stayed the same.
     59             if initial_brightness != final_brightness:
     60                 raise error.TestFail(
     61                     ('Backlight level changed from %d to %d when it should ' + \
     62                      'have stayed the same.') %
     63                     (initial_brightness, final_brightness))
     64 
     65             keyvals['initial_brightness'] = initial_brightness
     66             keyvals['final_brightness'] = final_brightness
     67             self.write_perf_keyval(keyvals)
     68 
     69 
     70     def cleanup(self):
     71         utils.restart_job('powerd')
     72