Bug 1520968 - Make toolkit/components/passwordmgr/test/test_xml_load.html work with e10s. r=MattN

Make toolkit/components/passwordmgr/test/test_xml_load.html work with e10s

Differential Revision: https://phabricator.services.mozilla.com/D17715

--HG--
rename : toolkit/components/passwordmgr/test/test_xml_load.html => toolkit/components/passwordmgr/test/mochitest/test_xml_load.html
extra : moz-landing-system : lando
This commit is contained in:
prathiksha 2019-01-30 23:53:44 +00:00
parent 0b892f60bb
commit cef7a8c742
6 changed files with 187 additions and 190 deletions

View File

@ -14,5 +14,3 @@ support-files =
[test_xhr.html]
skip-if = toolkit == 'android' # Tests desktop prompts
[test_xml_load.html]
skip-if = toolkit == 'android' # Tests desktop prompts

View File

@ -94,3 +94,6 @@ skip-if = e10s || os == "linux" || toolkit == 'android' # Tests desktop prompts
[test_username_focus.html]
skip-if = toolkit == 'android' # android:autocomplete.
[test_xhr_2.html]
[test_xml_load.html]
skip-if = toolkit == 'android' # Tests desktop prompts

View File

@ -0,0 +1,146 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test XML document prompts</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/AddTask.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<script type="text/javascript" src="prompt_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Login Manager test: XML prompt
<p id="display"></p>
<div id="content" style="display: none">
<iframe id="iframe"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Login Manager: XML prompts. **/
// Force parent to not look for tab-modal prompts, as they're not used for auth prompts.
// Used by prompt_common.js.
isTabModal = false;
function makeRequest(uri, expectedUser, expectedPass) {
let xmlDoc = document.implementation.createDocument("", "test", null);
xmlDoc.load(uri);
return new Promise(resolve => {
xmlDoc.addEventListener("load", documentLoaded);
function documentLoaded(e) {
let username = xmlDoc.getElementById("user").textContent;
let password = xmlDoc.getElementById("pass").textContent;
is(username, expectedUser, "Checking provided username");
is(password, expectedPass, "Checking provided password");
resolve();
}
});
}
function checkWindowFocus() {
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
// Check that the right tab is focused:
let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
let spec = browserWin.gBrowser.selectedBrowser.currentURI.spec;
sendAsyncMessage("focusResult", spec.startsWith("http://mochi.test:8888"));
}
runInParent(function initLogins() {
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
let login1 = Cc["@mozilla.org/login-manager/loginInfo;1"]
.createInstance(Ci.nsILoginInfo);
let login2 = Cc["@mozilla.org/login-manager/loginInfo;1"]
.createInstance(Ci.nsILoginInfo);
login1.init("http://mochi.test:8888", null, "xml",
"xmluser1", "xmlpass1", "", "");
login2.init("http://mochi.test:8888", null, "xml2",
"xmluser2", "xmlpass2", "", "");
Services.logins.addLogin(login1);
Services.logins.addLogin(login2);
});
add_task(async function test_promptUsernameAndPassword_accept() {
let loadPromise = makeRequest("authenticate.sjs?user=xmluser1&pass=xmlpass1&realm=xml", "xmluser1", "xmlpass1");
let state = {
msg: `http://mochi.test:8888 is requesting your username and password. The site says: “xml”`,
title: "Authentication Required",
textValue: "xmluser1",
passValue: "xmlpass1",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
let action = {
buttonClick: "ok",
};
await handlePrompt(state, action);
await loadPromise;
});
add_task(async function test_backgroundTab() {
// Test correct parenting, by opening another tab in the foreground,
// and making sure the prompt re-focuses the original tab when shown:
let newWin = window.open();
newWin.focus();
let loadPromise = makeRequest("authenticate.sjs?user=xmluser2&pass=xmlpass2&realm=xml2", "xmluser2", "xmlpass2");
// We do this because the handlePrompt function ensures that the dialog exists before proceeding with other checks.
let state = {
msg: `http://mochi.test:8888 is requesting your username and password. The site says: “xml2”`,
title: "Authentication Required",
textValue: "xmluser2",
passValue: "xmlpass2",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
let action = {
buttonClick: "none",
};
await handlePrompt(state, action);
await checkPromptModal();
await new Promise(resolve => {
let focusScript = runInParent(checkWindowFocus);
focusScript.addMessageListener("focusResult", (msg) => {
focusScript.removeMessageListener("focusResult");
ok(msg, "Dialog appears on the right tab");
resolve(true);
});
});
action = {
buttonClick: "ok",
};
await handlePrompt(state, action);
await loadPromise;
newWin.close();
});
</script>
</pre>
</body>
</html>

View File

@ -1,188 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test XML document prompts</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<script type="text/javascript" src="prompt_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Login Manager test: XML prompt
<p id="display"></p>
<div id="content" style="display: none">
<iframe id="iframe"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Login Manager: XML prompts. **/
var login1, login2;
function initLogins() {
login1 = SpecialPowers.Cc["@mozilla.org/login-manager/loginInfo;1"]
.createInstance(Ci.nsILoginInfo);
login2 = SpecialPowers.Cc["@mozilla.org/login-manager/loginInfo;1"]
.createInstance(Ci.nsILoginInfo);
login1.init("http://mochi.test:8888", null, "xml",
"xmluser1", "xmlpass1", "", "");
login2.init("http://mochi.test:8888", null, "xml2",
"xmluser2", "xmlpass2", "", "");
SpecialPowers.Services.logins.addLogin(login1);
SpecialPowers.Services.logins.addLogin(login2);
}
function handleDialog(doc, testNum) {
ok(true, "handleDialog running for test " + testNum);
var clickOK = true;
var userfield = doc.getElementById("loginTextbox");
var passfield = doc.getElementById("password1Textbox");
var username = userfield.getAttribute("value");
var password = passfield.getAttribute("value");
var dialog = doc.getElementById("commonDialog");
switch (testNum) {
case 1:
is(username, "xmluser1", "Checking provided username");
is(password, "xmlpass1", "Checking provided password");
break;
case 2:
is(username, "xmluser2", "Checking provided username");
is(password, "xmlpass2", "Checking provided password");
// Check that the dialog is modal, chrome and dependent;
// We can't just check window.opener because that'll be
// a content window, which therefore isn't exposed (it'll lie and
// be null).
var win = doc.defaultView;
var Ci = SpecialPowers.Ci;
var treeOwner = win.docShell.treeOwner;
treeOwner.QueryInterface(Ci.nsIInterfaceRequestor);
var flags = treeOwner.getInterface(Ci.nsIXULWindow).chromeFlags;
var wbc = treeOwner.getInterface(Ci.nsIWebBrowserChrome);
info("Flags: " + flags);
ok((flags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_CHROME) != 0,
"Dialog should be opened as chrome");
ok((flags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_DIALOG) != 0,
"Dialog should be opened as a dialog");
ok((flags & Ci.nsIWebBrowserChrome.CHROME_DEPENDENT) != 0,
"Dialog should be opened as dependent.");
ok(wbc.isWindowModal(), "Dialog should be modal");
// Check that the right tab is focused:
var browserWin = SpecialPowers.Services.wm.getMostRecentWindow("navigator:browser");
var spec = browserWin.gBrowser.selectedBrowser.currentURI.spec;
ok(spec.startsWith("http://mochi.test:8888"),
"Tab with remote URI (rather than about:blank) should be focused (" + spec + ")");
break;
default:
ok(false, "Uhh, unhandled switch for testNum #" + testNum);
break;
}
// Explicitly cancel the dialog and report a fail in this failure
// case, rather than letting the dialog get stuck due to an auth
// failure and having the test timeout.
if (!username && !password) {
ok(false, "No values prefilled");
clickOK = false;
}
if (clickOK) {
dialog.acceptDialog();
} else {
dialog.cancelDialog();
}
ok(true, "handleDialog done");
didDialog = true;
}
var newWin;
function xmlLoad(responseDoc) {
ok(true, "xmlLoad running for test " + testNum);
// The server echos back the user/pass it received.
var username = responseDoc.getElementById("user").textContent;
var password = responseDoc.getElementById("pass").textContent;
var authok = responseDoc.getElementById("ok").textContent;
switch (testNum) {
case 1:
is(username, "xmluser1", "Checking provided username");
is(password, "xmlpass1", "Checking provided password");
break;
case 2:
is(username, "xmluser2", "Checking provided username");
is(password, "xmlpass2", "Checking provided password");
newWin.close();
break;
default:
ok(false, "Uhh, unhandled switch for testNum #" + testNum);
break;
}
doTest();
}
function doTest() {
switch (++testNum) {
case 1:
startCallbackTimer();
makeRequest("authenticate.sjs?user=xmluser1&pass=xmlpass1&realm=xml");
break;
case 2:
// Test correct parenting, by opening another tab in the foreground,
// and making sure the prompt re-focuses the original tab when shown:
newWin = window.open();
newWin.focus();
startCallbackTimer();
makeRequest("authenticate.sjs?user=xmluser2&pass=xmlpass2&realm=xml2");
break;
default:
SimpleTest.finish();
}
}
function makeRequest(uri) {
var xmlDoc = document.implementation.createDocument("", "test", null);
function documentLoaded(e) {
xmlLoad(xmlDoc);
}
xmlDoc.addEventListener("load", documentLoaded);
xmlDoc.load(uri);
}
initLogins();
// clear plain HTTP auth sessions before the test, to allow
// running them more than once.
var authMgr = SpecialPowers.Cc["@mozilla.org/network/http-auth-manager;1"]
.getService(SpecialPowers.Ci.nsIHttpAuthManager);
authMgr.clearAll();
// start the tests
testNum = 0;
doTest();
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

View File

@ -25,6 +25,30 @@ function handlePromptWhenItAppears(action, isTabModal, isSelect) {
}, 100);
}
addMessageListener("checkPromptModal", () => {
checkPromptIsModal();
});
function checkPromptIsModal() {
// Check that the dialog is modal, chrome and dependent;
// We can't just check window.opener because that'll be
// a content window, which therefore isn't exposed (it'll lie and
// be null).
let result = {};
let doc = getDialogDoc();
let win = doc.defaultView;
let treeOwner = win.docShell.treeOwner;
treeOwner.QueryInterface(Ci.nsIInterfaceRequestor);
let flags = treeOwner.getInterface(Ci.nsIXULWindow).chromeFlags;
let wbc = treeOwner.getInterface(Ci.nsIWebBrowserChrome);
result.chrome = (flags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_CHROME) != 0;
result.dialog = (flags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_DIALOG) != 0;
result.chromeDependent = (flags & Ci.nsIWebBrowserChrome.CHROME_DEPENDENT) != 0;
result.isWindowModal = wbc.isWindowModal();
sendAsyncMessage("checkPromptModalResult", result);
}
function handlePrompt(action, isTabModal, isSelect) {
let ui;

View File

@ -35,6 +35,20 @@ function handlePrompt(state, action) {
});
}
function checkPromptModal() {
return new Promise(resolve => {
gChromeScript.addMessageListener("checkPromptModalResult", function handled(result) {
gChromeScript.removeMessageListener("checkPromptModalResult", handled);
ok(result.chrome, "Dialog should be opened as chrome");
ok(result.dialog, "Dialog should be a dialog");
ok(result.chromeDependent, "Dialog should be chrome dependent");
ok(result.isWindowModal, "Dialog should be a window modal");
resolve(true);
});
gChromeScript.sendAsyncMessage("checkPromptModal");
});
}
function checkPromptState(promptState, expectedState) {
info(`checkPromptState: ${expectedState.msg}`);
// XXX check title? OS X has title in content