accessible/tests/mochitest/events/test_text.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <html>
michael@0 2
michael@0 3 <head>
michael@0 4 <title>Accessible mutation events testing</title>
michael@0 5
michael@0 6 <link rel="stylesheet" type="text/css"
michael@0 7 href="chrome://mochikit/content/tests/SimpleTest/test.css" />
michael@0 8
michael@0 9 <script type="application/javascript"
michael@0 10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 <script type="application/javascript"
michael@0 12 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
michael@0 13
michael@0 14 <script type="application/javascript"
michael@0 15 src="../common.js"></script>
michael@0 16 <script type="application/javascript"
michael@0 17 src="../events.js"></script>
michael@0 18
michael@0 19 <script type="application/javascript">
michael@0 20 ////////////////////////////////////////////////////////////////////////////
michael@0 21 // Invokers
michael@0 22
michael@0 23 /**
michael@0 24 * Base text remove invoker and checker.
michael@0 25 */
michael@0 26 function textRemoveInvoker(aID, aStart, aEnd, aText)
michael@0 27 {
michael@0 28 this.DOMNode = getNode(aID);
michael@0 29
michael@0 30 this.eventSeq = [
michael@0 31 new textChangeChecker(aID, aStart, aEnd, aText, false)
michael@0 32 ];
michael@0 33 }
michael@0 34
michael@0 35 function textInsertInvoker(aID, aStart, aEnd, aText)
michael@0 36 {
michael@0 37 this.DOMNode = getNode(aID);
michael@0 38
michael@0 39 this.eventSeq = [
michael@0 40 new textChangeChecker(aID, aStart, aEnd, aText, true)
michael@0 41 ];
michael@0 42 }
michael@0 43
michael@0 44 /**
michael@0 45 * Remove inaccessible child node containing accessibles.
michael@0 46 */
michael@0 47 function removeChildSpan(aID)
michael@0 48 {
michael@0 49 this.__proto__ = new textRemoveInvoker(aID, 0, 5, "33322");
michael@0 50
michael@0 51 this.invoke = function removeChildSpan_invoke()
michael@0 52 {
michael@0 53 // remove HTML span, a first child of the node
michael@0 54 this.DOMNode.removeChild(this.DOMNode.firstChild);
michael@0 55 }
michael@0 56
michael@0 57 this.getID = function removeChildSpan_getID()
michael@0 58 {
michael@0 59 return "Remove inaccessible span containing accessible nodes" + prettyName(aID);
michael@0 60 }
michael@0 61 }
michael@0 62
michael@0 63 /**
michael@0 64 * Insert inaccessible child node containing accessibles.
michael@0 65 */
michael@0 66 function insertChildSpan(aID, aInsertAllTogether)
michael@0 67 {
michael@0 68 this.__proto__ = new textInsertInvoker(aID, 0, 5, "33322");
michael@0 69
michael@0 70 this.invoke = function insertChildSpan_invoke()
michael@0 71 {
michael@0 72 // <span><span>333</span><span>22</span></span>
michael@0 73 if (aInsertAllTogether) {
michael@0 74 var topSpan = document.createElement("span");
michael@0 75 var fSpan = document.createElement("span");
michael@0 76 fSpan.textContent = "333";
michael@0 77 topSpan.appendChild(fSpan);
michael@0 78 var sSpan = document.createElement("span");
michael@0 79 sSpan.textContent = "22";
michael@0 80 topSpan.appendChild(sSpan);
michael@0 81
michael@0 82 this.DOMNode.insertBefore(topSpan, this.DOMNode.childNodes[0]);
michael@0 83
michael@0 84 } else {
michael@0 85 var topSpan = document.createElement("span");
michael@0 86 this.DOMNode.insertBefore(topSpan, this.DOMNode.childNodes[0]);
michael@0 87
michael@0 88 var fSpan = document.createElement("span");
michael@0 89 fSpan.textContent = "333";
michael@0 90 topSpan.appendChild(fSpan);
michael@0 91
michael@0 92 var sSpan = document.createElement("span");
michael@0 93 sSpan.textContent = "22";
michael@0 94 topSpan.appendChild(sSpan);
michael@0 95 }
michael@0 96 }
michael@0 97
michael@0 98 this.getID = function insertChildSpan_getID()
michael@0 99 {
michael@0 100 return "Insert inaccessible span containing accessibles" +
michael@0 101 prettyName(aID);
michael@0 102 }
michael@0 103 }
michael@0 104
michael@0 105 /**
michael@0 106 * Remove child embedded accessible.
michael@0 107 */
michael@0 108 function removeChildDiv(aID)
michael@0 109 {
michael@0 110 this.__proto__ = new textRemoveInvoker(aID, 5, 6, kEmbedChar);
michael@0 111
michael@0 112 this.invoke = function removeChildDiv_invoke()
michael@0 113 {
michael@0 114 var childDiv = this.DOMNode.childNodes[1];
michael@0 115
michael@0 116 // Ensure accessible is created to get text remove event when it's
michael@0 117 // removed.
michael@0 118 getAccessible(childDiv);
michael@0 119
michael@0 120 this.DOMNode.removeChild(childDiv);
michael@0 121 }
michael@0 122
michael@0 123 this.getID = function removeChildDiv_getID()
michael@0 124 {
michael@0 125 return "Remove accessible div from the middle of text accessible " +
michael@0 126 prettyName(aID);
michael@0 127 }
michael@0 128 }
michael@0 129
michael@0 130 /**
michael@0 131 * Insert child embedded accessible.
michael@0 132 */
michael@0 133 function insertChildDiv(aID)
michael@0 134 {
michael@0 135 this.__proto__ = new textInsertInvoker(aID, 5, 6, kEmbedChar);
michael@0 136
michael@0 137 this.invoke = function insertChildDiv_invoke()
michael@0 138 {
michael@0 139 var childDiv = document.createElement("div");
michael@0 140 this.DOMNode.insertBefore(childDiv, this.DOMNode.childNodes[1]);
michael@0 141 }
michael@0 142
michael@0 143 this.getID = function insertChildDiv_getID()
michael@0 144 {
michael@0 145 return "Insert accessible div into the middle of text accessible " +
michael@0 146 prettyName(aID);
michael@0 147 }
michael@0 148 }
michael@0 149
michael@0 150 /**
michael@0 151 * Remove children from text container from first to last child or vice
michael@0 152 * versa.
michael@0 153 */
michael@0 154 function removeChildren(aID, aLastToFirst, aStart, aEnd, aText)
michael@0 155 {
michael@0 156 this.__proto__ = new textRemoveInvoker(aID, aStart, aEnd, aText);
michael@0 157
michael@0 158 this.invoke = function removeChildren_invoke()
michael@0 159 {
michael@0 160 if (aLastToFirst) {
michael@0 161 while (this.DOMNode.firstChild)
michael@0 162 this.DOMNode.removeChild(this.DOMNode.lastChild);
michael@0 163 } else {
michael@0 164 while (this.DOMNode.firstChild)
michael@0 165 this.DOMNode.removeChild(this.DOMNode.firstChild);
michael@0 166 }
michael@0 167 }
michael@0 168
michael@0 169 this.getID = function removeChildren_getID()
michael@0 170 {
michael@0 171 return "remove children of " + prettyName(aID) +
michael@0 172 (aLastToFirst ? " from last to first" : " from first to last");
michael@0 173 }
michael@0 174 }
michael@0 175
michael@0 176 /**
michael@0 177 * Remove text from HTML input.
michael@0 178 */
michael@0 179 function removeTextFromInput(aID, aStart, aEnd, aText)
michael@0 180 {
michael@0 181 this.__proto__ = new textRemoveInvoker(aID, aStart, aEnd, aText);
michael@0 182
michael@0 183 this.eventSeq.push(new invokerChecker(EVENT_VALUE_CHANGE, this.DOMNode));
michael@0 184
michael@0 185 this.invoke = function removeTextFromInput_invoke()
michael@0 186 {
michael@0 187 const nsIDOMNSEditableElement =
michael@0 188 Components.interfaces.nsIDOMNSEditableElement;
michael@0 189
michael@0 190 this.DOMNode.focus();
michael@0 191 this.DOMNode.setSelectionRange(aStart, aEnd);
michael@0 192
michael@0 193 synthesizeKey("VK_DELETE", {});
michael@0 194 }
michael@0 195
michael@0 196 this.getID = function removeTextFromInput_getID()
michael@0 197 {
michael@0 198 return "Remove text from " + aStart + " to " + aEnd + " for " +
michael@0 199 prettyName(aID);
michael@0 200 }
michael@0 201 }
michael@0 202
michael@0 203 /**
michael@0 204 * Add text into HTML input.
michael@0 205 */
michael@0 206 function insertTextIntoInput(aID, aStart, aEnd, aText)
michael@0 207 {
michael@0 208 this.__proto__ = new textInsertInvoker(aID, aStart, aEnd, aText);
michael@0 209
michael@0 210 this.eventSeq.push(new invokerChecker(EVENT_VALUE_CHANGE, this.DOMNode));
michael@0 211
michael@0 212 this.invoke = function insertTextIntoInput_invoke()
michael@0 213 {
michael@0 214 this.DOMNode.focus();
michael@0 215 synthesizeKey("a", {});
michael@0 216 }
michael@0 217
michael@0 218 this.getID = function insertTextIntoInput_getID()
michael@0 219 {
michael@0 220 return "Insert text to " + aStart + " for " + prettyName(aID);
michael@0 221 }
michael@0 222 }
michael@0 223
michael@0 224 /**
michael@0 225 * Remove text data from text node of editable area.
michael@0 226 */
michael@0 227 function removeTextFromEditable(aID, aStart, aEnd, aText, aTextNode)
michael@0 228 {
michael@0 229 this.__proto__ = new textRemoveInvoker(aID, aStart, aEnd, aText);
michael@0 230
michael@0 231 this.invoke = function removeTextFromEditable_invoke()
michael@0 232 {
michael@0 233 this.DOMNode.focus();
michael@0 234
michael@0 235 var selection = window.getSelection();
michael@0 236 var range = document.createRange();
michael@0 237 range.setStart(this.textNode, aStart);
michael@0 238 range.setEnd(this.textNode, aEnd);
michael@0 239 selection.addRange(range);
michael@0 240
michael@0 241 synthesizeKey("VK_DELETE", {});
michael@0 242 }
michael@0 243
michael@0 244 this.getID = function removeTextFromEditable_getID()
michael@0 245 {
michael@0 246 return "Remove text from " + aStart + " to " + aEnd + " for " +
michael@0 247 prettyName(aID);
michael@0 248 }
michael@0 249
michael@0 250 this.textNode = getNode(aTextNode);
michael@0 251 }
michael@0 252
michael@0 253 ////////////////////////////////////////////////////////////////////////////
michael@0 254 // Do tests
michael@0 255 var gQueue = null;
michael@0 256 //gA11yEventDumpID = "eventdump"; // debug stuff
michael@0 257
michael@0 258 function doTests()
michael@0 259 {
michael@0 260 gQueue = new eventQueue();
michael@0 261
michael@0 262 // Text remove event on inaccessible child HTML span removal containing
michael@0 263 // accessible text nodes.
michael@0 264 gQueue.push(new removeChildSpan("p"));
michael@0 265 gQueue.push(new insertChildSpan("p"), true);
michael@0 266 gQueue.push(new insertChildSpan("p"), false);
michael@0 267
michael@0 268 // Remove embedded character.
michael@0 269 gQueue.push(new removeChildDiv("div"));
michael@0 270 gQueue.push(new insertChildDiv("div"));
michael@0 271
michael@0 272 // Remove all children.
michael@0 273 var text = kEmbedChar + "txt" + kEmbedChar;
michael@0 274 gQueue.push(new removeChildren("div2", true, 0, 5, text));
michael@0 275 gQueue.push(new removeChildren("div3", false, 0, 5, text));
michael@0 276
michael@0 277 // Text remove from text node within hypertext accessible.
michael@0 278 gQueue.push(new removeTextFromInput("input", 1, 3, "al"));
michael@0 279 gQueue.push(new insertTextIntoInput("input", 1, 2, "a"));
michael@0 280
michael@0 281 // bug 570691
michael@0 282 todo(false, "Fix text change events from editable area, see bug 570691");
michael@0 283 //var textNode = getNode("editable").firstChild;
michael@0 284 //gQueue.push(new removeTextFromEditable("editable", 1, 3, "al", textNode));
michael@0 285 //textNode = getNode("editable2").firstChild.firstChild;
michael@0 286 //gQueue.push(new removeTextFromEditable("editable2", 1, 3, "al", textNode));
michael@0 287
michael@0 288 gQueue.invoke(); // Will call SimpleTest.finish();
michael@0 289 }
michael@0 290
michael@0 291 SimpleTest.waitForExplicitFinish();
michael@0 292 addA11yLoadEvent(doTests);
michael@0 293 </script>
michael@0 294 </head>
michael@0 295
michael@0 296 <body>
michael@0 297
michael@0 298 <a target="_blank"
michael@0 299 href="https://bugzilla.mozilla.org/show_bug.cgi?id=566293"
michael@0 300 title=" wrong length of text remove event when inaccessible node containing accessible nodes is removed">
michael@0 301 Mozilla Bug 566293
michael@0 302 </a><br>
michael@0 303 <a target="_blank"
michael@0 304 href="https://bugzilla.mozilla.org/show_bug.cgi?id=570710"
michael@0 305 title="Avoid extra array traversal during text event creation">
michael@0 306 Mozilla Bug 570710
michael@0 307 </a><br>
michael@0 308 <a target="_blank"
michael@0 309 href="https://bugzilla.mozilla.org/show_bug.cgi?id=574003"
michael@0 310 title="Coalesce text events on nodes removal">
michael@0 311 Mozilla Bug 574003
michael@0 312 </a>
michael@0 313 <a target="_blank"
michael@0 314 href="https://bugzilla.mozilla.org/show_bug.cgi?id=575052"
michael@0 315 title="Cache text offsets within hypertext accessible">
michael@0 316 Mozilla Bug 575052
michael@0 317 </a>
michael@0 318 <a target="_blank"
michael@0 319 href="https://bugzilla.mozilla.org/show_bug.cgi?id=570275"
michael@0 320 title="Rework accessible tree update code">
michael@0 321 Mozilla Bug 570275
michael@0 322 </a>
michael@0 323
michael@0 324 <p id="display"></p>
michael@0 325 <div id="content" style="display: none"></div>
michael@0 326 <pre id="test">
michael@0 327 </pre>
michael@0 328 <div id="eventdump"></div>
michael@0 329
michael@0 330 <p id="p"><span><span>333</span><span>22</span></span>1111</p>
michael@0 331 <div id="div">hello<div>hello</div>hello</div>
michael@0 332 <div id="div2"><div>txt</div>txt<div>txt</div></div>
michael@0 333 <div id="div3"><div>txt</div>txt<div>txt</div></div>
michael@0 334 <input id="input" value="value">
michael@0 335 <div contentEditable="true" id="editable">value</div>
michael@0 336 <div contentEditable="true" id="editable2"><span>value</span></div>
michael@0 337 </body>
michael@0 338 </html>

mercurial