Skip to content

Instantly share code, notes, and snippets.

@jgraham
Created May 8, 2012 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgraham/2636212 to your computer and use it in GitHub Desktop.
Save jgraham/2636212 to your computer and use it in GitHub Desktop.
Add possibility to disable / explicitly control timeouts
diff -r 639d5836906a apisample3.htm
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apisample3.htm Tue May 08 17:17:26 2012 +0200
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Sample HTML5 API Tests</title>
+</head>
+<script src="testharness.js"></script>
+
+<body onload="load_test_attr.done()">
+<h1>Sample HTML5 API Tests</h1>
+<div id="log"></div>
+<script>
+setup({explicit_timeout:true});
+var t = async_test("This test should give a status of 'Not Run' without a delay");
+timeout();
+</script>
+</body>
+</html>
diff -r 639d5836906a testharness.js
--- a/testharness.js Mon Mar 12 13:08:03 2012 -0600
+++ b/testharness.js Tue May 08 17:17:26 2012 +0200
@@ -973,6 +973,8 @@
};
this.phase = this.phases.INITIAL;
+ this.properties = {};
+
//All tests can't be done until the load event fires
this.all_loaded = false;
this.wait_for_finish = false;
@@ -980,7 +982,6 @@
this.timeout_length = settings.timeout;
this.timeout_id = null;
- this.set_timeout();
this.start_callbacks = [];
this.test_done_callbacks = [];
@@ -999,7 +1000,8 @@
this_obj.complete();
}
});
- this.properties = {};
+
+ this.set_timeout();
}
Tests.prototype.setup = function(func, properties)
@@ -1024,12 +1026,14 @@
if (properties.timeout)
{
this.timeout_length = properties.timeout;
- this.set_timeout();
}
if (properties.explicit_done)
{
this.wait_for_finish = true;
}
+ if (properties.explicit_timeout) {
+ this.timeout_length = null;
+ }
if (func)
{
@@ -1042,15 +1046,20 @@
this.status.message = e;
};
}
+ this.set_timeout();
};
Tests.prototype.set_timeout = function()
{
var this_obj = this;
clearTimeout(this.timeout_id);
- this.timeout_id = setTimeout(function() {
- this_obj.timeout();
- }, this.timeout_length);
+ if (this.timeout_length !== null)
+ {
+
+ this.timeout_id = setTimeout(function() {
+ this_obj.timeout();
+ }, this.timeout_length);
+ }
};
Tests.prototype.timeout = function() {
@@ -1069,7 +1078,7 @@
Tests.prototype.push = function(test)
{
if (this.phase < this.phases.HAVE_TESTS) {
- this.notify_start();
+ this.start();
}
this.num_pending++;
this.tests.push(test);
@@ -1201,6 +1210,14 @@
var tests = new Tests();
+ function timeout() {
+ if (tests.timeout_length === null)
+ {
+ tests.timeout();
+ }
+ }
+ expose(timeout, 'timeout');
+
function add_start_callback(callback) {
tests.start_callbacks.push(callback);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment