From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- toolkit/components/prompts/test/.eslintrc.js | 7 + .../components/prompts/test/bug619644_inner.html | 7 + .../components/prompts/test/bug625187_iframe.html | 16 + toolkit/components/prompts/test/chromeScript.js | 241 ++++ toolkit/components/prompts/test/mochitest.ini | 19 + toolkit/components/prompts/test/prompt_common.js | 158 +++ .../components/prompts/test/test_bug619644.html | 76 ++ .../components/prompts/test/test_bug620145.html | 105 ++ .../components/prompts/test/test_dom_prompts.html | 208 ++++ .../prompts/test/test_modal_prompts.html | 1184 ++++++++++++++++++++ .../components/prompts/test/test_modal_select.html | 146 +++ .../prompts/test/test_subresources_prompts.html | 202 ++++ 12 files changed, 2369 insertions(+) create mode 100644 toolkit/components/prompts/test/.eslintrc.js create mode 100644 toolkit/components/prompts/test/bug619644_inner.html create mode 100644 toolkit/components/prompts/test/bug625187_iframe.html create mode 100644 toolkit/components/prompts/test/chromeScript.js create mode 100644 toolkit/components/prompts/test/mochitest.ini create mode 100644 toolkit/components/prompts/test/prompt_common.js create mode 100644 toolkit/components/prompts/test/test_bug619644.html create mode 100644 toolkit/components/prompts/test/test_bug620145.html create mode 100644 toolkit/components/prompts/test/test_dom_prompts.html create mode 100644 toolkit/components/prompts/test/test_modal_prompts.html create mode 100644 toolkit/components/prompts/test/test_modal_select.html create mode 100644 toolkit/components/prompts/test/test_subresources_prompts.html (limited to 'toolkit/components/prompts/test') diff --git a/toolkit/components/prompts/test/.eslintrc.js b/toolkit/components/prompts/test/.eslintrc.js new file mode 100644 index 000000000..3c788d6d6 --- /dev/null +++ b/toolkit/components/prompts/test/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + "extends": [ + "../../../../testing/mochitest/mochitest.eslintrc.js" + ] +}; diff --git a/toolkit/components/prompts/test/bug619644_inner.html b/toolkit/components/prompts/test/bug619644_inner.html new file mode 100644 index 000000000..f929c5649 --- /dev/null +++ b/toolkit/components/prompts/test/bug619644_inner.html @@ -0,0 +1,7 @@ +

Original content

+ diff --git a/toolkit/components/prompts/test/bug625187_iframe.html b/toolkit/components/prompts/test/bug625187_iframe.html new file mode 100644 index 000000000..740d59a61 --- /dev/null +++ b/toolkit/components/prompts/test/bug625187_iframe.html @@ -0,0 +1,16 @@ + + + Test for Bug 625187 - the iframe + + + +

+

