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 | --> |
michael@0 | 5 | <head> |
michael@0 | 6 | <title>Test on the html copy encoder</title> |
michael@0 | 7 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 8 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 9 | </head> |
michael@0 | 10 | <body> |
michael@0 | 11 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=422403">Mozilla Bug </a> |
michael@0 | 12 | <p id="display"></p> |
michael@0 | 13 | <div id="content" style="display: none"> |
michael@0 | 14 | </div> |
michael@0 | 15 | <pre id="test"> |
michael@0 | 16 | <script class="testbody" type="text/javascript"> |
michael@0 | 17 | |
michael@0 | 18 | function testHtmlCopyEncoder () { |
michael@0 | 19 | const de = SpecialPowers.Ci.nsIDocumentEncoder; |
michael@0 | 20 | var encoder = SpecialPowers.Cc["@mozilla.org/layout/htmlCopyEncoder;1"] |
michael@0 | 21 | .createInstance(SpecialPowers.Ci.nsIDocumentEncoder); |
michael@0 | 22 | var out, expected; |
michael@0 | 23 | |
michael@0 | 24 | var node = document.getElementById('draggable'); |
michael@0 | 25 | |
michael@0 | 26 | |
michael@0 | 27 | // in the following tests, we must use the OutputLFLineBreak flag, to avoid |
michael@0 | 28 | // to have the default line break of the platform in the result, so the test |
michael@0 | 29 | // can pass on all platform |
michael@0 | 30 | |
michael@0 | 31 | |
michael@0 | 32 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 33 | encoder.setContainerNode(node); |
michael@0 | 34 | out = encoder.encodeToString(); |
michael@0 | 35 | expected = 'This is a <em>draggable</em> bit of text.'; |
michael@0 | 36 | is(out, expected, "test container node "); |
michael@0 | 37 | |
michael@0 | 38 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 39 | encoder.setNode(node); |
michael@0 | 40 | out = encoder.encodeToString(); |
michael@0 | 41 | expected = "<div id=\"draggable\" ondragstart=\"doDragStartSelection(event)\">This is a <em>draggable</em> bit of text.</div>"; |
michael@0 | 42 | is(out, expected, "test node"); |
michael@0 | 43 | |
michael@0 | 44 | var select = window.getSelection(); |
michael@0 | 45 | select.selectAllChildren(node); |
michael@0 | 46 | |
michael@0 | 47 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 48 | encoder.setSelection(select); |
michael@0 | 49 | out = encoder.encodeToString(); |
michael@0 | 50 | expected = "<div style=\"display: none\">\n\n<div id=\"draggable\" ondragstart=\"doDragStartSelection(event)\">This is a <em>draggable</em> bit of text.</div>\n\n</div>"; |
michael@0 | 51 | is(out, expected, "test selection"); |
michael@0 | 52 | |
michael@0 | 53 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputAbsoluteLinks | de.OutputEncodeHTMLEntities | de.OutputSelectionOnly | de.OutputRaw); |
michael@0 | 54 | encoder.setSelection(select); |
michael@0 | 55 | var outContext = {value:''}, outInfo = {value:''}; |
michael@0 | 56 | out = encoder.encodeToStringWithContext(outContext, outInfo); |
michael@0 | 57 | expected = "<div style=\"display: none\">\n\n<div id=\"draggable\" ondragstart=\"doDragStartSelection(event)\">This is a <em>draggable</em> bit of text.</div>\n\n</div>"; |
michael@0 | 58 | is(out, expected, "test encodeToStringWithContext with selection "); |
michael@0 | 59 | |
michael@0 | 60 | node.nextSibling.data="\nfoo bar\n"; |
michael@0 | 61 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 62 | encoder.setSelection(select); |
michael@0 | 63 | out = encoder.encodeToString(); |
michael@0 | 64 | expected = "<div id=\"draggable\" ondragstart=\"doDragStartSelection(event)\">This is a <em>draggable</em> bit of text.</div>"; |
michael@0 | 65 | is(out, expected, "test selection with additional data"); |
michael@0 | 66 | |
michael@0 | 67 | node = document.getElementById('aList'); |
michael@0 | 68 | |
michael@0 | 69 | var select = window.getSelection(); |
michael@0 | 70 | select.selectAllChildren(node); |
michael@0 | 71 | |
michael@0 | 72 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 73 | encoder.setSelection(select); |
michael@0 | 74 | out = encoder.encodeToString(); |
michael@0 | 75 | expected = '<ol id=\"aList\">\n <li>Lorem ipsum dolor</li>\n <li>sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n</ol>'; |
michael@0 | 76 | is(out, expected, "test list selection"); |
michael@0 | 77 | |
michael@0 | 78 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 79 | encoder.setContainerNode(node); |
michael@0 | 80 | out = encoder.encodeToString(); |
michael@0 | 81 | expected = '\n <li>Lorem ipsum dolor</li>\n <li>sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n'; |
michael@0 | 82 | is(out, expected, "test list container node"); |
michael@0 | 83 | |
michael@0 | 84 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 85 | encoder.setNode(node); |
michael@0 | 86 | out = encoder.encodeToString(); |
michael@0 | 87 | expected = "<ol id=\"aList\">\n <li>Lorem ipsum dolor</li>\n <li>sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n</ol>"; |
michael@0 | 88 | is(out, expected, "test list node"); |
michael@0 | 89 | |
michael@0 | 90 | var liList = node.getElementsByTagName("li"); |
michael@0 | 91 | var range = document.createRange(); |
michael@0 | 92 | |
michael@0 | 93 | // selection start at the first child of the ol, and end after the element ol |
michael@0 | 94 | range.setStart(node, 1); |
michael@0 | 95 | range.setEnd(node.parentNode, 2); |
michael@0 | 96 | select.removeAllRanges(); |
michael@0 | 97 | select.addRange(range); |
michael@0 | 98 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 99 | encoder.setSelection(select); |
michael@0 | 100 | out = encoder.encodeToString(); |
michael@0 | 101 | expected = '<ol id="aList">\n <li>Lorem ipsum dolor</li>\n <li>sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n</ol>'; |
michael@0 | 102 | is(out, expected, "test list selection with range: selection start at the first child of the ol, and end after the element ol"); |
michael@0 | 103 | |
michael@0 | 104 | // selection start at the third child of the ol, and end after the element ol |
michael@0 | 105 | range.setStart(node, 3); |
michael@0 | 106 | range.setEnd(node.parentNode, 2); |
michael@0 | 107 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 108 | encoder.setSelection(select); |
michael@0 | 109 | out = encoder.encodeToString(); |
michael@0 | 110 | expected = '<ol id="aList"><li value=\"2\">sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n</ol>'; |
michael@0 | 111 | is(out, expected, "test list selection with range: selection start at the third child of the ol, and end after the element ol"); |
michael@0 | 112 | |
michael@0 | 113 | |
michael@0 | 114 | // selection start at the third child of the ol, and end after the element ol + ol start at the value 5 |
michael@0 | 115 | range.setStart(node, 3); |
michael@0 | 116 | range.setEnd(node.parentNode, 2); |
michael@0 | 117 | node.setAttribute("start","5"); |
michael@0 | 118 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 119 | encoder.setSelection(select); |
michael@0 | 120 | out = encoder.encodeToString(); |
michael@0 | 121 | expected = '<ol start=\"5\" id=\"aList\"><li value=\"6\">sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n</ol>'; |
michael@0 | 122 | is(out, expected, "test list selection with range: selection start at the third child of the ol, and end after the element ol + ol start at the value 5"); |
michael@0 | 123 | |
michael@0 | 124 | // selection contains only some child of the ol |
michael@0 | 125 | node.removeAttribute("start"); |
michael@0 | 126 | range.setStart(node, 3); |
michael@0 | 127 | range.setEnd(node, 5); |
michael@0 | 128 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 129 | encoder.setSelection(select); |
michael@0 | 130 | out = encoder.encodeToString(); |
michael@0 | 131 | expected = '<li>sit amet, <strong>consectetuer</strong> </li>\n '; |
michael@0 | 132 | is(out, expected, "test list selection with range: selection contains only some child of the ol"); |
michael@0 | 133 | |
michael@0 | 134 | // selection contains only some child of the ol + ol start at the value 5 |
michael@0 | 135 | node.setAttribute("start","5"); |
michael@0 | 136 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 137 | encoder.setSelection(select); |
michael@0 | 138 | out = encoder.encodeToString(); |
michael@0 | 139 | expected = '<li>sit amet, <strong>consectetuer</strong> </li>\n '; |
michael@0 | 140 | is(out, expected, "test list selection with range: selection contains only some child of the ol + ol start at the value 5"); |
michael@0 | 141 | |
michael@0 | 142 | // selection contains only some child of the ol + a value is set on the first li |
michael@0 | 143 | node.removeAttribute("start"); |
michael@0 | 144 | liList[0].setAttribute("value","8"); |
michael@0 | 145 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 146 | encoder.setSelection(select); |
michael@0 | 147 | out = encoder.encodeToString(); |
michael@0 | 148 | expected = '<li>sit amet, <strong>consectetuer</strong> </li>\n '; |
michael@0 | 149 | is(out, expected, "test list selection with range: selection contains only some child of the ol + ol start at the value 5"); |
michael@0 | 150 | |
michael@0 | 151 | select.selectAllChildren(node); |
michael@0 | 152 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 153 | encoder.setSelection(select); |
michael@0 | 154 | out = encoder.encodeToString(); |
michael@0 | 155 | expected = '<ol id=\"aList\">\n <li value=\"8\">Lorem ipsum dolor</li>\n <li>sit amet, <strong>consectetuer</strong> </li>\n <li>adipiscing elit</li>\n <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li>\n <li>aptent taciti</li>\n</ol>'; |
michael@0 | 156 | is(out, expected, "test list selection with a value on a LI"); |
michael@0 | 157 | |
michael@0 | 158 | //test Bug 436703 |
michael@0 | 159 | node = document.getElementById('aContentEditable'); |
michael@0 | 160 | select.selectAllChildren(node); |
michael@0 | 161 | encoder.init(document, "text/html", de.OutputLFLineBreak | de.OutputSelectionOnly); |
michael@0 | 162 | encoder.setSelection(select); |
michael@0 | 163 | out = encoder.encodeToString(); |
michael@0 | 164 | expected = '<p>one</p><p>two</p>'; |
michael@0 | 165 | is(out, expected, "select all children in an contentEditable div should not select the div itself"); |
michael@0 | 166 | |
michael@0 | 167 | SimpleTest.finish(); |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | |
michael@0 | 171 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 172 | |
michael@0 | 173 | addLoadEvent(testHtmlCopyEncoder); |
michael@0 | 174 | |
michael@0 | 175 | </script> |
michael@0 | 176 | </pre> |
michael@0 | 177 | <div style="display: none"> |
michael@0 | 178 | |
michael@0 | 179 | <div id="draggable" ondragstart="doDragStartSelection(event)">This is a <em>draggable</em> bit of text.</div> |
michael@0 | 180 | |
michael@0 | 181 | </div> |
michael@0 | 182 | <div style="display: none"> |
michael@0 | 183 | |
michael@0 | 184 | <ol id="aList"> |
michael@0 | 185 | <li>Lorem ipsum dolor</li> |
michael@0 | 186 | <li>sit amet, <strong>consectetuer</strong> </li> |
michael@0 | 187 | <li>adipiscing elit</li> |
michael@0 | 188 | <li>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class</li> |
michael@0 | 189 | <li>aptent taciti</li> |
michael@0 | 190 | </ol> |
michael@0 | 191 | foo bar |
michael@0 | 192 | </div> |
michael@0 | 193 | |
michael@0 | 194 | <div id="aContentEditable" contentEditable="true"><p>one</p><p>two</p></div> |
michael@0 | 195 | </body> |
michael@0 | 196 | </html> |