summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_bug366946.html
blob: bd35238a40a4e94a5d83e424680ad94f132378a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=366946
-->
<head>
  <title>Test for Bug 366946</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=366946">Mozilla Bug 366946</a>
<p id="display"></p>
<div id="content" style="display: none">
  <div id="1"></div>
  <div id="2"></div>
  <div id="3"></div>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
  /** Test for Bug 366946 **/
  SimpleTest.waitForExplicitFinish();

  addLoadEvent(function() {
    var doc1 = document;

    // Set up a new document.
    var doc2 = document.implementation.createDocument('', '', null);

    // Copy some nodes into doc2
    var node1 = doc2.importNode(doc1.getElementById('1'), false);
    var node2 = doc2.importNode(doc1.getElementById('1'), false);
    node1.appendChild(node2);
    doc2.appendChild(node1);

    // Create two ranges in doc1 to compare.
    var range1 = doc1.createRange();
    range1.setStart(doc1.getElementById('1'), 0);
    range1.setEnd(doc1.getElementById('2'), 0);
    
    var range2 = doc1.createRange();
    range2.setStart(doc1.getElementById('2'), 0);
    range2.setEnd(doc1.getElementById('3'), 0);

    // Create a range in doc2.
    var range3 = doc2.createRange();
    range3.setStart(node1, 0);
    range3.setEnd(node2, 0);

    // Compare range1 and range2: Should return 1.
    try {
      var result1 = range2.compareBoundaryPoints(Range.START_TO_START, range1);
    }
    catch (ex) {
    }
    ok(result1 ===  1, "range1 and range2 are compared correctly.");

    // Compare range1 and range3: Should throw DOMException WRONG_DOCUMENT_ERR.
    try {
      var result2 = range3.compareBoundaryPoints(Range.START_TO_START, range1);
    }
    catch (ex) {
      var error = ex.name;
      var errorCode = ex.code;
    }

    ok(error == "WrongDocumentError",
      "The WrongDocumentError exception thrown when comparing ranges from " +
      "different documents ");
    ok(errorCode == DOMException.WRONG_DOCUMENT_ERR,
      "The exception thrown when comparing ranges from different documents " +
      "has the code DOMException.WRONG_DOCUMENT_ERR");
    ok(result2 === undefined, "range1 and range3 couldn't be compared as expected.");
    SimpleTest.finish();
  });
</script>
</pre>
</body>
</html>