+ + diff --git a/toolkit/components/prompts/test/chromeScript.js b/toolkit/components/prompts/test/chromeScript.js new file mode 100644 index 000000000..7b2d37100 --- /dev/null +++ b/toolkit/components/prompts/test/chromeScript.js @@ -0,0 +1,241 @@ +const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; +Components.utils.import("resource://gre/modules/Services.jsm"); +Components.utils.import("resource://gre/modules/Timer.jsm"); + +// Define these to make EventUtils happy. +let window = this; +let parent = {}; + +let EventUtils = {}; +Services.scriptloader.loadSubScript( + "chrome://mochikit/content/tests/SimpleTest/EventUtils.js", + EventUtils +); + +addMessageListener("handlePrompt", msg => { + handlePromptWhenItAppears(msg.action, msg.isTabModal, msg.isSelect); +}); + +function handlePromptWhenItAppears(action, isTabModal, isSelect) { + let interval = setInterval(() => { + if (handlePrompt(action, isTabModal, isSelect)) { + clearInterval(interval); + } + }, 100); +} + +function handlePrompt(action, isTabModal, isSelect) { + let ui; + + if (isTabModal) { + let browserWin = Services.wm.getMostRecentWindow("navigator:browser"); + let gBrowser = browserWin.gBrowser; + let promptManager = gBrowser.getTabModalPromptBox(gBrowser.selectedBrowser); + let prompts = promptManager.listPrompts(); + if (!prompts.length) { + return false; // try again in a bit + } + + ui = prompts[0].Dialog.ui; + } else { + let doc = getDialogDoc(); + if (!doc) { + return false; // try again in a bit + } + + if (isSelect) + ui = doc; + else + ui = doc.defaultView.Dialog.ui; + + } + + let promptState; + if (isSelect) { + promptState = getSelectState(ui); + dismissSelect(ui, action); + } else { + promptState = getPromptState(ui); + dismissPrompt(ui, action); + } + sendAsyncMessage("promptHandled", { promptState: promptState }); + return true; +} + +function getSelectState(ui) { + let listbox = ui.getElementById("list"); + + let state = {}; + state.msg = ui.getElementById("info.txt").value; + state.selectedIndex = listbox.selectedIndex; + state.items = []; + + for (let i = 0; i < listbox.itemCount; i++) { + let item = listbox.getItemAtIndex(i).label; + state.items.push(item); + } + + return state; +} + +function getPromptState(ui) { + let state = {}; + state.msg = ui.infoBody.textContent; + state.titleHidden = ui.infoTitle.getAttribute("hidden") == "true"; + state.textHidden = ui.loginContainer.hidden; + state.passHidden = ui.password1Container.hidden; + state.checkHidden = ui.checkboxContainer.hidden; + state.checkMsg = ui.checkbox.label; + state.checked = ui.checkbox.checked; + // tab-modal prompts don't have an infoIcon + state.iconClass = ui.infoIcon ? ui.infoIcon.className : null; + state.textValue = ui.loginTextbox.getAttribute("value"); + state.passValue = ui.password1Textbox.getAttribute("value"); + + state.butt0Label = ui.button0.label; + state.butt1Label = ui.button1.label; + state.butt2Label = ui.button2.label; + + state.butt0Disabled = ui.button0.disabled; + state.butt1Disabled = ui.button1.disabled; + state.butt2Disabled = ui.button2.disabled; + + function isDefaultButton(b) { + return (b.hasAttribute("default") && + b.getAttribute("default") == "true"); + } + state.defButton0 = isDefaultButton(ui.button0); + state.defButton1 = isDefaultButton(ui.button1); + state.defButton2 = isDefaultButton(ui.button2); + + let fm = Cc["@mozilla.org/focus-manager;1"]. + getService(Ci.nsIFocusManager); + let e = fm.focusedElement; + + if (e == null) { + state.focused = null; + } else if (ui.button0.isSameNode(e)) { + state.focused = "button0"; + } else if (ui.button1.isSameNode(e)) { + state.focused = "button1"; + } else if (ui.button2.isSameNode(e)) { + state.focused = "button2"; + } else if (ui.loginTextbox.inputField.isSameNode(e)) { + state.focused = "textField"; + } else if (ui.password1Textbox.inputField.isSameNode(e)) { + state.focused = "passField"; + } else if (ui.infoBody.isSameNode(e)) { + state.focused = "infoBody"; + } else { + state.focused = "ERROR: unexpected element focused: " + (e ? e.localName : ""); + } + + return state; +} + +function dismissSelect(ui, action) { + let dialog = ui.getElementsByTagName("dialog")[0]; + let listbox = ui.getElementById("list"); + + if (action.selectItem) { + listbox.selectedIndex = 1; + } + + if (action.buttonClick == "ok") { + dialog.acceptDialog(); + } else if (action.buttonClick == "cancel") { + dialog.cancelDialog(); + } +} + +function dismissPrompt(ui, action) { + if (action.setCheckbox) { + // Annoyingly, the prompt code is driven by oncommand. + ui.checkbox.setChecked(true); + ui.checkbox.doCommand(); + } + + if ("textField" in action) { + ui.loginTextbox.setAttribute("value", action.textField); + } + + if ("passField" in action) { + ui.password1Textbox.setAttribute("value", action.passField); + } + + switch (action.buttonClick) { + case "ok": + case 0: + ui.button0.click(); + break; + case "cancel": + case 1: + ui.button1.click(); + break; + case 2: + ui.button2.click(); + break; + case "ESC": + // XXX This is assuming tab-modal. + let browserWin = Services.wm.getMostRecentWindow("navigator:browser"); + EventUtils.synthesizeKey("KEY_Escape", { code: "Escape" }, browserWin); + break; + case "pollOK": + // Buttons are disabled at the moment, poll until they're reenabled. + // Can't use setInterval here, because the window's in a modal state + // and thus DOM events are suppressed. + let interval = setInterval(() => { + if (ui.button0.disabled) + return; + ui.button0.click(); + clearInterval(interval); + }, 100); + break; + + default: + throw "dismissPrompt action listed unknown button."; + } +} + +function getDialogDoc() { + // Trudge through all the open windows, until we find the one + // that has either commonDialog.xul or selectDialog.xul loaded. + var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. + getService(Ci.nsIWindowMediator); + // var enumerator = wm.getEnumerator("navigator:browser"); + var enumerator = wm.getXULWindowEnumerator(null); + + while (enumerator.hasMoreElements()) { + var win = enumerator.getNext(); + var windowDocShell = win.QueryInterface(Ci.nsIXULWindow).docShell; + + var containedDocShells = windowDocShell.getDocShellEnumerator( + Ci.nsIDocShellTreeItem.typeChrome, + Ci.nsIDocShell.ENUMERATE_FORWARDS); + while (containedDocShells.hasMoreElements()) { + // Get the corresponding document for this docshell + var childDocShell = containedDocShells.getNext(); + // We don't want it if it's not done loading. + if (childDocShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE) + continue; + var childDoc = childDocShell.QueryInterface(Ci.nsIDocShell) + .contentViewer + .DOMDocument; + + if (childDoc.location.href != "chrome://global/content/commonDialog.xul" && + childDoc.location.href != "chrome://global/content/selectDialog.xul") + continue; + + // We're expecting the dialog to be focused. If it's not yet, try later. + // (In particular, this is needed on Linux to reliably check focused elements.) + let fm = Cc["@mozilla.org/focus-manager;1"]. + getService(Ci.nsIFocusManager); + if (fm.focusedWindow != childDoc.defaultView) + continue; + + return childDoc; + } + } + + return null; +} diff --git a/toolkit/components/prompts/test/mochitest.ini b/toolkit/components/prompts/test/mochitest.ini new file mode 100644 index 000000000..7f87650d6 --- /dev/null +++ b/toolkit/components/prompts/test/mochitest.ini @@ -0,0 +1,19 @@ +[DEFAULT] +support-files = + ../../passwordmgr/test/authenticate.sjs + bug619644_inner.html + bug625187_iframe.html + prompt_common.js + chromeScript.js + +[test_bug619644.html] +[test_bug620145.html] +skip-if = toolkit == 'android' #TIMED_OUT +[test_subresources_prompts.html] +skip-if = toolkit == 'android' +[test_dom_prompts.html] +skip-if = toolkit == 'android' #android: bug 1267092 +[test_modal_prompts.html] +skip-if = toolkit == 'android' || (os == 'linux' && (debug || asan)) #android: TIMED_OUT (For Linux : 950636) +[test_modal_select.html] +skip-if = toolkit == 'android' #android: TIMED_OUT diff --git a/toolkit/components/prompts/test/prompt_common.js b/toolkit/components/prompts/test/prompt_common.js new file mode 100644 index 000000000..e3a69b347 --- /dev/null +++ b/toolkit/components/prompts/test/prompt_common.js @@ -0,0 +1,158 @@ +const Ci = SpecialPowers.Ci; +const Cc = SpecialPowers.Cc; +ok(Ci != null, "Access Ci"); +ok(Cc != null, "Access Cc"); + +function hasTabModalPrompts() { + var prefName = "prompts.tab_modal.enabled"; + var Services = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm").Services; + return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL && + Services.prefs.getBoolPref(prefName); +} +var isTabModal = hasTabModalPrompts(); +var isSelectDialog = false; +var isOSX = ("nsILocalFileMac" in SpecialPowers.Ci); +var isE10S = SpecialPowers.Services.appinfo.processType == 2; + + +var gChromeScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("chromeScript.js")); +SimpleTest.registerCleanupFunction(() => gChromeScript.destroy()); + +function onloadPromiseFor(id) { + var iframe = document.getElementById(id); + return new Promise(resolve => { + iframe.addEventListener("load", function onload(e) { + iframe.removeEventListener("load", onload); + resolve(true); + }); + }); +} + +function handlePrompt(state, action) { + return new Promise(resolve => { + gChromeScript.addMessageListener("promptHandled", function handled(msg) { + gChromeScript.removeMessageListener("promptHandled", handled); + checkPromptState(msg.promptState, state); + resolve(true); + }); + gChromeScript.sendAsyncMessage("handlePrompt", { action: action, isTabModal: isTabModal}); + }); +} + +function checkPromptState(promptState, expectedState) { + // XXX check title? OS X has title in content + is(promptState.msg, expectedState.msg, "Checking expected message"); + if (isOSX && !isTabModal) + ok(!promptState.titleHidden, "Checking title always visible on OS X"); + else + is(promptState.titleHidden, expectedState.titleHidden, "Checking title visibility"); + is(promptState.textHidden, expectedState.textHidden, "Checking textbox visibility"); + is(promptState.passHidden, expectedState.passHidden, "Checking passbox visibility"); + is(promptState.checkHidden, expectedState.checkHidden, "Checking checkbox visibility"); + is(promptState.checkMsg, expectedState.checkMsg, "Checking checkbox label"); + is(promptState.checked, expectedState.checked, "Checking checkbox checked"); + if (!isTabModal) + is(promptState.iconClass, "spaced " + expectedState.iconClass, "Checking expected icon CSS class"); + is(promptState.textValue, expectedState.textValue, "Checking textbox value"); + is(promptState.passValue, expectedState.passValue, "Checking passbox value"); + + if (expectedState.butt0Label) { + is(promptState.butt0Label, expectedState.butt0Label, "Checking accept-button label"); + } + if (expectedState.butt1Label) { + is(promptState.butt1Label, expectedState.butt1Label, "Checking cancel-button label"); + } + if (expectedState.butt2Label) { + is(promptState.butt2Label, expectedState.butt2Label, "Checking extra1-button label"); + } + + // For prompts with a time-delay button. + if (expectedState.butt0Disabled) { + is(promptState.butt0Disabled, true, "Checking accept-button is disabled"); + is(promptState.butt1Disabled, false, "Checking cancel-button isn't disabled"); + } + + is(promptState.defButton0, expectedState.defButton == "button0", "checking button0 default"); + is(promptState.defButton1, expectedState.defButton == "button1", "checking button1 default"); + is(promptState.defButton2, expectedState.defButton == "button2", "checking button2 default"); + + if (isOSX && expectedState.focused && expectedState.focused.startsWith("button")) { + is(promptState.focused, "infoBody", "buttons don't focus on OS X, but infoBody does instead"); + } else { + is(promptState.focused, expectedState.focused, "Checking focused element"); + } +} + +function checkEchoedAuthInfo(expectedState, doc) { + // The server echos back the HTTP auth info it received. + let username = doc.getElementById("user").textContent; + let password = doc.getElementById("pass").textContent; + let authok = doc.getElementById("ok").textContent; + + is(authok, "PASS", "Checking for successful authentication"); + is(username, expectedState.user, "Checking for echoed username"); + is(password, expectedState.pass, "Checking for echoed password"); +} + +/** + * Create a Proxy to relay method calls on an nsIAuthPrompt[2] prompter to a chrome script which can + * perform the calls in the parent. Out and inout params will be copied back from the parent to + * content. + * + * @param chromeScript The reference to the chrome script that will listen to `proxyPrompter` + * messages in the parent and call the `methodName` method. + * The return value from the message handler should be an object with properties: + * `rv` - containing the return value of the method call. + * `args` - containing the array of arguments passed to the method since out or inout ones could have + * been modified. + */ +function PrompterProxy(chromeScript) { + return new Proxy({}, { + get(target, prop, receiver) { + return (...args) => { + // Array of indices of out/inout params to copy from the parent back to the caller. + let outParams = []; + + switch (prop) { + case "prompt": { + outParams = [/* result */ 5]; + break; + } + case "promptAuth": { + outParams = []; + break; + } + case "promptPassword": { + outParams = [/* pwd */ 4]; + break; + } + case "promptUsernameAndPassword": { + outParams = [/* user */ 4, /* pwd */ 5]; + break; + } + default: { + throw new Error("Unknown nsIAuthPrompt method"); + } + } + + let result = chromeScript.sendSyncMessage("proxyPrompter", { + args, + methodName: prop, + })[0][0]; + + for (let outParam of outParams) { + // Copy the out or inout param value over the original + args[outParam].value = result.args[outParam].value; + } + + if (prop == "promptAuth") { + args[2].username = result.args[2].username; + args[2].password = result.args[2].password; + args[2].domain = result.args[2].domain; + } + + return result.rv; + }; + }, + }); +} diff --git a/toolkit/components/prompts/test/test_bug619644.html b/toolkit/components/prompts/test/test_bug619644.html new file mode 100644 index 000000000..9f61eb18b --- /dev/null +++ b/toolkit/components/prompts/test/test_bug619644.html @@ -0,0 +1,76 @@ + + + + + Test for Bug 619644 + + + + + + + +Mozilla Bug 619644 +
+
+
+ + diff --git a/toolkit/components/prompts/test/test_bug620145.html b/toolkit/components/prompts/test/test_bug620145.html new file mode 100644 index 000000000..bb4470259 --- /dev/null +++ b/toolkit/components/prompts/test/test_bug620145.html @@ -0,0 +1,105 @@ + + + Test for Bug 620145 + + + + + + + + +Mozilla Bug 620145 +
+
+ +
+ This is a short piece of text used for testing that mouse selecting is + stopped when an alert appears. +
+
+ This is another short piece of text used for testing that mouse selecting is + stopped when an alert appears. +
+ + + + + + diff --git a/toolkit/components/prompts/test/test_dom_prompts.html b/toolkit/components/prompts/test/test_dom_prompts.html new file mode 100644 index 000000000..413ed8fd5 --- /dev/null +++ b/toolkit/components/prompts/test/test_dom_prompts.html @@ -0,0 +1,208 @@ + + + Test for DOM prompts + + + + + + + + +
+
+ + + + + diff --git a/toolkit/components/prompts/test/test_modal_prompts.html b/toolkit/components/prompts/test/test_modal_prompts.html new file mode 100644 index 000000000..42e6be52c --- /dev/null +++ b/toolkit/components/prompts/test/test_modal_prompts.html @@ -0,0 +1,1184 @@ + + + + Modal Prompts Test + + + + + + +Prompter tests: modal prompts +

+ + + +
+
+
+ + diff --git a/toolkit/components/prompts/test/test_modal_select.html b/toolkit/components/prompts/test/test_modal_select.html new file mode 100644 index 000000000..1e008d0f4 --- /dev/null +++ b/toolkit/components/prompts/test/test_modal_select.html @@ -0,0 +1,146 @@ + + + + Modal Prompts Test + + + + + + +Prompter tests: modal prompts +

+ + + +
+
+
+ + diff --git a/toolkit/components/prompts/test/test_subresources_prompts.html b/toolkit/components/prompts/test/test_subresources_prompts.html new file mode 100644 index 000000000..241ce430f --- /dev/null +++ b/toolkit/components/prompts/test/test_subresources_prompts.html @@ -0,0 +1,202 @@ + + + Test subresources prompts (Bug 625187 and bug 1230462) + + + + + + + + + +Mozilla Bug 625187 +Mozilla Bug 1230462 + +

+ + + + + + + +

+
+
+
+
-- 
cgit v1.2.3