diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/battery-status | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
20 files changed, 674 insertions, 0 deletions
diff --git a/testing/web-platform/tests/battery-status/META.yml b/testing/web-platform/tests/battery-status/META.yml new file mode 100644 index 0000000000..77d19a828d --- /dev/null +++ b/testing/web-platform/tests/battery-status/META.yml @@ -0,0 +1,4 @@ +spec: https://w3c.github.io/battery/ +suggested_reviewers: + - anssiko + - Honry diff --git a/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html b/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html new file mode 100644 index 0000000000..f65f3629df --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<body> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=/permissions-policy/resources/permissions-policy.js></script> +<script> +'use strict'; + +const relative_path = '/permissions-policy/resources/permissions-policy-battery.html'; +const base_src = '/permissions-policy/resources/redirect-on-load.html#'; +const same_origin_src = base_src + relative_path; +const cross_origin_src = base_src + 'https://{{domains[www]}}:{{ports[https][0]}}' + + relative_path; +const header = 'permissions policy allow="battery"'; + +async_test(t => { + test_feature_availability( + 'navigator.getBattery()', t, same_origin_src, + expect_feature_available_default, 'battery'); +}, `${header} allows same-origin relocation.`); + +async_test(t => { + test_feature_availability( + 'navigator.getBattery()', t, cross_origin_src, + expect_feature_unavailable_default, 'battery'); +}, `${header} disallows cross-origin relocation.`); +</script> +</body> diff --git a/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy-attribute.https.sub.html b/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy-attribute.https.sub.html new file mode 100644 index 0000000000..fc4a7bad81 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy-attribute.https.sub.html @@ -0,0 +1,27 @@ +<!DOCTYPE html> +<body> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=/permissions-policy/resources/permissions-policy.js></script> +<script> +'use strict'; + +const same_origin_src = '/permissions-policy/resources/permissions-policy-battery.html'; +const cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' + + same_origin_src; +const feature_name = 'permissions policy "battery"'; +const header = 'allow="battery" attribute'; + +async_test(t => { + test_feature_availability( + 'navigator.getBattery()', t, same_origin_src, + expect_feature_available_default, 'battery'); +}, `${feature_name} can be enabled in same-origin iframe using ${header}`); + +async_test(t => { + test_feature_availability( + 'navigator.getBattery()', t, cross_origin_src, + expect_feature_available_default, 'battery'); +}, `${feature_name} can be enabled in cross-origin iframe using ${header}`); +</script> +</body> diff --git a/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy.https.sub.html b/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy.https.sub.html new file mode 100644 index 0000000000..8cbf39997b --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy.https.sub.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<body> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=/permissions-policy/resources/permissions-policy.js></script> +<script> +'use strict'; + +const same_origin_src = '/permissions-policy/resources/permissions-policy-battery.html'; +const cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' + + same_origin_src; +const header = 'Permissions-Policy header "battery=*"'; + +promise_test( + async () => await navigator.getBattery(), + `${header} allows the top-level document.`); + +async_test(t => { + test_feature_availability('navigator.getBattery()', t, same_origin_src, + expect_feature_available_default); +}, `${header} allows same-origin iframes.`); + +async_test(t => { + test_feature_availability('navigator.getBattery()', t, cross_origin_src, + expect_feature_available_default); +}, `${header} allows cross-origin iframes.`); +</script> +</body> diff --git a/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy.https.sub.html.headers b/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy.https.sub.html.headers new file mode 100644 index 0000000000..989fdc3df8 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-allowed-by-permissions-policy.https.sub.html.headers @@ -0,0 +1 @@ +Permissions-Policy: battery=* diff --git a/testing/web-platform/tests/battery-status/battery-allowed-in-same-origin-iframe.https.html b/testing/web-platform/tests/battery-status/battery-allowed-in-same-origin-iframe.https.html new file mode 100644 index 0000000000..c0d684f26d --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-allowed-in-same-origin-iframe.https.html @@ -0,0 +1,26 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: navigator.getBattery() is allowed in same origin iframe</title> +<link rel="author" title="Intel" href="http://www.intel.com"> +<link rel="help" href="https://www.w3.org/TR/battery-status/"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<iframe id="blank" src="about:blank" style="display: none"></iframe> +<script> + +function load_iframe(iframe, src) { + return new Promise((resolve, reject) => { + iframe.onload = () => resolve(iframe); + iframe.src = src; + }); +} + +promise_test(async t => { + let iframe = document.getElementById('blank'); + const src = 'support-iframe.html'; + iframe = await load_iframe(iframe, src); + await iframe.contentWindow.navigator.getBattery(); +}, "navigator.getBattery() is allowed in same origin iframe"); + +</script> diff --git a/testing/web-platform/tests/battery-status/battery-charging-manual.https.html b/testing/web-platform/tests/battery-status/battery-charging-manual.https.html new file mode 100644 index 0000000000..9ff7421638 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-charging-manual.https.html @@ -0,0 +1,54 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: battery neither empty or full, charger plugged in</title> +<link rel="author" title="Intel" href="http://www.intel.com"> +<link rel="help" href="https://www.w3.org/TR/battery-status/"> +<meta name="flags" content="interact"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<h2>Description</h2> +<p> + This test validates that all of the BatteryManager attributes exist and are set to their correct values when battery is charging. +</p> + +<h2>Preconditions</h2> +<ol> + <li> + The device is plugged in to the charger before this test is run. + </li> + <li> + The battery must neither be empty or full, nor reach empty or full capacity during the test. + </li> + <li> + Waiting for battery level change to fire levelchange event, maybe need a long time + </li> +</ol> + +<script> + +setup({ explicit_timeout: true }); + +async_test(function (t) { + navigator.getBattery().then(function (battery) { + t.step(function () { + assert_true(battery.charging, 'charging must be set to true'); + assert_equals(battery.dischargingTime, Infinity, 'dischargingTime must be set to Infinity'); + assert_greater_than(battery.level, 0, 'level must be greater than 0'); + assert_less_than_equal(battery.level, 1.0, 'level must be less than or equal to 1.0'); + + var battery_level = battery.level; + battery.onlevelchange = t.step_func(function () { + assert_greater_than(battery.level, battery_level, 'The value of the level attribute must increase'); + t.done(); + }); + }); + }, function (error) { + t.step(function () { + assert_unreached(error.message); + }); + t.done(); + }); +}, document.title); + +</script> diff --git a/testing/web-platform/tests/battery-status/battery-default-permissions-policy.https.sub.html b/testing/web-platform/tests/battery-status/battery-default-permissions-policy.https.sub.html new file mode 100644 index 0000000000..7485250dae --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-default-permissions-policy.https.sub.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<body> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=/permissions-policy/resources/permissions-policy.js></script> +<script> +'use strict'; + +const same_origin_src = '/permissions-policy/resources/permissions-policy-battery.html'; +const cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' + + same_origin_src; +const header = 'Default "battery" permissions policy'; + +promise_test( + async () => await navigator.getBattery(), + `${header} allows the top-level document.`); + +async_test(t => { + test_feature_availability('navigator.getBattery()', t, same_origin_src, + expect_feature_available_default); +}, `${header} allows same-origin iframes.`); + +async_test(t => { + test_feature_availability('navigator.getBattery()', t, cross_origin_src, + expect_feature_unavailable_default); +}, `${header} disallows cross-origin iframes.`); +</script> +</body> diff --git a/testing/web-platform/tests/battery-status/battery-disabled-by-permissions-policy.https.sub.html b/testing/web-platform/tests/battery-status/battery-disabled-by-permissions-policy.https.sub.html new file mode 100644 index 0000000000..4afdee8a0c --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-disabled-by-permissions-policy.https.sub.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<body> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=/permissions-policy/resources/permissions-policy.js></script> +<script> +'use strict'; + +const same_origin_src = '/permissions-policy/resources/permissions-policy-battery.html'; +const cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' + + same_origin_src; +const header = 'Permissions-Policy header "battery=()"'; + +promise_test(async t => { + await promise_rejects_dom(t, 'NotAllowedError', navigator.getBattery()); +}, `${header} disallows the top-level document.`); + +async_test(t => { + test_feature_availability('navigator.getBattery()', t, same_origin_src, + expect_feature_unavailable_default); +}, `${header} disallows same-origin iframes.`); + +async_test(t => { + test_feature_availability('navigator.getBattery()', t, cross_origin_src, + expect_feature_unavailable_default); +}, `${header} disallows cross-origin iframes.`); +</script> +</body> diff --git a/testing/web-platform/tests/battery-status/battery-disabled-by-permissions-policy.https.sub.html.headers b/testing/web-platform/tests/battery-status/battery-disabled-by-permissions-policy.https.sub.html.headers new file mode 100644 index 0000000000..9ff0bc6190 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-disabled-by-permissions-policy.https.sub.html.headers @@ -0,0 +1 @@ +Permissions-Policy: battery=() diff --git a/testing/web-platform/tests/battery-status/battery-disallowed-in-cross-origin-iframe.https.sub.html b/testing/web-platform/tests/battery-status/battery-disallowed-in-cross-origin-iframe.https.sub.html new file mode 100644 index 0000000000..097db219cf --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-disallowed-in-cross-origin-iframe.https.sub.html @@ -0,0 +1,27 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: navigator.getBattery() is not allowed in cross origin iframe</title> +<link rel="author" title="Intel" href="http://www.intel.com"> +<link rel="help" href="https://www.w3.org/TR/battery-status/"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<iframe id="blank" src="about:blank" style="display: none"></iframe> +<script> + +function load_iframe(iframe, src) { + return new Promise((resolve, reject) => { + iframe.onload = () => resolve(iframe); + iframe.src = src; + }); +} + +promise_test(async t => { + let iframe = document.getElementById('blank'); + const path = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1); + const src = 'https://{{domains[www1]}}:{{ports[https][0]}}' + path + 'support-iframe.html'; + iframe = await load_iframe(iframe, src); + await promise_rejects_dom(t, 'NotAllowedError', iframe.contentWindow.navigator.getBattery()); +}, "throw a 'NotAllowedError' when invoking navigator.getBattery() within cross-origin iframe"); + +</script> diff --git a/testing/web-platform/tests/battery-status/battery-discharging-manual.https.html b/testing/web-platform/tests/battery-status/battery-discharging-manual.https.html new file mode 100644 index 0000000000..f321cf7548 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-discharging-manual.https.html @@ -0,0 +1,54 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: battery neither empty or full, charger unplugged in</title> +<link rel="author" title="Intel" href="http://www.intel.com"> +<link rel="help" href="https://www.w3.org/TR/battery-status/"> +<meta name="flags" content="interact"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<h2>Description</h2> +<p> + This test validates that all of the BatteryManager attributes exist and are set to their correct values when battery is discharging. +</p> + +<h2>Preconditions</h2> +<ol> + <li> + The device is unplugged from the charger before this test is run. + </li> + <li> + The battery must neither be empty or full, nor reach empty or full capacity during the test. + </li> + <li> + Waiting for battery level change to fire levelchange event, maybe need a long time + </li> +</ol> + +<script> + +setup({ explicit_timeout: true }); + +async_test(function (t) { + navigator.getBattery().then(function (battery) { + t.step(function () { + assert_false(battery.charging, 'charging must be set to false'); + assert_equals(battery.chargingTime, Infinity, 'chargingTime must be set to Infinity'); + assert_greater_than(battery.level, 0, 'level must be greater than 0'); + assert_less_than_equal(battery.level, 1.0, 'level must be less than or equal to 1.0'); + + var battery_level = battery.level; + battery.onlevelchange = t.step_func(function () { + assert_less_than(battery.level, battery_level, 'The value of the level attribute must decrease'); + t.done(); + }); + }); + }, function (error) { + t.step(function () { + assert_unreached(error.message); + }); + t.done(); + }); +}, document.title); + +</script> diff --git a/testing/web-platform/tests/battery-status/battery-full-manual.https.html b/testing/web-platform/tests/battery-status/battery-full-manual.https.html new file mode 100644 index 0000000000..0680b7d933 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-full-manual.https.html @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: battery full, charger plugged in</title> +<link rel="author" title="Intel" href="http://www.intel.com"> +<link rel="help" href="https://www.w3.org/TR/battery-status/"> +<meta name="flags" content="interact"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<h2>Description</h2> +<p> + This test validates that all of the BatteryManager attributes exist and are set to their correct values when battery is full. +</p> + +<h2>Preconditions</h2> +<ol> + <li> + The device is plugged in to the charger before this test is run. + </li> + <li> + The battery is full. + </li> +</ol> + +<script> + +async_test(function (t) { + navigator.getBattery().then(function (battery) { + t.step(function () { + assert_true(battery.charging, 'charging must be set to true'); + assert_equals(battery.chargingTime, 0, 'chargingTime must be set to 0'); + assert_equals(battery.dischargingTime, Infinity, 'dischargingTime must be set to Infinity'); + assert_equals(battery.level, 1.0, 'level must be set to 1.0'); + }); + t.done(); + }, function (error) { + t.step(function () { + assert_unreached(error.message); + }); + t.done(); + }); +}, document.title); + +</script> diff --git a/testing/web-platform/tests/battery-status/battery-plugging-in-manual.https.html b/testing/web-platform/tests/battery-status/battery-plugging-in-manual.https.html new file mode 100644 index 0000000000..1445bd7e26 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-plugging-in-manual.https.html @@ -0,0 +1,127 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: battery not full, charger plugging in</title> +<link rel="author" title="Intel" href="http://www.intel.com"> +<link rel="help" href="https://www.w3.org/TR/battery-status/"> +<meta name="flags" content="interact"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<style> + #note { + background-color: #fef1b5; + border: solid 1px #cdab2d; + padding: 5px; + margin: 15px; + display: block; + } +</style> + +<h2>Description</h2> +<p> + This test validates that all of the BatteryManager 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 before the time the test is run. + </li> +</ol> + +<div id="note"> + <ol> + <li> + Plug in the charger and wait for all the tests to complete. + </li> + <li> + The tests may take long time since the definition of how + often the chargingtimechange, dischargingtimechange, and levelchange + events are fired is left to the implementation. + </li> + </ol> +</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.'); + 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.'); + 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 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 batterySuccess = function (battery) { + battery.onchargingchange = onchargingchange_test.step_func(function () { + assert_true(battery.charging, 'The charging attribute must be set to true.'); + onchargingchange_test.done(); + }); + + var battery_chargingtime = battery.chargingTime; + battery.onchargingtimechange = onchargingtimechange_test.step_func(function () { + assert_less_than(battery.chargingTime, battery_chargingtime, + 'The value of the chargingTime attribute must decrease.'); + onchargingtimechange_test.done(); + }); + + battery.ondischargingtimechange = ondischargingtimechange_test.step_func(function () { + if (battery.charging) { + assert_equals(battery.dischargingTime, Infinity, + 'The value of the dischargingTime attribute must be set to Infinity.'); + ondischargingtimechange_test.done(); + } + }); + + battery.onlevelchange = onlevelchange_test.step_func(function () { + assert_greater_than(battery.level, 0); + assert_less_than_equal(battery.level, 1.0); + onlevelchange_test.done(); + }); + }; + + var batteryFailure = function (error) { + onchargingchange_test.step(function () { + assert_unreached(error.message); + }); + onchargingchange_test.done(); + + onchargingtimechange_test.step(function () { + assert_unreached(error.message); + }); + onchargingtimechange_test.done(); + + ondischargingtimechange_test.step(function () { + assert_unreached(error.message); + }); + ondischargingtimechange_test.done(); + + onlevelchange_test.step(function () { + assert_unreached(error.message); + }); + onlevelchange_test.done(); + }; + + navigator.getBattery().then(batterySuccess, batteryFailure); + +})(); + +</script> diff --git a/testing/web-platform/tests/battery-status/battery-promise-window.https.html b/testing/web-platform/tests/battery-status/battery-promise-window.https.html new file mode 100644 index 0000000000..37700aa5cb --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-promise-window.https.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: window.open() makes a different Navigator object</title> +<link rel="author" title="Intel" href="http://www.intel.com"> +<link rel="help" href="https://www.w3.org/TR/battery-status/"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<style> + #note { + background-color: #fef1b5; + border: solid 1px #cdab2d; + padding: 5px; + margin: 15px; + display: block; + } +</style> +<div id="note"> + Allow pop-up windows before running the tests. +</div> +<div id="log"></div> +<script> +async_test(function (t) { + var win = window.open('support-window-open.html'); + window.onmessage = t.step_func(function(e) { + assert_array_equals(e.data, [false, false, true]); + win.close(); + t.done(); + }); +}, 'window.open() makes a different Navigator object thus getting another battery promise'); +</script> diff --git a/testing/web-platform/tests/battery-status/battery-promise.https.html b/testing/web-platform/tests/battery-status/battery-promise.https.html new file mode 100644 index 0000000000..ecf7318e1c --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-promise.https.html @@ -0,0 +1,20 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: navigator.getBattery() always return same battery promise</title> +<link rel="author" title="Intel" href="http://www.intel.com"> +<link rel="help" href="https://www.w3.org/TR/battery-status/"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<script> +promise_test(function () { + return navigator.getBattery().then(function (result) { + assert_class_string(result, 'BatteryManager', + 'getBattery should return BatteryManager Object.'); + }); +}, 'navigator.getBattery() shall return BatteryManager as a promise'); + +test(function () { + assert_equals(navigator.getBattery(), navigator.getBattery()); +}, 'navigator.getBattery() shall always return the same promise'); +</script> diff --git a/testing/web-platform/tests/battery-status/battery-unplugging-manual.https.html b/testing/web-platform/tests/battery-status/battery-unplugging-manual.https.html new file mode 100644 index 0000000000..3b515786dc --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-unplugging-manual.https.html @@ -0,0 +1,112 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: charger unplugging</title> +<link rel="author" title="Intel" href="http://www.intel.com"> +<link rel="help" href="https://www.w3.org/TR/battery-status/"> +<meta name="flags" content="interact"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<style> + #note { + background-color: #fef1b5; + border: solid 1px #cdab2d; + padding: 5px; + margin: 15px; + display: block; + } +</style> + +<h2>Description</h2> +<p> + 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. +</p> + +<h2>Preconditions</h2> +<ol> + <li> + The device is plugged in to the charger before this test is run. + </li> +</ol> + +<div id="note"> + Unplug 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 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.'); + onchargingchange_test.done(); + }); + + battery.onchargingtimechange = onchargingtimechange_test.step_func(function () { + assert_equals(battery.chargingTime, Infinity, + 'The value of the chargingTime attribute must be set to Infinity.'); + onchargingtimechange_test.done(); + }); + + 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.'); + ondischargingtimechange_test.done(); + }); + + battery.onlevelchange = onlevelchange_test.step_func(function () { + assert_greater_than(battery.level, 0); + assert_less_than_equal(battery.level, 1.0); + onlevelchange_test.done(); + }); + }; + + var batteryFailure = function (error) { + onchargingchange_test.step(function () { + assert_unreached(error.message); + }); + onchargingchange_test.done(); + + onchargingtimechange_test.step(function () { + assert_unreached(error.message); + }); + onchargingtimechange_test.done(); + + ondischargingtimechange_test.step(function () { + assert_unreached(error.message); + }); + ondischargingtimechange_test.done(); + + onlevelchange_test.step(function () { + assert_unreached(error.message); + }); + onlevelchange_test.done(); + }; + + navigator.getBattery().then(batterySuccess, batteryFailure); + +})(); + +</script> diff --git a/testing/web-platform/tests/battery-status/idlharness.https.window.js b/testing/web-platform/tests/battery-status/idlharness.https.window.js new file mode 100644 index 0000000000..8113d9e779 --- /dev/null +++ b/testing/web-platform/tests/battery-status/idlharness.https.window.js @@ -0,0 +1,20 @@ +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js +// META: timeout=long + +// https://w3c.github.io/battery/ + +'use strict'; + +idl_test( + ['battery-status'], + ['dom', 'html'], + async idl_array => { + idl_array.add_objects({ + Navigator: ['navigator'], + BatteryManager: ['manager'], + }) + + self.manager = await navigator.getBattery(); + } +); diff --git a/testing/web-platform/tests/battery-status/support-iframe.html b/testing/web-platform/tests/battery-status/support-iframe.html new file mode 100644 index 0000000000..d4e5b31f13 --- /dev/null +++ b/testing/web-platform/tests/battery-status/support-iframe.html @@ -0,0 +1,5 @@ +<!DOCTYPE HTML> +<meta charset="utf-8"> +<div> +Hello! +</div> diff --git a/testing/web-platform/tests/battery-status/support-window-open.html b/testing/web-platform/tests/battery-status/support-window-open.html new file mode 100644 index 0000000000..afffc3af28 --- /dev/null +++ b/testing/web-platform/tests/battery-status/support-window-open.html @@ -0,0 +1,10 @@ +<!DOCTYPE HTML> +<meta charset="utf-8"> +<script> +var data = [ + navigator === window.opener.navigator, + navigator.getBattery() === window.opener.navigator.getBattery(), + navigator.getBattery() === navigator.getBattery() +]; +window.opener.postMessage(data, '*'); +</script> |