2012-02-24 05:19:49 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
2013-02-08 12:25:37 -08:00
|
|
|
<title>Test for DOMRequest</title>
|
2012-02-24 05:19:49 -08:00
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="application/javascript;version=1.7">
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var reqserv = SpecialPowers.getDOMRequestService();
|
|
|
|
ok("createRequest" in reqserv, "appears to be a service");
|
|
|
|
|
|
|
|
// create a request
|
|
|
|
var req = reqserv.createRequest(window);
|
|
|
|
ok("result" in req, "request has result");
|
|
|
|
ok("error" in req, "request has error");
|
|
|
|
ok("onsuccess" in req, "request has onsuccess");
|
|
|
|
ok("onerror" in req, "request has onerror");
|
|
|
|
ok("readyState" in req, "request has readyState");
|
|
|
|
|
|
|
|
is(req.readyState, "pending", "readyState is pending");
|
|
|
|
is(req.result, undefined, "result is undefined");
|
|
|
|
is(req.onsuccess, null, "onsuccess is null");
|
|
|
|
is(req.onerror, null, "onerror is null");
|
|
|
|
|
|
|
|
// fire success
|
|
|
|
var ev = null;
|
|
|
|
req.onsuccess = function(e) {
|
|
|
|
ev = e;
|
|
|
|
}
|
2012-08-08 14:07:39 -07:00
|
|
|
reqserv.fireSuccess(req, "my result");
|
2012-02-24 05:19:49 -08:00
|
|
|
ok(ev, "got success event");
|
|
|
|
is(ev.type, "success", "correct type during success");
|
|
|
|
is(ev.target, req, "correct target during success");
|
|
|
|
is(req.readyState, "done", "correct readyState after success");
|
|
|
|
is(req.error, null, "correct error after success");
|
|
|
|
is(req.result, "my result", "correct result after success");
|
|
|
|
|
|
|
|
// fire error
|
|
|
|
req = reqserv.createRequest(window);
|
|
|
|
ev = null;
|
|
|
|
req.onerror = function(e) {
|
|
|
|
ev = e;
|
|
|
|
}
|
2012-08-08 14:07:39 -07:00
|
|
|
reqserv.fireError(req, "OhMyError");
|
2013-06-27 19:53:44 -07:00
|
|
|
ok(ev, "got error event");
|
2012-02-24 05:19:49 -08:00
|
|
|
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");
|
|
|
|
|
2013-06-27 19:53:44 -07:00
|
|
|
// fire detailed error
|
|
|
|
req = reqserv.createRequest(window);
|
|
|
|
ev = null;
|
|
|
|
req.onerror = function(e) {
|
|
|
|
ev = e;
|
|
|
|
};
|
|
|
|
reqserv.fireDetailedError(req, new DOMError("detailedError"));
|
|
|
|
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, "detailedError", "correct error after error");
|
|
|
|
is(req.result, undefined, "correct result after error");
|
2012-02-24 05:19:49 -08:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|