1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/tests/mochitest/events/test_label.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,177 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.7 + type="text/css"?> 1.8 + 1.9 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.10 + title="Tests: accessible XUL label/description events"> 1.11 + 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> 1.14 + 1.15 + <script type="application/javascript" 1.16 + src="../common.js" /> 1.17 + <script type="application/javascript" 1.18 + src="../role.js" /> 1.19 + <script type="application/javascript" 1.20 + src="../events.js" /> 1.21 + 1.22 + <script type="application/javascript"> 1.23 + <![CDATA[ 1.24 + //////////////////////////////////////////////////////////////////////////// 1.25 + // Invokers 1.26 + 1.27 + const kRecreated = 0; 1.28 + const kTextRemoved = 1; 1.29 + const kTextChanged = 2; 1.30 + 1.31 + const kNoValue = 0; 1.32 + 1.33 + /** 1.34 + * Set/remove @value attribute. 1.35 + */ 1.36 + function setValue(aID, aValue, aResult, aOldValue) 1.37 + { 1.38 + this.labelNode = getNode(aID); 1.39 + 1.40 + this.eventSeq = []; 1.41 + 1.42 + switch (aResult) { 1.43 + case kRecreated: 1.44 + this.eventSeq.push(new invokerChecker(EVENT_HIDE, this.labelNode)); 1.45 + this.eventSeq.push(new invokerChecker(EVENT_SHOW, this.labelNode)); 1.46 + break; 1.47 + case kTextRemoved: 1.48 + this.eventSeq.push( 1.49 + new textChangeChecker(this.labelNode, 0, aOldValue.length, 1.50 + aOldValue, false)); 1.51 + break; 1.52 + case kTextChanged: 1.53 + this.eventSeq.push( 1.54 + new textChangeChecker(this.labelNode, 0, aOldValue.length, 1.55 + aOldValue, false)); 1.56 + this.eventSeq.push( 1.57 + new textChangeChecker(this.labelNode, 0, aValue.length, 1.58 + aValue, true)); 1.59 + break; 1.60 + } 1.61 + 1.62 + this.invoke = function setValue_invoke() 1.63 + { 1.64 + if (aValue === kNoValue) 1.65 + this.labelNode.removeAttribute("value"); 1.66 + else 1.67 + this.labelNode.setAttribute("value", aValue); 1.68 + } 1.69 + 1.70 + this.finalCheck = function setValue_finalCheck() 1.71 + { 1.72 + var tree = 1.73 + { LABEL: [ 1.74 + { TEXT_LEAF: [ ] } 1.75 + ] }; 1.76 + testAccessibleTree(aID, tree); 1.77 + } 1.78 + 1.79 + this.getID = function setValue_getID() 1.80 + { 1.81 + return "set @value='" + aValue + "' for label " + prettyName(aID); 1.82 + } 1.83 + } 1.84 + 1.85 + /** 1.86 + * Change @crop attribute. 1.87 + */ 1.88 + function setCrop(aID, aCropValue, aRemovedText, aInsertedText) 1.89 + { 1.90 + this.labelNode = getNode(aID); 1.91 + this.width = this.labelNode.boxObject.width; 1.92 + this.charWidth = this.width / this.labelNode.value.length; 1.93 + 1.94 + this.eventSeq = [ 1.95 + new textChangeChecker(this.labelNode, 0, -1, aRemovedText, false), 1.96 + new textChangeChecker(this.labelNode, 0, -1, aInsertedText, true) 1.97 + ]; 1.98 + 1.99 + this.invoke = function setCrop_invoke() 1.100 + { 1.101 + if (!this.labelNode.hasAttribute("crop")) 1.102 + this.labelNode.width = Math.floor(this.width - 2 * this.charWidth); 1.103 + 1.104 + this.labelNode.setAttribute("crop", aCropValue); 1.105 + } 1.106 + 1.107 + this.getID = function setCrop_finalCheck() 1.108 + { 1.109 + return "set crop " + aCropValue; 1.110 + } 1.111 + } 1.112 + 1.113 + //////////////////////////////////////////////////////////////////////////// 1.114 + // Test 1.115 + 1.116 + gA11yEventDumpToConsole = true; 1.117 + 1.118 + var gQueue = null; 1.119 + function doTest() 1.120 + { 1.121 + gQueue = new eventQueue(); 1.122 + 1.123 + gQueue.push(new setValue("label", "shiroka strana", kRecreated)); 1.124 + gQueue.push(new setValue("label", "?<>!+_", kTextChanged, "shiroka strana")); 1.125 + gQueue.push(new setValue("label", "", kTextRemoved, "?<>!+_")); 1.126 + gQueue.push(new setValue("label", kNoValue, kRecreated)); 1.127 + 1.128 + gQueue.push(new setValue("descr", "hello world", kRecreated)); 1.129 + gQueue.push(new setValue("descr", "si_ya", kTextChanged, "hello world")); 1.130 + gQueue.push(new setValue("descr", "", kTextRemoved, "si_ya")); 1.131 + gQueue.push(new setValue("descr", kNoValue, kRecreated)); 1.132 + 1.133 + if (MAC) { 1.134 + // "valuetocro" -> "…etocro" 1.135 + gQueue.push(new setCrop("croplabel", "left", "valu", "…")); 1.136 + // "…etocro", "val…cro" 1.137 + gQueue.push(new setCrop("croplabel", "center", "…eto", "val…")); 1.138 + } else { 1.139 + // "valuetocro" -> "…uetocro" 1.140 + gQueue.push(new setCrop("croplabel", "left", "val", "…")); 1.141 + // "…uetocro" -> "valu…cro" 1.142 + gQueue.push(new setCrop("croplabel", "center", "…ueto", "valu…")); 1.143 + } 1.144 + 1.145 + gQueue.invoke(); // Will call SimpleTest.finish(); 1.146 + } 1.147 + 1.148 + SimpleTest.waitForExplicitFinish(); 1.149 + addA11yLoadEvent(doTest); 1.150 + ]]> 1.151 + </script> 1.152 + 1.153 + <hbox flex="1" style="overflow: auto;"> 1.154 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.155 + <a target="_blank" 1.156 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=396166" 1.157 + title="xul:label@value accessible should implement nsIAccessibleText"> 1.158 + Bug 396166 1.159 + </a> 1.160 + <br/> 1.161 + <p id="display"></p> 1.162 + <div id="content" style="display: none"> 1.163 + </div> 1.164 + <pre id="test"> 1.165 + </pre> 1.166 + </body> 1.167 + 1.168 + <vbox flex="1"> 1.169 + <label id="label">hello</label> 1.170 + <description id="descr">hello</description> 1.171 + 1.172 + <hbox> 1.173 + <label id="croplabel" value="valuetocro" 1.174 + style="font-family: monospace;"/> 1.175 + </hbox> 1.176 + </vbox> 1.177 + </hbox> 1.178 + 1.179 +</window> 1.180 +