1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/base/tests/test_after_paint_pref.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,123 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=608030 1.8 +--> 1.9 +<head> 1.10 + <title>Test for MozAfterPaint pref Bug 608030</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.13 +</head> 1.14 +<body> 1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=608030">Mozilla Bug 608030</a> 1.16 +<div id="display" style="width: 10em; height: 5em; background-color: red"></div> 1.17 +<pre id="test"> 1.18 +<script type="application/javascript"> 1.19 + 1.20 +/** Test for Bug 608030 **/ 1.21 + 1.22 +function get_pref() 1.23 +{ 1.24 + return SpecialPowers.getBoolPref("dom.send_after_paint_to_content"); 1.25 +} 1.26 + 1.27 +function set_pref(val) 1.28 +{ 1.29 + SpecialPowers.setBoolPref("dom.send_after_paint_to_content", val); 1.30 +} 1.31 + 1.32 +SimpleTest.waitForExplicitFinish(); 1.33 + 1.34 +window.addEventListener("load", step0, false); 1.35 + 1.36 +is(get_pref(), true, "pref defaults to true in mochitest harness"); 1.37 + 1.38 +function print_rect(rect) { 1.39 + return "(top=" + rect.top + ",left=" + rect.left + ",width=" + rect.width + ",height=" + rect.height + ")"; 1.40 +} 1.41 + 1.42 +function print_event(event) { 1.43 + var res = "boundingClientRect=" + print_rect(event.boundingClientRect); 1.44 + var rects = event.clientRects; 1.45 + for (var i = 0; i < rects.length; ++i) { 1.46 + res += " clientRects[" + i + "]=" + print_rect(rects[i]); 1.47 + } 1.48 + return res; 1.49 +} 1.50 + 1.51 +function step0(event) { 1.52 + // Wait until we get the MozAfterPaint following the load event 1.53 + // before starting. 1.54 + ok(true, "loaded"); 1.55 + window.addEventListener("MozAfterPaint", step1, false); 1.56 + 1.57 + // Ensure a MozAfterPaint event is fired 1.58 + div.style.backgroundColor = "yellow"; 1.59 +} 1.60 + 1.61 +var start; 1.62 +var div = document.getElementById("display"); 1.63 + 1.64 +function step1(event) 1.65 +{ 1.66 + ok(true, "step1 reached: " + print_event(event)); 1.67 + window.removeEventListener("MozAfterPaint", step1, false); 1.68 + 1.69 + start = Date.now(); 1.70 + 1.71 + window.addEventListener("MozAfterPaint", step2, false); 1.72 + 1.73 + div.style.backgroundColor = "blue"; 1.74 +} 1.75 + 1.76 +function step2(event) 1.77 +{ 1.78 + ok(true, "step2 reached: " + print_event(event)); 1.79 + window.removeEventListener("MozAfterPaint", step2, false); 1.80 + 1.81 + var end = Date.now(); 1.82 + var timeout = 3 * Math.max(end - start, 300); 1.83 + 1.84 + ok(true, "got MozAfterPaint (timeout for next step is " + timeout + "ms)"); 1.85 + 1.86 + // Set the pref for our second test 1.87 + set_pref(false); 1.88 + 1.89 + // When there was previously another page in our window, we seem to 1.90 + // get duplicate events, simultaneously, so we need to register our 1.91 + // next listener after a zero timeout. 1.92 + setTimeout(step3, 0, timeout); 1.93 +} 1.94 +function step3(timeout) 1.95 +{ 1.96 + ok(true, "step3 reached"); 1.97 + window.addEventListener("MozAfterPaint", failstep, false); 1.98 + 1.99 + div.style.backgroundColor = "fuchsia"; 1.100 + 1.101 + setTimeout(step4, timeout); 1.102 +} 1.103 + 1.104 +function failstep(event) 1.105 +{ 1.106 + ok(true, "failstep reached: " + print_event(event)); 1.107 + ok(false, "got MozAfterPaint when we should not have"); 1.108 +} 1.109 + 1.110 +function step4() 1.111 +{ 1.112 + ok(true, "step4 reached"); // If we didn't get the failure in failstep, 1.113 + // then we passed. 1.114 + 1.115 + window.removeEventListener("MozAfterPaint", failstep, false); 1.116 + 1.117 + // Set the pref back in its initial state. 1.118 + set_pref(true); 1.119 + 1.120 + SimpleTest.finish(); 1.121 +} 1.122 + 1.123 +</script> 1.124 +</pre> 1.125 +</body> 1.126 +</html>