summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_zoomToFocusedInput_iframe-2.html
blob: 68b2db35ca976a2d74d4f46cedd30a45b5d1f21b (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=2100,initial-scale=0.4"/>
  <title>Tests that zoomToFocusedInput in iframe works regardless whether cross-origin or not</title>
  <script src="apz_test_native_event_utils.js"></script>
  <script src="apz_test_utils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <style>
  html {
    /* To avoid bug 1865573 */
    scrollbar-width: none;
  }
  iframe {
    position: absolute;
    top: 100px;
    left: 100px;
    border: none;
  }
  </style>
</head>
<body>
<iframe width="500" height="500"></iframe>
<script>
async function setupIframe(aURL) {
  const iframe = document.querySelector("iframe");
  const iframeLoadPromise = promiseOneEvent(iframe, "load", null);
  iframe.src = aURL;
  await iframeLoadPromise;
  info(`${aURL} loaded`);

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

let initial_resolution;
async function test(aTestFile) {
  let iframeURL = SimpleTest.getTestFileURL(aTestFile);

  // Load the test document in the same origin.
  await setupIframe(iframeURL);

  initial_resolution = await getResolution();
  ok(initial_resolution > 0,
     "The initial_resolution is " + initial_resolution + ", which is some sane value");

  const iframe = document.querySelector("iframe");
  let transformEndPromise = promiseTransformEnd();
  await SpecialPowers.spawn(iframe, [], async () => {
    SpecialPowers.DOMWindowUtils.zoomToFocusedInput();
  });
  await transformEndPromise;
  await promiseApzFlushedRepaints();

  const zoomedInState = cloneVisualViewport();

  // Reset the scale to the initial value.
  SpecialPowers.DOMWindowUtils.setResolutionAndScaleTo(initial_resolution);
  await promiseApzFlushedRepaints();

  // Now load the document in an OOP iframe.
  iframeURL = iframeURL.replace(window.location.origin, "https://example.com");
  await setupIframe(iframeURL);

  transformEndPromise = promiseTransformEnd();
  await SpecialPowers.spawn(iframe, [], async () => {
    SpecialPowers.DOMWindowUtils.zoomToFocusedInput();
  });
  await transformEndPromise;
  await promiseApzFlushedRepaints();

  compareVisualViewport(zoomedInState, cloneVisualViewport(), "zoomed-in state");
}

async function moveIframe() {
  const iframe = document.querySelector("iframe");
  iframe.style.top = "500vh";

  // Scroll to the bottom to make the layout scroll offset non-zero.
  window.scrollTo(0, document.documentElement.scrollHeight);
  ok(window.scrollY > 0, "The root scroll position should be non-zero");

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

waitUntilApzStable()
.then(async () => test("helper_zoomToFocusedInput_iframe_subframe.html?margin-top=200vh"))
.then(async () => {
  // Reset the scale to the initial value.
  SpecialPowers.DOMWindowUtils.setResolutionAndScaleTo(initial_resolution);
  await promiseApzFlushedRepaints();
})
// A test case where the layout scroll offset isn't zero.
.then(async () => moveIframe())
.then(async () => test("helper_zoomToFocusedInput_iframe_subframe.html"))
.then(subtestDone, subtestFailed);
</script>
</body>
</html>