Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" |
michael@0 | 4 | type="text/css"?> |
michael@0 | 5 | |
michael@0 | 6 | <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 7 | title="Tests: accessible XUL label/description events"> |
michael@0 | 8 | |
michael@0 | 9 | <script type="application/javascript" |
michael@0 | 10 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> |
michael@0 | 11 | |
michael@0 | 12 | <script type="application/javascript" |
michael@0 | 13 | src="../common.js" /> |
michael@0 | 14 | <script type="application/javascript" |
michael@0 | 15 | src="../role.js" /> |
michael@0 | 16 | <script type="application/javascript" |
michael@0 | 17 | src="../events.js" /> |
michael@0 | 18 | |
michael@0 | 19 | <script type="application/javascript"> |
michael@0 | 20 | <![CDATA[ |
michael@0 | 21 | //////////////////////////////////////////////////////////////////////////// |
michael@0 | 22 | // Invokers |
michael@0 | 23 | |
michael@0 | 24 | const kRecreated = 0; |
michael@0 | 25 | const kTextRemoved = 1; |
michael@0 | 26 | const kTextChanged = 2; |
michael@0 | 27 | |
michael@0 | 28 | const kNoValue = 0; |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * Set/remove @value attribute. |
michael@0 | 32 | */ |
michael@0 | 33 | function setValue(aID, aValue, aResult, aOldValue) |
michael@0 | 34 | { |
michael@0 | 35 | this.labelNode = getNode(aID); |
michael@0 | 36 | |
michael@0 | 37 | this.eventSeq = []; |
michael@0 | 38 | |
michael@0 | 39 | switch (aResult) { |
michael@0 | 40 | case kRecreated: |
michael@0 | 41 | this.eventSeq.push(new invokerChecker(EVENT_HIDE, this.labelNode)); |
michael@0 | 42 | this.eventSeq.push(new invokerChecker(EVENT_SHOW, this.labelNode)); |
michael@0 | 43 | break; |
michael@0 | 44 | case kTextRemoved: |
michael@0 | 45 | this.eventSeq.push( |
michael@0 | 46 | new textChangeChecker(this.labelNode, 0, aOldValue.length, |
michael@0 | 47 | aOldValue, false)); |
michael@0 | 48 | break; |
michael@0 | 49 | case kTextChanged: |
michael@0 | 50 | this.eventSeq.push( |
michael@0 | 51 | new textChangeChecker(this.labelNode, 0, aOldValue.length, |
michael@0 | 52 | aOldValue, false)); |
michael@0 | 53 | this.eventSeq.push( |
michael@0 | 54 | new textChangeChecker(this.labelNode, 0, aValue.length, |
michael@0 | 55 | aValue, true)); |
michael@0 | 56 | break; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | this.invoke = function setValue_invoke() |
michael@0 | 60 | { |
michael@0 | 61 | if (aValue === kNoValue) |
michael@0 | 62 | this.labelNode.removeAttribute("value"); |
michael@0 | 63 | else |
michael@0 | 64 | this.labelNode.setAttribute("value", aValue); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | this.finalCheck = function setValue_finalCheck() |
michael@0 | 68 | { |
michael@0 | 69 | var tree = |
michael@0 | 70 | { LABEL: [ |
michael@0 | 71 | { TEXT_LEAF: [ ] } |
michael@0 | 72 | ] }; |
michael@0 | 73 | testAccessibleTree(aID, tree); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | this.getID = function setValue_getID() |
michael@0 | 77 | { |
michael@0 | 78 | return "set @value='" + aValue + "' for label " + prettyName(aID); |
michael@0 | 79 | } |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | /** |
michael@0 | 83 | * Change @crop attribute. |
michael@0 | 84 | */ |
michael@0 | 85 | function setCrop(aID, aCropValue, aRemovedText, aInsertedText) |
michael@0 | 86 | { |
michael@0 | 87 | this.labelNode = getNode(aID); |
michael@0 | 88 | this.width = this.labelNode.boxObject.width; |
michael@0 | 89 | this.charWidth = this.width / this.labelNode.value.length; |
michael@0 | 90 | |
michael@0 | 91 | this.eventSeq = [ |
michael@0 | 92 | new textChangeChecker(this.labelNode, 0, -1, aRemovedText, false), |
michael@0 | 93 | new textChangeChecker(this.labelNode, 0, -1, aInsertedText, true) |
michael@0 | 94 | ]; |
michael@0 | 95 | |
michael@0 | 96 | this.invoke = function setCrop_invoke() |
michael@0 | 97 | { |
michael@0 | 98 | if (!this.labelNode.hasAttribute("crop")) |
michael@0 | 99 | this.labelNode.width = Math.floor(this.width - 2 * this.charWidth); |
michael@0 | 100 | |
michael@0 | 101 | this.labelNode.setAttribute("crop", aCropValue); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | this.getID = function setCrop_finalCheck() |
michael@0 | 105 | { |
michael@0 | 106 | return "set crop " + aCropValue; |
michael@0 | 107 | } |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | //////////////////////////////////////////////////////////////////////////// |
michael@0 | 111 | // Test |
michael@0 | 112 | |
michael@0 | 113 | gA11yEventDumpToConsole = true; |
michael@0 | 114 | |
michael@0 | 115 | var gQueue = null; |
michael@0 | 116 | function doTest() |
michael@0 | 117 | { |
michael@0 | 118 | gQueue = new eventQueue(); |
michael@0 | 119 | |
michael@0 | 120 | gQueue.push(new setValue("label", "shiroka strana", kRecreated)); |
michael@0 | 121 | gQueue.push(new setValue("label", "?<>!+_", kTextChanged, "shiroka strana")); |
michael@0 | 122 | gQueue.push(new setValue("label", "", kTextRemoved, "?<>!+_")); |
michael@0 | 123 | gQueue.push(new setValue("label", kNoValue, kRecreated)); |
michael@0 | 124 | |
michael@0 | 125 | gQueue.push(new setValue("descr", "hello world", kRecreated)); |
michael@0 | 126 | gQueue.push(new setValue("descr", "si_ya", kTextChanged, "hello world")); |
michael@0 | 127 | gQueue.push(new setValue("descr", "", kTextRemoved, "si_ya")); |
michael@0 | 128 | gQueue.push(new setValue("descr", kNoValue, kRecreated)); |
michael@0 | 129 | |
michael@0 | 130 | if (MAC) { |
michael@0 | 131 | // "valuetocro" -> "…etocro" |
michael@0 | 132 | gQueue.push(new setCrop("croplabel", "left", "valu", "…")); |
michael@0 | 133 | // "…etocro", "val…cro" |
michael@0 | 134 | gQueue.push(new setCrop("croplabel", "center", "…eto", "val…")); |
michael@0 | 135 | } else { |
michael@0 | 136 | // "valuetocro" -> "…uetocro" |
michael@0 | 137 | gQueue.push(new setCrop("croplabel", "left", "val", "…")); |
michael@0 | 138 | // "…uetocro" -> "valu…cro" |
michael@0 | 139 | gQueue.push(new setCrop("croplabel", "center", "…ueto", "valu…")); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | gQueue.invoke(); // Will call SimpleTest.finish(); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 146 | addA11yLoadEvent(doTest); |
michael@0 | 147 | ]]> |
michael@0 | 148 | </script> |
michael@0 | 149 | |
michael@0 | 150 | <hbox flex="1" style="overflow: auto;"> |
michael@0 | 151 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 152 | <a target="_blank" |
michael@0 | 153 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=396166" |
michael@0 | 154 | title="xul:label@value accessible should implement nsIAccessibleText"> |
michael@0 | 155 | Bug 396166 |
michael@0 | 156 | </a> |
michael@0 | 157 | <br/> |
michael@0 | 158 | <p id="display"></p> |
michael@0 | 159 | <div id="content" style="display: none"> |
michael@0 | 160 | </div> |
michael@0 | 161 | <pre id="test"> |
michael@0 | 162 | </pre> |
michael@0 | 163 | </body> |
michael@0 | 164 | |
michael@0 | 165 | <vbox flex="1"> |
michael@0 | 166 | <label id="label">hello</label> |
michael@0 | 167 | <description id="descr">hello</description> |
michael@0 | 168 | |
michael@0 | 169 | <hbox> |
michael@0 | 170 | <label id="croplabel" value="valuetocro" |
michael@0 | 171 | style="font-family: monospace;"/> |
michael@0 | 172 | </hbox> |
michael@0 | 173 | </vbox> |
michael@0 | 174 | </hbox> |
michael@0 | 175 | |
michael@0 | 176 | </window> |
michael@0 | 177 |