Backed out changeset a8acb6aa4a52 (bug 1534480)for chrome mochitest failures on dom_overlays/test_same_attribute.html CLOSED TREE

This commit is contained in:
arthur.iakab 2019-04-16 20:54:11 +03:00
parent b573fad459
commit efa7bba713
7 changed files with 17 additions and 224 deletions

View File

@ -2793,16 +2793,12 @@ class LocalizationHandler : public PromiseNativeHandler {
l10nData[i].mAttributes;
if (!attributes.IsNull()) {
for (size_t j = 0; j < attributes.Value().Length(); ++j) {
nsString& name = attributes.Value()[j].mName;
nsString& value = attributes.Value()[j].mValue;
RefPtr<nsAtom> nameAtom = NS_Atomize(name);
if (!elem->AttrValueIs(kNameSpaceID_None, nameAtom, value,
eCaseMatters)) {
rv = elem->SetAttr(kNameSpaceID_None, nameAtom, value, true);
if (rv.Failed()) {
mReturnValuePromise->MaybeRejectWithUndefined();
return;
}
// Use SetAttribute here to validate the attribute name!
elem->SetAttribute(attributes.Value()[j].mName,
attributes.Value()[j].mValue, rv);
if (rv.Failed()) {
mReturnValuePromise->MaybeRejectWithUndefined();
return;
}
}
}

View File

@ -151,18 +151,6 @@ function overlayChildNodes(fromFragment, toElement) {
toElement.appendChild(fromFragment);
}
function hasAttribute(attributes, name) {
if (!attributes) {
return false;
}
for (let attr of attributes) {
if (attr.name === name) {
return true;
}
}
return false;
}
/**
* Transplant localizable attributes of an element to another element.
*
@ -179,11 +167,9 @@ function overlayAttributes(fromElement, toElement) {
.split(",").map(i => i.trim())
: null;
// Remove existing localizable attributes if they
// will not be used in the new translation.
// Remove existing localizable attributes.
for (const attr of Array.from(toElement.attributes)) {
if (isAttrNameLocalizable(attr.name, toElement, explicitlyAllowed)
&& !hasAttribute(fromElement.attributes, attr.name)) {
if (isAttrNameLocalizable(attr.name, toElement, explicitlyAllowed)) {
toElement.removeAttribute(attr.name);
}
}
@ -197,8 +183,7 @@ function overlayAttributes(fromElement, toElement) {
// Set localizable attributes.
for (const attr of Array.from(fromElement.attributes)) {
if (isAttrNameLocalizable(attr.name, toElement, explicitlyAllowed)
&& toElement.getAttribute(attr.name) !== attr.value) {
if (isAttrNameLocalizable(attr.name, toElement, explicitlyAllowed)) {
toElement.setAttribute(attr.name, attr.value);
}
}
@ -490,15 +475,10 @@ class DOMLocalization extends Localization {
* @param {Object<string, string>} args - KVP list of l10n arguments
* @returns {Element}
*/
setAttributes(element, id, args = null) {
if (element.getAttribute(L10NID_ATTR_NAME) !== id) {
element.setAttribute(L10NID_ATTR_NAME, id);
}
setAttributes(element, id, args) {
element.setAttribute(L10NID_ATTR_NAME, id);
if (args) {
let argsString = JSON.stringify(args);
if (argsString !== element.getAttribute(L10NARGS_ATTR_NAME)) {
element.setAttribute(L10NARGS_ATTR_NAME, argsString);
}
element.setAttribute(L10NARGS_ATTR_NAME, JSON.stringify(args));
} else {
element.removeAttribute(L10NARGS_ATTR_NAME);
}

View File

@ -263,11 +263,10 @@ void DocumentL10n::SetAttributes(JSContext* aCx, Element& aElement,
const nsAString& aId,
const Optional<JS::Handle<JSObject*>>& aArgs,
ErrorResult& aRv) {
if (!aElement.AttrValueIs(kNameSpaceID_None, nsGkAtoms::datal10nid, aId,
eCaseMatters)) {
aElement.SetAttr(kNameSpaceID_None, nsGkAtoms::datal10nid, aId, true);
aElement.SetAttribute(NS_LITERAL_STRING("data-l10n-id"), aId, aRv);
if (aRv.Failed()) {
return;
}
if (aArgs.WasPassed()) {
nsAutoString data;
JS::Rooted<JS::Value> val(aCx, JS::ObjectValue(*aArgs.Value()));
@ -275,12 +274,9 @@ void DocumentL10n::SetAttributes(JSContext* aCx, Element& aElement,
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return;
}
if (!aElement.AttrValueIs(kNameSpaceID_None, nsGkAtoms::datal10nargs, data,
eCaseMatters)) {
aElement.SetAttr(kNameSpaceID_None, nsGkAtoms::datal10nargs, data, true);
}
aElement.SetAttribute(NS_LITERAL_STRING("data-l10n-args"), data, aRv);
} else {
aElement.UnsetAttr(kNameSpaceID_None, nsGkAtoms::datal10nargs, true);
aElement.RemoveAttribute(NS_LITERAL_STRING("data-l10n-args"), aRv);
}
}

View File

@ -26,7 +26,3 @@
[dom/test_docl10n.html]
[dom/test_docl10n_ready_rejected.html]
[dom/test_docl10n_removeResourceIds.html]
[dom_overlays/test_same_id.html]
[dom_overlays/test_same_id_args.html]
[dom_overlays/test_same_attribute.html]

View File

@ -1,61 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test Amount of mutations generated from DOM Overlays</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<link rel="localization" href="browser/preferences/preferences.ftl"/>
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
let config = {
attributes: true,
attributeOldValue: true,
characterData: true,
characterDataOldValue: true,
childList: true,
subtree: true,
};
let allMutations = [];
document.addEventListener("DOMContentLoaded", async function() {
await document.l10n.ready;
let optionElem = document.getElementById("use-current-pages");
// Test for initial localization applied.
is(optionElem.getAttribute("label").length > 0, true);
let observer = new MutationObserver((mutations) => {
for (let mutation of mutations) {
allMutations.push(mutation);
}
});
observer.observe(optionElem, config);
document.l10n.setAttributes(optionElem, "use-current-pages", {
tabCount: 6,
});
// Due to the async iteractions between nsINode.localize
// and DOMLocalization.jsm, we'll need to wait two frames
// to verify that no mutations happened.
requestAnimationFrame(() => {
requestAnimationFrame(() => {
// We only expect the `data-l10n-args` attribute
// to be updated and cause a single mutation.
// Since the result value of the attribute stays
// the same, there should be no mutation fired for it.
is(allMutations.length, 1);
SimpleTest.finish();
});
});
}, { once: true});
</script>
</head>
<body>
<option id="use-current-pages" data-l10n-id="use-current-pages" data-l10n-args='{"tabCount":5}'></option>
</body>
</html>

View File

@ -1,57 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test Amount of mutations generated from DOM Overlays</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<link rel="localization" href="browser/aboutConfig.ftl"/>
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
let config = {
attributes: true,
attributeOldValue: true,
characterData: true,
characterDataOldValue: true,
childList: true,
subtree: true,
};
let allMutations = [];
document.addEventListener("DOMContentLoaded", async function() {
await document.l10n.ready;
let inputElem = document.getElementById("search-input");
// Test for initial localization applied.
is(inputElem.getAttribute("placeholder").length > 0, true);
let observer = new MutationObserver((mutations) => {
for (let mutation of mutations) {
allMutations.push(mutation);
}
});
observer.observe(inputElem, config);
document.l10n.setAttributes(inputElem, "about-config-search-input");
// Due to the async iteractions between nsINode.localize
// and DOMLocalization.jsm, we'll need to wait two frames
// to verify that no mutations happened.
requestAnimationFrame(() => {
requestAnimationFrame(() => {
// Since the l10n-id is the same as the previous one
// no mutation should happen in result.
is(allMutations.length, 0);
SimpleTest.finish();
});
});
}, { once: true});
</script>
</head>
<body>
<input id="search-input" data-l10n-id="about-config-search-input"></input>
</body>
</html>

View File

@ -1,57 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test Amount of mutations generated from DOM Overlays</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<link rel="localization" href="browser/aboutConfig.ftl"/>
<script type="application/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
let config = {
attributes: true,
attributeOldValue: true,
characterData: true,
characterDataOldValue: true,
childList: true,
subtree: true,
};
let allMutations = [];
document.addEventListener("DOMContentLoaded", async function() {
await document.l10n.ready;
let inputElem = document.getElementById("search-input");
// Test for initial localization applied.
is(inputElem.getAttribute("aria-label").length > 0, true);
let observer = new MutationObserver((mutations) => {
for (let mutation of mutations) {
allMutations.push(mutation);
}
});
observer.observe(inputElem, config);
document.l10n.setAttributes(inputElem, "about-config-pref-accessible-value-default", {value: "Test"});
// Due to the async iteractions between nsINode.localize
// and DOMLocalization.jsm, we'll need to wait two frames
// to verify that no mutations happened.
requestAnimationFrame(() => {
requestAnimationFrame(() => {
// Since the l10n-id is the same as the previous one
// no mutation should happen in result.
is(allMutations.length, 0);
SimpleTest.finish();
});
});
}, { once: true});
</script>
</head>
<body>
<input id="search-input" data-l10n-id="about-config-pref-accessible-value-default" data-l10n-args='{"value":"Test"}'></input>
</body>
</html>