1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/test/mochitest/test_visibility.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +<!DOCTYPE html> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test whether windowless plugins receive correct visible/invisible notifications.</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 + 1.11 + <style> 1.12 + .hidden { visibility: hidden; } 1.13 + </style> 1.14 + 1.15 +<body onload="startTest()"> 1.16 + <p id="display"></p> 1.17 + 1.18 + <script type="application/javascript" src="utils.js"></script> 1.19 + <script type="application/javascript"> 1.20 + SimpleTest.waitForExplicitFinish(); 1.21 + setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED); 1.22 + 1.23 + var didPaint = function() {}; 1.24 + 1.25 + function startTest() { 1.26 + if (SimpleTest.testPluginIsOOP()) { 1.27 + if (p.getPaintCount() < 1) { 1.28 + setTimeout(startTest, 0); 1.29 + return; 1.30 + } 1.31 + } 1.32 + 1.33 + didPaint = function() { 1.34 + ok(false, "Plugin should not paint until it is visible!"); 1.35 + }; 1.36 + 1.37 + ok(!p.isVisible(), "Plugin should not be visible."); 1.38 + paintCountIs(p, 0, "Plugin should not have painted."); 1.39 + 1.40 + didPaint = part2; 1.41 + 1.42 + p.style.visibility = 'visible'; 1.43 + } 1.44 + 1.45 + function part2() { 1.46 + ok(p.isVisible(), "Plugin should now be visible."); 1.47 + paintCountIs(p, 1, "Plugin should have painted once."); 1.48 + 1.49 + didPaint = part3; 1.50 + 1.51 + p.setColor('FF0000FF'); // this causes an invalidate/repaint 1.52 + } 1.53 + 1.54 + const kTimeout = 5000; // 5 seconds 1.55 + var part4GiveUp; 1.56 + var part4Interval; 1.57 + 1.58 + function part3() { 1.59 + ok(p.isVisible(), "Plugin should still be visible."); 1.60 + paintCountIs(p, 2, "Plugin should have painted twice."); 1.61 + 1.62 + didPaint = function() { 1.63 + ok(false, "Plugin should not paint when it is invisible."); 1.64 + }; 1.65 + 1.66 + p.style.visibility = 'hidden'; 1.67 + 1.68 + part4GiveUp = Date.now() + kTimeout; 1.69 + part4Interval = setInterval(part4, 100); 1.70 + } 1.71 + 1.72 + function part4() { 1.73 + if (p.isVisible()) { 1.74 + if (Date.now() < part4GiveUp) 1.75 + return; 1.76 + 1.77 + ok(false, "Plugin never became invisible in part4."); 1.78 + SimpleTest.finish(); 1.79 + return; 1.80 + } 1.81 + 1.82 + clearInterval(part4Interval); 1.83 + 1.84 + ok(true, "Plugin became invisible again."); 1.85 + p.setColor('FF00FF00'); 1.86 + setTimeout(SimpleTest.finish, 500); 1.87 + // wait to make sure we don't actually paint 1.88 + } 1.89 + 1.90 + function inPaint() { 1.91 + // We're actually in the middle of painting the plugin so don't do anything 1.92 + // complex here, for the sake of cases where async plugin painting isn't 1.93 + // enabled yet 1.94 + setTimeout(didPaint, 0); 1.95 + // Don't run that didPaint callback again 1.96 + didPaint = function() {}; 1.97 + } 1.98 + </script> 1.99 + 1.100 + <embed id="theplugin" class="hidden" type="application/x-test" drawmode="solid" color="FFFF0000" paintscript="inPaint()"></embed> 1.101 + 1.102 + <script type="application/javascript"> 1.103 + var p = document.getElementById('theplugin'); 1.104 + </script>