summaryrefslogtreecommitdiff
path: root/layout/generic/test/test_selection_expanding.html
blob: fad31a65d00979c1af8382b3597f2df0bf3266e1 (plain)
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<!DOCTYPE>
<html>
<head>
<title>selection expanding test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />

<style type="text/css">
  .testingDiv {
    font-size: 16px;
    width: 300px;
    height: 140px;
    background-color: white;
  }
  #fixedDiv1, #fixedDiv2 {
    position: fixed;
    right: 0;
    overflow: scroll;
    width: 200px;
  }
  #fixedDiv1 {
    top: 0;
  }
  #fixedDiv2 {
    top: 150px;
  }
  iframe, input, textarea {
    font-size: 16px;
    height: 16px;
    width: 80px;
    margin: 0;
    padding: 0;
  }
  #xbl {
    -moz-binding: url(selection_expanding_xbl.xml#binding);
  }
</style>

</head>
<body>
<div id="div1" class="testingDiv">
  aaaaaaa
  <iframe id="iframe" src="data:text/html,<style type='text/css'>*{margin: 0; padding: 0; font-size: 16px;}</style><div>ffffff ffffff ffffff ffffff</div>"></iframe>
  aaaaaaa aaaaaaa<br>aaaaaaa aaaaaaa aaaaaaa aaaaaaa<br>aaaaaaa
</div>
<div id="div2" class="testingDiv">
  bbbbbbb
  <input id="input" type="text" value="iiiiiiiii iiiiiiiii iiiiiiiii">
  bbbbbbb bbbbbbb<br>bbbbbbb bbbbbbb bbbbbbb<br>bbbbbbb
</div>
<div id="div3" class="testingDiv">
  ccccccc
  <textarea id="textarea">tttttt tttttt tttttt</textarea>
  ccccccc ccccccc<br>ccccccc ccccccc ccccccc ccccccc<br>ccccccc
  <div id="fixedDiv1" class="testingDiv">
    dddddd dddddd dddddd
  </div>
</div>
<div id="xbl">
  <p id="xbl_child">yyyyyyy yyyyyyy yyyyyyy</p>
</div>
<div id="fixedDiv2" class="testingDiv">
  eeeeee eeeeee eeeeee
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

var div1 = document.getElementById("div1");
var div2 = document.getElementById("div2");
var div3 = document.getElementById("div3");
var xbl = document.getElementById("xbl");
var xbl_child = document.getElementById("xbl_child");
var fixedDiv1 = document.getElementById("fixedDiv1");
var fixedDiv2 = document.getElementById("fixedDiv2");
var iframe = document.getElementById("iframe");
var input = document.getElementById("input");
var textarea = SpecialPowers.wrap(document.getElementById("textarea"));

