Bug 783426: Patch 2 - Tests for Async DOMRequest Firing
authorKyle Machulis <kyle@nonpolynomial.com>
Wed, 22 Aug 2012 17:58:05 -0700
changeset 105126 542abbd151391c20a58cc7b05c2fa2e988591ff2
parent 105125 df43ad6d04c1b0f8e72a376377e3acbef6b9cdaa
child 105127 d029dd0ae5a5676c7116bc1609ad26ecae316964
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
bugs783426
milestone17.0a1
Bug 783426: Patch 2 - Tests for Async DOMRequest Firing
dom/base/test/test_domrequest.html
testing/mochitest/tests/SimpleTest/specialpowersAPI.js
--- a/dom/base/test/test_domrequest.html
+++ b/dom/base/test/test_domrequest.html
@@ -45,19 +45,50 @@ is(req.result, "my result", "correct res
 
 // fire error
 req = reqserv.createRequest(window);
 ev = null;
 req.onerror = function(e) {
   ev = e;
 }
 reqserv.fireError(req, "OhMyError");
-ok(ev, "got success event");
+ok(ev, "got error event");
 is(ev.type, "error", "correct type during error");
 is(ev.target, req, "correct target during error");
 is(req.readyState, "done", "correct readyState after error");
 is(req.error.name, "OhMyError", "correct error after error");
 is(req.result, undefined, "correct result after error");
 
+// fire success
+req = reqserv.createRequest(window);
+ev = null;
+req.onsuccess = function(e) {
+  ev = e;
+  ok(ev, "got async success event");
+  is(ev.type, "success", "correct type during async success");
+  is(ev.target, this, "correct target during async success");
+  is(this.readyState, "done", "correct readyState after async success");
+  is(this.error, null, "correct error after async success");
+  is(this.result, "my async result", "correct result after async success");
+}
+reqserv.fireSuccessAsync(req, "my async result");
+
+// fire error
+req = reqserv.createRequest(window);
+ev = null;
+req.onerror = function(e) {
+  ev = e;
+  ok(ev, "got async error event");
+  is(ev.type, "error", "correct type during async error");
+  is(ev.target, this, "correct target during async error");
+  is(this.readyState, "done", "correct readyState after async error");
+  is(this.error.name, "OhMyAsyncError", "correct error after async error");
+  is(this.result, undefined, "correct result after async error");
+  SimpleTest.finish();
+}
+reqserv.fireErrorAsync(req, "OhMyAsyncError");
+
+SimpleTest.waitForExplicitFinish();
+
 </script>
 </pre>
 </body>
 </html>
--- a/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
+++ b/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
@@ -919,17 +919,18 @@ SpecialPowersAPI.prototype = {
       getService(Ci.nsIEventListenerService).
       removeSystemEventListener(target, type, listener, useCapture);
   },
 
   getDOMRequestService: function() {
     var serv = Cc["@mozilla.org/dom/dom-request-service;1"].
       getService(Ci.nsIDOMRequestService);
     var res = { __exposedProps__: {} };
-    var props = ["createRequest", "fireError", "fireSuccess"];
+    var props = ["createRequest", "fireError", "fireSuccess", 
+								 "fireErrorAsync", "fireSuccessAsync"];
     for (i in props) {
       let prop = props[i];
       res[prop] = function() { return serv[prop].apply(serv, arguments) };
       res.__exposedProps__[prop] = "r";
     }
     return res;
   },