File: test_after_paint_pref.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (123 lines) | stat: -rw-r--r-- 3,511 bytes parent folder | download | duplicates (3)
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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=608030
-->
<head>
  <title>Test for MozAfterPaint pref Bug 608030</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=608030">Mozilla Bug 608030</a>
<div id="display" style="width: 10em; height: 5em; background-color: red"></div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 608030 */

SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");

window.addEventListener("load", step0);

is(SpecialPowers.getBoolPref("dom.send_after_paint_to_content"), true, "pref defaults to true in mochitest harness");

function print_rect(rect) {
  if (!rect) {
    rect = { top: 0, left: 0, width: 0, right: 0 };
  }
  return "(top=" + rect.top + ",left=" + rect.left + ",width=" + rect.width + ",height=" + rect.height + ")";
}

function print_event(event) {
  var res = "boundingClientRect=" + print_rect(event.boundingClientRect);
  var rects = event.clientRects;
  if (rects) {
    for (var i = 0; i < rects.length; ++i) {
      res += " clientRects[" + i + "]=" + print_rect(rects[i]);
    }
  }
  return res;
}

function step0(event) {
  // Wait until we get the MozAfterPaint following the load event
  // before starting.
  ok(true, "loaded");
  window.addEventListener("MozAfterPaint", step1);

  // Ensure a MozAfterPaint event is fired
  div.style.backgroundColor = "yellow";
}

var start;
var div = document.getElementById("display");

function step1(event)
{
  ok(true, "step1 reached: " + print_event(event));
  window.removeEventListener("MozAfterPaint", step1);

  start = Date.now();

  window.addEventListener("MozAfterPaint", step2);

  div.style.backgroundColor = "blue";
}

async function step2(event)
{
  ok(true, "step2 reached: " + print_event(event));
  window.removeEventListener("MozAfterPaint", step2);

  var end = Date.now();
  var timeout = 3 * Math.max(end - start, 300);

  ok(true, "got MozAfterPaint (timeout for next step is " + timeout + "ms)");

  // Set the pref for our second test

  // When there was previously another page in our window, we seem to
  // get duplicate events, simultaneously, so we need to register our
  // next listener after a zero timeout.
  await SpecialPowers.pushPrefEnv({'set': [['dom.send_after_paint_to_content', false]]});

  // Wait for a double-rAF, to ensure we get a refresh driver tick (which, for
  // this pref, is what actually makes the pref-adjustment take effect).
  await new Promise(resolve  => requestAnimationFrame(resolve));
  await new Promise(resolve  => requestAnimationFrame(resolve));

  setTimeout(step3, 0, timeout);
}
function step3(timeout)
{
  ok(true, "step3 reached");
  window.addEventListener("MozAfterPaint", failstep);

  div.style.backgroundColor = "fuchsia";

  setTimeout(step4, timeout);
}

function failstep(event)
{
  ok(true, "failstep reached: " + print_event(event));
  ok(false, "got MozAfterPaint when we should not have");
}

function step4()
{
  ok(true, "step4 reached"); // If we didn't get the failure in failstep,
                             // then we passed.

  window.removeEventListener("MozAfterPaint", failstep);

  // Set the pref back in its initial state.
  SpecialPowers.pushPrefEnv({'set': [['dom.send_after_paint_to_content', true]]}, SimpleTest.finish);
}

</script>
</pre>
</body>
</html>