dom/plugins/test/mochitest/cocoa_window_focus.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/mochitest/cocoa_window_focus.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +<html>
     1.5 +<head>
     1.6 +  <title>NPCocoaEventWindowFocusChanged Tests</title>
     1.7 +</head>
     1.8 +<body onload="runTests()">
     1.9 +  <embed id="plugin1" type="application/x-test" width="400" height="400"></embed>
    1.10 +  <embed id="plugin2" type="application/x-test" width="400" height="400"></embed>
    1.11 +  <script type="application/javascript">
    1.12 +    function is(aLeft, aRight, aMessage) {
    1.13 +      window.opener.SimpleTest.is(aLeft, aRight, aMessage);
    1.14 +    }
    1.15 +
    1.16 +    function ok(aValue, aMessage) {
    1.17 +      window.opener.SimpleTest.ok(aValue, aMessage);
    1.18 +    }
    1.19 +
    1.20 +    function executeSoon(func) {
    1.21 +      window.opener.SimpleTest.executeSoon(func);
    1.22 +    }
    1.23 +
    1.24 +    function waitForFocus(aCb, aTarget, aBlank) {
    1.25 +      window.opener.SimpleTest.waitForFocus(aCb, aTarget, aBlank);
    1.26 +    }
    1.27 +
    1.28 +    function runTests() {
    1.29 +      var plugin1 = document.getElementById("plugin1");
    1.30 +      var plugin2 = document.getElementById("plugin2");
    1.31 +
    1.32 +      if (plugin1.getEventModel() != 1) {
    1.33 +        window.opener.todo(false, "Skipping this test when not testing the Cocoa event model");
    1.34 +        window.opener.testsFinished();
    1.35 +        return;
    1.36 +      }
    1.37 +
    1.38 +      // The first plugin will have in-page focus for these tests.
    1.39 +      plugin1.focus();
    1.40 +
    1.41 +      // The expected event count which applies to all instances.
    1.42 +      // Initialize to 1 to account for the initial state event.
    1.43 +      var expectedEventCount = 1;
    1.44 +
    1.45 +      // First make sure the plugins got an initial window focus event.
    1.46 +      // Since this window was just opened it should be in the front. If
    1.47 +      // the plugin has not been sent an initial window state then it will
    1.48 +      // be in an unknown state and it will throw an exception.
    1.49 +      try {
    1.50 +        is(plugin1.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
    1.51 +        is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    1.52 +
    1.53 +        is(plugin2.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
    1.54 +        is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    1.55 +      } catch (e) {
    1.56 +        ok(false, "Plugin does not know its initial top-level window activation state!");
    1.57 +      }
    1.58 +
    1.59 +      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    1.60 +      var fm = SpecialPowers.Cc["@mozilla.org/focus-manager;1"].
    1.61 +                             getService(SpecialPowers.Ci.nsIFocusManager);
    1.62 +
    1.63 +      waitForFocus(function() {
    1.64 +        // Make sure the plugin handled the focus event before checking.
    1.65 +        executeSoon(function() {
    1.66 +          expectedEventCount++;
    1.67 +
    1.68 +          is(plugin1.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated");
    1.69 +          is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    1.70 +
    1.71 +          is(plugin2.getTopLevelWindowActivationState(), false, "Activation state should be: deactivated");
    1.72 +          is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    1.73 +
    1.74 +          // Bring our window back to the front and make sure plugins were properly notified.
    1.75 +          netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    1.76 +          fm.focusedWindow = window;
    1.77 +
    1.78 +          waitForFocus(function() {
    1.79 +            // Make sure the plugin handled the focus event before checking.
    1.80 +            executeSoon(function() {
    1.81 +              expectedEventCount++;
    1.82 +
    1.83 +              is(plugin1.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
    1.84 +              is(plugin1.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    1.85 +
    1.86 +              is(plugin2.getTopLevelWindowActivationState(), true, "Activation state should be: activated");
    1.87 +              is(plugin2.getTopLevelWindowActivationEventCount(), expectedEventCount, "Window focus event count should be " + expectedEventCount);
    1.88 +
    1.89 +              window.opener.testsFinished();
    1.90 +            });
    1.91 +          }, window);
    1.92 +        });
    1.93 +      }, window.opener);
    1.94 +
    1.95 +      // Send our window to the back and make sure plugins were properly notified.
    1.96 +      // Calling window.blur() is not allowed.
    1.97 +      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    1.98 +      fm.focusedWindow = window.opener;
    1.99 +    }
   1.100 +  </script>
   1.101 +</body>
   1.102 +</html>

mercurial