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