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