layout/base/tests/test_after_paint_pref.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=608030
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for MozAfterPaint pref Bug 608030</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=608030">Mozilla Bug 608030</a>
michael@0 13 <div id="display" style="width: 10em; height: 5em; background-color: red"></div>
michael@0 14 <pre id="test">
michael@0 15 <script type="application/javascript">
michael@0 16
michael@0 17 /** Test for Bug 608030 **/
michael@0 18
michael@0 19 function get_pref()
michael@0 20 {
michael@0 21 return SpecialPowers.getBoolPref("dom.send_after_paint_to_content");
michael@0 22 }
michael@0 23
michael@0 24 function set_pref(val)
michael@0 25 {
michael@0 26 SpecialPowers.setBoolPref("dom.send_after_paint_to_content", val);
michael@0 27 }
michael@0 28
michael@0 29 SimpleTest.waitForExplicitFinish();
michael@0 30
michael@0 31 window.addEventListener("load", step0, false);
michael@0 32
michael@0 33 is(get_pref(), true, "pref defaults to true in mochitest harness");
michael@0 34
michael@0 35 function print_rect(rect) {
michael@0 36 return "(top=" + rect.top + ",left=" + rect.left + ",width=" + rect.width + ",height=" + rect.height + ")";
michael@0 37 }
michael@0 38
michael@0 39 function print_event(event) {
michael@0 40 var res = "boundingClientRect=" + print_rect(event.boundingClientRect);
michael@0 41 var rects = event.clientRects;
michael@0 42 for (var i = 0; i < rects.length; ++i) {
michael@0 43 res += " clientRects[" + i + "]=" + print_rect(rects[i]);
michael@0 44 }
michael@0 45 return res;
michael@0 46 }
michael@0 47
michael@0 48 function step0(event) {
michael@0 49 // Wait until we get the MozAfterPaint following the load event
michael@0 50 // before starting.
michael@0 51 ok(true, "loaded");
michael@0 52 window.addEventListener("MozAfterPaint", step1, false);
michael@0 53
michael@0 54 // Ensure a MozAfterPaint event is fired
michael@0 55 div.style.backgroundColor = "yellow";
michael@0 56 }
michael@0 57
michael@0 58 var start;
michael@0 59 var div = document.getElementById("display");
michael@0 60
michael@0 61 function step1(event)
michael@0 62 {
michael@0 63 ok(true, "step1 reached: " + print_event(event));
michael@0 64 window.removeEventListener("MozAfterPaint", step1, false);
michael@0 65
michael@0 66 start = Date.now();
michael@0 67
michael@0 68 window.addEventListener("MozAfterPaint", step2, false);
michael@0 69
michael@0 70 div.style.backgroundColor = "blue";
michael@0 71 }
michael@0 72
michael@0 73 function step2(event)
michael@0 74 {
michael@0 75 ok(true, "step2 reached: " + print_event(event));
michael@0 76 window.removeEventListener("MozAfterPaint", step2, false);
michael@0 77
michael@0 78 var end = Date.now();
michael@0 79 var timeout = 3 * Math.max(end - start, 300);
michael@0 80
michael@0 81 ok(true, "got MozAfterPaint (timeout for next step is " + timeout + "ms)");
michael@0 82
michael@0 83 // Set the pref for our second test
michael@0 84 set_pref(false);
michael@0 85
michael@0 86 // When there was previously another page in our window, we seem to
michael@0 87 // get duplicate events, simultaneously, so we need to register our
michael@0 88 // next listener after a zero timeout.
michael@0 89 setTimeout(step3, 0, timeout);
michael@0 90 }
michael@0 91 function step3(timeout)
michael@0 92 {
michael@0 93 ok(true, "step3 reached");
michael@0 94 window.addEventListener("MozAfterPaint", failstep, false);
michael@0 95
michael@0 96 div.style.backgroundColor = "fuchsia";
michael@0 97
michael@0 98 setTimeout(step4, timeout);
michael@0 99 }
michael@0 100
michael@0 101 function failstep(event)
michael@0 102 {
michael@0 103 ok(true, "failstep reached: " + print_event(event));
michael@0 104 ok(false, "got MozAfterPaint when we should not have");
michael@0 105 }
michael@0 106
michael@0 107 function step4()
michael@0 108 {
michael@0 109 ok(true, "step4 reached"); // If we didn't get the failure in failstep,
michael@0 110 // then we passed.
michael@0 111
michael@0 112 window.removeEventListener("MozAfterPaint", failstep, false);
michael@0 113
michael@0 114 // Set the pref back in its initial state.
michael@0 115 set_pref(true);
michael@0 116
michael@0 117 SimpleTest.finish();
michael@0 118 }
michael@0 119
michael@0 120 </script>
michael@0 121 </pre>
michael@0 122 </body>
michael@0 123 </html>

mercurial