summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_fission_checkerboard_severity.html
blob: ef7943b29f3fe3798469ac5e4bac922345533271 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>
    A test to make sure checkerboard severity isn't reported for non-scrollable
    OOP iframe
  </title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <script src="helper_fission_utils.js"></script>
  <script src="apz_test_utils.js"></script>
  <script src="apz_test_native_event_utils.js"></script>
  <script>

fission_subtest_init();

FissionTestHelper.startTestPromise
  .then(waitUntilApzStable)
  .then(loadOOPIFrame("testframe", "helper_fission_empty.html"))
  .then(waitUntilApzStable)
  .then(test)
  .then(FissionTestHelper.subtestDone, FissionTestHelper.subtestFailed);


// The actual test

let code_for_oopif_to_run = function() {
  document.addEventListener("click", function(e) {
    dump(`OOPIF got click at ${e.clientX},${e.clientY}\n`);
    let result = { x: e.clientX, y: e.clientY };
    FissionTestHelper.fireEventInEmbedder("OOPIF:ClickData", result);
  });
  dump("OOPIF registered click listener\n");
  return true;
};

async function getIframeDisplayport(iframe) {
  let oopif_displayport = function() {
    let result = getLastContentDisplayportFor("fission_empty_docelement", false);
    FissionTestHelper.fireEventInEmbedder("OOPIF:Displayport", result);
    return true;
  };

  let iframePromise = promiseOneEvent(window, "OOPIF:Displayport", null);
  ok(await FissionTestHelper.sendToOopif(iframe, `(${oopif_displayport})()`));
  let iframeResponse = await iframePromise;
  dump("OOPIF response for Displayport: " +
       JSON.stringify(iframeResponse.data) + "\n");

  return iframeResponse.data;
}

async function getIframeScrollMax(iframe) {
  let oopif_scroll_max = function() {
    let result = {
      scrollMaxX: window.scrollMaxX,
      scrollMaxY: window.scrollMaxY
    };
    FissionTestHelper.fireEventInEmbedder("OOPIF:ScrollMax", result);
    return true;
  };

  let iframePromise = promiseOneEvent(window, "OOPIF:ScrollMax", null);
  ok(await FissionTestHelper.sendToOopif(iframe, `(${oopif_scroll_max})()`));
  let iframeResponse = await iframePromise;
  dump("OOPIF response for ScrollMax: " +
       JSON.stringify(iframeResponse.data) + "\n");

  return iframeResponse.data;
}

async function test() {
  await SpecialPowers.spawnChrome([], () => {
    Services.telemetry.getHistogramById("CHECKERBOARD_SEVERITY").clear();
  });

  const iframe = document.getElementById("testframe");

  // Make sure the iframe content is not scrollable.
  const { scrollMaxX, scrollMaxY } = await getIframeScrollMax(iframe);
  is(scrollMaxX, 0, "The iframe content should not be scrollable");
  is(scrollMaxY, 0, "The iframe content should not be scrollable");

  // Since bug 1709460 any visible OOP iframe initially has set the displayport.
  let displayport = await getIframeDisplayport(iframe);
  is(displayport.width, 400);
  is(displayport.height, 300);

  let iframeResponse =
    await FissionTestHelper.sendToOopif(iframe, `(${code_for_oopif_to_run})()`);
  dump("OOPIF response: " + JSON.stringify(iframeResponse) + "\n");
  ok(iframeResponse, "code_for_oopif_to_run successfully installed");

  // Click on the iframe via APZ so that it triggers a RequestContentRepaint
  // call then it sets zero display port margins for the iframe's root scroller,
  // thus as a result it will report a checkerboard event if there had been
  // checkerboarding.
  iframePromise = promiseOneEvent(window, "OOPIF:ClickData", null);
  await synthesizeNativeMouseEventWithAPZ(
    { type: "click", target: iframe, offsetX: 10, offsetY: 10 },
    () => dump("Finished synthesizing click, waiting for OOPIF message...\n")
  );
  iframeResponse = await iframePromise;
  dump("OOPIF response: " + JSON.stringify(iframeResponse.data) + "\n");

  // Now the displayport size should have been set.
  displayport = await getIframeDisplayport(iframe);
  is(displayport.width, 400, "The displayport size should be same as the iframe size");
  is(displayport.height, 300, "The displayport size should be same as the iframe size");

  // Wait 100ms to give a chance to deliver the checkerboard event.
  await new Promise(resolve => {
    setTimeout(resolve, 100);
  });

  const hasCheckerboardSeverity = await SpecialPowers.spawnChrome([], () => {
    const histograms = Services.telemetry.getSnapshotForHistograms(
        "main",
        true /* clear the histograms after taking this snapshot*/).parent;

    return histograms.hasOwnProperty("CHECKERBOARD_SEVERITY");
  });
  ok(!hasCheckerboardSeverity, "there should be no checkerboard severity data");
}
  </script>
  <style>
    iframe {
        width: 400px;
        height: 300px;
        border: none;
    }
  </style>
</head>
<body>
<iframe id="testframe"></iframe>
</body>
</html>