accessible/tests/mochitest/treeupdate/test_doc.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 <!DOCTYPE html>
michael@0 2 <html>
michael@0 3
michael@0 4 <head>
michael@0 5 <title>Test document root content mutations</title>
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
michael@0 12 <script type="application/javascript"
michael@0 13 src="../common.js"></script>
michael@0 14 <script type="application/javascript"
michael@0 15 src="../role.js"></script>
michael@0 16 <script type="application/javascript"
michael@0 17 src="../states.js"></script>
michael@0 18 <script type="application/javascript"
michael@0 19 src="../events.js"></script>
michael@0 20
michael@0 21 <script type="application/javascript">
michael@0 22
michael@0 23 ////////////////////////////////////////////////////////////////////////////
michael@0 24 // Helpers
michael@0 25
michael@0 26 function getDocNode(aID)
michael@0 27 {
michael@0 28 return getNode(aID).contentDocument;
michael@0 29 }
michael@0 30 function getDocChildNode(aID)
michael@0 31 {
michael@0 32 return getDocNode(aID).body.firstChild;
michael@0 33 }
michael@0 34
michael@0 35 function rootContentReplaced(aID, aTextName, aRootContentRole)
michael@0 36 {
michael@0 37 this.eventSeq = [
michael@0 38 new invokerChecker(EVENT_SHOW, getDocChildNode, aID),
michael@0 39 new invokerChecker(EVENT_REORDER, getDocNode, aID)
michael@0 40 ];
michael@0 41
michael@0 42 this.finalCheck = function rootContentReplaced_finalCheck()
michael@0 43 {
michael@0 44 var tree = {
michael@0 45 role: aRootContentRole || ROLE_DOCUMENT,
michael@0 46 children: [
michael@0 47 {
michael@0 48 role: ROLE_TEXT_LEAF,
michael@0 49 name: aTextName
michael@0 50 }
michael@0 51 ]
michael@0 52 };
michael@0 53 testAccessibleTree(getDocNode(aID), tree);
michael@0 54 }
michael@0 55 }
michael@0 56
michael@0 57 function rootContentRemoved(aID)
michael@0 58 {
michael@0 59 this.eventSeq = [
michael@0 60 new invokerChecker(EVENT_HIDE, null),
michael@0 61 new invokerChecker(EVENT_REORDER, getDocNode, aID)
michael@0 62 ];
michael@0 63
michael@0 64 this.preinvoke = function rootContentRemoved_preinvoke()
michael@0 65 {
michael@0 66 // Set up target for hide event before we invoke.
michael@0 67 var text = getAccessible(getAccessible(getDocNode(aID)).firstChild);
michael@0 68 this.eventSeq[0].target = text;
michael@0 69 }
michael@0 70
michael@0 71 this.finalCheck = function rootContentRemoved_finalCheck()
michael@0 72 {
michael@0 73 var tree = {
michael@0 74 role: ROLE_DOCUMENT,
michael@0 75 children: [ ]
michael@0 76 };
michael@0 77 testAccessibleTree(getDocNode(aID), tree);
michael@0 78 }
michael@0 79 }
michael@0 80
michael@0 81 function rootContentInserted(aID, aTextName)
michael@0 82 {
michael@0 83 this.eventSeq = [
michael@0 84 new invokerChecker(EVENT_SHOW, getDocChildNode, aID),
michael@0 85 new invokerChecker(EVENT_REORDER, getDocNode, aID)
michael@0 86 ];
michael@0 87
michael@0 88 this.finalCheck = function rootContentInserted_finalCheck()
michael@0 89 {
michael@0 90 var tree = {
michael@0 91 role: ROLE_DOCUMENT,
michael@0 92 children: [
michael@0 93 {
michael@0 94 role: ROLE_TEXT_LEAF,
michael@0 95 name: aTextName
michael@0 96 }
michael@0 97 ]
michael@0 98 };
michael@0 99 testAccessibleTree(getDocNode(aID), tree);
michael@0 100 }
michael@0 101 }
michael@0 102
michael@0 103 ////////////////////////////////////////////////////////////////////////////
michael@0 104 // Invokers
michael@0 105
michael@0 106 function writeIFrameDoc(aID)
michael@0 107 {
michael@0 108 this.__proto__ = new rootContentReplaced(aID, "hello");
michael@0 109
michael@0 110 this.invoke = function writeIFrameDoc_invoke()
michael@0 111 {
michael@0 112 var docNode = getDocNode(aID);
michael@0 113
michael@0 114 // We can't use open/write/close outside of iframe document because of
michael@0 115 // security error.
michael@0 116 var script = docNode.createElement("script");
michael@0 117 script.textContent = "document.open(); document.write('hello'); document.close();";
michael@0 118 docNode.body.appendChild(script);
michael@0 119 }
michael@0 120
michael@0 121 this.getID = function writeIFrameDoc_getID()
michael@0 122 {
michael@0 123 return "write document";
michael@0 124 }
michael@0 125 }
michael@0 126
michael@0 127 /**
michael@0 128 * Replace HTML element.
michael@0 129 */
michael@0 130 function replaceIFrameHTMLElm(aID)
michael@0 131 {
michael@0 132 this.__proto__ = new rootContentReplaced(aID, "New Wave");
michael@0 133
michael@0 134 this.invoke = function replaceIFrameHTMLElm_invoke()
michael@0 135 {
michael@0 136 var docNode = getDocNode(aID);
michael@0 137 var newHTMLNode = docNode.createElement("html");
michael@0 138 var newBodyNode = docNode.createElement("body");
michael@0 139 var newTextNode = docNode.createTextNode("New Wave");
michael@0 140 newBodyNode.appendChild(newTextNode);
michael@0 141 newHTMLNode.appendChild(newBodyNode);
michael@0 142 docNode.replaceChild(newHTMLNode, docNode.documentElement);
michael@0 143 }
michael@0 144
michael@0 145 this.getID = function replaceIFrameHTMLElm_getID()
michael@0 146 {
michael@0 147 return "replace HTML element";
michael@0 148 }
michael@0 149 }
michael@0 150
michael@0 151 /**
michael@0 152 * Replace HTML body on new body having ARIA role.
michael@0 153 */
michael@0 154 function replaceIFrameBody(aID)
michael@0 155 {
michael@0 156 this.__proto__ = new rootContentReplaced(aID, "New Hello");
michael@0 157
michael@0 158 this.invoke = function replaceIFrameBody_invoke()
michael@0 159 {
michael@0 160 var docNode = getDocNode(aID);
michael@0 161 var newBodyNode = docNode.createElement("body");
michael@0 162 var newTextNode = docNode.createTextNode("New Hello");
michael@0 163 newBodyNode.appendChild(newTextNode);
michael@0 164 docNode.documentElement.replaceChild(newBodyNode, docNode.body);
michael@0 165 }
michael@0 166
michael@0 167 this.getID = function replaceIFrameBody_getID()
michael@0 168 {
michael@0 169 return "replace body";
michael@0 170 }
michael@0 171 }
michael@0 172
michael@0 173 /**
michael@0 174 * Replace HTML body on new body having ARIA role.
michael@0 175 */
michael@0 176 function replaceIFrameBodyOnARIARoleBody(aID)
michael@0 177 {
michael@0 178 this.__proto__ = new rootContentReplaced(aID, "New Hello",
michael@0 179 ROLE_PUSHBUTTON);
michael@0 180
michael@0 181 this.invoke = function replaceIFrameBodyOnARIARoleBody_invoke()
michael@0 182 {
michael@0 183 var docNode = getDocNode(aID);
michael@0 184 var newBodyNode = docNode.createElement("body");
michael@0 185 var newTextNode = docNode.createTextNode("New Hello");
michael@0 186 newBodyNode.appendChild(newTextNode);
michael@0 187 newBodyNode.setAttribute("role", "button");
michael@0 188 docNode.documentElement.replaceChild(newBodyNode, docNode.body);
michael@0 189 }
michael@0 190
michael@0 191 this.getID = function replaceIFrameBodyOnARIARoleBody_getID()
michael@0 192 {
michael@0 193 return "replace body on body having ARIA role";
michael@0 194 }
michael@0 195 }
michael@0 196
michael@0 197 /**
michael@0 198 * Open/close document pair.
michael@0 199 */
michael@0 200 function openIFrameDoc(aID)
michael@0 201 {
michael@0 202 this.__proto__ = new rootContentRemoved(aID);
michael@0 203
michael@0 204 this.invoke = function openIFrameDoc_invoke()
michael@0 205 {
michael@0 206 this.preinvoke();
michael@0 207
michael@0 208 // Open document.
michael@0 209 var docNode = getDocNode(aID);
michael@0 210 var script = docNode.createElement("script");
michael@0 211 script.textContent = "function closeMe() { document.write('Works?'); document.close(); } window.closeMe = closeMe; document.open();";
michael@0 212 docNode.body.appendChild(script);
michael@0 213 }
michael@0 214
michael@0 215 this.getID = function openIFrameDoc_getID()
michael@0 216 {
michael@0 217 return "open document";
michael@0 218 }
michael@0 219 }
michael@0 220
michael@0 221 function closeIFrameDoc(aID)
michael@0 222 {
michael@0 223 this.__proto__ = new rootContentInserted(aID, "Works?");
michael@0 224
michael@0 225 this.invoke = function closeIFrameDoc_invoke()
michael@0 226 {
michael@0 227 // Write and close document.
michael@0 228 getDocNode(aID).write('Works?'); getDocNode(aID).close();
michael@0 229 }
michael@0 230
michael@0 231 this.getID = function closeIFrameDoc_getID()
michael@0 232 {
michael@0 233 return "close document";
michael@0 234 }
michael@0 235 }
michael@0 236
michael@0 237 /**
michael@0 238 * Remove/insert HTML element pair.
michael@0 239 */
michael@0 240 function removeHTMLFromIFrameDoc(aID)
michael@0 241 {
michael@0 242 this.__proto__ = new rootContentRemoved(aID);
michael@0 243
michael@0 244 this.invoke = function removeHTMLFromIFrameDoc_invoke()
michael@0 245 {
michael@0 246 this.preinvoke();
michael@0 247
michael@0 248 // Remove HTML element.
michael@0 249 var docNode = getDocNode(aID);
michael@0 250 docNode.removeChild(docNode.firstChild);
michael@0 251 }
michael@0 252
michael@0 253 this.getID = function removeHTMLFromIFrameDoc_getID()
michael@0 254 {
michael@0 255 return "remove HTML element";
michael@0 256 }
michael@0 257 }
michael@0 258
michael@0 259 function insertHTMLToIFrameDoc(aID)
michael@0 260 {
michael@0 261 this.__proto__ = new rootContentInserted(aID, "Haha");
michael@0 262
michael@0 263 this.invoke = function insertHTMLToIFrameDoc_invoke()
michael@0 264 {
michael@0 265 // Insert HTML element.
michael@0 266 var docNode = getDocNode(aID);
michael@0 267 var html = docNode.createElement("html");
michael@0 268 var body = docNode.createElement("body");
michael@0 269 var text = docNode.createTextNode("Haha");
michael@0 270 body.appendChild(text);
michael@0 271 html.appendChild(body);
michael@0 272 docNode.appendChild(html);
michael@0 273 }
michael@0 274
michael@0 275 this.getID = function insertHTMLToIFrameDoc_getID()
michael@0 276 {
michael@0 277 return "insert HTML element document";
michael@0 278 }
michael@0 279 }
michael@0 280
michael@0 281 /**
michael@0 282 * Remove/insert HTML body pair.
michael@0 283 */
michael@0 284 function removeBodyFromIFrameDoc(aID)
michael@0 285 {
michael@0 286 this.__proto__ = new rootContentRemoved(aID);
michael@0 287
michael@0 288 this.invoke = function removeBodyFromIFrameDoc_invoke()
michael@0 289 {
michael@0 290 this.preinvoke();
michael@0 291
michael@0 292 // Remove body element.
michael@0 293 var docNode = getDocNode(aID);
michael@0 294 docNode.documentElement.removeChild(docNode.body);
michael@0 295 }
michael@0 296
michael@0 297 this.getID = function removeBodyFromIFrameDoc_getID()
michael@0 298 {
michael@0 299 return "remove body element";
michael@0 300 }
michael@0 301 }
michael@0 302
michael@0 303 function insertElmUnderDocElmWhileBodyMissed(aID)
michael@0 304 {
michael@0 305 this.docNode = null;
michael@0 306 this.inputNode = null;
michael@0 307
michael@0 308 function getInputNode()
michael@0 309 { return this.inputNode; }
michael@0 310
michael@0 311 this.eventSeq = [
michael@0 312 new invokerChecker(EVENT_SHOW, getInputNode.bind(this)),
michael@0 313 new invokerChecker(EVENT_REORDER, getDocNode, aID)
michael@0 314 ];
michael@0 315
michael@0 316 this.invoke = function invoke()
michael@0 317 {
michael@0 318 this.docNode = getDocNode(aID);
michael@0 319 this.inputNode = this.docNode.createElement("input");
michael@0 320 this.docNode.documentElement.appendChild(this.inputNode);
michael@0 321 }
michael@0 322
michael@0 323 this.finalCheck = function finalCheck()
michael@0 324 {
michael@0 325 var tree =
michael@0 326 { DOCUMENT: [
michael@0 327 { ENTRY: [ ] }
michael@0 328 ] };
michael@0 329 testAccessibleTree(this.docNode, tree);
michael@0 330
michael@0 331 // Remove aftermath of this test before next test starts.
michael@0 332 this.docNode.documentElement.removeChild(this.inputNode);
michael@0 333 }
michael@0 334
michael@0 335 this.getID = function getID()
michael@0 336 {
michael@0 337 return "Insert element under document element while body is missed.";
michael@0 338 }
michael@0 339 }
michael@0 340
michael@0 341 function insertBodyToIFrameDoc(aID)
michael@0 342 {
michael@0 343 this.__proto__ = new rootContentInserted(aID, "Yo ho ho i butylka roma!");
michael@0 344
michael@0 345 this.invoke = function insertBodyToIFrameDoc_invoke()
michael@0 346 {
michael@0 347 // Insert body element.
michael@0 348 var docNode = getDocNode(aID);
michael@0 349 var body = docNode.createElement("body");
michael@0 350 var text = docNode.createTextNode("Yo ho ho i butylka roma!");
michael@0 351 body.appendChild(text);
michael@0 352 docNode.documentElement.appendChild(body);
michael@0 353 }
michael@0 354
michael@0 355 this.getID = function insertBodyToIFrameDoc_getID()
michael@0 356 {
michael@0 357 return "insert body element";
michael@0 358 }
michael@0 359 }
michael@0 360
michael@0 361 function changeSrc(aID)
michael@0 362 {
michael@0 363 this.containerNode = getNode(aID);
michael@0 364
michael@0 365 this.eventSeq = [
michael@0 366 new invokerChecker(EVENT_REORDER, this.containerNode)
michael@0 367 ];
michael@0 368
michael@0 369 this.invoke = function changeSrc_invoke()
michael@0 370 {
michael@0 371 this.containerNode.src = "data:text/html,<html><input></html>";
michael@0 372 }
michael@0 373
michael@0 374 this.finalCheck = function changeSrc_finalCheck()
michael@0 375 {
michael@0 376 var tree =
michael@0 377 { INTERNAL_FRAME: [
michael@0 378 { DOCUMENT: [
michael@0 379 { ENTRY: [ ] }
michael@0 380 ] }
michael@0 381 ] };
michael@0 382 testAccessibleTree(this.containerNode, tree);
michael@0 383 }
michael@0 384
michael@0 385 this.getID = function changeSrc_getID()
michael@0 386 {
michael@0 387 return "change src on iframe";
michael@0 388 }
michael@0 389 }
michael@0 390
michael@0 391 ////////////////////////////////////////////////////////////////////////////
michael@0 392 // Test
michael@0 393
michael@0 394 //gA11yEventDumpID = "eventdump"; // debug stuff
michael@0 395 //gA11yEventDumpToConsole = true;
michael@0 396
michael@0 397 var gQueue = null;
michael@0 398
michael@0 399 function doTest()
michael@0 400 {
michael@0 401 gQueue = new eventQueue();
michael@0 402
michael@0 403 gQueue.push(new writeIFrameDoc("iframe"));
michael@0 404 gQueue.push(new replaceIFrameHTMLElm("iframe"));
michael@0 405 gQueue.push(new replaceIFrameBody("iframe"));
michael@0 406 gQueue.push(new openIFrameDoc("iframe"));
michael@0 407 gQueue.push(new closeIFrameDoc("iframe"));
michael@0 408 gQueue.push(new removeHTMLFromIFrameDoc("iframe"));
michael@0 409 gQueue.push(new insertHTMLToIFrameDoc("iframe"));
michael@0 410 gQueue.push(new removeBodyFromIFrameDoc("iframe"));
michael@0 411 gQueue.push(new insertElmUnderDocElmWhileBodyMissed("iframe"));
michael@0 412 gQueue.push(new insertBodyToIFrameDoc("iframe"));
michael@0 413 gQueue.push(new changeSrc("iframe"));
michael@0 414 gQueue.push(new replaceIFrameBodyOnARIARoleBody("iframe"));
michael@0 415
michael@0 416 gQueue.invoke(); // SimpleTest.finish() will be called in the end
michael@0 417 }
michael@0 418
michael@0 419 SimpleTest.waitForExplicitFinish();
michael@0 420 addA11yLoadEvent(doTest);
michael@0 421 </script>
michael@0 422 </head>
michael@0 423 <body>
michael@0 424
michael@0 425 <a target="_blank"
michael@0 426 title="Update accessible tree when root element is changed"
michael@0 427 href="https://bugzilla.mozilla.org/show_bug.cgi?id=606082">Mozilla Bug 606082</a>
michael@0 428 <a target="_blank"
michael@0 429 title="Elements inserted outside the body aren't accessible"
michael@0 430 href="https://bugzilla.mozilla.org/show_bug.cgi?id=608887">Mozilla Bug 608887</a>
michael@0 431 <a target="_blank"
michael@0 432 title="Reorder event for document must be fired after document initial tree creation"
michael@0 433 href="https://bugzilla.mozilla.org/show_bug.cgi?id=669263">Mozilla Bug 669263</a>
michael@0 434 <a target="_blank"
michael@0 435 title="Changing the HTML body doesn't pick up ARIA role"
michael@0 436 href="https://bugzilla.mozilla.org/show_bug.cgi?id=818407">Mozilla Bug 818407</a>
michael@0 437
michael@0 438 <p id="display"></p>
michael@0 439 <div id="content" style="display: none"></div>
michael@0 440 <pre id="test">
michael@0 441 </pre>
michael@0 442
michael@0 443 <iframe id="iframe"></iframe>
michael@0 444
michael@0 445 <div id="eventdump"></div>
michael@0 446 </body>
michael@0 447 </html>

mercurial