summaryrefslogtreecommitdiffstats
path: root/layout/generic/test/test_selection_cross_shadow_boundary_multi_ranges_backward_click.html
blob: a2a0d0e2becb849404ee8f2a971788dc758ecc2a (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
<!DOCTYPE HTML>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/layout/generic/test/selection_cross_shadow_boundary_helper.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script>
SimpleTest.waitForExplicitFinish();
function run() {
  const inner1 = host1.shadowRoot.querySelector("span");
  const rect1 = inner1.getBoundingClientRect();

  // Click the bottom right of "InnerText1"
  synthesizeMouse(inner1, rect1.width - 1, rect1.height - 1, { type: "mousedown" });
  synthesizeMouse(inner1, rect1.width - 1, rect1.height - 1, { type: "mouseup" });

  // Click the top left of "OuterText1"
  synthesizeMouse(document.getElementById("outer1"), 0, 0, { type: "mousedown", shiftKey: true });
  synthesizeMouse(document.getElementById("outer1"), 0, 0, { type: "mouseup", shiftKey: true });

  const inner2 = host2.shadowRoot.querySelector("span");
  const rect2 = inner2.getBoundingClientRect();

  // Click the bottom right of "InnerText2" with accelKey
  synthesizeMouse(inner2, rect2.width, rect2.height, { type: "mousedown", accelKey: true});
  synthesizeMouse(inner2, rect2.width, rect2.height, { type: "mouseup" , accelKey: true});

  // Click the top left of "OuterText2"
  synthesizeMouse(document.getElementById("outer2"), 1, 1, { type: "mousedown", shiftKey: true});
  synthesizeMouse(document.getElementById("outer2"), 1, 1, { type: "mouseup", shiftKey: true});

  const ranges = document.getSelection().getComposedRanges(host1.shadowRoot, host2.shadowRoot);
  is(ranges.length, 2, "Above two drag selection should produce two ranges");

  is(ranges[0].startContainer, outer1.firstChild, "startContainer is the OuterText1");
  is(ranges[0].startOffset, 0, "startOffset starts at the first character");
  is(ranges[0].endContainer, inner1.firstChild, "endContainer is the InnerText1");
  is(ranges[0].endOffset, 10, "endOffset ends at the last character");

  is(ranges[1].startContainer, outer2.firstChild, "startContainer is the OuterText2");
  is(ranges[1].startOffset, 0, "startOffset starts at the first character");
  is(ranges[1].endContainer, inner2.firstChild, "endContainer is the InnerText2");
  is(ranges[1].endOffset, 10, "endOffset ends at the last character");

  SimpleTest.finish();
}
</script>
<body onload="SimpleTest.waitForFocus(run);">
  <span id="outer1">OuterText1</span>
  <div id="host1">
    <template shadowrootmode="open">
      <span>InnerText1</span>
    </template>
  </div>
  <br>
  <span id="outer2">OuterText2</span>
  <div id="host2">
    <template shadowrootmode="open">
      <span>InnerText2</span>
    </template>
  </div>
</body>