summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_scroll_over_subframe.html
blob: 21efcbd9d6bced989c6a6f19aec948b502481ed0 (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
<!DOCTYPE html>
<html>
  <title>A scroll over an iframe should not terminate the wheel transaction</title>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
<head>
<style>
body {
  height: 250vh;
  width: 100%;
  margin: 0;
  padding: 0;
}

#spacer {
  height: 50px;
  width: 100vw;
  background: yellow;
}

#subframe {
  width: 80vw;
  height: 60vh;
}
</style>
</head>
<body>
  <div id="spacer"></div>
  <iframe id="subframe">
  </iframe>
</body>
<script>
const searchParams = new URLSearchParams(location.search);

async function scrollWithPan() {
  await NativePanHandler.promiseNativePanEvent(
    document.scrollingElement,
    50,
    30,
    0,
    NativePanHandler.delta,
    NativePanHandler.beginPhase,
  );

  await NativePanHandler.promiseNativePanEvent(
    document.scrollingElement,
    50,
    30,
    0,
    NativePanHandler.delta,
    NativePanHandler.updatePhase,
  );

  await NativePanHandler.promiseNativePanEvent(
    document.scrollingElement,
    50,
    30,
    0,
    NativePanHandler.delta,
    NativePanHandler.endPhase,
  );
}

async function scrollWithWheel() {
  await promiseMoveMouseAndScrollWheelOver(document.scrollingElement, 50, 30,
                                           false, 100);
}

async function test() {
  let iframeURL =
       SimpleTest.getTestFileURL("helper_scroll_over_subframe_child.html");

  switch (searchParams.get("oop")) {
    case "true":
      iframeURL = iframeURL.replace(window.location.origin, "https://example.com/");
      break;
    default:
      break;
  }

  const iframeLoadPromise = promiseOneEvent(subframe, "load", null);
  subframe.src = iframeURL;
  await iframeLoadPromise;

  await SpecialPowers.spawn(subframe, [], async () => {
    await content.wrappedJSObject.waitUntilApzStable();
    await SpecialPowers.contentTransformsReceived(content);
  });

  let childWindowReceivedWheelEvent = false;

  window.addEventListener("message", e => {
    if (e.data == "child-received-wheel-event") {
      childWindowReceivedWheelEvent = true;
    }
  });

  await SpecialPowers.spawn(subframe, [], () => {
    let target = content.document.getElementById("target")
    target.style.backgroundColor = "green";
    content.getComputedStyle(target).backgroundColor;
    target.addEventListener("wheel", () => {
      target.style.backgroundColor = "red";
      content.getComputedStyle(target).backgroundColor;
    });
    return new Promise(resolve => resolve());
  });

  await promiseFrame();

  let transformEndPromise = promiseTransformEnd();

  // Scroll over the iframe
  switch (searchParams.get("scroll")) {
    case "wheel":
      await scrollWithWheel();
      break;
    case "pan":
      await scrollWithPan();
      break;
    default:
      ok(false, "Unsupported scroll value: " + searchParams.get("scroll"));
      break;
  }

  await transformEndPromise;

  // Wait an extra frame to ensure any message from the child has
  // extra time to be sent to the parent.
  await promiseFrame();

  let res = await SpecialPowers.spawn(subframe, [], () => {
    let target = content.document.getElementById("target")
    return target.style.backgroundColor;
  });

  await promiseFrame();

  // We should not have fired a wheel event to the element in the iframe
  ok(!childWindowReceivedWheelEvent, "Child window should not receive wheel events");
  is(res, "green", "OOP iframe does not halt user scroll of parent");
}
waitUntilApzStable().then(test).then(subtestDone, subtestFailed);
</script>
</html>