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

     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>
    15 <body onload="go();">
    16   <embed id="plugin" type="application/x-test" width="400" height="400" drawmode="solid" color="FF00FFFF"></embed>
    18   <script type="application/javascript;version=1.7">
    20   SimpleTest.waitForExplicitFinish();
    22   const Ci = Components.interfaces;
    23   const utils = window.QueryInterface(Ci.nsIInterfaceRequestor).
    24                                     getInterface(Ci.nsIDOMWindowUtils);
    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   }
    41   function go() {
    42     var plugin = document.getElementById('plugin');
    43     var objLoadingContent = SpecialPowers.wrap(plugin);
    44     ok(!objLoadingContent.activated, "plugin should not be activated");
    46     SimpleTest.waitForFocus(afterWindowFocus);
    47   }
    49   function afterWindowFocus() {
    50     var plugin = document.getElementById('plugin');
    51     var objLoadingContent = SpecialPowers.wrap(plugin);
    53     objLoadingContent.playPlugin();
    54     var condition = function() plugin.setColor !== undefined;
    55     waitForCondition(condition, afterPluginActivation, "Waited too long for plugin to activate");
    56   }
    58   function afterPluginActivation() {
    59     var plugin = document.getElementById('plugin');
    60     var objLoadingContent = SpecialPowers.wrap(plugin);
    61     ok(objLoadingContent.activated, "plugin should be activated now");
    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   }
    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     }
    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   }
    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     }
    91     Services.prefs.clearUserPref("plugins.click_to_play");
    92     SimpleTest.finish();
    93   }
    95   </script>
    96 </body>
    97 </html>

mercurial