1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/tests/test_plugin_scroll_invalidation.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for plugin child widgets not being invalidated by scrolling</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.10 +</head> 1.11 +<body onload="initialize()"> 1.12 +<script type="application/javascript"> 1.13 +var pluginHost = SpecialPowers.Cc["@mozilla.org/plugin/host;1"] 1.14 + .getService(SpecialPowers.Ci.nsIPluginHost); 1.15 +var pluginTags = pluginHost.getPluginTags(); 1.16 +for (var tag of pluginTags) { 1.17 + if (tag.name == "Test Plug-in") { 1.18 + tag.enabledState = SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED;; 1.19 + } 1.20 +} 1.21 +</script> 1.22 + 1.23 +<p id="display"> 1.24 + <iframe id="i" src="plugin_scroll_invalidation.html" 1.25 + width="50" height="50" scrolling="no"></iframe> 1.26 +</p> 1.27 +<div id="content" style="display: none"> 1.28 + 1.29 +</div> 1.30 +<pre id="test"> 1.31 +</pre> 1.32 + 1.33 +<script type="application/javascript"> 1.34 +SimpleTest.waitForExplicitFinish(); 1.35 + 1.36 +var scrolling; 1.37 +var scrolling_plugins = []; 1.38 +var paint_waiter; 1.39 +var last_paint_counts; 1.40 + 1.41 +function initialize() { 1.42 + scrolling = document.getElementById("i").contentWindow; 1.43 + scrolling_plugins = scrolling.document.querySelectorAll("embed.scrolling"); 1.44 + paint_waiter = scrolling.document.getElementById("paint-waiter"); 1.45 + 1.46 + scrolling.scrollTo(50, 45); 1.47 + 1.48 + is(paint_waiter.getPaintCount(), 0, "zero-sized plugin not painted"); 1.49 + 1.50 + waitForPaint(scrollAround); 1.51 +} 1.52 + 1.53 +function scrollAround() { 1.54 + var paints = getPaintCounts(); 1.55 + 1.56 + for (var i = 0; i < paints.length; ++i) { 1.57 + isnot(paints[i], 0, "embed " + scrolling_plugins[i].id + " is painted"); 1.58 + } 1.59 + 1.60 + last_paint_counts = paints; 1.61 + 1.62 + scrolling.scrollBy(-5, 5); 1.63 + scrolling.scrollBy(5, 5); 1.64 + scrolling.scrollBy(5, -5); 1.65 + scrolling.scrollBy(-5, -5); 1.66 + 1.67 + scrolling.scrollTo(45, 45); 1.68 + scrolling.scrollBy(10, 0); 1.69 + scrolling.scrollBy(0, 10); 1.70 + scrolling.scrollBy(-10, 0); 1.71 + scrolling.scrollBy(0, -10); 1.72 + 1.73 + waitForPaint(done); 1.74 +} 1.75 + 1.76 +function done() { 1.77 + var paints = getPaintCounts(); 1.78 + for (var i = 0; i < paints.length; ++i) { 1.79 + is(paints[i], last_paint_counts[i], "embed " + scrolling_plugins[i].id + " is not painted on scroll"); 1.80 + } 1.81 + SimpleTest.finish(); 1.82 +} 1.83 + 1.84 +// Waits for the paint_waiter plugin to be repainted and then 1.85 +// calls 'func' to continue. 1.86 +function waitForPaint(func) { 1.87 + paint_waiter.last_paint_count = paint_waiter.getPaintCount(); 1.88 + 1.89 + paint_waiter.style.left = scrolling.scrollX + "px"; 1.90 + paint_waiter.style.top = scrolling.scrollY + "px"; 1.91 + 1.92 + // Fiddle with the style in a way that should force some repainting 1.93 + paint_waiter.style.width = 1.94 + (paint_waiter.getBoundingClientRect().width + 1) + "px"; 1.95 + paint_waiter.style.height = "1px"; 1.96 + 1.97 + function waitForPaintHelper() { 1.98 + if (paint_waiter.getPaintCount() != paint_waiter.last_paint_count) { 1.99 + setTimeout(func, 0); 1.100 + return; 1.101 + } 1.102 + setTimeout(waitForPaintHelper, 0); 1.103 + } 1.104 + waitForPaintHelper(); 1.105 +} 1.106 + 1.107 +function getPaintCounts() { 1.108 + var result = []; 1.109 + for (var i = 0; i < scrolling_plugins.length; ++i) { 1.110 + result[i] = scrolling_plugins[i].getPaintCount(); 1.111 + } 1.112 + return result; 1.113 +} 1.114 + 1.115 +</script> 1.116 +</body> 1.117 +</html>