mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 14:15:30 +00:00
77 lines
2.4 KiB
HTML
77 lines
2.4 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Test for DOMRequest</title>
|
|
<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;
|
|
}
|
|
reqserv.fireSuccess(req, "my result");
|
|
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;
|
|
}
|
|
reqserv.fireError(req, "OhMyError");
|
|
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 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");
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|