content/base/test/test_bug737565.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug737565.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +<!doctype html>
     1.5 +<!--
     1.6 +https://bugzilla.mozilla.org/show_bug.cgi?id=737565
     1.7 +-->
     1.8 +<title>Test for Bug 737565</title>
     1.9 +<script src="/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
    1.11 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=737565">Mozilla Bug 737565</a>
    1.12 +<script>
    1.13 +
    1.14 +/** Test for Bug 737565 **/
    1.15 +var offsets = [-1, 0, 1, 2, 3, 65536, 1 << 31];
    1.16 +// This is supposed to be an unsigned long, so adding or subtracting 1 << 32
    1.17 +// should have no effect
    1.18 +var offsetOffsets = [0, -Math.pow(2, 32), Math.pow(2, 32)];
    1.19 +
    1.20 +for (var i = 0; i < offsets.length; i++) {
    1.21 +  for (var j = 0; j < offsetOffsets.length; j++) {
    1.22 +    var offset = offsets[i] + offsetOffsets[j];
    1.23 +
    1.24 +    // Doctype always needs to throw
    1.25 +    var threw = false;
    1.26 +    try {
    1.27 +      var range = document.createRange();
    1.28 +      range.comparePoint(document.doctype, offset);
    1.29 +    } catch(e) {
    1.30 +      threw = true;
    1.31 +      is(e.name, "InvalidNodeTypeError",
    1.32 +         "comparePoint(document.doctype, " + offset
    1.33 +         + ") must throw InvalidNodeTypeError");
    1.34 +      is(Object.getPrototypeOf(e), DOMException.prototype,
    1.35 +         "comparePoint(document.doctype, " + offset
    1.36 +         + ") must throw DOMException");
    1.37 +      is(e.code, DOMException.INVALID_NODE_TYPE_ERR,
    1.38 +         "comparePoint(document.doctype, " + offset
    1.39 +         + ") must throw INVALID_NODE_TYPE_ERR");
    1.40 +    }
    1.41 +    ok(threw, "comparePoint(document.doctype, " + offset + ") must throw");
    1.42 +
    1.43 +    threw = false;
    1.44 +    // document.documentElement has two children, head and body
    1.45 +    var expectedThrew = offsets[i] < 0 || offsets[i] > 2;
    1.46 +    try {
    1.47 +      var range = document.createRange();
    1.48 +      range.comparePoint(document.documentElement, offset);
    1.49 +    } catch(e) {
    1.50 +      threw = true;
    1.51 +      is(e.name, "IndexSizeError",
    1.52 +         "comparePoint(document.documentElement, " + offset
    1.53 +         + ") must throw IndexSizeError");
    1.54 +      is(Object.getPrototypeOf(e), DOMException.prototype,
    1.55 +         "comparePoint(document.documentElement, " + offset
    1.56 +         + ") must throw DOMException");
    1.57 +      is(e.code, DOMException.INDEX_SIZE_ERR,
    1.58 +         "comparePoint(document.documentElement, " + offset
    1.59 +         + ") must throw INDEX_SIZE_ERR");
    1.60 +    }
    1.61 +    is(threw, expectedThrew,
    1.62 +       "comparePoint(document.documentElement, " + offset
    1.63 +       + ") must " + (expectedThrew ? "" : "not ") + "throw");
    1.64 +  }
    1.65 +}
    1.66 +
    1.67 +</script>

mercurial