content/base/test/test_bug454325.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug454325.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,147 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=454325
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 454325</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=454325">Mozilla Bug 454325</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script class="testbody" type="text/javascript">
    1.22 +
    1.23 +/** Test for Bug 454325 **/
    1.24 +
    1.25 +function testDocument1() {
    1.26 +  var doc = document.implementation.createDocument("", "", null);
    1.27 +  var html = doc.createElement('html');
    1.28 +  doc.appendChild(html);
    1.29 +  var body = doc.createElement('body');
    1.30 +  html.appendChild(body);
    1.31 +  var h1 = doc.createElement('h1');
    1.32 +  var t1 = doc.createTextNode('Hello ');
    1.33 +  h1.appendChild(t1);
    1.34 +  var em = doc.createElement('em');
    1.35 +  var t2 = doc.createTextNode('Wonderful');
    1.36 +  em.appendChild(t2);
    1.37 +  h1.appendChild(em);
    1.38 +  var t3 = doc.createTextNode(' Kitty');
    1.39 +  h1.appendChild(t3);
    1.40 +  body.appendChild(h1);
    1.41 +  var p = doc.createElement('p');
    1.42 +  var t4 = doc.createTextNode(' How are you?');
    1.43 +  p.appendChild(t4);
    1.44 +  body.appendChild(p);
    1.45 +  var r = doc.createRange();
    1.46 +  r.selectNodeContents(doc);
    1.47 +  is(r.toString(), "Hello Wonderful Kitty How are you?",
    1.48 +     "toString() on range selecting Document gave wrong output");
    1.49 +  r.setStart(h1, 3);
    1.50 +  r.setEnd(p, 0);
    1.51 +  // <html><body><h1>Hello <em>Wonder ful<\em> Kitty<\h1><p>How are you?<\p><\body></html>
    1.52 +  //                                                ^ -----^
    1.53 +  is(r.toString(), "", "toString() on range crossing text nodes gave wrong output");
    1.54 +  var c1 = r.cloneContents();
    1.55 +  is(c1.childNodes.length, 2, "Wrong child nodes");
    1.56 +  try {
    1.57 +    is(c1.childNodes[0].localName, "h1", "Wrong child node");
    1.58 +    is(c1.childNodes[1].localName, "p", "Wrong child node");
    1.59 +  } catch(ex) {
    1.60 +    ok(!ex, ex);
    1.61 +  }
    1.62 +
    1.63 +  r.setStart(t2, 6);
    1.64 +  r.setEnd(p, 0);
    1.65 +  // <html><body><h1>Hello <em>Wonder ful<\em> Kitty<\h1><p>How are you?<\p><\body></html>
    1.66 +  //                                 ^----------------------^
    1.67 +  is(r.toString(), "ful Kitty", "toString() on range crossing text nodes gave wrong output");
    1.68 +  var c2 = r.cloneContents();
    1.69 +  is(c2.childNodes.length, 2, "Wrong child nodes");
    1.70 +  try {
    1.71 +    is(c1.childNodes[0].localName, "h1", "Wrong child node");
    1.72 +    is(c1.childNodes[1].localName, "p", "Wrong child node");
    1.73 +  } catch(ex) {
    1.74 +    ok(!ex, ex);
    1.75 +  }
    1.76 +
    1.77 +  var e1 = r.extractContents();
    1.78 +  is(e1.childNodes.length, 2, "Wrong child nodes");
    1.79 +  try {
    1.80 +    is(e1.childNodes[0].localName, "h1", "Wrong child node");
    1.81 +    is(e1.childNodes[1].localName, "p", "Wrong child node");
    1.82 +  } catch(ex) {
    1.83 +    ok(!ex, ex);
    1.84 +  }
    1.85 +}
    1.86 +
    1.87 +function testDocument2() {
    1.88 +  var doc = document.implementation.createDocument("", "", null);
    1.89 +  var html = doc.createElement('html');
    1.90 +  doc.appendChild(html);
    1.91 +  var head = doc.createElement('head');
    1.92 +  html.appendChild(head);
    1.93 +  var foohead = doc.createElement('foohead');
    1.94 +  html.appendChild(foohead);
    1.95 +  var body = doc.createElement('body');
    1.96 +  html.appendChild(body);
    1.97 +  var d1 = doc.createElement('div');
    1.98 +  head.appendChild(d1);
    1.99 +  var t1 = doc.createTextNode("|||");
   1.100 +  d1.appendChild(t1);
   1.101 +  var d2 = doc.createElement("div");
   1.102 +  body.appendChild(d2);
   1.103 +  var d3 = doc.createElement("div");
   1.104 +  d2.appendChild(d3);
   1.105 +  var d4 = doc.createElement("div");
   1.106 +  d2.appendChild(d4);
   1.107 +  var r = doc.createRange();
   1.108 +  r.setStart(t1, 1);
   1.109 +  r.setEnd(d2, 2);
   1.110 +  is(r.toString(), "||", "Wrong range");
   1.111 +  var c1 = r.cloneContents();
   1.112 +  var e1 = r.extractContents();
   1.113 +  ok(c1.isEqualNode(e1), "Wrong cloning or extracting!");
   1.114 +}
   1.115 +
   1.116 +function testSurroundContents() {
   1.117 +  var div = document.createElement('div');
   1.118 +  document.body.appendChild(div);
   1.119 +  div.innerHTML = '<div>hello</div>world';
   1.120 +  var innerDiv = div.firstChild;
   1.121 +  var hello = innerDiv.firstChild;
   1.122 +  var range = document.createRange();
   1.123 +  range.setStart(hello, 0);
   1.124 +  range.setEnd(hello, 5);
   1.125 +  range.surroundContents(document.createElement('code'));
   1.126 +  is(innerDiv.childNodes.length, 3, "Wrong childNodes count");
   1.127 +  is(innerDiv.childNodes[0].nodeName, "#text", "Wrong node name (1)");
   1.128 +  is(innerDiv.childNodes[0].textContent, "", "Wrong textContent (1)");
   1.129 +  is(innerDiv.childNodes[1].nodeName, "CODE", "Wrong node name (2)");
   1.130 +  is(innerDiv.childNodes[1].textContent, "hello", "Wrong textContent (2)");
   1.131 +  is(innerDiv.childNodes[2].nodeName, "#text", "Wrong node name (3)");
   1.132 +  is(innerDiv.childNodes[2].textContent, "", "Wrong textContent (3)");
   1.133 +}
   1.134 +
   1.135 +function runTest() {
   1.136 +  testDocument1();
   1.137 +  testDocument2();
   1.138 +  testSurroundContents();
   1.139 +  SimpleTest.finish();
   1.140 +}
   1.141 +
   1.142 +SimpleTest.waitForExplicitFinish();
   1.143 +addLoadEvent(runTest);
   1.144 +
   1.145 +
   1.146 +</script>
   1.147 +</pre>
   1.148 +</body>
   1.149 +</html>
   1.150 +

mercurial