dom/plugins/test/mochitest/cocoa_window_focus.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <html>
     2 <head>
     3   <title>NPCocoaEventWindowFocusChanged Tests</title>
     4 </head>
     5 <body onload="runTests()">
     6   <embed id="plugin1" type="application/x-test" width="400" height="400"></embed>
     7   <embed id="plugin2" type="application/x-test" width="400" height="400"></embed>
     8   <script type="application/javascript">
     9     function is(aLeft, aRight, aMessage) {
    10       window.opener.SimpleTest.is(aLeft, aRight, aMessage);
    11     }
    13     function ok(aValue, aMessage) {
    14       window.opener.SimpleTest.ok(aValue, aMessage);
    15     }
    17     function executeSoon(func) {
    18       window.opener.SimpleTest.executeSoon(func);
    19     }
    21     function waitForFocus(aCb, aTarget, aBlank) {
    22       window.opener.SimpleTest.waitForFocus(aCb, aTarget, aBlank);
    23     }
    25     function runTests() {
    26       var plugin1 = document.getElementById("plugin1");
    27       var plugin2 = document.getElementById("plugin2");
    29       if (plugin1.getEventModel() != 1) {
    30         window.opener.todo(false, "Skipping this test when not testing the Cocoa event model");
    31         window.opener.testsFinished();
    32         return;
    33       }
    35       // The first plugin will have in-page focus for these tests.
    36       plugin1.focus();
    38       // The expected event count which applies to all instances.
    39       // Initialize to 1 to account for the initial state event.
    40       var expectedEventCount = 1;
    42       // First make sure the plugins got an initial window focus event.
    43       // Since this window was just opened it should be in the front. If
    44       // the plugin has not been sent an initial window state then it will
    45       // be in an unknown state and it will throw an exception.
    46       try {
    47         is(plugin1.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
    48         is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    50         is(plugin2.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
    51         is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    52       } catch (e) {
    53         ok(false, "Plugin does not know its initial top-level window activation state!");
    54       }
    56       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    57       var fm = SpecialPowers.Cc["@mozilla.org/focus-manager;1"].
    58                              getService(SpecialPowers.Ci.nsIFocusManager);
    60       waitForFocus(function() {
    61         // Make sure the plugin handled the focus event before checking.
    62         executeSoon(function() {
    63           expectedEventCount++;
    65           is(plugin1.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated");
    66           is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    68           is(plugin2.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated");
    69           is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    71           // Bring our window back to the front and make sure plugins were properly notified.
    72           netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    73           fm.focusedWindow = window;
    75           waitForFocus(function() {
    76             // Make sure the plugin handled the focus event before checking.
    77             executeSoon(function() {
    78               expectedEventCount++;
    80               is(plugin1.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
    81               is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    83               is(plugin2.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
    84               is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    86               window.opener.testsFinished();
    87             });
    88           }, window);
    89         });
    90       }, window.opener);
    92       // Send our window to the back and make sure plugins were properly notified.
    93       // Calling window.blur() is not allowed.
    94       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    95       fm.focusedWindow = window.opener;
    96     }
    97   </script>
    98 </body>
    99 </html>

mercurial