diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/battery-status | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/battery-status')
13 files changed, 605 insertions, 0 deletions
diff --git a/testing/web-platform/tests/battery-status/OWNERS b/testing/web-platform/tests/battery-status/OWNERS new file mode 100644 index 000000000..eb86aa069 --- /dev/null +++ b/testing/web-platform/tests/battery-status/OWNERS @@ -0,0 +1,3 @@ +@anssiko +@dontcallmedom +@zqzhang diff --git a/testing/web-platform/tests/battery-status/battery-charging-manual.html b/testing/web-platform/tests/battery-status/battery-charging-manual.html new file mode 100644 index 000000000..8e80e30a2 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-charging-manual.html @@ -0,0 +1,52 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: battery neither empty or full, charger plugged in</title> +<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-discharging-manual.html b/testing/web-platform/tests/battery-status/battery-discharging-manual.html new file mode 100644 index 000000000..c4ccbe445 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-discharging-manual.html @@ -0,0 +1,52 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: battery neither empty or full, charger unplugged in</title> +<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.html b/testing/web-platform/tests/battery-status/battery-full-manual.html new file mode 100644 index 000000000..883d71f40 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-full-manual.html @@ -0,0 +1,42 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: battery full, charger plugged in</title> +<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-interface-idlharness.html b/testing/web-platform/tests/battery-status/battery-interface-idlharness.html new file mode 100644 index 000000000..4e9b209d4 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-interface-idlharness.html @@ -0,0 +1,74 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery test: IDL</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/WebIDLParser.js"></script> +<script src="/resources/idlharness.js"></script> +<script type="text/plain" class="untested"> +interface Navigator { }; + +interface EventTarget { + void addEventListener(DOMString type, EventListener? callback, optional boolean capture); + void removeEventListener(DOMString type, EventListener? callback, optional boolean capture); + boolean dispatchEvent(Event event); +}; + +[Callback] +interface EventListener { + void handleEvent(Event event); +}; +[TreatNonObjectAsNull] +callback EventHandlerNonNull = any (Event event); +typedef EventHandlerNonNull? EventHandler; +</script> +<script type="text/plain"> +partial interface Navigator { + Promise<BatteryManager> getBattery (); +}; + +interface BatteryManager : EventTarget { + readonly attribute boolean charging; + readonly attribute unrestricted double chargingTime; + readonly attribute unrestricted double dischargingTime; + readonly attribute double level; + attribute EventHandler onchargingchange; + attribute EventHandler onchargingtimechange; + attribute EventHandler ondischargingtimechange; + attribute EventHandler onlevelchange; +}; +</script> +<script> +"use strict"; +var t = async_test(); +var idl_array = new IdlArray(); +var idls; +var manager; +[].forEach.call(document.querySelectorAll('script[type=text\\/plain]'), function(node) { + idls = node.textContent; + idl_array[(node.className === 'untested') ? 'add_untested_idls' : 'add_idls'](idls); +}); +t.step(function() { + assert_idl_attribute(navigator, 'getBattery', 'navigator must have getBattery attribute'); + navigator.getBattery().then(function(bm) { + manager = bm; + idl_array.add_objects({Navigator: ['navigator'], BatteryManager: ['manager']}); + idl_array.test(); + t.done(); + }).catch(function(err) { + t.assert_unreached("navigator.getBattery failed"); + }); +}); +</script> + +<h2>Description</h2> +<p> + This test validates the BatteryManager interface IDL. +</p> +<p> + This test uses <a href="/resources/idlharness.js">idlharness.js</a>, and + is complementary to the <a href="battery-interface.html">battery-interface.html</a> + test. +</p> + +<div id="log"></div> diff --git a/testing/web-platform/tests/battery-status/battery-plugging-in-manual.html b/testing/web-platform/tests/battery-status/battery-plugging-in-manual.html new file mode 100644 index 000000000..4d16cf187 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-plugging-in-manual.html @@ -0,0 +1,125 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: battery not full, charger plugging in</title> +<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-iframe.html b/testing/web-platform/tests/battery-status/battery-promise-iframe.html new file mode 100644 index 000000000..6add86106 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-promise-iframe.html @@ -0,0 +1,80 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: iframe has a different Navigator object</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<style> + iframe { + display: none; + } +</style> +<div id="log"></div> +<iframe id="blank" src="about:blank"></iframe> +<iframe id="frame"></iframe> +<script> +promise_test(function(t) { + var iframe = document.querySelector('#blank'); + var originalPromise = navigator.getBattery(); + + return originalPromise.then(function(originalManager) { + var promise = iframe.contentWindow.navigator.getBattery(); + + assert_true(originalManager instanceof BatteryManager); + assert_not_equals(iframe.contentWindow.navigator, + navigator, + 'navigator objects shall be different'); + assert_not_equals(promise, + originalPromise, + 'battery promises in different navigators shall be different'); + assert_equals(iframe.contentWindow.navigator.getBattery(), + promise, + 'battery promises in same navigator shall be same'); + + return promise; + }).then(function(manager) { + assert_equals(manager.__proto__, + iframe.contentWindow.BatteryManager.prototype); + assert_true(manager instanceof iframe.contentWindow.BatteryManager); + }); + +}, 'iframe has a different Navigator object thus getting another battery promise'); + +async_test(function (t) { + var iframe = document.querySelector('#blank'); + var originalNavigator = iframe.contentWindow.navigator; + var originalPromise = iframe.contentWindow.navigator.getBattery(); + + iframe.onload = t.step_func(function() { + assert_equals(iframe.contentWindow.navigator, + originalNavigator, + 'navigator objects shall be same'); + assert_equals(iframe.contentWindow.navigator.getBattery(), + originalPromise, + 'battery status promises shall be same'); + t.done(); + }); + + iframe.src = 'support-iframe.html'; +}, 'setting src of an iframe with initial about:blank makes same Navigator object and battery promise'); + +async_test(function (t) { + var iframe = document.querySelector('#frame'); + iframe.src = 'support-iframe-initial.html'; + iframe.onload = t.step_func(function() { + var originalNavigator = iframe.contentWindow.navigator; + var originalPromise = iframe.contentWindow.navigator.getBattery(); + + iframe.onload = t.step_func(function() { + assert_not_equals(iframe.contentWindow.navigator, + originalNavigator, + 'navigator objects shall be changed'); + assert_not_equals(iframe.contentWindow.navigator.getBattery(), + originalPromise, + 'battery status promises shall be different'); + t.done(); + }); + + iframe.src = 'support-iframe.html'; + }); +}, 'setting src of an iframe with initial frame makes its Navigator object vary thus getting another battery promise'); +</script> diff --git a/testing/web-platform/tests/battery-status/battery-promise-window.html b/testing/web-platform/tests/battery-status/battery-promise-window.html new file mode 100644 index 000000000..a7d708c05 --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-promise-window.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: window.open() makes a different Navigator object</title> +<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.html b/testing/web-platform/tests/battery-status/battery-promise.html new file mode 100644 index 000000000..8c552eb3f --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-promise.html @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: navigator.getBattery() always return same battery promise</title> +<link rel="author" title="YuichiNukiyama" href="https://github.com/YuichiNukiyama"> +<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.html b/testing/web-platform/tests/battery-status/battery-unplugging-manual.html new file mode 100644 index 000000000..bb576da2b --- /dev/null +++ b/testing/web-platform/tests/battery-status/battery-unplugging-manual.html @@ -0,0 +1,110 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Battery Test: charger unplugging</title> +<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/support-iframe-initial.html b/testing/web-platform/tests/battery-status/support-iframe-initial.html new file mode 100644 index 000000000..d4e5b31f1 --- /dev/null +++ b/testing/web-platform/tests/battery-status/support-iframe-initial.html @@ -0,0 +1,5 @@ +<!DOCTYPE HTML> +<meta charset="utf-8"> +<div> +Hello! +</div> 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 000000000..d4e5b31f1 --- /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 000000000..afffc3af2 --- /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> |