dap commit: add timeout countdown to long running tests

changeset:   279:513bcbcd497d
user:        Anssi Kostiainen <anssi.kostiainen@nokia.com>
date:        Thu Nov 22 12:44:32 2012 +0200
files:       battery/tests/submissions/anssik/battery-charging.html battery/tests/submissions/anssik/battery-discharging.html battery/tests/submissions/anssik/battery-plugged-in.html battery/tests/submissions/anssik/battery-unplugged.html battery/tests/submissions/anssik/countdown.js
description:
add timeout countdown to long running tests


diff -r a567476d8bd4 -r 513bcbcd497d battery/tests/submissions/anssik/battery-charging.html
--- a/battery/tests/submissions/anssik/battery-charging.html	Tue Nov 20 15:28:34 2012 +0200
+++ b/battery/tests/submissions/anssik/battery-charging.html	Thu Nov 22 12:44:32 2012 +0200
@@ -3,6 +3,7 @@
   <head>
     <title>Battery Status API Test Suite</title>
     <script src="/resources/testharness.js"></script>
+    <script src="countdown.js"></script>
     <link rel="stylesheet" href="/resources/testharness.css" media="all"/>
     <meta name="flags" content="interact">
   </head>
@@ -24,7 +25,9 @@
     <script>
     (function() {
 
-      setup({ timeout: 5*60*1000 });
+      var t = 5*60*1000;
+      setup({ timeout: t });
+      countdown({ timeout: t });
 
       test(function() {
         assert_true(navigator.battery.charging);
diff -r a567476d8bd4 -r 513bcbcd497d battery/tests/submissions/anssik/battery-discharging.html
--- a/battery/tests/submissions/anssik/battery-discharging.html	Tue Nov 20 15:28:34 2012 +0200
+++ b/battery/tests/submissions/anssik/battery-discharging.html	Thu Nov 22 12:44:32 2012 +0200
@@ -3,6 +3,7 @@
   <head>
     <title>Battery Status API Test Suite</title>
     <script src="/resources/testharness.js"></script>
+    <script src="countdown.js"></script>
     <link rel="stylesheet" href="/resources/testharness.css" media="all"/>
     <meta name="flags" content="interact">
   </head>
@@ -27,7 +28,9 @@
     <script>
     (function() {
 
-      setup({ timeout: 5*60*1000 });
+      var t = 5*60*1000;
+      setup({ timeout: t });
+      countdown({ timeout: t });
       
       test(function() {
         assert_false(navigator.battery.charging);
diff -r a567476d8bd4 -r 513bcbcd497d battery/tests/submissions/anssik/battery-plugged-in.html
--- a/battery/tests/submissions/anssik/battery-plugged-in.html	Tue Nov 20 15:28:34 2012 +0200
+++ b/battery/tests/submissions/anssik/battery-plugged-in.html	Thu Nov 22 12:44:32 2012 +0200
@@ -3,6 +3,7 @@
   <head>
     <title>Battery Status API Test Suite</title>
     <script src="/resources/testharness.js"></script>
+    <script src="countdown.js"></script>
     <link rel="stylesheet" href="/resources/testharness.css" media="all"/>
     <meta name="flags" content="interact">
   </head>
@@ -24,7 +25,9 @@
     <script>
     (function() {
 
-      setup({ timeout: 5*60*1000 });
+      var t = 5*60*1000;
+      setup({ timeout: t });
+      countdown({ timeout: t });
       
       alert('Unplug the device from its charger (if not already unplugged), and click OK.');
       
diff -r a567476d8bd4 -r 513bcbcd497d battery/tests/submissions/anssik/battery-unplugged.html
--- a/battery/tests/submissions/anssik/battery-unplugged.html	Tue Nov 20 15:28:34 2012 +0200
+++ b/battery/tests/submissions/anssik/battery-unplugged.html	Thu Nov 22 12:44:32 2012 +0200
@@ -3,6 +3,7 @@
   <head>
     <title>Battery Status API Test Suite</title>
     <script src="/resources/testharness.js"></script>
+    <script src="countdown.js"></script>
     <link rel="stylesheet" href="/resources/testharness.css" media="all"/>
     <meta name="flags" content="interact">
   </head>
@@ -24,7 +25,9 @@
     <script>
     (function() {
 
-      setup({ timeout: 5*60*1000 });
+      var t = 5*60*1000;
+      setup({ timeout: t });
+      countdown({ timeout: t });
       
       alert('Plug the device into its charger (if not already plugged in), and click OK.');
       
diff -r a567476d8bd4 -r 513bcbcd497d battery/tests/submissions/anssik/countdown.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/battery/tests/submissions/anssik/countdown.js	Thu Nov 22 12:44:32 2012 +0200
@@ -0,0 +1,38 @@
+function countdown(prop) {
+  var seconds = !isNaN(parseInt(prop.timeout, 10)) ? (prop.timeout / 1000) : 0,
+      body = document.getElementsByTagName('body')[0],
+      div = document.createElement('div'),
+      timer, remaining_time, min, sec;
+
+  add_completion_callback(function () {
+    clearInterval(timer);
+    body.removeChild(div);
+  });
+  
+  div.innerHTML = 'This test will timeout in <span id="remaining_time">...</span>';
+  body.appendChild(div);
+    
+  remaining_time = document.querySelector('#remaining_time');
+  
+  timer = setInterval(function() {
+    function zeroPad(n) {
+      return (n < 10) ? '0' + n : n;
+    }
+  
+    if (seconds / 60 >= 1) {
+      min = Math.floor(seconds / 60);
+      sec = seconds % 60;
+    } else {
+      min = 0;
+      sec = seconds;
+    }
+    
+    if (seconds === 0) {
+      div.innerHTML = 'Timeout exceeded. Increase the timeout and re-run.';
+      clearInterval(timer);
+    }
+    
+    remaining_time.textContent = zeroPad(min) + ':' + zeroPad(sec);
+    seconds--;
+  }, 1000);
+}

Received on Thursday, 22 November 2012 13:27:55 UTC