--- a/battery/tests/submissions/anssik/battery-charging.html Tue Oct 30 14:42:08 2012 +0100
+++ b/battery/tests/submissions/anssik/battery-charging.html Tue Oct 30 15:27:43 2012 +0100
@@ -23,6 +23,9 @@
<script>
(function() {
+ // timeout in 5 mins
+ setup({ timeout: 5*60*1000 });
+
test(function() {
assert_true(navigator.battery.charging);
}, 'The charging attribute must be set to true if the battery is charging.');
@@ -40,6 +43,13 @@
assert_true(0 < navigator.battery.level && navigator.battery.level < 1.0);
}, 'The level attribute must be set to the current battery level scaled from 0 to 1.0.');
+ var onlevelchange_test = async_test('When the battery\'s level changes, must increase 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 > battery_level, 'The value of the level attribute must increase, if the battery is charging.');
+ onlevelchange_test.done();
+ });
+
})();
</script>
</body>
--- a/battery/tests/submissions/anssik/battery-discharging.html Tue Oct 30 14:42:08 2012 +0100
+++ b/battery/tests/submissions/anssik/battery-discharging.html Tue Oct 30 15:27:43 2012 +0100
@@ -23,6 +23,9 @@
<script>
(function() {
+ // timeout in 5 mins
+ setup({ timeout: 5*60*1000 });
+
test(function() {
assert_false(navigator.battery.charging);
}, 'The charging attribute must be set to false if the battery is discharging.');
@@ -40,6 +43,14 @@
assert_true(0 <= navigator.battery.level && navigator.battery.level <= 1.0);
}, 'The level attribute must be set to the current battery level scaled from 0 to 1.0');
+ var onlevelchange_test = async_test('When the battery\'s level changes, must decrease the level attribute\'s value and fire a levelchange event.');
+ var battery_level = navigator.battery.level;
+ // TODO: run some computationally heavy stuff e.g. in a worker to make the battery deplete faster?
+ navigator.battery.onlevelchange = onlevelchange_test.step_func(function (e) {
+ assert_true(navigator.battery.level < battery_level, 'The value of the level attribute must decrease, if the battery is discharging.');
+ onlevelchange_test.done();
+ });
+
})();
</script>
</body>