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

mercurial