content/base/test/test_bug454325.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=454325
     5 -->
     6 <head>
     7   <title>Test for Bug 454325</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    10 </head>
    11 <body>
    12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=454325">Mozilla Bug 454325</a>
    13 <p id="display"></p>
    14 <div id="content" style="display: none">
    16 </div>
    17 <pre id="test">
    18 <script class="testbody" type="text/javascript">
    20 /** Test for Bug 454325 **/
    22 function testDocument1() {
    23   var doc = document.implementation.createDocument("", "", null);
    24   var html = doc.createElement('html');
    25   doc.appendChild(html);
    26   var body = doc.createElement('body');
    27   html.appendChild(body);
    28   var h1 = doc.createElement('h1');
    29   var t1 = doc.createTextNode('Hello ');
    30   h1.appendChild(t1);
    31   var em = doc.createElement('em');
    32   var t2 = doc.createTextNode('Wonderful');
    33   em.appendChild(t2);
    34   h1.appendChild(em);
    35   var t3 = doc.createTextNode(' Kitty');
    36   h1.appendChild(t3);
    37   body.appendChild(h1);
    38   var p = doc.createElement('p');
    39   var t4 = doc.createTextNode(' How are you?');
    40   p.appendChild(t4);
    41   body.appendChild(p);
    42   var r = doc.createRange();
    43   r.selectNodeContents(doc);
    44   is(r.toString(), "Hello Wonderful Kitty How are you?",
    45      "toString() on range selecting Document gave wrong output");
    46   r.setStart(h1, 3);
    47   r.setEnd(p, 0);
    48   // <html><body><h1>Hello <em>Wonder ful<\em> Kitty<\h1><p>How are you?<\p><\body></html>
    49   //                                                ^ -----^
    50   is(r.toString(), "", "toString() on range crossing text nodes gave wrong output");
    51   var c1 = r.cloneContents();
    52   is(c1.childNodes.length, 2, "Wrong child nodes");
    53   try {
    54     is(c1.childNodes[0].localName, "h1", "Wrong child node");
    55     is(c1.childNodes[1].localName, "p", "Wrong child node");
    56   } catch(ex) {
    57     ok(!ex, ex);
    58   }
    60   r.setStart(t2, 6);
    61   r.setEnd(p, 0);
    62   // <html><body><h1>Hello <em>Wonder ful<\em> Kitty<\h1><p>How are you?<\p><\body></html>
    63   //                                 ^----------------------^
    64   is(r.toString(), "ful Kitty", "toString() on range crossing text nodes gave wrong output");
    65   var c2 = r.cloneContents();
    66   is(c2.childNodes.length, 2, "Wrong child nodes");
    67   try {
    68     is(c1.childNodes[0].localName, "h1", "Wrong child node");
    69     is(c1.childNodes[1].localName, "p", "Wrong child node");
    70   } catch(ex) {
    71     ok(!ex, ex);
    72   }
    74   var e1 = r.extractContents();
    75   is(e1.childNodes.length, 2, "Wrong child nodes");
    76   try {
    77     is(e1.childNodes[0].localName, "h1", "Wrong child node");
    78     is(e1.childNodes[1].localName, "p", "Wrong child node");
    79   } catch(ex) {
    80     ok(!ex, ex);
    81   }
    82 }
    84 function testDocument2() {
    85   var doc = document.implementation.createDocument("", "", null);
    86   var html = doc.createElement('html');
    87   doc.appendChild(html);
    88   var head = doc.createElement('head');
    89   html.appendChild(head);
    90   var foohead = doc.createElement('foohead');
    91   html.appendChild(foohead);
    92   var body = doc.createElement('body');
    93   html.appendChild(body);
    94   var d1 = doc.createElement('div');
    95   head.appendChild(d1);
    96   var t1 = doc.createTextNode("|||");
    97   d1.appendChild(t1);
    98   var d2 = doc.createElement("div");
    99   body.appendChild(d2);
   100   var d3 = doc.createElement("div");
   101   d2.appendChild(d3);
   102   var d4 = doc.createElement("div");
   103   d2.appendChild(d4);
   104   var r = doc.createRange();
   105   r.setStart(t1, 1);
   106   r.setEnd(d2, 2);
   107   is(r.toString(), "||", "Wrong range");
   108   var c1 = r.cloneContents();
   109   var e1 = r.extractContents();
   110   ok(c1.isEqualNode(e1), "Wrong cloning or extracting!");
   111 }
   113 function testSurroundContents() {
   114   var div = document.createElement('div');
   115   document.body.appendChild(div);
   116   div.innerHTML = '<div>hello</div>world';
   117   var innerDiv = div.firstChild;
   118   var hello = innerDiv.firstChild;
   119   var range = document.createRange();
   120   range.setStart(hello, 0);
   121   range.setEnd(hello, 5);
   122   range.surroundContents(document.createElement('code'));
   123   is(innerDiv.childNodes.length, 3, "Wrong childNodes count");
   124   is(innerDiv.childNodes[0].nodeName, "#text", "Wrong node name (1)");
   125   is(innerDiv.childNodes[0].textContent, "", "Wrong textContent (1)");
   126   is(innerDiv.childNodes[1].nodeName, "CODE", "Wrong node name (2)");
   127   is(innerDiv.childNodes[1].textContent, "hello", "Wrong textContent (2)");
   128   is(innerDiv.childNodes[2].nodeName, "#text", "Wrong node name (3)");
   129   is(innerDiv.childNodes[2].textContent, "", "Wrong textContent (3)");
   130 }
   132 function runTest() {
   133   testDocument1();
   134   testDocument2();
   135   testSurroundContents();
   136   SimpleTest.finish();
   137 }
   139 SimpleTest.waitForExplicitFinish();
   140 addLoadEvent(runTest);
   143 </script>
   144 </pre>
   145 </body>
   146 </html>

mercurial