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

mercurial