|
1 <html> |
|
2 <head> |
|
3 <title>Bug 751809</title> |
|
4 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
5 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
|
6 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/paint_listener.js"></script> |
|
7 <script type="application/javascript" src="utils.js"></script> |
|
8 <script type="application/javascript;version=1.7"> |
|
9 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
10 Services.prefs.setBoolPref("plugins.click_to_play", true); |
|
11 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_CLICKTOPLAY); |
|
12 </script> |
|
13 </head> |
|
14 |
|
15 <body onload="go();"> |
|
16 <embed id="plugin" type="application/x-test" width="400" height="400" drawmode="solid" color="FF00FFFF"></embed> |
|
17 |
|
18 <script type="application/javascript;version=1.7"> |
|
19 |
|
20 SimpleTest.waitForExplicitFinish(); |
|
21 |
|
22 const Ci = Components.interfaces; |
|
23 const utils = window.QueryInterface(Ci.nsIInterfaceRequestor). |
|
24 getInterface(Ci.nsIDOMWindowUtils); |
|
25 |
|
26 function waitForCondition(condition, nextTest, errorMsg) { |
|
27 var tries = 0; |
|
28 var interval = setInterval(function() { |
|
29 if (tries >= 30) { |
|
30 ok(false, errorMsg); |
|
31 moveOn(); |
|
32 } |
|
33 if (condition()) { |
|
34 moveOn(); |
|
35 } |
|
36 tries++; |
|
37 }, 100); |
|
38 var moveOn = function() { clearInterval(interval); nextTest(); }; |
|
39 } |
|
40 |
|
41 function go() { |
|
42 var plugin = document.getElementById('plugin'); |
|
43 var objLoadingContent = SpecialPowers.wrap(plugin); |
|
44 ok(!objLoadingContent.activated, "plugin should not be activated"); |
|
45 |
|
46 SimpleTest.waitForFocus(afterWindowFocus); |
|
47 } |
|
48 |
|
49 function afterWindowFocus() { |
|
50 var plugin = document.getElementById('plugin'); |
|
51 var objLoadingContent = SpecialPowers.wrap(plugin); |
|
52 |
|
53 objLoadingContent.playPlugin(); |
|
54 var condition = function() plugin.setColor !== undefined; |
|
55 waitForCondition(condition, afterPluginActivation, "Waited too long for plugin to activate"); |
|
56 } |
|
57 |
|
58 function afterPluginActivation() { |
|
59 var plugin = document.getElementById('plugin'); |
|
60 var objLoadingContent = SpecialPowers.wrap(plugin); |
|
61 ok(objLoadingContent.activated, "plugin should be activated now"); |
|
62 |
|
63 // Triggering a paint and waiting for it to be flushed makes sure |
|
64 // that both plugin and platform see the plugin element as visible. |
|
65 // See bug 805330 for details. |
|
66 plugin.setColor("FF000088"); |
|
67 waitForAllPaintsFlushed(afterPaintsFlushed); |
|
68 } |
|
69 |
|
70 function afterPaintsFlushed() { |
|
71 var plugin = document.getElementById('plugin'); |
|
72 try { |
|
73 is(plugin.getMouseUpEventCount(), 0, "Plugin should not have received mouse events yet."); |
|
74 } catch(e) { |
|
75 ok(false, "plugin.getMouseUpEventCount() shouldn't throw"); |
|
76 } |
|
77 |
|
78 synthesizeMouseAtCenter(plugin, {}); |
|
79 var condition = function() plugin.getMouseUpEventCount() > 0; |
|
80 waitForCondition(condition, afterFirstClick, "Waited too long for plugin to receive the mouse click"); |
|
81 } |
|
82 |
|
83 function afterFirstClick() { |
|
84 var plugin = document.getElementById('plugin'); |
|
85 try { |
|
86 is(plugin.getMouseUpEventCount(), 1, "Plugin should have received 1 mouse up event."); |
|
87 } catch(e) { |
|
88 ok(false, "plugin.getMouseUpEventCount() shouldn't throw"); |
|
89 } |
|
90 |
|
91 Services.prefs.clearUserPref("plugins.click_to_play"); |
|
92 SimpleTest.finish(); |
|
93 } |
|
94 |
|
95 </script> |
|
96 </body> |
|
97 </html> |