dom/base/test/test_domcursor.html
author Nicholas Nethercote <nnethercote@mozilla.com>
Mon, 05 Oct 2015 16:59:32 -0700
changeset 301715 3897da20e42dec0bcf73987af1eaac4f8ce950b8
parent 236780 a14b8bf72b1655f2dd70d1a7bc022abb6f9bf96d
child 393926 a072d7934ff7c6fd2ad974d7abc0b08d11041aca
permissions -rw-r--r--
Bug 1211324 (part 3) - Remove GraphicsFilter::FILTER_FAST and replace it with FILTER_BEST. r=mattwoodrow. This may sound like an odd change but it's what the current code effectively already does due to the way ToFilter() and ThebesFilter() are defined.

<!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>