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