| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>Battery Status API Test Suite</title> |
| <script src="/resources/testharness.js"></script> |
| <script src="countdown.js"></script> |
| <link rel="stylesheet" href="/resources/testharness.css" media="all"/> |
| <style> |
| #note { background-color: #fef1b5; border: solid 1px #cdab2d; padding: 5px; margin: 15px; display: none; } |
| </style> |
| <meta name="flags" content="interact"> |
| </head> |
| <body> |
| <h1>Description</h1> |
| <p> |
| This test validates that all of the navigator.battery attributes exist and are set to correct values, with corresponding events fired, when the charger is plugged in. |
| </p> |
| <h2>Preconditions</h2> |
| <ol> |
| <li> |
| The device is unplugged from the charger before this test is run. |
| </li> |
| <li> |
| The battery must not be full or reach full capacity during the time the test is run. |
| </li> |
| </ol> |
| <div id="note"> |
| Plug in the charger and wait for all the tests to complete. |
| </div> |
| <div id="log"></div> |
| <script> |
| (function() { |
| |
| setup({ explicit_timeout: true }); |
| |
| var onchargingchange_test = async_test('When the device is plugged in and its charging state is updated, must set the charging attribute\'s value to true and fire a chargingchange event.'); |
| navigator.battery.onchargingchange = onchargingchange_test.step_func(function (e) { |
| assert_true(navigator.battery.charging, 'The charging attribute must be set to true.') |
| onchargingchange_test.done(); |
| }); |
| |
| var onchargingtimechange_test = async_test('When the device is plugged in and its charging time is updated, must set the chargingTime attribute\'s value and fire a chargingtimechange event. If the reported charging time ' + navigator.battery.chargingTime + ' seconds or ' + Math.round(navigator.battery.chargingTime/60) + ' minutes is not correct, please indicate that the test has failed.'); |
| var battery_chargingtime = navigator.battery.chargingTime; |
| navigator.battery.onchargingtimechange = onchargingtimechange_test.step_func(function (e) { |
| assert_true(navigator.battery.chargingTime < battery_chargingtime, 'The value of the chargingTime attribute must decrease.'); |
| onchargingtimechange_test.done(); |
| }); |
| |
| var ondischargingtimechange_test = async_test('When the device is plugged in and its discharging time is updated, must set the dischargingTime attribute\'s value to Infinity and fire a dischargingtimechange event.'); |
| var battery_dischargingtime = navigator.battery.dischargingTime; |
| navigator.battery.ondischargingtimechange = ondischargingtimechange_test.step_func(function (e) { |
| assert_true(navigator.battery.dischargingTime === Infinity, 'The value of the dischargingTime attribute must be set to Infinity.'); |
| ondischargingtimechange_test.done(); |
| }); |
| |
| var onlevelchange_test = async_test('When the device is plugged in and the battery level is updated, must set the level attribute\'s value and fire a levelchange event.'); |
| var battery_level = navigator.battery.level; |
| navigator.battery.onlevelchange = onlevelchange_test.step_func(function (e) { |
| assert_true(navigator.battery.level > 0 && navigator.battery.level < 1.0, 'The level attribute must be set to the current battery level scaled from 0 to 1.0. If the reported battery level ' + navigator.battery.level + ' is not correct, please indicate that the test has failed.'); |
| onlevelchange_test.done(); |
| }); |
| |
| setTimeout(function() { |
| var note = document.querySelector('#note'); |
| note.style.display = 'block'; |
| navigator.battery.onchargingchange = function (e) { |
| if (navigator.battery.charging) { |
| note.style.display = 'none'; |
| } |
| }; |
| }, 4000); |
| |
| })(); |
| </script> |
| </body> |
| </html> |