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