function test()
{
  function getSelectionForEditor(aEditorElement)
  {
    const nsIDOMNSEditableElement = SpecialPowers.Ci.nsIDOMNSEditableElement;
    return SpecialPowers.wrap(aEditorElement).editor.selection;
  }

  function clear()
  {
    synthesizeMouse(div1, 10, 5, { type: "mouseup" });
    var sel = window.getSelection();
    if (sel.rangeCount > 0)
      sel.collapseToEnd();
    sel = iframe.contentWindow.getSelection();
    if (sel.rangeCount > 0)
      sel.collapseToEnd();
    sel = getSelectionForEditor(input);
    if (sel.rangeCount > 0)
      sel.collapseToEnd();
    sel = getSelectionForEditor(textarea);
    if (sel.rangeCount > 0)
      sel.collapseToEnd();

    div1.scrollTop = 0;
    div1.scrollLeft = 0;
    div2.scrollTop = 0;
    div2.scrollLeft = 0;
    div3.scrollTop = 0;
    div3.scrollLeft = 0;
  }

  const kFalse = 0;
  const kTrue  = 1;
  const kToDo  = 2;

  function check(aDiv1ShouldBeSelected,
                 aDiv2ShouldBeSelected,
                 aDiv3ShouldBeSelected,
                 aFixedDiv1ShouldBeSelected,
                 aXBLChildShouldBeSelected,
                 aFixedDiv2ShouldBeSelected,
                 aIFrameShouldBeSelected,
                 aInputShouldBeSelected,
                 aTextareaShouldBeSelected,
                 aTestingDescription)
  {
    function checkCharacter(aSelectedText,
                            aShouldBeIncludedCharacter,
                            aSouldBeSelected,
                            aElementName)
    {
      var boolvalue = aSouldBeSelected & kTrue;
      var f = aSouldBeSelected & kToDo ? todo : ok;
      var str = aSelectedText.replace('\n', '\\n');
      if (boolvalue) {
        f(aSelectedText.indexOf(aShouldBeIncludedCharacter) >= 0,
          "The contents of " + aElementName +
          " aren't selected (" + aTestingDescription +
          "): Selected String: \"" + str + "\"");
      } else {
        f(aSelectedText.indexOf(aShouldBeIncludedCharacter) < 0,
          "The contents of " + aElementName +
          " are selected (" + aTestingDescription +
          "): Selected String: \"" + str + "\"");
      }
    }

    var sel = window.getSelection().toString();
    checkCharacter(sel, "a", aDiv1ShouldBeSelected, "div1");
    checkCharacter(sel, "b", aDiv2ShouldBeSelected, "div2");
    checkCharacter(sel, "c", aDiv3ShouldBeSelected, "div3");
    checkCharacter(sel, "y", aXBLChildShouldBeSelected, "xbl_child");
    checkCharacter(sel, "d", aFixedDiv1ShouldBeSelected, "fixedDiv1");
    checkCharacter(sel, "e", aFixedDiv2ShouldBeSelected, "fixedDiv2");

    // iframe/input/xbl-bound contents must not be included on the parent
    // selection.
    checkCharacter(sel, "f", false, "iframe (checking on parent)");
    checkCharacter(sel, "i", false, "input (checking on parent)");
    checkCharacter(sel, "x", false, "XBL bound contents (checking on parent)");

    var selInIFrame = iframe.contentWindow.getSelection().toString();
    checkCharacter(selInIFrame, "f", aIFrameShouldBeSelected, "iframe");

    var selInput = getSelectionForEditor(input).toString();
    checkCharacter(selInput, "i", aInputShouldBeSelected, "input");
    var selTextarea = getSelectionForEditor(textarea).toString();
    checkCharacter(selTextarea, "t", aTextareaShouldBeSelected, "textarea");
  }

  // ***********************************************************
  // Set all divs to overflow: auto;
  const kOverflows = ["visible", "hidden", "scroll", "auto"];
  for (var i = 0; i < kOverflows.length; i++) {
    div1.style.overflow = kOverflows[i];
    div2.style.overflow = kOverflows[i];
    div3.style.overflow = kOverflows[i];

    // ***********************************************************
    // selection starting at div1
    synthesizeMouse(div1, 30, 5, { type: "mousedown" });

    // XXX if we move the mouse cursor to another document, the
    // nsFrameSelection::HandleDrag method is called on the another document's.

    // to iframe
    synthesizeMouse(iframe, 30, 5, { type: "mousemove" });
    check(kTrue | kToDo, kFalse, kFalse,
          kFalse, kFalse, kFalse, kFalse, kFalse, kFalse,
          "div1-iframe, all boxes are overflow: " + kOverflows[i] + ";");

    // XXX if the overflow is visible, synthesizeMouse with the input element
    // or textarea element doesn't work fine.
    var isVisibleTesting = kOverflows[i] == "visible";
    var todoFlag = isVisibleTesting ? kToDo : 0;
    // to input
    synthesizeMouse(input, 30, 5, { type: "mousemove" });
    check(kTrue | todoFlag, kTrue | todoFlag, kFalse,
          kFalse, kFalse, kFalse, kFalse, kFalse, kFalse,
         "div1-input, all boxes are overflow: " + kOverflows[i] + ";");

    // to textarea
    synthesizeMouse(textarea, 30, 5, { type: "mousemove" });
    check(kTrue | todoFlag, kTrue | todoFlag, kTrue | todoFlag,
          kFalse, kFalse, kFalse, kFalse, kFalse, kFalse,
          "div1-textarea, all boxes are overflow: " + kOverflows[i] + ";");

    // to div2
    synthesizeMouse(div2, 30, 5, { type: "mousemove" });
    check(kTrue, kTrue, kFalse,
          kFalse, kFalse, kFalse, kFalse, kFalse, kFalse,
          "div1-div2, all boxes are overflow: " + kOverflows[i] + ";");

    // to div3
    synthesizeMouse(div3, 30, 5, { type: "mousemove" });
    check(kTrue, kTrue, kTrue,
          kFalse, kFalse, kFalse, kFalse, kFalse, kFalse,
          "div1-div3, all boxes are overflow: " + kOverflows[i] + ";");

    // to fixedDiv1 (child of div3)
    synthesizeMouse(fixedDiv1, 30, 5, { type: "mousemove" });
    check(kTrue, kTrue, kTrue,
          kTrue, kFalse, kFalse, kFalse, kFalse, kFalse,
          "div1-fixedDiv1, all boxes are overflow: " + kOverflows[i] + ";");

    // to xbl_child
    synthesizeMouse(xbl_child, 30, 5, { type: "mousemove" });
    check(kTrue, kTrue, kTrue,
          kTrue, kTrue, kFalse, kFalse, kFalse, kFalse,
          "div1-xbl_child, all boxes are overflow: " + kOverflows[i] + ";");

    // to fixedDiv2 (sibling of div*)
    synthesizeMouse(fixedDiv2, 30, 5, { type: "mousemove" });
    check(kTrue, kTrue, kTrue,
          kTrue, kTrue, kTrue, kFalse, kFalse, kFalse,
          "div1-fixedDiv2, all boxes are overflow: " + kOverflows[i] + ";");

    clear();

    // ***********************************************************
    // selection starting at fixedDiv1
    synthesizeMouse(fixedDiv1, 30, 5, { type: "mousedown" });

    // to xbl_child
    synthesizeMouse(xbl_child, 30, 5, { type: "mousemove" });
    check(kFalse, kFalse, kFalse,
          kTrue, kTrue, kFalse, kFalse, kFalse, kFalse,
          "fixedDiv1-xbl_child, all boxes are overflow: " + kOverflows[i] + ";");

    // to fixedDiv2
    synthesizeMouse(fixedDiv2, 30, 5, { type: "mousemove" });
    check(kFalse, kFalse, kFalse,
          kTrue, kTrue, kTrue, kFalse, kFalse, kFalse,
          "fixedDiv1-fixedDiv2, all boxes are overflow: " + kOverflows[i] + ";");

    clear();

    // ***********************************************************
    // selection starting at fixedDiv2
    synthesizeMouse(fixedDiv2, 30, 5, { type: "mousedown" });

    // to xbl_child
    synthesizeMouse(xbl_child, 30, 5, { type: "mousemove" });
    check(kFalse, kFalse, kFalse,
          kFalse, kTrue, kTrue, kFalse, kFalse, kFalse,
          "fixedDiv2-xbl_child, all boxes are overflow: " + kOverflows[i] + ";");

    // to fixedDiv1
    synthesizeMouse(fixedDiv1, 30, 5, { type: "mousemove" });
    check(kFalse, kFalse, kFalse,
          kTrue, kTrue, kTrue, kFalse, kFalse, kFalse,
          "fixedDiv2-fixedDiv1, all boxes are overflow: " + kOverflows[i] + ";");

    clear();

    // ***********************************************************
    div2.style.overflow = "visible";

    // ***********************************************************
    // selection starting at div2
    synthesizeMouse(div2, 30, 5, { type: "mousedown" });

    // to div3
    synthesizeMouse(div3, 30, 5, { type: "mousemove" });
    check(kFalse, kTrue, kTrue,
          kFalse, kFalse, kFalse, kFalse, kFalse, kFalse,
          "div2-div3, div3 is overflow: " + kOverflows[i] +
          ";, but div2 is overflow: visible;");

    // to fixedDiv1 (child of div3)
    synthesizeMouse(fixedDiv1, 30, 5, { type: "mousemove" });
    check(kFalse, kTrue, kTrue,
          kTrue, kFalse, kFalse, kFalse, kFalse, kFalse,
          "div2-fixedDiv1, div3 is overflow: " + kOverflows[i] +
          ";, but div2 is overflow: visible;");

    // to xbl_child
    synthesizeMouse(xbl_child, 30, 5, { type: "mousemove" });
    check(kFalse, kTrue, kTrue,
          kTrue, kTrue, kFalse, kFalse, kFalse, kFalse,
          "div2-xbl_child, div3 is overflow: " + kOverflows[i] +
          ";, but div2 is overflow: visible;");

    // to fixedDiv2 (sibling of div*)
    synthesizeMouse(fixedDiv2, 30, 5, { type: "mousemove" });
    check(kFalse, kTrue, kTrue,
          kTrue, kTrue, kTrue, kFalse, kFalse, kFalse,
          "div2-fixedDiv2, div3 is overflow: " + kOverflows[i] +
          ";, but div2 is overflow: visible;");

    clear();

    // ***********************************************************
    // selection starting at div3
    synthesizeMouse(div3, 30, 5, { type: "mousedown" });

    // to div2
    synthesizeMouse(div2, 30, 5, { type: "mousemove" });
    check(kFalse, kTrue, kTrue,
          kFalse, kFalse, kFalse, kFalse, kFalse, kFalse,
          "div3-div2, div3 is overflow: " + kOverflows[i] +
          ";, but div2 is overflow: visible;");

    // to fixedDiv1 (child of div3)
    synthesizeMouse(fixedDiv1, 30, 5, { type: "mousemove" });
    check(kFalse, kFalse, kTrue,
          kTrue, kFalse, kFalse, kFalse, kFalse, kFalse,
          "div3-fixedDiv1, div3 is overflow: " + kOverflows[i] +
          ";, but div2 is overflow: visible;");

    // to xbl_child
    synthesizeMouse(xbl_child, 30, 5, { type: "mousemove" });
    check(kFalse, kFalse, kTrue,
          kTrue, kTrue, kFalse, kFalse, kFalse, kFalse,
          "div3-xbl_child, div3 is overflow: " + kOverflows[i] +
          ";, but div2 is overflow: visible;");

    // to fixedDiv2 (sibling of div*)
    synthesizeMouse(fixedDiv2, 30, 5, { type: "mousemove" });
    check(kFalse, kFalse, kTrue,
          kTrue, kTrue, kTrue, kFalse, kFalse, kFalse,
          "div3-fixedDiv2, div3 is overflow: " + kOverflows[i] +
          ";, but div2 is overflow: visible;");

    clear();
  }

  // ***********************************************************
  // selection starting at iframe
  synthesizeMouse(iframe, 30, 5, { type: "mousedown" });

  // inside iframe
  synthesizeMouse(iframe, 50, 5, { type: "mousemove" });
  check(kFalse, kFalse, kFalse,
        kFalse, kFalse, kFalse, kTrue, kFalse, kFalse,
        "iframe-iframe");

  // to div2
  synthesizeMouse(div2, 30, 5, { type: "mousemove" });
  check(kFalse, kFalse, kFalse,
        kFalse, kFalse, kFalse, kTrue, kFalse, kFalse,
        "iframe-div2");

  clear();

  // ***********************************************************
  // selection starting at input
  synthesizeMouse(input, 20, 5, { type: "mousedown" });

  // inside input
  synthesizeMouse(input, 40, 5, { type: "mousemove" });
  check(kFalse, kFalse, kFalse,
        kFalse, kFalse, kFalse, kFalse, kTrue, kFalse,
        "input-input");

  // to div3
  synthesizeMouse(div3, 30, 5, { type: "mousemove" });
  check(kFalse, kFalse, kFalse,
        kFalse, kFalse, kFalse, kFalse, kTrue, kFalse,
        "input-div3");

  clear();

  // ***********************************************************
  // selection starting at textarea
  synthesizeMouse(textarea, 30, 5, { type: "mousedown" });

  // inside textarea
  synthesizeMouse(textarea, 50, 5, { type: "mousemove" });
  check(kFalse, kFalse, kFalse,
        kFalse, kFalse, kFalse, kFalse, kFalse, kTrue,
        "textarea-textarea");

  // to div2
  synthesizeMouse(div2, 30, 5, { type: "mousemove" });
  check(kFalse, kFalse, kFalse,
        kFalse, kFalse, kFalse, kFalse, kFalse, kTrue,
        "textarea-div2");

  clear();

  SimpleTest.finish();
}
window.onload = function() { setTimeout(test, 0); };
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>