diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/tests/mochitest/bugs/utils_bug260264.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/tests/mochitest/bugs/utils_bug260264.js')
-rw-r--r-- | dom/tests/mochitest/bugs/utils_bug260264.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/dom/tests/mochitest/bugs/utils_bug260264.js b/dom/tests/mochitest/bugs/utils_bug260264.js new file mode 100644 index 000000000..07b98ea7e --- /dev/null +++ b/dom/tests/mochitest/bugs/utils_bug260264.js @@ -0,0 +1,60 @@ +const ALLOW_ACTION = SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION; +const DENY_ACTION = SpecialPowers.Ci.nsIPermissionManager.DENY_ACTION; +const UNKNOWN_ACTION = SpecialPowers.Ci.nsIPermissionManager.UNKNOWN_ACTION; +const PROMPT_ACTION = SpecialPowers.Ci.nsIPermissionManager.PROMPT_ACTION; + +/** + * Dispatches |handler| to |element|, as if fired in response to |event|. + */ +function send(element, event, handler) { + function unique_handler() { return handler.apply(this, arguments) } + element.addEventListener(event, unique_handler, false); + try { sendMouseEvent({ type: event }, element.id) } + finally { element.removeEventListener(event, unique_handler, false) } +} + +/** + * Because it's not nice to leave popup windows open after the tests are + * finished, we need a foolproof way to close some/all window.opened windows. + */ +(function(originalOpen) { + var wins = []; + (window.open = function() { + var win = originalOpen.apply(window, arguments); + if (win) + wins[wins.length] = win; + return win; + }).close = function(n) { + var promises = []; + if (arguments.length < 1) + n = wins.length; + while (n --> 0) { + var win = wins.pop(); + if (win) { + let openedWindowID = + SpecialPowers.getDOMWindowUtils(win).outerWindowID; + promises.push((function(openedWindow) { + return new Promise(function(resolve) { + let observer = { + observe(subject) { + let wrapped = SpecialPowers.wrap(subject); + let winID = wrapped.QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data; + if (winID == openedWindowID) { + SpecialPowers.removeObserver(observer, "outer-window-destroyed"); + SimpleTest.executeSoon(resolve); + } + } + }; + + SpecialPowers.addObserver(observer, "outer-window-destroyed", false); + }); + })(win)); + win.close(); + } else { + promises.push(Promise.resolve()); + break; + } + } + return Promise.all(promises); + }; +})(window.open); |