Bug 452706 - Avoid the confusion of indistinguishable failure reasons. r=sayrer a=tests
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Fri, 21 Jan 2011 12:36:59 +0100
changeset 61076 85c787353aacc434acf5c825e6af6c215b277570
parent 61075 e0ea4e4d401ffb439fc87a6196c84302aa4b3ec8
child 61077 a7026bd0bd6b664758e48225fcd78b11b20603e5
push idunknown
push userunknown
push dateunknown
reviewerssayrer, tests
bugs452706
milestone2.0b10pre
Bug 452706 - Avoid the confusion of indistinguishable failure reasons. r=sayrer a=tests
dom/tests/mochitest/ajax/prototype/test/lib/unittest.js
dom/tests/mochitest/ajax/prototype/test/unit/ajax_test.js
--- a/dom/tests/mochitest/ajax/prototype/test/lib/unittest.js
+++ b/dom/tests/mochitest/ajax/prototype/test/lib/unittest.js
@@ -210,21 +210,23 @@ Test.Unit.Runner = Class.create({
         { method: 'get', parameters: this.getResult(), asynchronous: false });
     }
   },
   
   runTests: function() {
     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;
     }
     
     this.logger.finish(test.status(), test.summary());
     if (actions = test.actions) this.logger.appendActionButtons(actions);
     this.currentTest++;
     // tail recursive, hopefully the browser will skip the stackframe
     this.runTests();
@@ -482,27 +484,40 @@ Test.Unit.Testcase = Class.create(Test.U
     this.setup          = setup    || Prototype.emptyFunction;
     this.teardown       = teardown || Prototype.emptyFunction;
     this.messages       = [];
     this.actions        = {};
   },
   
   isWaiting:  false,
   timeToWait: 1000,
+  timerID:   -1,
+  runner:     null,
   assertions: 0,
   failures:   0,
   errors:     0,
   isRunningFromRake: window.location.port == 4711,
   
   wait: function(time, nextPart) {
     this.isWaiting = true;
     this.test = nextPart;
     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 {
         if (!this.isWaiting) this.setup();
         this.isWaiting = false;
         this.test();
       } finally {
         if (!this.isWaiting) {
--- a/dom/tests/mochitest/ajax/prototype/test/unit/ajax_test.js
+++ b/dom/tests/mochitest/ajax/prototype/test/unit/ajax_test.js
@@ -44,33 +44,40 @@ new Test.Unit.Runner({
       var h2 = $("content").firstChild;
       this.assertEqual("Hello world!", h2.innerHTML);
     });
   },
   
   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.");
     }); 
   },
   
   testUpdaterWithInsertion: function() {
     $('content').update();
     new Ajax.Updater("content", "../fixtures/content.html", { method:'get', insertion: Insertion.Top });
     this.wait(1000, function() {
       // bug 452706       this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());