Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | |
michael@0 | 4 | <window title="Popup Prevent Default Tests" |
michael@0 | 5 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 6 | |
michael@0 | 7 | <!-- |
michael@0 | 8 | This tests checks that preventDefault can be called on a popupshowing |
michael@0 | 9 | event or popuphiding event to prevent the default behaviour. |
michael@0 | 10 | --> |
michael@0 | 11 | |
michael@0 | 12 | <script> |
michael@0 | 13 | |
michael@0 | 14 | var gBlockShowing = true; |
michael@0 | 15 | var gBlockHiding = true; |
michael@0 | 16 | var gShownNotAllowed = true; |
michael@0 | 17 | var gHiddenNotAllowed = true; |
michael@0 | 18 | |
michael@0 | 19 | var fm = Components.classes["@mozilla.org/focus-manager;1"]. |
michael@0 | 20 | getService(Components.interfaces.nsIFocusManager); |
michael@0 | 21 | |
michael@0 | 22 | var is = function(l, r, v) { window.opener.wrappedJSObject.SimpleTest.is(l, r, v); } |
michael@0 | 23 | var isnot = function(l, r, v) { window.opener.wrappedJSObject.SimpleTest.isnot(l, r, v); } |
michael@0 | 24 | |
michael@0 | 25 | function runTest() |
michael@0 | 26 | { |
michael@0 | 27 | var menu = document.getElementById("menu"); |
michael@0 | 28 | |
michael@0 | 29 | is(fm.activeWindow, window, "active window at start"); |
michael@0 | 30 | is(fm.focusedWindow, window, "focused window at start"); |
michael@0 | 31 | |
michael@0 | 32 | is(window.windowState, window.STATE_NORMAL, "window is normal"); |
michael@0 | 33 | // the minimizing test sometimes fails on Linux so don't test it there |
michael@0 | 34 | if (navigator.platform.indexOf("Lin") == 0) { |
michael@0 | 35 | menu.open = true; |
michael@0 | 36 | return; |
michael@0 | 37 | } |
michael@0 | 38 | window.minimize(); |
michael@0 | 39 | is(window.windowState, window.STATE_MINIMIZED, "window is minimized"); |
michael@0 | 40 | |
michael@0 | 41 | isnot(fm.activeWindow, window, "active window after minimize"); |
michael@0 | 42 | isnot(fm.focusedWindow, window, "focused window after minimize"); |
michael@0 | 43 | |
michael@0 | 44 | menu.open = true; |
michael@0 | 45 | |
michael@0 | 46 | setTimeout(runTestAfterMinimize, 0); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function runTestAfterMinimize() |
michael@0 | 50 | { |
michael@0 | 51 | var menu = document.getElementById("menu"); |
michael@0 | 52 | is(menu.firstChild.state, "closed", "popup not opened when window minimized"); |
michael@0 | 53 | |
michael@0 | 54 | window.restore(); |
michael@0 | 55 | is(window.windowState, window.STATE_NORMAL, "window is restored"); |
michael@0 | 56 | |
michael@0 | 57 | is(fm.activeWindow, window, "active window after restore"); |
michael@0 | 58 | is(fm.focusedWindow, window, "focused window after restore"); |
michael@0 | 59 | |
michael@0 | 60 | menu.open = true; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | function popupShowing(event) |
michael@0 | 64 | { |
michael@0 | 65 | if (gBlockShowing) { |
michael@0 | 66 | event.preventDefault(); |
michael@0 | 67 | gBlockShowing = false; |
michael@0 | 68 | setTimeout(function() { |
michael@0 | 69 | gShownNotAllowed = false; |
michael@0 | 70 | document.getElementById("menu").open = true; |
michael@0 | 71 | }, 3000, true); |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function popupShown() |
michael@0 | 76 | { |
michael@0 | 77 | window.opener.wrappedJSObject.SimpleTest.ok(!gShownNotAllowed, "popupshowing preventDefault"); |
michael@0 | 78 | document.getElementById("menu").open = false; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function popupHiding(event) |
michael@0 | 82 | { |
michael@0 | 83 | if (gBlockHiding) { |
michael@0 | 84 | event.preventDefault(); |
michael@0 | 85 | gBlockHiding = false; |
michael@0 | 86 | setTimeout(function() { |
michael@0 | 87 | gHiddenNotAllowed = false; |
michael@0 | 88 | document.getElementById("menu").open = false; |
michael@0 | 89 | }, 3000, true); |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function popupHidden() |
michael@0 | 94 | { |
michael@0 | 95 | window.opener.wrappedJSObject.SimpleTest.ok(!gHiddenNotAllowed, "popuphiding preventDefault"); |
michael@0 | 96 | window.opener.wrappedJSObject.SimpleTest.finish(); |
michael@0 | 97 | window.close(); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | window.opener.wrappedJSObject.SimpleTest.waitForFocus(runTest, window); |
michael@0 | 101 | </script> |
michael@0 | 102 | |
michael@0 | 103 | <button id="menu" type="menu" label="Menu"> |
michael@0 | 104 | <menupopup onpopupshowing="popupShowing(event);" |
michael@0 | 105 | onpopupshown="popupShown();" |
michael@0 | 106 | onpopuphiding="popupHiding(event);" |
michael@0 | 107 | onpopuphidden="popupHidden();"> |
michael@0 | 108 | <menuitem label="Item"/> |
michael@0 | 109 | </menupopup> |
michael@0 | 110 | </button> |
michael@0 | 111 | |
michael@0 | 112 | |
michael@0 | 113 | </window> |