Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <meta charset="utf-8"> |
| 3 | <title>Battery Test: battery neither empty or full, charger plugged in</title> |
| 4 | <meta name="flags" content="interact"> |
| 5 | <script src="/resources/testharness.js"></script> |
| 6 | <script src="/resources/testharnessreport.js"></script> |
| 7 | |
| 8 | <h2>Description</h2> |
| 9 | <p> |
| 10 | This test validates that all of the BatteryManager attributes exist and are set to their correct values when battery is charging. |
| 11 | </p> |
| 12 | |
| 13 | <h2>Preconditions</h2> |
| 14 | <ol> |
| 15 | <li> |
| 16 | The device is plugged in to the charger before this test is run. |
| 17 | </li> |
| 18 | <li> |
| 19 | The battery must neither be empty or full, nor reach empty or full capacity during the test. |
| 20 | </li> |
| 21 | <li> |
| 22 | Waiting for battery level change to fire levelchange event, maybe need a long time |
| 23 | </li> |
| 24 | </ol> |
| 25 | |
| 26 | <script> |
| 27 | |
| 28 | setup({ explicit_timeout: true }); |
| 29 | |
| 30 | async_test(function (t) { |
| 31 | navigator.getBattery().then(function (battery) { |
| 32 | t.step(function () { |
| 33 | assert_true(battery.charging, 'charging must be set to true'); |
| 34 | assert_less_than(battery.chargingTime, Infinity, 'chargingTime must be less than Infinity'); |
| 35 | assert_equals(battery.dischargingTime, Infinity, 'dischargingTime must be set to Infinity'); |
| 36 | assert_greater_than(battery.level, 0, 'level must be greater than 0'); |
| 37 | assert_less_than(battery.level, 1.0, 'level must be less than 1.0'); |
| 38 | |
| 39 | var battery_level = battery.level; |
| 40 | battery.onlevelchange = t.step_func(function () { |
| 41 | assert_greater_than(battery.level, battery_level, 'The value of the level attribute must increase'); |
| 42 | t.done(); |
| 43 | }); |
| 44 | }); |
| 45 | }, function (error) { |
| 46 | t.step(function () { |
| 47 | assert_unreached(error.message); |
| 48 | }); |
| 49 | t.done(); |
| 50 | }); |
| 51 | }, document.title); |
| 52 | |
| 53 | </script> |