add prime computation to the battery-unplugged test
authorAnssi Kostiainen <anssi.kostiainen@nokia.com>
Wed, 31 Oct 2012 11:56:27 +0100
changeset 265 b0ba6739390f
parent 264 cda35cc7cd40
child 266 62e0b2b6fd1c
add prime computation to the battery-unplugged test
battery/tests/submissions/anssik/battery-unplugged.html
--- a/battery/tests/submissions/anssik/battery-unplugged.html	Wed Oct 31 11:43:48 2012 +0100
+++ b/battery/tests/submissions/anssik/battery-unplugged.html	Wed Oct 31 11:56:27 2012 +0100
@@ -49,9 +49,18 @@
       
       var onlevelchange_test = async_test('When the battery\'s level changes, must fire a levelchange event.');
       var battery_level = navigator.battery.level;
+      
+      // compute primes to deplete the battery faster
+      var w = new Worker('prime.js');
+      w.postMessage('compute');
+      w.onmessage = function (e) {
+        document.querySelector('#prime').textContent = e.data;
+      };
+      
       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.');
         onlevelchange_test.done();
+        w.terminate();
       });
 
       alert('Unplug in the charger, and click OK.');