Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test for DOMRequest</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | <p id="display"></p> |
michael@0 | 10 | <div id="content" style="display: none"> |
michael@0 | 11 | |
michael@0 | 12 | </div> |
michael@0 | 13 | <pre id="test"> |
michael@0 | 14 | <script class="testbody" type="application/javascript;version=1.7"> |
michael@0 | 15 | "use strict"; |
michael@0 | 16 | |
michael@0 | 17 | var reqserv = SpecialPowers.getDOMRequestService(); |
michael@0 | 18 | ok("createRequest" in reqserv, "appears to be a service"); |
michael@0 | 19 | |
michael@0 | 20 | // create a request |
michael@0 | 21 | var req = reqserv.createRequest(window); |
michael@0 | 22 | ok("result" in req, "request has result"); |
michael@0 | 23 | ok("error" in req, "request has error"); |
michael@0 | 24 | ok("onsuccess" in req, "request has onsuccess"); |
michael@0 | 25 | ok("onerror" in req, "request has onerror"); |
michael@0 | 26 | ok("readyState" in req, "request has readyState"); |
michael@0 | 27 | |
michael@0 | 28 | is(req.readyState, "pending", "readyState is pending"); |
michael@0 | 29 | is(req.result, undefined, "result is undefined"); |
michael@0 | 30 | is(req.onsuccess, null, "onsuccess is null"); |
michael@0 | 31 | is(req.onerror, null, "onerror is null"); |
michael@0 | 32 | |
michael@0 | 33 | // fire success |
michael@0 | 34 | var ev = null; |
michael@0 | 35 | req.onsuccess = function(e) { |
michael@0 | 36 | ev = e; |
michael@0 | 37 | } |
michael@0 | 38 | reqserv.fireSuccess(req, "my result"); |
michael@0 | 39 | ok(ev, "got success event"); |
michael@0 | 40 | is(ev.type, "success", "correct type during success"); |
michael@0 | 41 | is(ev.target, req, "correct target during success"); |
michael@0 | 42 | is(req.readyState, "done", "correct readyState after success"); |
michael@0 | 43 | is(req.error, null, "correct error after success"); |
michael@0 | 44 | is(req.result, "my result", "correct result after success"); |
michael@0 | 45 | |
michael@0 | 46 | // fire error |
michael@0 | 47 | req = reqserv.createRequest(window); |
michael@0 | 48 | ev = null; |
michael@0 | 49 | req.onerror = function(e) { |
michael@0 | 50 | ev = e; |
michael@0 | 51 | } |
michael@0 | 52 | reqserv.fireError(req, "OhMyError"); |
michael@0 | 53 | ok(ev, "got error event"); |
michael@0 | 54 | is(ev.type, "error", "correct type during error"); |
michael@0 | 55 | is(ev.target, req, "correct target during error"); |
michael@0 | 56 | is(req.readyState, "done", "correct readyState after error"); |
michael@0 | 57 | is(req.error.name, "OhMyError", "correct error after error"); |
michael@0 | 58 | is(req.result, undefined, "correct result after error"); |
michael@0 | 59 | |
michael@0 | 60 | // fire detailed error |
michael@0 | 61 | req = reqserv.createRequest(window); |
michael@0 | 62 | ev = null; |
michael@0 | 63 | req.onerror = function(e) { |
michael@0 | 64 | ev = e; |
michael@0 | 65 | }; |
michael@0 | 66 | reqserv.fireDetailedError(req, new DOMError("detailedError")); |
michael@0 | 67 | ok(ev, "got error event"); |
michael@0 | 68 | is(ev.type, "error", "correct type during error"); |
michael@0 | 69 | is(ev.target, req, "correct target during error"); |
michael@0 | 70 | is(req.readyState, "done", "correct readyState after error"); |
michael@0 | 71 | is(req.error.name, "detailedError", "correct error after error"); |
michael@0 | 72 | is(req.result, undefined, "correct result after error"); |
michael@0 | 73 | </script> |
michael@0 | 74 | </pre> |
michael@0 | 75 | </body> |
michael@0 | 76 | </html> |