Bug 1529038 [wpt PR 15361] - KV storage: add schema checks when initializing, a=testonly
[gecko.git] / testing / web-platform / tests / battery-status / battery-plugging-in-manual.https.html
blob1445bd7e2600bcf531cb50bdaf2337152d6638ae
1 <!DOCTYPE html>
2 <meta charset="utf-8">
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>
9 <style>
10 #note {
11 background-color: #fef1b5;
12 border: solid 1px #cdab2d;
13 padding: 5px;
14 margin: 15px;
15 display: block;
17 </style>
19 <h2>Description</h2>
20 <p>
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.
24 </p>
26 <h2>Preconditions</h2>
27 <ol>
28 <li>
29 The device is unplugged from the charger before this test is run.
30 </li>
31 <li>
32 The battery must not be full or reach full capacity before the time the test is run.
33 </li>
34 </ol>
36 <div id="note">
37 <ol>
38 <li>
39 Plug in the charger and wait for all the tests to complete.
40 </li>
41 <li>
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.
45 </li>
46 </ol>
47 </div>
49 <div id="log"></div>
51 <script>
53 (function() {
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();
77 });
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();
84 });
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();
92 });
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();
98 });
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);
125 })();
127 </script>