зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1415739
- Use type/autocomplete properties, instead of attributes, to decide whether to save FormData. r=mikedeboer
The property values are already normalized according to the spec. MozReview-Commit-ID: DbKZf9KXCji --HG-- extra : rebase_source : 13b94e29dc0a32185d9fcb60e503988a722ea60a
This commit is contained in:
Родитель
06b8d461cc
Коммит
a78811c737
|
@ -5,6 +5,17 @@
|
|||
|
||||
const URL = ROOT + "browser_456342_sample.xhtml";
|
||||
|
||||
const EXPECTED_IDS = new Set([
|
||||
"searchTerm",
|
||||
]);
|
||||
|
||||
const EXPECTED_XPATHS = new Set([
|
||||
"/xhtml:html/xhtml:body/xhtml:form/xhtml:p[2]/xhtml:input",
|
||||
"/xhtml:html/xhtml:body/xhtml:form/xhtml:p[3]/xhtml:input[@name='fill-in']",
|
||||
"/xhtml:html/xhtml:body/xhtml:form/xhtml:p[4]/xhtml:input[@name='mistyped']",
|
||||
"/xhtml:html/xhtml:body/xhtml:form/xhtml:p[5]/xhtml:textarea[@name='textarea_pass']",
|
||||
]);
|
||||
|
||||
/**
|
||||
* Bug 456342 - Restore values from non-standard input field types.
|
||||
*/
|
||||
|
@ -23,25 +34,22 @@ add_task(async function test_restore_nonstandard_input_values() {
|
|||
let undoItems = JSON.parse(ss.getClosedTabData(window));
|
||||
let savedFormData = undoItems[0].state.formdata;
|
||||
|
||||
let countGood = 0, countBad = 0;
|
||||
let foundIds = 0;
|
||||
for (let id of Object.keys(savedFormData.id)) {
|
||||
if (savedFormData.id[id] == expectedValue) {
|
||||
countGood++;
|
||||
} else {
|
||||
countBad++;
|
||||
}
|
||||
ok(EXPECTED_IDS.has(id), `Check saved ID "${id}" was expected`);
|
||||
is(savedFormData.id[id], expectedValue, `Check saved value for #${id}`);
|
||||
foundIds++;
|
||||
}
|
||||
|
||||
let foundXpaths = 0;
|
||||
for (let exp of Object.keys(savedFormData.xpath)) {
|
||||
if (savedFormData.xpath[exp] == expectedValue) {
|
||||
countGood++;
|
||||
} else {
|
||||
countBad++;
|
||||
}
|
||||
ok(EXPECTED_XPATHS.has(exp), `Check saved xpath "${exp}" was expected`);
|
||||
is(savedFormData.xpath[exp], expectedValue, `Check saved value for ${exp}`);
|
||||
foundXpaths++;
|
||||
}
|
||||
|
||||
is(countGood, 4, "Saved text for non-standard input fields");
|
||||
is(countBad, 0, "Didn't save text for ignored field types");
|
||||
is(foundIds, EXPECTED_IDS.size, "Check number of fields saved by ID");
|
||||
is(foundXpaths, EXPECTED_XPATHS.size, "Check number of fields saved by xpath");
|
||||
});
|
||||
|
||||
function setFormElementValues(browser, data) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
<p>Image Search: <input type="image search" /></p>
|
||||
<p>Autocomplete: <input type="autocomplete" name="fill-in"/></p>
|
||||
<p>Mistyped: <input type="txet" name="mistyped"/></p>
|
||||
<p>Invalid attr: <textarea type="password" name="textarea_pass"/></p>
|
||||
|
||||
<h3>Ignored types</h3>
|
||||
<input type="hidden" name="hideme"/>
|
||||
|
@ -24,6 +25,8 @@
|
|||
<input type="PASSWORD" name="password3"/>
|
||||
<input autocomplete="off" name="auto1"/>
|
||||
<input type="text" autocomplete="OFF" name="auto2"/>
|
||||
<input type="text" autocomplete=" OFF " name="auto5"/>
|
||||
<input autocomplete=" off " name="auto6"/>
|
||||
<textarea autocomplete="off" name="auto3"/>
|
||||
<select autocomplete="off" name="auto4">
|
||||
<option value="1" selected="true"/>
|
||||
|
|
|
@ -78,14 +78,14 @@ function isValidCCNumber(value) {
|
|||
|
||||
// For a comprehensive list of all available <INPUT> types see
|
||||
// https://dxr.mozilla.org/mozilla-central/search?q=kInputTypeTable&redirect=false
|
||||
const IGNORE_ATTRIBUTES = [
|
||||
const IGNORE_PROPERTIES = [
|
||||
["type", new Set(["password", "hidden", "button", "image", "submit", "reset"])],
|
||||
["autocomplete", new Set(["off"])]
|
||||
];
|
||||
function shouldIgnoreNode(node) {
|
||||
for (let i = 0; i < IGNORE_ATTRIBUTES.length; ++i) {
|
||||
let [attrName, attrValues] = IGNORE_ATTRIBUTES[i];
|
||||
if (node.hasAttribute(attrName) && attrValues.has(node.getAttribute(attrName).toLowerCase())) {
|
||||
for (let i = 0; i < IGNORE_PROPERTIES.length; ++i) {
|
||||
let [propName, propValues] = IGNORE_PROPERTIES[i];
|
||||
if (node[propName] && propValues.has(node[propName])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче