1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/test/mochitest/test_bug751809.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +<html> 1.5 +<head> 1.6 + <title>Bug 751809</title> 1.7 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.8 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.9 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/paint_listener.js"></script> 1.10 + <script type="application/javascript" src="utils.js"></script> 1.11 + <script type="application/javascript;version=1.7"> 1.12 + Components.utils.import("resource://gre/modules/Services.jsm"); 1.13 + Services.prefs.setBoolPref("plugins.click_to_play", true); 1.14 + setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_CLICKTOPLAY); 1.15 + </script> 1.16 +</head> 1.17 + 1.18 +<body onload="go();"> 1.19 + <embed id="plugin" type="application/x-test" width="400" height="400" drawmode="solid" color="FF00FFFF"></embed> 1.20 + 1.21 + <script type="application/javascript;version=1.7"> 1.22 + 1.23 + SimpleTest.waitForExplicitFinish(); 1.24 + 1.25 + const Ci = Components.interfaces; 1.26 + const utils = window.QueryInterface(Ci.nsIInterfaceRequestor). 1.27 + getInterface(Ci.nsIDOMWindowUtils); 1.28 + 1.29 + function waitForCondition(condition, nextTest, errorMsg) { 1.30 + var tries = 0; 1.31 + var interval = setInterval(function() { 1.32 + if (tries >= 30) { 1.33 + ok(false, errorMsg); 1.34 + moveOn(); 1.35 + } 1.36 + if (condition()) { 1.37 + moveOn(); 1.38 + } 1.39 + tries++; 1.40 + }, 100); 1.41 + var moveOn = function() { clearInterval(interval); nextTest(); }; 1.42 + } 1.43 + 1.44 + function go() { 1.45 + var plugin = document.getElementById('plugin'); 1.46 + var objLoadingContent = SpecialPowers.wrap(plugin); 1.47 + ok(!objLoadingContent.activated, "plugin should not be activated"); 1.48 + 1.49 + SimpleTest.waitForFocus(afterWindowFocus); 1.50 + } 1.51 + 1.52 + function afterWindowFocus() { 1.53 + var plugin = document.getElementById('plugin'); 1.54 + var objLoadingContent = SpecialPowers.wrap(plugin); 1.55 + 1.56 + objLoadingContent.playPlugin(); 1.57 + var condition = function() plugin.setColor !== undefined; 1.58 + waitForCondition(condition, afterPluginActivation, "Waited too long for plugin to activate"); 1.59 + } 1.60 + 1.61 + function afterPluginActivation() { 1.62 + var plugin = document.getElementById('plugin'); 1.63 + var objLoadingContent = SpecialPowers.wrap(plugin); 1.64 + ok(objLoadingContent.activated, "plugin should be activated now"); 1.65 + 1.66 + // Triggering a paint and waiting for it to be flushed makes sure 1.67 + // that both plugin and platform see the plugin element as visible. 1.68 + // See bug 805330 for details. 1.69 + plugin.setColor("FF000088"); 1.70 + waitForAllPaintsFlushed(afterPaintsFlushed); 1.71 + } 1.72 + 1.73 + function afterPaintsFlushed() { 1.74 + var plugin = document.getElementById('plugin'); 1.75 + try { 1.76 + is(plugin.getMouseUpEventCount(), 0, "Plugin should not have received mouse events yet."); 1.77 + } catch(e) { 1.78 + ok(false, "plugin.getMouseUpEventCount() shouldn't throw"); 1.79 + } 1.80 + 1.81 + synthesizeMouseAtCenter(plugin, {}); 1.82 + var condition = function() plugin.getMouseUpEventCount() > 0; 1.83 + waitForCondition(condition, afterFirstClick, "Waited too long for plugin to receive the mouse click"); 1.84 + } 1.85 + 1.86 + function afterFirstClick() { 1.87 + var plugin = document.getElementById('plugin'); 1.88 + try { 1.89 + is(plugin.getMouseUpEventCount(), 1, "Plugin should have received 1 mouse up event."); 1.90 + } catch(e) { 1.91 + ok(false, "plugin.getMouseUpEventCount() shouldn't throw"); 1.92 + } 1.93 + 1.94 + Services.prefs.clearUserPref("plugins.click_to_play"); 1.95 + SimpleTest.finish(); 1.96 + } 1.97 + 1.98 + </script> 1.99 +</body> 1.100 +</html>