blob: 3b515786dc75e72c8d821f4a6189722021803edb [file] [log] [blame]
<!DOCTYPE html>
<meta charset="utf-8">
<title>Battery Test: charger unplugging</title>
<link rel="author" title="Intel" href="">
<link rel="help" href="">
<meta name="flags" content="interact">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
#note {
background-color: #fef1b5;
border: solid 1px #cdab2d;
padding: 5px;
margin: 15px;
display: block;
This test validates that all of the BatteryManager attributes exist and
are set to correct values, with corresponding events fired,
when the charger is unplugged.
The device is plugged in to the charger before this test is run.
<div id="note">
Unplug the charger and wait for all the tests to complete.
<div id="log"></div>
(function() {
setup({ explicit_timeout: true });
var onchargingchange_test = async_test(
'When the device is unplugged in and its charging state is updated, ' +
'must set the charging attribute\'s value to false and ' +
'fire a chargingchange event.');
var onchargingtimechange_test = async_test(
'When the device is unplugged in and its charging time is updated, ' +
'must set the chargingTime attribute\'s value to Infinity and ' +
'fire a chargingtimechange event.');
var ondischargingtimechange_test = async_test(
'When the device is unplugged in and its discharging time is updated, ' +
'must set the dischargingTime attribute\'s value and ' +
'fire a dischargingtimechange event.');
var onlevelchange_test = async_test(
'When the device is unplugged in and the battery level is updated, ' +
'must set the level attribute\'s value and fire a levelchange event.');
var batterySuccess = function (battery) {
battery.onchargingchange = onchargingchange_test.step_func(function () {
assert_false(battery.charging, 'The charging attribute must be set to false.');
battery.onchargingtimechange = onchargingtimechange_test.step_func(function () {
assert_equals(battery.chargingTime, Infinity,
'The value of the chargingTime attribute must be set to Infinity.');
battery.ondischargingtimechange = ondischargingtimechange_test.step_func(function () {
assert_less_than(battery.dischargingTime, Infinity,
'The value of the dischargingTime attribute must be set to the remaining discharging time.');
battery.onlevelchange = onlevelchange_test.step_func(function () {
assert_greater_than(battery.level, 0);
assert_less_than_equal(battery.level, 1.0);
var batteryFailure = function (error) {
onchargingchange_test.step(function () {
onchargingtimechange_test.step(function () {
ondischargingtimechange_test.step(function () {
onlevelchange_test.step(function () {
navigator.getBattery().then(batterySuccess, batteryFailure);