browser_UITour_modalDialog.js (3015B)
1 "use strict"; 2 3 /* eslint-disable mozilla/use-chromeutils-generateqi */ 4 5 var gTestTab; 6 var gContentAPI; 7 var handleDialog; 8 9 // Modified from toolkit/components/passwordmgr/test/prompt_common.js 10 var didDialog; 11 12 var timer; // keep in outer scope so it's not GC'd before firing 13 function startCallbackTimer() { 14 didDialog = false; 15 16 // Delay before the callback twiddles the prompt. 17 const dialogDelay = 10; 18 19 // Use a timer to invoke a callback to twiddle the authentication dialog 20 timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); 21 timer.init(observer, dialogDelay, Ci.nsITimer.TYPE_ONE_SHOT); 22 } 23 24 var observer = SpecialPowers.wrapCallbackObject({ 25 QueryInterface(iid) { 26 const interfaces = [ 27 Ci.nsIObserver, 28 Ci.nsISupports, 29 Ci.nsISupportsWeakReference, 30 ]; 31 32 if ( 33 !interfaces.some(function (v) { 34 return iid.equals(v); 35 }) 36 ) { 37 throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE; 38 } 39 return this; 40 }, 41 42 observe() { 43 var doc = getDialogDoc(); 44 if (doc) { 45 handleDialog(doc); 46 } else { 47 startCallbackTimer(); 48 } // try again in a bit 49 }, 50 }); 51 52 function getDialogDoc() { 53 // Find the <browser> which contains notifyWindow, by looking 54 // through all the open windows and all the <browsers> in each. 55 56 // var enumerator = wm.getEnumerator("navigator:browser"); 57 for (let { docShell } of Services.wm.getEnumerator(null)) { 58 var containedDocShells = docShell.getAllDocShellsInSubtree( 59 docShell.typeChrome, 60 docShell.ENUMERATE_FORWARDS 61 ); 62 for (let childDocShell of containedDocShells) { 63 // Get the corresponding document for this docshell 64 // We don't want it if it's not done loading. 65 if (childDocShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE) { 66 continue; 67 } 68 var childDoc = childDocShell.docViewer.DOMDocument; 69 70 // ok(true, "Got window: " + childDoc.location.href); 71 if ( 72 childDoc.location.href == "chrome://global/content/commonDialog.xhtml" 73 ) { 74 return childDoc; 75 } 76 } 77 } 78 79 return null; 80 } 81 82 function test() { 83 UITourTest(); 84 } 85 86 var tests = [ 87 taskify(async function test_modal_dialog_while_opening_tooltip() { 88 let panelShown; 89 let popup; 90 91 handleDialog = doc => { 92 popup = document.getElementById("UITourTooltip"); 93 gContentAPI.showInfo("appMenu", "test title", "test text"); 94 doc.defaultView.setTimeout(function () { 95 is( 96 popup.state, 97 "closed", 98 "Popup shouldn't be shown while dialog is up" 99 ); 100 panelShown = promisePanelElementShown(window, popup); 101 let dialog = doc.getElementById("commonDialog"); 102 dialog.acceptDialog(); 103 }, 1000); 104 }; 105 startCallbackTimer(); 106 executeSoon(() => alert("test")); 107 await waitForConditionPromise( 108 () => panelShown, 109 "Timed out waiting for panel promise to be assigned", 110 100 111 ); 112 await panelShown; 113 114 await hideInfoPromise(); 115 }), 116 ];