3 <title>Battery Test: battery not full, charger plugging in
</title>
4 <link rel=
"author" title=
"Intel" href=
"http://www.intel.com">
5 <link rel=
"help" href=
"https://www.w3.org/TR/battery-status/">
6 <meta name=
"flags" content=
"interact">
7 <script src=
"/resources/testharness.js"></script>
8 <script src=
"/resources/testharnessreport.js"></script>
11 background-color: #fef1b5;
12 border: solid
1px #cdab2d;
21 This test validates that all of the BatteryManager attributes exist and
22 are set to correct values, with corresponding events fired,
23 when the charger is plugged in.
26 <h2>Preconditions
</h2>
29 The device is unplugged from the charger before this test is run.
32 The battery must not be full or reach full capacity before the time the test is run.
39 Plug in the charger and wait for all the tests to complete.
42 The tests may take long time since the definition of how
43 often the chargingtimechange, dischargingtimechange, and levelchange
44 events are fired is left to the implementation.
55 setup({ explicit_timeout
: true });
57 var onchargingchange_test
= async_test(
58 'When the device is plugged in and its charging state is updated, ' +
59 'must set the charging attribute\'s value to true and ' +
60 'fire a chargingchange event.');
61 var onchargingtimechange_test
= async_test(
62 'When the device is plugged in and its charging time is updated, ' +
63 'must set the chargingTime attribute\'s value and fire ' +
64 'a chargingtimechange event.');
65 var ondischargingtimechange_test
= async_test(
66 'When the device is plugged in and its discharging time is updated, ' +
67 'must set the dischargingTime attribute\'s value to Infinity and ' +
68 'fire a dischargingtimechange event.');
69 var onlevelchange_test
= async_test(
70 'When the device is plugged in and the battery level is updated, ' +
71 'must set the level attribute\'s value and fire a levelchange event.');
73 var batterySuccess = function (battery
) {
74 battery
.onchargingchange
= onchargingchange_test
.step_func(function () {
75 assert_true(battery
.charging
, 'The charging attribute must be set to true.');
76 onchargingchange_test
.done();
79 var battery_chargingtime
= battery
.chargingTime
;
80 battery
.onchargingtimechange
= onchargingtimechange_test
.step_func(function () {
81 assert_less_than(battery
.chargingTime
, battery_chargingtime
,
82 'The value of the chargingTime attribute must decrease.');
83 onchargingtimechange_test
.done();
86 battery
.ondischargingtimechange
= ondischargingtimechange_test
.step_func(function () {
87 if (battery
.charging
) {
88 assert_equals(battery
.dischargingTime
, Infinity
,
89 'The value of the dischargingTime attribute must be set to Infinity.');
90 ondischargingtimechange_test
.done();
94 battery
.onlevelchange
= onlevelchange_test
.step_func(function () {
95 assert_greater_than(battery
.level
, 0);
96 assert_less_than_equal(battery
.level
, 1.0);
97 onlevelchange_test
.done();
101 var batteryFailure = function (error
) {
102 onchargingchange_test
.step(function () {
103 assert_unreached(error
.message
);
105 onchargingchange_test
.done();
107 onchargingtimechange_test
.step(function () {
108 assert_unreached(error
.message
);
110 onchargingtimechange_test
.done();
112 ondischargingtimechange_test
.step(function () {
113 assert_unreached(error
.message
);
115 ondischargingtimechange_test
.done();
117 onlevelchange_test
.step(function () {
118 assert_unreached(error
.message
);
120 onlevelchange_test
.done();
123 navigator
.getBattery().then(batterySuccess
, batteryFailure
);