utils_bug260264.js (2247B)
1 const ALLOW_ACTION = SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION; 2 const DENY_ACTION = SpecialPowers.Ci.nsIPermissionManager.DENY_ACTION; 3 const UNKNOWN_ACTION = SpecialPowers.Ci.nsIPermissionManager.UNKNOWN_ACTION; 4 const PROMPT_ACTION = SpecialPowers.Ci.nsIPermissionManager.PROMPT_ACTION; 5 6 /** 7 * Dispatches |handler| to |element|, as if fired in response to |event|. 8 */ 9 function send(element, event, handler) { 10 function unique_handler() { 11 return handler.apply(this, arguments); 12 } 13 element.addEventListener(event, unique_handler); 14 try { 15 sendMouseEvent({ type: event }, element.id); 16 } finally { 17 element.removeEventListener(event, unique_handler); 18 } 19 } 20 function sendWithUserActivation(element, event, handler) { 21 SpecialPowers.wrap(document).notifyUserGestureActivation(); 22 send(element, event, handler); 23 } 24 25 /** 26 * Because it's not nice to leave popup windows open after the tests are 27 * finished, we need a foolproof way to close some/all window.opened windows. 28 */ 29 (function (originalOpen) { 30 var wins = []; 31 (window.open = function () { 32 var win = originalOpen.apply(window, arguments); 33 if (win) { 34 wins[wins.length] = win; 35 } 36 return win; 37 }).close = function (n) { 38 var promises = []; 39 if (arguments.length < 1) { 40 n = wins.length; 41 } 42 while (n-- > 0) { 43 var win = wins.pop(); 44 if (win) { 45 let openedBrowsingContextID = SpecialPowers.getBrowsingContextID(win); 46 promises.push( 47 (function (openedWindow) { 48 return new Promise(function (resolve) { 49 let observer = { 50 observe(subject) { 51 if (subject.id == openedBrowsingContextID) { 52 SpecialPowers.removeObserver( 53 observer, 54 "browsing-context-discarded" 55 ); 56 SimpleTest.executeSoon(resolve); 57 } 58 }, 59 }; 60 61 SpecialPowers.addObserver(observer, "browsing-context-discarded"); 62 }); 63 })(win) 64 ); 65 win.close(); 66 } else { 67 promises.push(Promise.resolve()); 68 break; 69 } 70 } 71 return Promise.all(promises); 72 }; 73 })(window.open);