Bug 783426: Patch 2 - Async DOMRequest Firing Tests; r=sicking
☠☠ backed out by 15584c68bf81 ☠ ☠
authorKyle Machulis <kyle@nonpolynomial.com>
Thu, 23 Aug 2012 09:52:54 -0700
changeset 105225 c129811b87ef38c26d4fa80b1df7fbcee033a72e
parent 105224 f98bea38e654fc7a14d166f3582e0988a32da807
child 105226 fcbf82dee1db51014afea64aa31a4921ed5aa374
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewerssicking
bugs783426
milestone17.0a1
Bug 783426: Patch 2 - Async DOMRequest Firing Tests; r=sicking
dom/base/DOMRequest.cpp
dom/base/test/test_domrequest.html
testing/mochitest/tests/SimpleTest/specialpowersAPI.js
--- a/dom/base/DOMRequest.cpp
+++ b/dom/base/DOMRequest.cpp
@@ -231,17 +231,17 @@ public:
                        const jsval& aResult) :
     mReq(aRequest),
     mResult(aResult)
   {
     JSContext* cx = mReq->GetJSContextForEventHandlers();
     JS_AddValueRoot(cx, &mResult);
   }
 
-  nsresult
+  NS_IMETHODIMP
   Run()
   {
     static_cast<DOMRequest*>(mReq)->FireSuccess(mResult);
     return NS_OK;
   }
 
   ~FireSuccessAsyncTask()
   {
@@ -258,17 +258,17 @@ class FireErrorAsyncTask : public nsRunn
 public:
   FireErrorAsyncTask(nsIDOMDOMRequest* aRequest,
                      const nsAString& aError) :
     mReq(aRequest),
     mError(aError)
   {
   }
 
-  nsresult
+  NS_IMETHODIMP  
   Run()
   {
     static_cast<DOMRequest*>(mReq)->FireError(mError);
     return NS_OK;
   }
 private:
   nsIDOMDOMRequest* mReq;
   nsString mError;
--- 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;
   },