gecko-dev/dom/base/test/test_domcursor.html
Ehsan Akhgari 9fe74dfec0 Bug 839838 - Implement DOMRequest.then; r=sicking,bzbarsky
This is implemented by creating a Promise object internally and
forwarding the .then() call to it. Any further callbacks passed to
future .then() calls will be added as callbacks on the same internal
promise object. We also take care of resolving or rejecting the promise
if the success/error event of the DOMRequest object has been fired
before .then() is called.
2014-10-11 09:46:01 -04:00

141 lines
4.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for DOMCursor</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";
SimpleTest.waitForExplicitFinish();
var reqserv = SpecialPowers.getDOMRequestService();
ok("createRequest" in reqserv, "appears to be a service");
var req;
var lastContinue = false;
var index = 0;
function next() {
if (index < tests.length) {
ok(true, "Begin test");
tests[index++]();
} else {
ok(true, "All done");
SimpleTest.finish();
}
}
var tests = [
function() {
// create a cursor, test its interface and its initial state
req = reqserv.createCursor(window, function() {
if (lastContinue) {
reqserv.fireDone(req);
} else {
reqserv.fireSuccess(req, "next result")
}
});
ok("result" in req, "cursor has result");
ok("error" in req, "cursor has error");
ok("onsuccess" in req, "cursor has onsuccess");
ok("onerror" in req, "cursor has onerror");
ok("readyState" in req, "cursor has readyState");
ok("done" in req, "cursor has finished");
ok("continue" in req, "cursor has continue");
ok(!("then" in req), "cursor should not have a then method");
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");
next();
},
function() {
// fire success
req.onsuccess = function(e) {
ok(e, "got success event");
is(e.type, "success", "correct type during success");
is(e.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");
is(req.done, false, "cursor is not done after continue")
next();
}
reqserv.fireSuccess(req, "my result");
},
function() {
// continue
req.onsuccess = function(e) {
ok(e, "got success event after continue");
is(e.type, "success", "correct type during continue");
is(e.target, req, "correct target during continue");
is(req.readyState, "done", "correct readyState after continue");
is(req.error, null, "correct error after continue");
is(req.result, "next result", "correct result after continue");
is(req.done, false, "cursor is not done after continue")
next();
}
req.continue();
},
function() {
// FireDone
req.onsuccess = function(e) {
ok(e, "got success event after continue");
is(e.type, "success", "correct type during continue");
is(e.target, req, "correct target during continue");
is(req.readyState, "done", "correct readyState after continue");
is(req.error, null, "correct error after continue");
is(req.result, undefined, "no result after last continue");
is(req.done, true, "cursor is done after last continue")
try {
req.continue();
ok(false, "continue when cursor is done should fail");
} catch (e) {
ok(true, "continue when cursor is done should fail");
}
next();
}
lastContinue = true;
req.continue();
},
function() {
// fire error
req = reqserv.createCursor(window, function(){});
req.onerror = function(e) {
ok(e, "got success event");
is(e.type, "error", "correct type during error");
is(e.target, req, "correct target during error");
is(req.readyState, "done", "correct readyState after error");
is(req.error.name, "error msg", "correct error after error");
is(req.result, undefined, "correct result after error");
try {
req.continue();
ok(false, "continue while in an error state should fail");
} catch (e) {
ok(true, "continue while in an error state should fail");
}
next();
}
reqserv.fireError(req, "error msg");
}
];
next();
</script>
</pre>
</body>
</html>