dom/plugins/test/mochitest/test_visibility.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 <head>
michael@0 4 <title>Test whether windowless plugins receive correct visible/invisible notifications.</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 7
michael@0 8 <style>
michael@0 9 .hidden { visibility: hidden; }
michael@0 10 </style>
michael@0 11
michael@0 12 <body onload="startTest()">
michael@0 13 <p id="display"></p>
michael@0 14
michael@0 15 <script type="application/javascript" src="utils.js"></script>
michael@0 16 <script type="application/javascript">
michael@0 17 SimpleTest.waitForExplicitFinish();
michael@0 18 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
michael@0 19
michael@0 20 var didPaint = function() {};
michael@0 21
michael@0 22 function startTest() {
michael@0 23 if (SimpleTest.testPluginIsOOP()) {
michael@0 24 if (p.getPaintCount() < 1) {
michael@0 25 setTimeout(startTest, 0);
michael@0 26 return;
michael@0 27 }
michael@0 28 }
michael@0 29
michael@0 30 didPaint = function() {
michael@0 31 ok(false, "Plugin should not paint until it is visible!");
michael@0 32 };
michael@0 33
michael@0 34 ok(!p.isVisible(), "Plugin should not be visible.");
michael@0 35 paintCountIs(p, 0, "Plugin should not have painted.");
michael@0 36
michael@0 37 didPaint = part2;
michael@0 38
michael@0 39 p.style.visibility = 'visible';
michael@0 40 }
michael@0 41
michael@0 42 function part2() {
michael@0 43 ok(p.isVisible(), "Plugin should now be visible.");
michael@0 44 paintCountIs(p, 1, "Plugin should have painted once.");
michael@0 45
michael@0 46 didPaint = part3;
michael@0 47
michael@0 48 p.setColor('FF0000FF'); // this causes an invalidate/repaint
michael@0 49 }
michael@0 50
michael@0 51 const kTimeout = 5000; // 5 seconds
michael@0 52 var part4GiveUp;
michael@0 53 var part4Interval;
michael@0 54
michael@0 55 function part3() {
michael@0 56 ok(p.isVisible(), "Plugin should still be visible.");
michael@0 57 paintCountIs(p, 2, "Plugin should have painted twice.");
michael@0 58
michael@0 59 didPaint = function() {
michael@0 60 ok(false, "Plugin should not paint when it is invisible.");
michael@0 61 };
michael@0 62
michael@0 63 p.style.visibility = 'hidden';
michael@0 64
michael@0 65 part4GiveUp = Date.now() + kTimeout;
michael@0 66 part4Interval = setInterval(part4, 100);
michael@0 67 }
michael@0 68
michael@0 69 function part4() {
michael@0 70 if (p.isVisible()) {
michael@0 71 if (Date.now() < part4GiveUp)
michael@0 72 return;
michael@0 73
michael@0 74 ok(false, "Plugin never became invisible in part4.");
michael@0 75 SimpleTest.finish();
michael@0 76 return;
michael@0 77 }
michael@0 78
michael@0 79 clearInterval(part4Interval);
michael@0 80
michael@0 81 ok(true, "Plugin became invisible again.");
michael@0 82 p.setColor('FF00FF00');
michael@0 83 setTimeout(SimpleTest.finish, 500);
michael@0 84 // wait to make sure we don't actually paint
michael@0 85 }
michael@0 86
michael@0 87 function inPaint() {
michael@0 88 // We're actually in the middle of painting the plugin so don't do anything
michael@0 89 // complex here, for the sake of cases where async plugin painting isn't
michael@0 90 // enabled yet
michael@0 91 setTimeout(didPaint, 0);
michael@0 92 // Don't run that didPaint callback again
michael@0 93 didPaint = function() {};
michael@0 94 }
michael@0 95 </script>
michael@0 96
michael@0 97 <embed id="theplugin" class="hidden" type="application/x-test" drawmode="solid" color="FFFF0000" paintscript="inPaint()"></embed>
michael@0 98
michael@0 99 <script type="application/javascript">
michael@0 100 var p = document.getElementById('theplugin');
michael@0 101 </script>

mercurial