mirror of
https://github.com/classilla/tenfourfox.git
synced 2025-02-01 00:33:57 +00:00
189 lines
6.0 KiB
HTML
189 lines
6.0 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Test capturing of fields outside of a form</title>
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script src="pwmgr_common.js"></script>
|
|
<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body>
|
|
<script type="application/javascript;version=1.8">
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
|
const LMCBackstagePass = Cu.import("resource://gre/modules/LoginManagerContent.jsm");
|
|
const { LoginManagerContent, FormLikeFactory } = LMCBackstagePass;
|
|
|
|
let parentScriptURL = SimpleTest.getTestFileURL("pwmgr_common.js");
|
|
let mm = SpecialPowers.loadChromeScript(parentScriptURL);
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
document.getElementById("loginFrame").addEventListener("load", (evt) => {
|
|
// Tell the parent to setup test logins.
|
|
mm.sendAsyncMessage("setupParent");
|
|
});
|
|
});
|
|
|
|
// When the setup is done, load a recipe for this test.
|
|
mm.addMessageListener("doneSetup", function doneSetup() {
|
|
mm.sendAsyncMessage("loadRecipes", {
|
|
siteRecipes: [{
|
|
hosts: ["test1.mochi.test:8888"],
|
|
usernameSelector: "input[name='recipeuname']",
|
|
passwordSelector: "input[name='recipepword']",
|
|
}],
|
|
});
|
|
});
|
|
|
|
mm.addMessageListener("loadedRecipes", () => runTest());
|
|
|
|
const DEFAULT_ORIGIN = "http://test1.mochi.test:8888";
|
|
const TESTCASES = [
|
|
{
|
|
// Inputs
|
|
document: `<input type=password value="pass1">`,
|
|
inputIndexForFormLike: 0,
|
|
|
|
// Expected outputs similar to RemoteLogins:onFormSubmit
|
|
hostname: DEFAULT_ORIGIN,
|
|
formSubmitURL: DEFAULT_ORIGIN,
|
|
usernameFieldValue: null,
|
|
newPasswordFieldValue: "pass1",
|
|
oldPasswordFieldValue: null,
|
|
},
|
|
{
|
|
document: `<input value="user1">
|
|
<input type=password value="pass1">`,
|
|
inputIndexForFormLike: 0,
|
|
hostname: DEFAULT_ORIGIN,
|
|
formSubmitURL: DEFAULT_ORIGIN,
|
|
usernameFieldValue: "user1",
|
|
newPasswordFieldValue: "pass1",
|
|
oldPasswordFieldValue: null,
|
|
},
|
|
{
|
|
document: `<input value="user1">
|
|
<input type=password value="pass1">`,
|
|
inputIndexForFormLike: 1,
|
|
hostname: DEFAULT_ORIGIN,
|
|
formSubmitURL: DEFAULT_ORIGIN,
|
|
usernameFieldValue: "user1",
|
|
newPasswordFieldValue: "pass1",
|
|
oldPasswordFieldValue: null,
|
|
},
|
|
{
|
|
document: `<input value="user1">
|
|
<input type=password value="pass1">
|
|
<input type=password value="pass2">`,
|
|
inputIndexForFormLike: 2,
|
|
hostname: DEFAULT_ORIGIN,
|
|
formSubmitURL: DEFAULT_ORIGIN,
|
|
usernameFieldValue: "user1",
|
|
newPasswordFieldValue: "pass2",
|
|
oldPasswordFieldValue: "pass1",
|
|
},
|
|
{
|
|
document: `<input value="user1">
|
|
<input type=password value="pass1">
|
|
<input type=password value="pass2">
|
|
<input type=password value="pass2">`,
|
|
inputIndexForFormLike: 3,
|
|
hostname: DEFAULT_ORIGIN,
|
|
formSubmitURL: DEFAULT_ORIGIN,
|
|
usernameFieldValue: "user1",
|
|
newPasswordFieldValue: "pass2",
|
|
oldPasswordFieldValue: "pass1",
|
|
},
|
|
{
|
|
document: `<input value="user1">
|
|
<input type=password value="user2" form="form1">
|
|
<input type=password value="pass1">
|
|
<form id="form1">
|
|
<input value="user3">
|
|
<input type=password value="pass2">
|
|
</form>`,
|
|
inputIndexForFormLike: 2,
|
|
hostname: DEFAULT_ORIGIN,
|
|
formSubmitURL: DEFAULT_ORIGIN,
|
|
usernameFieldValue: "user1",
|
|
newPasswordFieldValue: "pass1",
|
|
oldPasswordFieldValue: null,
|
|
},
|
|
{
|
|
document: `<!-- recipe field override -->
|
|
<input name="recipeuname" value="username from recipe">
|
|
<input value="default field username">
|
|
<input type=password value="pass1">
|
|
<input name="recipepword" type=password value="pass2">`,
|
|
inputIndexForFormLike: 2,
|
|
hostname: DEFAULT_ORIGIN,
|
|
formSubmitURL: DEFAULT_ORIGIN,
|
|
usernameFieldValue: "username from recipe",
|
|
newPasswordFieldValue: "pass2",
|
|
oldPasswordFieldValue: null,
|
|
},
|
|
];
|
|
|
|
function getSubmitMessage() {
|
|
info("getSubmitMessage");
|
|
return new Promise((resolve, reject) => {
|
|
mm.addMessageListener("formSubmissionProcessed", function processed(...args) {
|
|
info("got formSubmissionProcessed");
|
|
mm.removeMessageListener("formSubmissionProcessed", processed);
|
|
resolve(...args);
|
|
});
|
|
});
|
|
}
|
|
|
|
let runTest = Task.async(function*() {
|
|
let loginFrame = document.getElementById("loginFrame");
|
|
let frameDoc = loginFrame.contentWindow.document;
|
|
|
|
for (let tc of TESTCASES) {
|
|
info("Starting testcase: " + JSON.stringify(tc));
|
|
frameDoc.documentElement.innerHTML = tc.document;
|
|
let inputForFormLike = frameDoc.querySelectorAll("input")[tc.inputIndexForFormLike];
|
|
|
|
let formLike = FormLikeFactory.createFromField(inputForFormLike);
|
|
|
|
info("Calling _onFormSubmit with FormLike");
|
|
let processedPromise = getSubmitMessage();
|
|
LoginManagerContent._onFormSubmit(formLike);
|
|
|
|
let submittedResult = yield processedPromise;
|
|
|
|
// Check data sent via RemoteLogins:onFormSubmit
|
|
is(submittedResult.hostname, tc.hostname, "Check hostname");
|
|
is(submittedResult.formSubmitURL, tc.formSubmitURL, "Check formSubmitURL");
|
|
|
|
if (tc.usernameFieldValue === null) {
|
|
is(submittedResult.usernameField, tc.usernameFieldValue, "Check usernameField");
|
|
} else {
|
|
is(submittedResult.usernameField.value, tc.usernameFieldValue, "Check usernameField");
|
|
}
|
|
|
|
is(submittedResult.newPasswordField.value, tc.newPasswordFieldValue, "Check newPasswordFieldValue");
|
|
|
|
if (tc.oldPasswordFieldValue === null) {
|
|
is(submittedResult.oldPasswordField, tc.oldPasswordFieldValue, "Check oldPasswordFieldValue");
|
|
} else {
|
|
is(submittedResult.oldPasswordField.value, tc.oldPasswordFieldValue, "Check oldPasswordFieldValue");
|
|
}
|
|
}
|
|
|
|
SimpleTest.finish();
|
|
});
|
|
|
|
</script>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content">
|
|
<iframe id="loginFrame" src="http://test1.mochi.test:8888/tests/toolkit/components/passwordmgr/test/blank.html"></iframe>
|
|
</div>
|
|
<pre id="test"></pre>
|
|
</body>
|
|
</html>
|