diff --git a/dom/tests/mochitest/ajax/prototype/test/lib/unittest.js b/dom/tests/mochitest/ajax/prototype/test/lib/unittest.js index 8fba3057d69..b961ca98ec1 100644 --- a/dom/tests/mochitest/ajax/prototype/test/lib/unittest.js +++ b/dom/tests/mochitest/ajax/prototype/test/lib/unittest.js @@ -215,11 +215,13 @@ Test.Unit.Runner = Class.create({ var test = this.tests[this.currentTest], actions; if (!test) return this.finish(); + if (test.timerID > 0) test.timerID = -1; if (!test.isWaiting) this.logger.start(test.name); test.run(); if (test.isWaiting) { this.logger.message("Waiting for " + test.timeToWait + "ms"); - setTimeout(this.runTests.bind(this), test.timeToWait || 1000); + test.runner = this; + test.timerID = setTimeout(this.runTests.bind(this), test.timeToWait || 1000); return; } @@ -487,6 +489,8 @@ Test.Unit.Testcase = Class.create(Test.Unit.Assertions, { isWaiting: false, timeToWait: 1000, + timerID: -1, + runner: null, assertions: 0, failures: 0, errors: 0, @@ -498,6 +502,17 @@ Test.Unit.Testcase = Class.create(Test.Unit.Assertions, { this.timeToWait = time; }, + cancelWait: function() { + if (this.timerID > 0) { + clearTimeout(this.timerID); + this.timerID = -1; + this.test = function(){}; + // continue test + if (this.runner) + this.runner.runTests(); + } + }, + run: function(rethrow) { try { try { diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/ajax_test.js b/dom/tests/mochitest/ajax/prototype/test/unit/ajax_test.js index 6a26b71fa32..9d004650f24 100644 --- a/dom/tests/mochitest/ajax/prototype/test/unit/ajax_test.js +++ b/dom/tests/mochitest/ajax/prototype/test/unit/ajax_test.js @@ -49,23 +49,30 @@ new Test.Unit.Runner({ testUpdater: function() { this.assertEqual("", $("content").innerHTML); - new Ajax.Updater("content", "../fixtures/content.html", { method:'get' }); - + new Ajax.Updater("content", "../fixtures/content.html", { method:'get', onComplete: function() { + this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); + $('content').update(''); + this.assertEqual("", $("content").innerHTML); + new Ajax.Updater({ success:"content", failure:"content2" }, + "../fixtures/content.html", + { method:'get', parameters:{ pet:'monkey' }, onComplete: function() { + this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); + this.assertEqual("", $("content2").innerHTML); + $('content').update(''); + this.assertEqual("", $("content").innerHTML); + new Ajax.Updater("", "../fixtures/content.html", + { method:'get', parameters:"pet=monkey", onComplete: function() { + this.assertEqual("", $("content").innerHTML); + this.cancelWait(); + }.bind(this) + }); + }.bind(this) + }); + }.bind(this) + }); + this.wait(1000, function() { - this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); - - $('content').update(''); - this.assertEqual("", $("content").innerHTML); - - new Ajax.Updater({ success:"content", failure:"content2" }, - "../fixtures/content.html", { method:'get', parameters:{ pet:'monkey' } }); - - new Ajax.Updater("", "../fixtures/content.html", { method:'get', parameters:"pet=monkey" }); - - this.wait(1000, function() { - // bug 452706 this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase()); - this.assertEqual("", $("content2").innerHTML); - }); + this.flunk("The request was timeouted."); }); },