1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/tests/mochitest/relations/test_update.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,234 @@ 1.4 +<html> 1.5 + 1.6 +<head> 1.7 + <title>Test updating of accessible relations</title> 1.8 + <link rel="stylesheet" type="text/css" 1.9 + href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.10 + 1.11 + <script type="application/javascript" 1.12 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.13 + 1.14 + <script type="application/javascript" 1.15 + src="../common.js"></script> 1.16 + <script type="application/javascript" 1.17 + src="../relations.js"></script> 1.18 + <script type="application/javascript" 1.19 + src="../role.js"></script> 1.20 + <script type="application/javascript" 1.21 + src="../events.js"></script> 1.22 + 1.23 + <script type="application/javascript"> 1.24 + function testRelated(aRelAttr, aHostRelation, aDependentRelation, 1.25 + aHostID, aHostNodeID, aDependent1ID, aDependent2ID) 1.26 + { 1.27 + // no attribute 1.28 + testRelation(aDependent1ID, aDependentRelation, null); 1.29 + testRelation(aDependent2ID, aDependentRelation, null); 1.30 + if (aHostRelation) 1.31 + testRelation(aHostID, aHostRelation, null); 1.32 + 1.33 + // set attribute 1.34 + getNode(aHostNodeID).setAttribute(aRelAttr, aDependent1ID); 1.35 + testRelation(aDependent1ID, aDependentRelation, aHostID); 1.36 + testRelation(aDependent2ID, aDependentRelation, null); 1.37 + if (aHostRelation) 1.38 + testRelation(aHostID, aHostRelation, aDependent1ID); 1.39 + 1.40 + // change attribute 1.41 + getNode(aHostNodeID).setAttribute(aRelAttr, aDependent2ID); 1.42 + testRelation(aDependent1ID, aDependentRelation, null); 1.43 + testRelation(aDependent2ID, aDependentRelation, aHostID); 1.44 + if (aHostRelation) 1.45 + testRelation(aHostID, aHostRelation, aDependent2ID); 1.46 + 1.47 + // remove attribute 1.48 + getNode(aHostNodeID).removeAttribute(aRelAttr); 1.49 + testRelation(aDependent1ID, aDependentRelation, null); 1.50 + testRelation(aDependent2ID, aDependentRelation, null); 1.51 + if (aHostRelation) 1.52 + testRelation(aHostID, aHostRelation, null); 1.53 + } 1.54 + 1.55 + function insertRelated(aHostRelAttr, aDependentID, aInsertHostFirst, 1.56 + aHostRelation, aDependentRelation) 1.57 + { 1.58 + this.eventSeq = [ 1.59 + new invokerChecker(EVENT_REORDER, document) 1.60 + ]; 1.61 + 1.62 + this.invoke = function insertRelated_invoke() 1.63 + { 1.64 + this.hostNode = document.createElement("div"); 1.65 + this.hostNode.setAttribute(aHostRelAttr, aDependentID); 1.66 + 1.67 + this.dependentNode = document.createElement("div"); 1.68 + this.dependentNode.setAttribute("id", aDependentID); 1.69 + 1.70 + if (aInsertHostFirst) { 1.71 + document.body.appendChild(this.hostNode); 1.72 + document.body.appendChild(this.dependentNode); 1.73 + } else { 1.74 + document.body.appendChild(this.dependentNode); 1.75 + document.body.appendChild(this.hostNode); 1.76 + } 1.77 + } 1.78 + 1.79 + this.finalCheck = function insertRelated_finalCheck() 1.80 + { 1.81 + testRelation(this.dependentNode, aDependentRelation, this.hostNode); 1.82 + if (aHostRelation) 1.83 + testRelation(this.hostNode, aHostRelation, this.dependentNode); 1.84 + } 1.85 + 1.86 + this.getID = function insertRelated_getID() 1.87 + { 1.88 + return "Insert " + aHostRelAttr + "='" + aDependentID + "' node" + 1.89 + (aInsertHostFirst ? " before" : "after") + " dependent node"; 1.90 + } 1.91 + } 1.92 + 1.93 + /** 1.94 + * Relative accessible recreation shouldn't break accessible relations. 1.95 + * Note: modify this case if the invoke function doesn't change accessible 1.96 + * tree due to changes in layout module. It can be changed on any case 1.97 + * when accessibles are recreated. 1.98 + */ 1.99 + function recreateRelatives(aContainerID, aLabelID, aElmID) 1.100 + { 1.101 + this.containerNode = getNode(aContainerID); 1.102 + this.container = getNode(this.containerNode); 1.103 + 1.104 + this.eventSeq = [ 1.105 + new invokerChecker(EVENT_HIDE, this.container), 1.106 + new invokerChecker(EVENT_SHOW, this.containerNode) 1.107 + ]; 1.108 + 1.109 + this.invoke = function recreateRelatives_invoke() 1.110 + { 1.111 + testRelation(aLabelID, RELATION_LABEL_FOR, aElmID); 1.112 + testRelation(aElmID, RELATION_LABELLED_BY, aLabelID); 1.113 + 1.114 + this.containerNode.style.overflow = "visible"; 1.115 + } 1.116 + 1.117 + this.finalCheck = function recreateRelatives_finalCheck() 1.118 + { 1.119 + testRelation(aLabelID, RELATION_LABEL_FOR, aElmID); 1.120 + testRelation(aElmID, RELATION_LABELLED_BY, aLabelID); 1.121 + } 1.122 + 1.123 + this.getID = function recreateRelatives_getID() 1.124 + { 1.125 + return "recreate relatives "; 1.126 + } 1.127 + } 1.128 + 1.129 + //gA11yEventDumpToConsole = true; // debug 1.130 + 1.131 + var gQueue = null; 1.132 + 1.133 + function doTest() 1.134 + { 1.135 + // Relation updates on ARIA attribute changes. 1.136 + testRelated("aria-labelledby", 1.137 + RELATION_LABELLED_BY, RELATION_LABEL_FOR, 1.138 + "host", "host", "dependent1", "dependent2"); 1.139 + 1.140 + testRelated("aria-describedby", 1.141 + RELATION_DESCRIBED_BY, RELATION_DESCRIPTION_FOR, 1.142 + "host", "host", "dependent1", "dependent2"); 1.143 + 1.144 + testRelated("aria-owns", 1.145 + null, RELATION_NODE_CHILD_OF, 1.146 + "host", "host", "dependent1", "dependent2"); 1.147 + 1.148 + testRelated("aria-controls", 1.149 + RELATION_CONTROLLER_FOR, RELATION_CONTROLLED_BY, 1.150 + "host", "host", "dependent1", "dependent2"); 1.151 + 1.152 + testRelated("aria-flowto", 1.153 + RELATION_FLOWS_TO, RELATION_FLOWS_FROM, 1.154 + "host", "host", "dependent1", "dependent2"); 1.155 + 1.156 + // Document relation updates on ARIA attribute change. 1.157 + testRelated("aria-labelledby", 1.158 + RELATION_LABELLED_BY, RELATION_LABEL_FOR, 1.159 + document, "body", "dependent1", "dependent2"); 1.160 + 1.161 + // Insert related accessibles into tree. 1.162 + gQueue = new eventQueue(); 1.163 + gQueue.push(new insertRelated("aria-labelledby", "dependent3", true, 1.164 + RELATION_LABELLED_BY, RELATION_LABEL_FOR)); 1.165 + gQueue.push(new insertRelated("aria-labelledby", "dependent4", false, 1.166 + RELATION_LABELLED_BY, RELATION_LABEL_FOR)); 1.167 + 1.168 + gQueue.push(new insertRelated("aria-describedby", "dependent5", true, 1.169 + RELATION_DESCRIBED_BY, 1.170 + RELATION_DESCRIPTION_FOR)); 1.171 + gQueue.push(new insertRelated("aria-describedby", "dependent6", false, 1.172 + RELATION_DESCRIBED_BY, 1.173 + RELATION_DESCRIPTION_FOR)); 1.174 + 1.175 + gQueue.push(new insertRelated("aria-owns", "dependent7", true, 1.176 + null, RELATION_NODE_CHILD_OF)); 1.177 + gQueue.push(new insertRelated("aria-owns", "dependent8", false, 1.178 + null, RELATION_NODE_CHILD_OF)); 1.179 + 1.180 + gQueue.push(new insertRelated("aria-controls", "dependent9", true, 1.181 + RELATION_CONTROLLER_FOR, 1.182 + RELATION_CONTROLLED_BY)); 1.183 + gQueue.push(new insertRelated("aria-controls", "dependent10", false, 1.184 + RELATION_CONTROLLER_FOR, 1.185 + RELATION_CONTROLLED_BY)); 1.186 + 1.187 + gQueue.push(new insertRelated("aria-flowto", "dependent11", true, 1.188 + RELATION_FLOWS_TO, RELATION_FLOWS_FROM)); 1.189 + gQueue.push(new insertRelated("aria-flowto", "dependent12", false, 1.190 + RELATION_FLOWS_TO, RELATION_FLOWS_FROM)); 1.191 + 1.192 + // Update relations when accessibles are recreated 1.193 + gQueue.push(new recreateRelatives("container", "label", "input")); 1.194 + 1.195 + gQueue.invoke(); // will call SimpleTest.finish() 1.196 + 1.197 + } 1.198 + 1.199 + SimpleTest.waitForExplicitFinish(); 1.200 + addA11yLoadEvent(doTest); 1.201 + </script> 1.202 + 1.203 +</head> 1.204 + 1.205 +<body id="body"> 1.206 + 1.207 + <a target="_blank" 1.208 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=573469" 1.209 + title="Cache relations defined by ARIA attributes"> 1.210 + Mozilla Bug 573469 1.211 + </a> 1.212 + <a target="_blank" 1.213 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=631068" 1.214 + title="Accessible recreation breaks relations"> 1.215 + Mozilla Bug 631068 1.216 + </a> 1.217 + <a target="_blank" 1.218 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=635346" 1.219 + title="Allow relations for document defined on document content"> 1.220 + Mozilla Bug 635346 1.221 + </a> 1.222 + <br> 1.223 + <p id="display"></p> 1.224 + <div id="content" style="display: none"></div> 1.225 + <pre id="test"> 1.226 + </pre> 1.227 + 1.228 + <div id="dependent1">label</div> 1.229 + <div id="dependent2">label2</div> 1.230 + <div role="checkbox" id="host"></div> 1.231 + 1.232 + <form id="container" style="overflow: hidden;"> 1.233 + <label for="input" id="label">label</label> 1.234 + <input id="input"> 1.235 + </form> 1.236 +</body> 1.237 +</html>