Wed, 31 Dec 2014 06:09:35 +0100
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>Text selection testing</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 | |
michael@0 | 12 | <script type="application/javascript" |
michael@0 | 13 | src="../common.js"></script> |
michael@0 | 14 | <script type="application/javascript" |
michael@0 | 15 | src="../events.js"></script> |
michael@0 | 16 | |
michael@0 | 17 | <script type="application/javascript"> |
michael@0 | 18 | /** |
michael@0 | 19 | * Invokers |
michael@0 | 20 | */ |
michael@0 | 21 | function addSelection(aID, aStartOffset, aEndOffset) |
michael@0 | 22 | { |
michael@0 | 23 | this.hyperTextNode = getNode(aID); |
michael@0 | 24 | this.hyperText = getAccessible(aID, [ nsIAccessibleText ]); |
michael@0 | 25 | |
michael@0 | 26 | this.eventSeq = [ |
michael@0 | 27 | new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID) |
michael@0 | 28 | ]; |
michael@0 | 29 | |
michael@0 | 30 | this.invoke = function addSelection_invoke() |
michael@0 | 31 | { |
michael@0 | 32 | this.hyperText.addSelection(aStartOffset, aEndOffset); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | this.finalCheck = function addSelection_finalCheck() |
michael@0 | 36 | { |
michael@0 | 37 | is(this.hyperText.selectionCount, 1, |
michael@0 | 38 | "addSelection: Wrong selection count for " + aID); |
michael@0 | 39 | var startOffset = {}, endOffset = {}; |
michael@0 | 40 | this.hyperText.getSelectionBounds(0, startOffset, endOffset); |
michael@0 | 41 | |
michael@0 | 42 | is(startOffset.value, aStartOffset, |
michael@0 | 43 | "addSelection: Wrong start offset for " + aID); |
michael@0 | 44 | is(endOffset.value, aEndOffset, |
michael@0 | 45 | "addSelection: Wrong end offset for " + aID); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | this.getID = function addSelection_getID() |
michael@0 | 49 | { |
michael@0 | 50 | return "nsIAccessibleText::addSelection test for " + aID; |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function changeSelection(aID, aStartOffset, aEndOffset) |
michael@0 | 55 | { |
michael@0 | 56 | this.hyperTextNode = getNode(aID); |
michael@0 | 57 | this.hyperText = getAccessible(aID, [ nsIAccessibleText ]); |
michael@0 | 58 | |
michael@0 | 59 | this.eventSeq = [ |
michael@0 | 60 | new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID) |
michael@0 | 61 | ]; |
michael@0 | 62 | |
michael@0 | 63 | this.invoke = function changeSelection_invoke() |
michael@0 | 64 | { |
michael@0 | 65 | this.hyperText.setSelectionBounds(0, aStartOffset, aEndOffset); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | this.finalCheck = function changeSelection_finalCheck() |
michael@0 | 69 | { |
michael@0 | 70 | is(this.hyperText.selectionCount, 1, |
michael@0 | 71 | "setSelectionBounds: Wrong selection count for " + aID); |
michael@0 | 72 | var startOffset = {}, endOffset = {}; |
michael@0 | 73 | this.hyperText.getSelectionBounds(0, startOffset, endOffset); |
michael@0 | 74 | |
michael@0 | 75 | is(startOffset.value, aStartOffset, |
michael@0 | 76 | "setSelectionBounds: Wrong start offset for " + aID); |
michael@0 | 77 | is(endOffset.value, aEndOffset, |
michael@0 | 78 | "setSelectionBounds: Wrong end offset for " + aID); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | this.getID = function changeSelection_getID() |
michael@0 | 82 | { |
michael@0 | 83 | return "nsIAccessibleText::setSelectionBounds test for " + aID; |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function removeSelection(aID) |
michael@0 | 88 | { |
michael@0 | 89 | this.hyperText = getAccessible(aID, [ nsIAccessibleText ]); |
michael@0 | 90 | |
michael@0 | 91 | this.eventSeq = [ |
michael@0 | 92 | new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, document) |
michael@0 | 93 | ]; |
michael@0 | 94 | |
michael@0 | 95 | this.invoke = function removeSelection_invoke() |
michael@0 | 96 | { |
michael@0 | 97 | this.hyperText.removeSelection(0); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | this.finalCheck = function removeSelection_finalCheck() |
michael@0 | 101 | { |
michael@0 | 102 | is(this.hyperText.selectionCount, 0, |
michael@0 | 103 | "removeSelection: Wrong selection count for " + aID); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | this.getID = function removeSelection_getID() |
michael@0 | 107 | { |
michael@0 | 108 | return "nsIAccessibleText::removeSelection test for " + aID; |
michael@0 | 109 | } |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | function changeDOMSelection(aID, aNodeID1, aNodeOffset1, |
michael@0 | 113 | aNodeID2, aNodeOffset2, |
michael@0 | 114 | aStartOffset, aEndOffset) |
michael@0 | 115 | { |
michael@0 | 116 | this.hyperText = getAccessible(aID, [ nsIAccessibleText ]); |
michael@0 | 117 | |
michael@0 | 118 | this.eventSeq = [ |
michael@0 | 119 | new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID) |
michael@0 | 120 | ]; |
michael@0 | 121 | |
michael@0 | 122 | this.invoke = function changeDOMSelection_invoke() |
michael@0 | 123 | { |
michael@0 | 124 | var sel = window.getSelection(); |
michael@0 | 125 | var range = document.createRange(); |
michael@0 | 126 | range.setStart(getNode(aNodeID1), aNodeOffset1); |
michael@0 | 127 | range.setEnd(getNode(aNodeID2), aNodeOffset2); |
michael@0 | 128 | sel.addRange(range); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | this.finalCheck = function changeDOMSelection_finalCheck() |
michael@0 | 132 | { |
michael@0 | 133 | is(this.hyperText.selectionCount, 1, |
michael@0 | 134 | "setSelectionBounds: Wrong selection count for " + aID); |
michael@0 | 135 | var startOffset = {}, endOffset = {}; |
michael@0 | 136 | this.hyperText.getSelectionBounds(0, startOffset, endOffset); |
michael@0 | 137 | |
michael@0 | 138 | is(startOffset.value, aStartOffset, |
michael@0 | 139 | "setSelectionBounds: Wrong start offset for " + aID); |
michael@0 | 140 | is(endOffset.value, aEndOffset, |
michael@0 | 141 | "setSelectionBounds: Wrong end offset for " + aID); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | this.getID = function changeDOMSelection_getID() |
michael@0 | 145 | { |
michael@0 | 146 | return "DOM selection change for " + aID; |
michael@0 | 147 | } |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | function onfocusEventSeq(aID) |
michael@0 | 151 | { |
michael@0 | 152 | var caretMovedChecker = |
michael@0 | 153 | new invokerChecker(EVENT_TEXT_CARET_MOVED, aID); |
michael@0 | 154 | var selChangedChecker = |
michael@0 | 155 | new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID); |
michael@0 | 156 | selChangedChecker.unexpected = true; |
michael@0 | 157 | |
michael@0 | 158 | return [ caretMovedChecker, selChangedChecker ]; |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | /** |
michael@0 | 162 | * Do tests |
michael@0 | 163 | */ |
michael@0 | 164 | |
michael@0 | 165 | //gA11yEventDumpToConsole = true; // debug stuff |
michael@0 | 166 | |
michael@0 | 167 | var gQueue = null; |
michael@0 | 168 | function doTests() |
michael@0 | 169 | { |
michael@0 | 170 | gQueue = new eventQueue(); |
michael@0 | 171 | |
michael@0 | 172 | gQueue.push(new addSelection("paragraph", 1, 3)); |
michael@0 | 173 | gQueue.push(new changeSelection("paragraph", 2, 4)); |
michael@0 | 174 | gQueue.push(new removeSelection("paragraph")); |
michael@0 | 175 | |
michael@0 | 176 | gQueue.push(new synthFocus("textbox", onfocusEventSeq("textbox"))); |
michael@0 | 177 | gQueue.push(new changeSelection("textbox", 1, 3)); |
michael@0 | 178 | |
michael@0 | 179 | gQueue.push(new synthFocus("textarea", onfocusEventSeq("textarea"))); |
michael@0 | 180 | gQueue.push(new changeSelection("textarea", 1, 3)); |
michael@0 | 181 | |
michael@0 | 182 | gQueue.push(new changeDOMSelection("c1", "c1_span1", 0, "c1_span2", 0, 2, 2)); |
michael@0 | 183 | gQueue.invoke(); // Will call SimpleTest.finish(); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 187 | addA11yLoadEvent(doTests); |
michael@0 | 188 | </script> |
michael@0 | 189 | </head> |
michael@0 | 190 | |
michael@0 | 191 | <body> |
michael@0 | 192 | |
michael@0 | 193 | <a target="_blank" |
michael@0 | 194 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=688126" |
michael@0 | 195 | title="nsIAccessibleText::setSelectionBounds doesn't fire text selection changed events in some cases"> |
michael@0 | 196 | Bug 688126 |
michael@0 | 197 | </a> |
michael@0 | 198 | <a target="_blank" |
michael@0 | 199 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=688124" |
michael@0 | 200 | title="no text selection changed event when selection is removed"> |
michael@0 | 201 | Bug 688124 |
michael@0 | 202 | </a> |
michael@0 | 203 | <p id="display"></p> |
michael@0 | 204 | <div id="content" style="display: none"></div> |
michael@0 | 205 | <pre id="test"> |
michael@0 | 206 | </pre> |
michael@0 | 207 | |
michael@0 | 208 | <p id="paragraph">hello</p> |
michael@0 | 209 | <input id="textbox" value="hello"/> |
michael@0 | 210 | <textarea id="textarea">hello</textarea> |
michael@0 | 211 | <div id="c1">hi<span id="c1_span1"></span><span id="c1_span2"></span>hi</div> |
michael@0 | 212 | |
michael@0 | 213 | </body> |
michael@0 | 214 | </html> |