summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_wide_crossorigin_iframe_child.html
blob: edf3ad47287a703bf20fd4a77faa1bfc81fbfcc1 (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
<!DOCTYPE html>
<html id="helper_wide_crossorigin_iframe_child_docelement">
<meta charset=utf-8>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="apz_test_utils.js"></script>
  <script src="apz_test_native_event_utils.js"></script>
<style>
html {
    border: 5px solid lime;
    background: yellow;
    box-sizing: border-box;
    overflow-y: scroll;
}
</style>
<script>
  // negative means keep sending forever
  // we flip this to 10 when we hit onload, so that we send several
  // before load and some after.
  let numMoreTimesToSend = -1;
  function sendDpToParent() {
    if (numMoreTimesToSend > 0) {
      numMoreTimesToSend--;
    }
    if (numMoreTimesToSend == 0) {
      clearInterval(intervalId);
      parent.postMessage("wereDone", "*");
      return;
    }
    let dp = getLastContentDisplayportFor("helper_wide_crossorigin_iframe_child_docelement", /* expectPainted = */ false);
    if (dp != null) {
      info("result " + dp.x + " " + dp.y + " " + dp.width + " " + dp.height);

      parent.postMessage(dp, "*");
    } else {
      info("no dp yet");
    }
  }

  sendDpToParent();
  setTimeout(sendDpToParent,0);

  let intervalId = setInterval(sendDpToParent, 100);

  addEventListener("MozAfterPaint", sendAndSetTimeout);
  function sendAndSetTimeout() {
    sendDpToParent();
    setTimeout(sendDpToParent,0);
  }

  window.requestAnimationFrame(checkAndSendRaf);
  function checkAndSendRaf() {
    if (numMoreTimesToSend != 0) {
      window.requestAnimationFrame(checkAndSendRaf);
    }
    sendDpToParent();
    setTimeout(sendDpToParent,0);
  }

  window.onload = onloaded;
  window.onDOMContentLoaded = sendDpToParent;
  document.onreadystatechange = sendDpToParent;
  document.onafterscriptexecute = sendDpToParent;
  document.onbeforescriptexecute = sendDpToParent;
  document.onvisibilitychange = sendDpToParent;
  function onloaded() {
    numMoreTimesToSend = 10;
    sendDpToParent();
  }

</script>
<div style="background: blue; height: 400vh;"></div>