1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/tests/mochitest/textselection/test_general.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,214 @@ 1.4 +<html> 1.5 + 1.6 +<head> 1.7 + <title>Text selection testing</title> 1.8 + 1.9 + <link rel="stylesheet" type="text/css" 1.10 + href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.11 + 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.14 + 1.15 + <script type="application/javascript" 1.16 + src="../common.js"></script> 1.17 + <script type="application/javascript" 1.18 + src="../events.js"></script> 1.19 + 1.20 + <script type="application/javascript"> 1.21 + /** 1.22 + * Invokers 1.23 + */ 1.24 + function addSelection(aID, aStartOffset, aEndOffset) 1.25 + { 1.26 + this.hyperTextNode = getNode(aID); 1.27 + this.hyperText = getAccessible(aID, [ nsIAccessibleText ]); 1.28 + 1.29 + this.eventSeq = [ 1.30 + new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID) 1.31 + ]; 1.32 + 1.33 + this.invoke = function addSelection_invoke() 1.34 + { 1.35 + this.hyperText.addSelection(aStartOffset, aEndOffset); 1.36 + } 1.37 + 1.38 + this.finalCheck = function addSelection_finalCheck() 1.39 + { 1.40 + is(this.hyperText.selectionCount, 1, 1.41 + "addSelection: Wrong selection count for " + aID); 1.42 + var startOffset = {}, endOffset = {}; 1.43 + this.hyperText.getSelectionBounds(0, startOffset, endOffset); 1.44 + 1.45 + is(startOffset.value, aStartOffset, 1.46 + "addSelection: Wrong start offset for " + aID); 1.47 + is(endOffset.value, aEndOffset, 1.48 + "addSelection: Wrong end offset for " + aID); 1.49 + } 1.50 + 1.51 + this.getID = function addSelection_getID() 1.52 + { 1.53 + return "nsIAccessibleText::addSelection test for " + aID; 1.54 + } 1.55 + } 1.56 + 1.57 + function changeSelection(aID, aStartOffset, aEndOffset) 1.58 + { 1.59 + this.hyperTextNode = getNode(aID); 1.60 + this.hyperText = getAccessible(aID, [ nsIAccessibleText ]); 1.61 + 1.62 + this.eventSeq = [ 1.63 + new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID) 1.64 + ]; 1.65 + 1.66 + this.invoke = function changeSelection_invoke() 1.67 + { 1.68 + this.hyperText.setSelectionBounds(0, aStartOffset, aEndOffset); 1.69 + } 1.70 + 1.71 + this.finalCheck = function changeSelection_finalCheck() 1.72 + { 1.73 + is(this.hyperText.selectionCount, 1, 1.74 + "setSelectionBounds: Wrong selection count for " + aID); 1.75 + var startOffset = {}, endOffset = {}; 1.76 + this.hyperText.getSelectionBounds(0, startOffset, endOffset); 1.77 + 1.78 + is(startOffset.value, aStartOffset, 1.79 + "setSelectionBounds: Wrong start offset for " + aID); 1.80 + is(endOffset.value, aEndOffset, 1.81 + "setSelectionBounds: Wrong end offset for " + aID); 1.82 + } 1.83 + 1.84 + this.getID = function changeSelection_getID() 1.85 + { 1.86 + return "nsIAccessibleText::setSelectionBounds test for " + aID; 1.87 + } 1.88 + } 1.89 + 1.90 + function removeSelection(aID) 1.91 + { 1.92 + this.hyperText = getAccessible(aID, [ nsIAccessibleText ]); 1.93 + 1.94 + this.eventSeq = [ 1.95 + new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, document) 1.96 + ]; 1.97 + 1.98 + this.invoke = function removeSelection_invoke() 1.99 + { 1.100 + this.hyperText.removeSelection(0); 1.101 + } 1.102 + 1.103 + this.finalCheck = function removeSelection_finalCheck() 1.104 + { 1.105 + is(this.hyperText.selectionCount, 0, 1.106 + "removeSelection: Wrong selection count for " + aID); 1.107 + } 1.108 + 1.109 + this.getID = function removeSelection_getID() 1.110 + { 1.111 + return "nsIAccessibleText::removeSelection test for " + aID; 1.112 + } 1.113 + } 1.114 + 1.115 + function changeDOMSelection(aID, aNodeID1, aNodeOffset1, 1.116 + aNodeID2, aNodeOffset2, 1.117 + aStartOffset, aEndOffset) 1.118 + { 1.119 + this.hyperText = getAccessible(aID, [ nsIAccessibleText ]); 1.120 + 1.121 + this.eventSeq = [ 1.122 + new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID) 1.123 + ]; 1.124 + 1.125 + this.invoke = function changeDOMSelection_invoke() 1.126 + { 1.127 + var sel = window.getSelection(); 1.128 + var range = document.createRange(); 1.129 + range.setStart(getNode(aNodeID1), aNodeOffset1); 1.130 + range.setEnd(getNode(aNodeID2), aNodeOffset2); 1.131 + sel.addRange(range); 1.132 + } 1.133 + 1.134 + this.finalCheck = function changeDOMSelection_finalCheck() 1.135 + { 1.136 + is(this.hyperText.selectionCount, 1, 1.137 + "setSelectionBounds: Wrong selection count for " + aID); 1.138 + var startOffset = {}, endOffset = {}; 1.139 + this.hyperText.getSelectionBounds(0, startOffset, endOffset); 1.140 + 1.141 + is(startOffset.value, aStartOffset, 1.142 + "setSelectionBounds: Wrong start offset for " + aID); 1.143 + is(endOffset.value, aEndOffset, 1.144 + "setSelectionBounds: Wrong end offset for " + aID); 1.145 + } 1.146 + 1.147 + this.getID = function changeDOMSelection_getID() 1.148 + { 1.149 + return "DOM selection change for " + aID; 1.150 + } 1.151 + } 1.152 + 1.153 + function onfocusEventSeq(aID) 1.154 + { 1.155 + var caretMovedChecker = 1.156 + new invokerChecker(EVENT_TEXT_CARET_MOVED, aID); 1.157 + var selChangedChecker = 1.158 + new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID); 1.159 + selChangedChecker.unexpected = true; 1.160 + 1.161 + return [ caretMovedChecker, selChangedChecker ]; 1.162 + } 1.163 + 1.164 + /** 1.165 + * Do tests 1.166 + */ 1.167 + 1.168 + //gA11yEventDumpToConsole = true; // debug stuff 1.169 + 1.170 + var gQueue = null; 1.171 + function doTests() 1.172 + { 1.173 + gQueue = new eventQueue(); 1.174 + 1.175 + gQueue.push(new addSelection("paragraph", 1, 3)); 1.176 + gQueue.push(new changeSelection("paragraph", 2, 4)); 1.177 + gQueue.push(new removeSelection("paragraph")); 1.178 + 1.179 + gQueue.push(new synthFocus("textbox", onfocusEventSeq("textbox"))); 1.180 + gQueue.push(new changeSelection("textbox", 1, 3)); 1.181 + 1.182 + gQueue.push(new synthFocus("textarea", onfocusEventSeq("textarea"))); 1.183 + gQueue.push(new changeSelection("textarea", 1, 3)); 1.184 + 1.185 + gQueue.push(new changeDOMSelection("c1", "c1_span1", 0, "c1_span2", 0, 2, 2)); 1.186 + gQueue.invoke(); // Will call SimpleTest.finish(); 1.187 + } 1.188 + 1.189 + SimpleTest.waitForExplicitFinish(); 1.190 + addA11yLoadEvent(doTests); 1.191 + </script> 1.192 +</head> 1.193 + 1.194 +<body> 1.195 + 1.196 + <a target="_blank" 1.197 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=688126" 1.198 + title="nsIAccessibleText::setSelectionBounds doesn't fire text selection changed events in some cases"> 1.199 + Bug 688126 1.200 + </a> 1.201 + <a target="_blank" 1.202 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=688124" 1.203 + title="no text selection changed event when selection is removed"> 1.204 + Bug 688124 1.205 + </a> 1.206 + <p id="display"></p> 1.207 + <div id="content" style="display: none"></div> 1.208 + <pre id="test"> 1.209 + </pre> 1.210 + 1.211 + <p id="paragraph">hello</p> 1.212 + <input id="textbox" value="hello"/> 1.213 + <textarea id="textarea">hello</textarea> 1.214 + <div id="c1">hi<span id="c1_span1"></span><span id="c1_span2"></span>hi</div> 1.215 + 1.216 +</body> 1.217 +</html>