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 DOMCursor</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 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 18 | |
michael@0 | 19 | var reqserv = SpecialPowers.getDOMRequestService(); |
michael@0 | 20 | ok("createRequest" in reqserv, "appears to be a service"); |
michael@0 | 21 | |
michael@0 | 22 | var req; |
michael@0 | 23 | var lastContinue = false; |
michael@0 | 24 | |
michael@0 | 25 | var index = 0; |
michael@0 | 26 | |
michael@0 | 27 | function next() { |
michael@0 | 28 | if (index < tests.length) { |
michael@0 | 29 | ok(true, "Begin test"); |
michael@0 | 30 | tests[index++](); |
michael@0 | 31 | } else { |
michael@0 | 32 | ok(true, "All done"); |
michael@0 | 33 | SimpleTest.finish(); |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | var tests = [ |
michael@0 | 38 | function() { |
michael@0 | 39 | // create a cursor, test its interface and its initial state |
michael@0 | 40 | req = reqserv.createCursor(window, function() { |
michael@0 | 41 | if (lastContinue) { |
michael@0 | 42 | reqserv.fireDone(req); |
michael@0 | 43 | } else { |
michael@0 | 44 | reqserv.fireSuccess(req, "next result") |
michael@0 | 45 | } |
michael@0 | 46 | }); |
michael@0 | 47 | ok("result" in req, "cursor has result"); |
michael@0 | 48 | ok("error" in req, "cursor has error"); |
michael@0 | 49 | ok("onsuccess" in req, "cursor has onsuccess"); |
michael@0 | 50 | ok("onerror" in req, "cursor has onerror"); |
michael@0 | 51 | ok("readyState" in req, "cursor has readyState"); |
michael@0 | 52 | ok("done" in req, "cursor has finished"); |
michael@0 | 53 | ok("continue" in req, "cursor has continue"); |
michael@0 | 54 | |
michael@0 | 55 | is(req.readyState, "pending", "readyState is pending"); |
michael@0 | 56 | is(req.result, undefined, "result is undefined"); |
michael@0 | 57 | is(req.onsuccess, null, "onsuccess is null"); |
michael@0 | 58 | is(req.onerror, null, "onerror is null"); |
michael@0 | 59 | next(); |
michael@0 | 60 | }, |
michael@0 | 61 | function() { |
michael@0 | 62 | // fire success |
michael@0 | 63 | req.onsuccess = function(e) { |
michael@0 | 64 | ok(e, "got success event"); |
michael@0 | 65 | is(e.type, "success", "correct type during success"); |
michael@0 | 66 | is(e.target, req, "correct target during success"); |
michael@0 | 67 | is(req.readyState, "done", "correct readyState after success"); |
michael@0 | 68 | is(req.error, null, "correct error after success"); |
michael@0 | 69 | is(req.result, "my result", "correct result after success"); |
michael@0 | 70 | is(req.done, false, "cursor is not done after continue") |
michael@0 | 71 | next(); |
michael@0 | 72 | } |
michael@0 | 73 | reqserv.fireSuccess(req, "my result"); |
michael@0 | 74 | }, |
michael@0 | 75 | function() { |
michael@0 | 76 | // continue |
michael@0 | 77 | req.onsuccess = function(e) { |
michael@0 | 78 | ok(e, "got success event after continue"); |
michael@0 | 79 | is(e.type, "success", "correct type during continue"); |
michael@0 | 80 | is(e.target, req, "correct target during continue"); |
michael@0 | 81 | is(req.readyState, "done", "correct readyState after continue"); |
michael@0 | 82 | is(req.error, null, "correct error after continue"); |
michael@0 | 83 | is(req.result, "next result", "correct result after continue"); |
michael@0 | 84 | is(req.done, false, "cursor is not done after continue") |
michael@0 | 85 | next(); |
michael@0 | 86 | } |
michael@0 | 87 | req.continue(); |
michael@0 | 88 | try { |
michael@0 | 89 | req.continue(); |
michael@0 | 90 | ok(false, "calling continue twice should fail"); |
michael@0 | 91 | } catch (e) { |
michael@0 | 92 | ok(true, "calling continue twice should fail"); |
michael@0 | 93 | } |
michael@0 | 94 | }, |
michael@0 | 95 | function() { |
michael@0 | 96 | // FireDone |
michael@0 | 97 | req.onsuccess = function(e) { |
michael@0 | 98 | ok(e, "got success event after continue"); |
michael@0 | 99 | is(e.type, "success", "correct type during continue"); |
michael@0 | 100 | is(e.target, req, "correct target during continue"); |
michael@0 | 101 | is(req.readyState, "done", "correct readyState after continue"); |
michael@0 | 102 | is(req.error, null, "correct error after continue"); |
michael@0 | 103 | is(req.result, undefined, "no result after last continue"); |
michael@0 | 104 | is(req.done, true, "cursor is done after last continue") |
michael@0 | 105 | try { |
michael@0 | 106 | req.continue(); |
michael@0 | 107 | ok(false, "continue when cursor is done should fail"); |
michael@0 | 108 | } catch (e) { |
michael@0 | 109 | ok(true, "continue when cursor is done should fail"); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | next(); |
michael@0 | 113 | } |
michael@0 | 114 | lastContinue = true; |
michael@0 | 115 | req.continue(); |
michael@0 | 116 | }, |
michael@0 | 117 | function() { |
michael@0 | 118 | // fire error |
michael@0 | 119 | req = reqserv.createCursor(window, function(){}); |
michael@0 | 120 | req.onerror = function(e) { |
michael@0 | 121 | ok(e, "got success event"); |
michael@0 | 122 | is(e.type, "error", "correct type during error"); |
michael@0 | 123 | is(e.target, req, "correct target during error"); |
michael@0 | 124 | is(req.readyState, "done", "correct readyState after error"); |
michael@0 | 125 | is(req.error.name, "error msg", "correct error after error"); |
michael@0 | 126 | is(req.result, undefined, "correct result after error"); |
michael@0 | 127 | try { |
michael@0 | 128 | req.continue(); |
michael@0 | 129 | ok(false, "continue while in an error state should fail"); |
michael@0 | 130 | } catch (e) { |
michael@0 | 131 | ok(true, "continue while in an error state should fail"); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | next(); |
michael@0 | 135 | } |
michael@0 | 136 | reqserv.fireError(req, "error msg"); |
michael@0 | 137 | } |
michael@0 | 138 | ]; |
michael@0 | 139 | |
michael@0 | 140 | next(); |
michael@0 | 141 | |
michael@0 | 142 | </script> |
michael@0 | 143 | </pre> |
michael@0 | 144 | </body> |
michael@0 | 145 | </html> |