Bug 1168707 - Update test_formless_submit.html to test and cleanup recipes. r=dolske

This commit is contained in:
Matthew Noorenberghe 2015-06-29 00:11:33 -07:00
parent 349f606351
commit e43584af92
3 changed files with 51 additions and 19 deletions

View File

@ -33,17 +33,8 @@ function LoginRecipesParent(aOptions = { defaults: true }) {
if (Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
throw new Error("LoginRecipesParent should only be used from the main process");
}
this._recipesByHost = new Map();
if (aOptions.defaults) {
// XXX: Bug 1134850 will handle reading recipes from a file.
this.initializationPromise = this.load(DEFAULT_RECIPES).then(resolve => {
return this;
});
} else {
this.initializationPromise = Promise.resolve(this);
}
this._defaults = aOptions.defaults;
this.reset();
}
LoginRecipesParent.prototype = {
@ -54,6 +45,11 @@ LoginRecipesParent.prototype = {
*/
initializationPromise: null,
/**
* @type {bool} Whether default recipes were loaded at construction time.
*/
_defaults: null,
/**
* @type {Map} Map of hosts (including non-default port numbers) to Sets of recipes.
* e.g. "example.com:8080" => Set({...})
@ -84,6 +80,23 @@ LoginRecipesParent.prototype = {
return Promise.resolve();
},
/**
* Reset the set of recipes to the ones from the time of construction.
*/
reset() {
log.debug("Resetting recipes with defaults:", this._defaults);
this._recipesByHost = new Map();
if (this._defaults) {
// XXX: Bug 1134850 will handle reading recipes from a file.
this.initializationPromise = this.load(DEFAULT_RECIPES).then(resolve => {
return this;
});
} else {
this.initializationPromise = Promise.resolve(this);
}
},
/**
* Validate the recipe is sane and then add it to the set of recipes.
*

View File

@ -285,4 +285,12 @@ if (this.addMessageListener) {
globalMM.addMessageListener("RemoteLogins:onFormSubmit", function onFormSubmit(message) {
sendAsyncMessage("formSubmissionProcessed", message.data, message.objects);
});
} else {
// Code to only run in the mochitest pages (not in the chrome script).
SimpleTest.registerCleanupFunction(() => {
var { LoginManagerParent } = SpecialPowers.Cu.import("resource://gre/modules/LoginManagerParent.jsm", {});
return LoginManagerParent.recipeParentPromise.then((recipeParent) => {
SpecialPowers.wrap(recipeParent).reset();
});
});
}

View File

@ -4,6 +4,7 @@
<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>
@ -15,8 +16,6 @@ Cu.import("resource://gre/modules/Task.jsm");
const LMCBackstagePass = Cu.import("resource://gre/modules/LoginManagerContent.jsm");
const { LoginManagerContent, FormLikeFactory } = LMCBackstagePass;
SpecialPowers.Services.prefs.setBoolPref("signon.debug", true);
let parentScriptURL = SimpleTest.getTestFileURL("pwmgr_common.js");
let mm = SpecialPowers.loadChromeScript(parentScriptURL);
@ -31,21 +30,20 @@ document.addEventListener("DOMContentLoaded", () => {
mm.addMessageListener("doneSetup", function doneSetup() {
mm.sendAsyncMessage("loadRecipes", {
siteRecipes: [{
hosts: ["mochi.test:8888"],
usernameSelector: "input[name='uname1']",
passwordSelector: "input[name='pword2']",
hosts: ["test1.mochi.test:8888"],
usernameSelector: "input[name='recipeuname']",
passwordSelector: "input[name='recipepword']",
}],
});
});
mm.addMessageListener("loadedRecipes", () => runTest());
const DEFAULT_ORIGIN = "http://mochi.test:8888";
const DEFAULT_ORIGIN = "http://test1.mochi.test:8888";
const TESTCASES = [
{
// Inputs
document: `<input type=password value="pass1">`,
//documentURL: DEFAULT_ORIGIN,
inputIndexForFormLike: 0,
// Expected outputs similar to RemoteLogins:onFormSubmit
@ -103,6 +101,19 @@ const TESTCASES = [
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() {
@ -160,7 +171,7 @@ let runTest = Task.async(function*() {
<p id="display"></p>
<div id="content">
<iframe id="loginFrame" src="http://mochi.test:8888/tests/toolkit/components/passwordmgr/test/blank.html"></iframe>
<iframe id="loginFrame" src="http://test1.mochi.test:8888/tests/toolkit/components/passwordmgr/test/blank.html"></iframe>
</div>
<pre id="test"></pre>
</body>