mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
216 lines
5.8 KiB
HTML
216 lines
5.8 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Test for Login Manager</title>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
|
<script type="text/javascript" src="pwmgr_common.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body>
|
|
Login Manager test: multiple login autocomplete
|
|
|
|
<script>
|
|
commonInit();
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
// Get the pwmgr service
|
|
var pwmgr = SpecialPowers.Cc["@mozilla.org/login-manager;1"]
|
|
.getService(SpecialPowers.Ci.nsILoginManager);
|
|
ok(pwmgr != null, "nsLoginManager service");
|
|
|
|
// Create some logins just for this form, since we'll be deleting them.
|
|
var nsLoginInfo =
|
|
SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/login-manager/loginInfo;1",
|
|
SpecialPowers.Ci.nsILoginInfo, "init");
|
|
ok(nsLoginInfo != null, "nsLoginInfo constructor");
|
|
|
|
|
|
var login0 = new nsLoginInfo(
|
|
"http://mochi.test:8888", "http://autocomplete:8888", null,
|
|
"name", "pass", "uname", "pword");
|
|
|
|
var login1 = new nsLoginInfo(
|
|
"http://mochi.test:8888", "http://autocomplete:8888", null,
|
|
"Name", "Pass", "uname", "pword");
|
|
|
|
var login2 = new nsLoginInfo(
|
|
"http://mochi.test:8888", "http://autocomplete:8888", null,
|
|
"USER", "PASS", "uname", "pword");
|
|
|
|
try {
|
|
pwmgr.addLogin(login0);
|
|
pwmgr.addLogin(login1);
|
|
pwmgr.addLogin(login2);
|
|
} catch (e) {
|
|
ok(false, "addLogin threw: " + e);
|
|
}
|
|
|
|
</script>
|
|
<p id="display"></p>
|
|
|
|
<!-- we presumably can't hide the content for this test. -->
|
|
<div id="content">
|
|
|
|
<!-- form1 tests multiple matching logins -->
|
|
<form id="form1" action="http://autocomplete:8888/formtest.js" onsubmit="return false;">
|
|
<input type="text" name="uname">
|
|
<input type="password" name="pword">
|
|
<button type="submit">Submit</button>
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
/** Test for Login Manager: multiple login autocomplete. **/
|
|
|
|
var tester;
|
|
|
|
var uname = $_(1, "uname");
|
|
var pword = $_(1, "pword");
|
|
|
|
// Restore the form to the default state.
|
|
function restoreForm() {
|
|
uname.value = "";
|
|
pword.value = "";
|
|
uname.focus();
|
|
}
|
|
|
|
|
|
// Check for expected username/password in form.
|
|
function checkACForm(expectedUsername, expectedPassword) {
|
|
var formID = uname.parentNode.id;
|
|
is(uname.value, expectedUsername, "Checking " + formID + " username");
|
|
is(pword.value, expectedPassword, "Checking " + formID + " password");
|
|
}
|
|
|
|
|
|
function sendFakeAutocompleteEvent(element) {
|
|
var acEvent = document.createEvent("HTMLEvents");
|
|
acEvent.initEvent("DOMAutoComplete", true, false);
|
|
element.dispatchEvent(acEvent);
|
|
}
|
|
|
|
function addPopupListener(eventName, func, capture) {
|
|
autocompletePopup.addEventListener(eventName, func, capture);
|
|
}
|
|
|
|
function removePopupListener(eventName, func, capture) {
|
|
autocompletePopup.removeEventListener(eventName, func, capture);
|
|
}
|
|
|
|
/*
|
|
* Main section of test...
|
|
*
|
|
* This is a bit hacky, because the events are either being sent or
|
|
* processes asynchronously, so we need to interrupt our flow with lots of
|
|
* setTimeout() calls. The case statements are executed in order, one per
|
|
* timeout.
|
|
*/
|
|
function* runTest() {
|
|
function runNextTest() {
|
|
addPopupListener("popupshown", function() {
|
|
removePopupListener("popupshown", arguments.callee, false);
|
|
|
|
window.setTimeout(tester.next.bind(tester), 0);
|
|
}, false);
|
|
}
|
|
|
|
function waitForCompletion() {
|
|
var observer = SpecialPowers.wrapCallback(function(subject, topic, data) {
|
|
SpecialPowers.removeObserver(observer, "passwordmgr-found-logins");
|
|
tester.next();
|
|
});
|
|
SpecialPowers.addObserver(observer, "passwordmgr-found-logins", false);
|
|
}
|
|
|
|
/* test 1 */
|
|
// Make sure initial form is empty.
|
|
checkACForm("", "");
|
|
// Trigger autocomplete popup
|
|
restoreForm();
|
|
doKey("down");
|
|
yield runNextTest();
|
|
|
|
/* test 2 */
|
|
// Check first entry
|
|
doKey("down");
|
|
checkACForm("", ""); // value shouldn't update
|
|
doKey("return"); // not "enter"!
|
|
yield waitForCompletion();
|
|
checkACForm("name", "pass");
|
|
|
|
// Trigger autocomplete popup
|
|
restoreForm();
|
|
doKey("down");
|
|
yield runNextTest();
|
|
|
|
/* test 3 */
|
|
// Check second entry
|
|
doKey("down");
|
|
doKey("down");
|
|
doKey("return"); // not "enter"!
|
|
yield waitForCompletion();
|
|
checkACForm("Name", "Pass");
|
|
|
|
// Trigger autocomplete popup
|
|
restoreForm();
|
|
doKey("down");
|
|
yield runNextTest();
|
|
|
|
/* test 4 */
|
|
// Check third entry
|
|
doKey("down");
|
|
doKey("down");
|
|
doKey("down");
|
|
doKey("return");
|
|
yield waitForCompletion();
|
|
checkACForm("USER", "PASS");
|
|
|
|
// Trigger autocomplete popup
|
|
restoreForm();
|
|
uname.value = "user";
|
|
doKey("down");
|
|
yield runNextTest();
|
|
|
|
/* test 5 */
|
|
// Check that we don't clobber user-entered text when tabbing away
|
|
doKey("tab");
|
|
yield waitForCompletion();
|
|
checkACForm("user", "PASS");
|
|
|
|
// Trigger autocomplete popup
|
|
restoreForm();
|
|
SimpleTest.finish();
|
|
}
|
|
|
|
|
|
var autocompletePopup;
|
|
|
|
function startTest() {
|
|
var Ci = SpecialPowers.Ci;
|
|
chromeWin = SpecialPowers.wrap(window)
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
.QueryInterface(Ci.nsIDocShellTreeItem)
|
|
.rootTreeItem
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
.getInterface(Ci.nsIDOMWindow)
|
|
.QueryInterface(Ci.nsIDOMChromeWindow);
|
|
// shouldn't reach into browser internals like this and
|
|
// shouldn't assume ID is consistent across products
|
|
autocompletePopup = chromeWin.document.getElementById("PopupAutoComplete");
|
|
ok(autocompletePopup, "Got autocomplete popup");
|
|
tester = runTest();
|
|
tester.next();
|
|
}
|
|
|
|
window.addEventListener("runTests", startTest);
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|
|
|