accessible/tests/mochitest/events/test_focus_name.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <html>
michael@0 2
michael@0 3 <head>
michael@0 4 <title>Accessible name testing on focus</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 * Checker for invokers.
michael@0 22 */
michael@0 23 function actionChecker(aID, aDescription)
michael@0 24 {
michael@0 25 this.__proto__ = new invokerChecker(EVENT_FOCUS, aID);
michael@0 26
michael@0 27 this.check = function actionChecker_check(aEvent)
michael@0 28 {
michael@0 29 var target = aEvent.accessible;
michael@0 30 is(target.description, aDescription,
michael@0 31 "Wrong description for " + prettyName(target));
michael@0 32 }
michael@0 33 }
michael@0 34
michael@0 35 var gFocusHandler = {
michael@0 36 handleEvent: function gFocusHandler_handleEvent(aEvent) {
michael@0 37 var elm = aEvent.target;
michael@0 38 if (elm.nodeType != nsIDOMNode.ELEMENT_NODE)
michael@0 39 return;
michael@0 40
michael@0 41 gTooltipElm.style.display = "block";
michael@0 42
michael@0 43 elm.setAttribute("aria-describedby", "tooltip");
michael@0 44 }
michael@0 45 };
michael@0 46
michael@0 47 var gBlurHandler = {
michael@0 48 handleEvent: function gBlurHandler_handleEvent(aEvent) {
michael@0 49 gTooltipElm.style.display = "none";
michael@0 50
michael@0 51 var elm = aEvent.target;
michael@0 52 if (elm.nodeType == nsIDOMNode.ELEMENT_NODE)
michael@0 53 elm.removeAttribute("aria-describedby");
michael@0 54 }
michael@0 55 };
michael@0 56
michael@0 57 /**
michael@0 58 * Do tests.
michael@0 59 */
michael@0 60
michael@0 61 // gA11yEventDumpID = "eventdump"; // debug stuff
michael@0 62 //gA11yEventDumpToConsole = true;
michael@0 63
michael@0 64 var gQueue = null;
michael@0 65
michael@0 66 var gButtonElm = null;
michael@0 67 var gTextboxElm = null;
michael@0 68 var gTooltipElm = null;
michael@0 69
michael@0 70 function doTests()
michael@0 71 {
michael@0 72 gButtonElm = getNode("button");
michael@0 73 gTextboxElm = getNode("textbox");
michael@0 74 gTooltipElm = getNode("tooltip");
michael@0 75
michael@0 76 gButtonElm.addEventListener("focus", gFocusHandler, false);
michael@0 77 gButtonElm.addEventListener("blur", gBlurHandler, false);
michael@0 78 gTextboxElm.addEventListener("focus", gFocusHandler, false);
michael@0 79 gTextboxElm.addEventListener("blur", gBlurHandler, false);
michael@0 80
michael@0 81 // The aria-describedby is changed on DOM focus. Accessible description
michael@0 82 // should be updated when a11y focus is fired.
michael@0 83 gQueue = new eventQueue(nsIAccessibleEvent.EVENT_FOCUS);
michael@0 84 gQueue.onFinish = function()
michael@0 85 {
michael@0 86 gButtonElm.removeEventListener("focus", gFocusHandler, false);
michael@0 87 gButtonElm.removeEventListener("blur", gBlurHandler, false);
michael@0 88 gTextboxElm.removeEventListener("focus", gFocusHandler, false);
michael@0 89 gTextboxElm.removeEventListener("blur", gBlurHandler, false);
michael@0 90 }
michael@0 91
michael@0 92 var descr = "It's a tooltip";
michael@0 93 gQueue.push(new synthFocus("button", new actionChecker("button", descr)));
michael@0 94 gQueue.push(new synthTab("textbox", new actionChecker("textbox", descr)));
michael@0 95
michael@0 96 gQueue.invoke(); // Will call SimpleTest.finish();
michael@0 97 }
michael@0 98
michael@0 99 SimpleTest.waitForExplicitFinish();
michael@0 100 addA11yLoadEvent(doTests);
michael@0 101 </script>
michael@0 102 </head>
michael@0 103
michael@0 104 <body>
michael@0 105
michael@0 106 <a target="_blank"
michael@0 107 href="https://bugzilla.mozilla.org/show_bug.cgi?id=520709"
michael@0 108 title="mochitest to ensure name/description are updated on a11y focus if they were changed on DOM focus">
michael@0 109 Mozilla Bug 520709
michael@0 110 </a>
michael@0 111 <p id="display"></p>
michael@0 112 <div id="content" style="display: none"></div>
michael@0 113 <pre id="test">
michael@0 114 </pre>
michael@0 115
michael@0 116 <div id="tooltip" style="display: none" aria-hidden="true">It's a tooltip</div>
michael@0 117 <button id="button">button</button>
michael@0 118 <input id="textbox">
michael@0 119
michael@0 120 <div id="eventdump"></div>
michael@0 121 </body>
michael@0 122 </html>

mercurial