Bug 1560055 part 6. Add a test for reflection of percentage values and fix our one failure there. r=mccr8

Our new behavior should align with the Blink/WebKit behavior and the current
spec, though I also filed https://github.com/whatwg/html/issues/4737 on the spec
for the fact that dimension attributes reflecting as integers is a bit weird

Differential Revision: https://phabricator.services.mozilla.com/D36130

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-06-28 21:01:35 +00:00
Родитель 4530e9a97e
Коммит 9abd9bd6cd
9 изменённых файлов: 173 добавлений и 14 удалений

Просмотреть файл

@ -66,13 +66,17 @@ class HTMLVideoElement final : public HTMLMediaElement {
// WebIDL
uint32_t Width() const { return GetUnsignedIntAttr(nsGkAtoms::width, 0); }
uint32_t Width() const {
return GetDimensionAttrAsUnsignedInt(nsGkAtoms::width, 0);
}
void SetWidth(uint32_t aValue, ErrorResult& aRv) {
SetUnsignedIntAttr(nsGkAtoms::width, aValue, 0, aRv);
}
uint32_t Height() const { return GetUnsignedIntAttr(nsGkAtoms::height, 0); }
uint32_t Height() const {
return GetDimensionAttrAsUnsignedInt(nsGkAtoms::height, 0);
}
void SetHeight(uint32_t aValue, ErrorResult& aRv) {
SetUnsignedIntAttr(nsGkAtoms::height, aValue, 0, aRv);

Просмотреть файл

@ -1398,6 +1398,29 @@ uint32_t nsGenericHTMLElement::GetUnsignedIntAttr(nsAtom* aAttr,
return attrVal->GetIntegerValue();
}
uint32_t nsGenericHTMLElement::GetDimensionAttrAsUnsignedInt(
nsAtom* aAttr, uint32_t aDefault) const {
const nsAttrValue* attrVal = mAttrs.GetAttr(aAttr);
if (!attrVal) {
return aDefault;
}
if (attrVal->Type() == nsAttrValue::eInteger) {
return attrVal->GetIntegerValue();
}
if (attrVal->Type() == nsAttrValue::ePercent) {
// This is a nasty hack. When we parsed the value, we stored it as an
// ePercent, not eInteger, because there was a '%' after it in the string.
// But the spec says to basically re-parse the string as an integer.
// Luckily, we can just return the value we have stored. But
// GetPercentValue() divides it by 100, so we need to multiply it back.
return uint32_t(attrVal->GetPercentValue() * 100.0f);
}
return aDefault;
}
void nsGenericHTMLElement::GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr,
nsAString& aResult) const {
nsCOMPtr<nsIURI> uri;

Просмотреть файл

@ -786,6 +786,18 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase {
SetHTMLAttr(aName, value, aError);
}
/**
* Gets the unsigned integer-value of an attribute that is stored as a
* dimension (i.e. could be an integer or a percentage), returns specified
* default value if the attribute isn't set or isn't set to a dimension. Only
* works for attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aDefault default-value to return if attribute isn't set.
*/
uint32_t GetDimensionAttrAsUnsignedInt(nsAtom* aAttr,
uint32_t aDefault) const;
/**
* Sets value of attribute to specified double. Only works for attributes
* in null namespace.

Просмотреть файл

@ -899,6 +899,12 @@
[iframe.allowUserMedia: setAttribute() to 1.5]
expected: FAIL
[iframe.allowUserMedia: setAttribute() to 1.5]
expected: FAIL
[iframe.allowUserMedia: setAttribute() to "5%"]
expected: FAIL
[iframe.allowUserMedia: setAttribute() to true]
expected: FAIL
@ -947,6 +953,9 @@
[iframe.allowUserMedia: IDL set to 1.5]
expected: FAIL
[iframe.allowUserMedia: IDL set to "5%"]
expected: FAIL
[iframe.allowUserMedia: IDL set to false]
expected: FAIL
@ -1001,6 +1010,9 @@
[iframe.delegateStickyUserActivation: IDL set to 1.5]
expected: FAIL
[iframe.delegateStickyUserActivation: IDL set to "5%"]
expected: FAIL
[iframe.delegateStickyUserActivation: IDL set to true]
expected: FAIL
@ -1064,6 +1076,9 @@
[video.playsInline: IDL set to 1.5]
expected: FAIL
[video.playsInline: IDL set to "5%"]
expected: FAIL
[video.playsInline: setAttribute() to object "test-valueOf"]
expected: FAIL
@ -1094,6 +1109,9 @@
[video.playsInline: setAttribute() to 1.5]
expected: FAIL
[video.playsInline: setAttribute() to "5%"]
expected: FAIL
[video.playsInline: setAttribute() to object "[object Object\]"]
expected: FAIL

Просмотреть файл

@ -1963,6 +1963,9 @@
[input.dirName: setAttribute() to 1.5]
expected: FAIL
[input.dirName: setAttribute() to "5%"]
expected: FAIL
[input.dirName: setAttribute() to true]
expected: FAIL
@ -2008,6 +2011,9 @@
[input.dirName: IDL set to 1.5]
expected: FAIL
[input.dirName: IDL set to "5%"]
expected: FAIL
[input.dirName: IDL set to true]
expected: FAIL
@ -2485,6 +2491,9 @@
[textarea.dirName: setAttribute() to 1.5]
expected: FAIL
[textarea.dirName: setAttribute() to "5%"]
expected: FAIL
[textarea.dirName: setAttribute() to true]
expected: FAIL
@ -2530,6 +2539,9 @@
[textarea.dirName: IDL set to 1.5]
expected: FAIL
[textarea.dirName: IDL set to "5%"]
expected: FAIL
[textarea.dirName: IDL set to true]
expected: FAIL

Просмотреть файл

@ -56,6 +56,9 @@
[link.nonce: setAttribute() to 1.5]
expected: FAIL
[link.nonce: setAttribute() to "5%"]
expected: FAIL
[link.nonce: setAttribute() to true]
expected: FAIL
@ -101,6 +104,9 @@
[link.nonce: IDL set to 1.5]
expected: FAIL
[link.nonce: IDL set to "5%"]
expected: FAIL
[link.nonce: IDL set to true]
expected: FAIL
@ -701,6 +707,9 @@
[style.nonce: setAttribute() to 1.5]
expected: FAIL
[style.nonce: setAttribute() to "5%"]
expected: FAIL
[style.nonce: setAttribute() to true]
expected: FAIL
@ -746,6 +755,9 @@
[style.nonce: IDL set to 1.5]
expected: FAIL
[style.nonce: IDL set to "5%"]
expected: FAIL
[style.nonce: IDL set to true]
expected: FAIL

Просмотреть файл

@ -624,6 +624,9 @@
[script.nonce: setAttribute() to 1.5]
expected: FAIL
[script.nonce: setAttribute() to "5%"]
expected: FAIL
[script.nonce: setAttribute() to true]
expected: FAIL
@ -669,6 +672,9 @@
[script.nonce: IDL set to 1.5]
expected: FAIL
[script.nonce: IDL set to "5%"]
expected: FAIL
[script.nonce: IDL set to true]
expected: FAIL
@ -720,6 +726,9 @@
[undefinedelement.inputMode: setAttribute() to 1.5]
expected: FAIL
[undefinedelement.inputMode: setAttribute() to "5%"]
expected: FAIL
[undefinedelement.inputMode: setAttribute() to true]
expected: FAIL
@ -885,6 +894,9 @@
[undefinedelement.inputMode: IDL set to 1.5]
expected: FAIL
[undefinedelement.inputMode: IDL set to "5%"]
expected: FAIL
[undefinedelement.inputMode: IDL set to true]
expected: FAIL
@ -1242,9 +1254,15 @@
[undefinedelement.enterKeyHint: IDL set to 1.5]
expected: FAIL
[undefinedelement.enterKeyHint: IDL set to "5%"]
expected: FAIL
[undefinedelement.enterKeyHint: setAttribute() to 1.5]
expected: FAIL
[undefinedelement.enterKeyHint: setAttribute() to "5%"]
expected: FAIL
[undefinedelement.enterKeyHint: setAttribute() to "next"]
expected: FAIL

Просмотреть файл

@ -26,6 +26,9 @@
[applet.align: setAttribute() to 1.5]
expected: FAIL
[applet.align: setAttribute() to "5%"]
expected: FAIL
[applet.align: setAttribute() to true]
expected: FAIL
@ -71,6 +74,9 @@
[applet.align: IDL set to 1.5]
expected: FAIL
[applet.align: IDL set to "5%"]
expected: FAIL
[applet.align: IDL set to true]
expected: FAIL
@ -122,6 +128,9 @@
[applet.alt: setAttribute() to 1.5]
expected: FAIL
[applet.alt: setAttribute() to "5%"]
expected: FAIL
[applet.alt: setAttribute() to true]
expected: FAIL
@ -167,6 +176,9 @@
[applet.alt: IDL set to 1.5]
expected: FAIL
[applet.alt: IDL set to "5%"]
expected: FAIL
[applet.alt: IDL set to true]
expected: FAIL
@ -218,6 +230,9 @@
[applet.archive: setAttribute() to 1.5]
expected: FAIL
[applet.archive: setAttribute() to "5%"]
expected: FAIL
[applet.archive: setAttribute() to true]
expected: FAIL
@ -263,6 +278,9 @@
[applet.archive: IDL set to 1.5]
expected: FAIL
[applet.archive: IDL set to "5%"]
expected: FAIL
[applet.archive: IDL set to true]
expected: FAIL
@ -314,6 +332,9 @@
[applet.code: setAttribute() to 1.5]
expected: FAIL
[applet.code: setAttribute() to "5%"]
expected: FAIL
[applet.code: setAttribute() to true]
expected: FAIL
@ -359,6 +380,9 @@
[applet.code: IDL set to 1.5]
expected: FAIL
[applet.code: IDL set to "5%"]
expected: FAIL
[applet.code: IDL set to true]
expected: FAIL
@ -419,6 +443,9 @@
[applet.codeBase: setAttribute() to 1.5]
expected: FAIL
[applet.codeBase: setAttribute() to "5%"]
expected: FAIL
[applet.codeBase: setAttribute() to true]
expected: FAIL
@ -473,6 +500,9 @@
[applet.codeBase: IDL set to 1.5]
expected: FAIL
[applet.codeBase: IDL set to "5%"]
expected: FAIL
[applet.codeBase: IDL set to true]
expected: FAIL
@ -524,6 +554,9 @@
[applet.height: setAttribute() to 1.5]
expected: FAIL
[applet.height: setAttribute() to "5%"]
expected: FAIL
[applet.height: setAttribute() to true]
expected: FAIL
@ -569,6 +602,9 @@
[applet.height: IDL set to 1.5]
expected: FAIL
[applet.height: IDL set to "5%"]
expected: FAIL
[applet.height: IDL set to true]
expected: FAIL
@ -737,6 +773,9 @@
[applet.hspace: setAttribute() to 1.5]
expected: FAIL
[applet.hspace: setAttribute() to "5%"]
expected: FAIL
[applet.hspace: setAttribute() to true]
expected: FAIL
@ -806,6 +845,9 @@
[applet.name: setAttribute() to 1.5]
expected: FAIL
[applet.name: setAttribute() to "5%"]
expected: FAIL
[applet.name: setAttribute() to true]
expected: FAIL
@ -851,6 +893,9 @@
[applet.name: IDL set to 1.5]
expected: FAIL
[applet.name: IDL set to "5%"]
expected: FAIL
[applet.name: IDL set to true]
expected: FAIL
@ -911,6 +956,9 @@
[applet.object: setAttribute() to 1.5]
expected: FAIL
[applet.object: setAttribute() to "5%"]
expected: FAIL
[applet.object: setAttribute() to true]
expected: FAIL
@ -965,6 +1013,9 @@
[applet.object: IDL set to 1.5]
expected: FAIL
[applet.object: IDL set to "5%"]
expected: FAIL
[applet.object: IDL set to true]
expected: FAIL
@ -1133,6 +1184,9 @@
[applet.vspace: setAttribute() to 1.5]
expected: FAIL
[applet.vspace: setAttribute() to "5%"]
expected: FAIL
[applet.vspace: setAttribute() to true]
expected: FAIL
@ -1202,6 +1256,9 @@
[applet.width: setAttribute() to 1.5]
expected: FAIL
[applet.width: setAttribute() to "5%"]
expected: FAIL
[applet.width: setAttribute() to true]
expected: FAIL
@ -1247,6 +1304,9 @@
[applet.width: IDL set to 1.5]
expected: FAIL
[applet.width: IDL set to "5%"]
expected: FAIL
[applet.width: IDL set to true]
expected: FAIL

Просмотреть файл

@ -145,7 +145,7 @@ ReflectionTests.typeMap = {
"string": {
"jsType": "string",
"defaultVal": "",
"domTests": ["", " " + binaryString + " foo ", undefined, 7, 1.5, true,
"domTests": ["", " " + binaryString + " foo ", undefined, 7, 1.5, "5%", true,
false, {"test": 6}, NaN, +Infinity, -Infinity, "\0", null,
{"toString":function(){return "test-toString";}},
{"valueOf":function(){return "test-valueOf";}, toString:null}
@ -168,7 +168,7 @@ ReflectionTests.typeMap = {
"jsType": "string",
"defaultVal": "",
"domTests": ["", " foo ", "http://site.example/",
"//site.example/path???@#l", binaryString, undefined, 7, 1.5, true,
"//site.example/path???@#l", binaryString, undefined, 7, 1.5, "5%", true,
false, {"test": 6}, NaN, +Infinity, -Infinity, "\0", null,
{"toString":function(){return "test-toString";}},
{"valueOf":function(){return "test-valueOf";}, toString:null}],
@ -233,7 +233,7 @@ ReflectionTests.typeMap = {
"enum": {
"jsType": "string",
"defaultVal": "",
"domTests": ["", " " + binaryString + " foo ", undefined, 7, 1.5, true,
"domTests": ["", " " + binaryString + " foo ", undefined, 7, 1.5, "5%", true,
false, {"test": 6}, NaN, +Infinity, -Infinity, "\0", null,
{"toString":function(){return "test-toString";}},
{"valueOf":function(){return "test-valueOf";}, toString:null}]
@ -249,7 +249,7 @@ ReflectionTests.typeMap = {
"boolean": {
"jsType": "boolean",
"defaultVal": false,
"domTests": ["", " foo ", undefined, null, 7, 1.5, true, false,
"domTests": ["", " foo ", undefined, null, 7, 1.5, "5%", true, false,
{"test": 6}, NaN, +Infinity, -Infinity, "\0",
{"toString":function(){return "test-toString";}},
{"valueOf":function(){return "test-valueOf";}, toString:null}],
@ -282,7 +282,7 @@ ReflectionTests.typeMap = {
"\u20007", "\u20017", "\u20027", "\u20037", "\u20047", "\u20057",
"\u20067", "\u20077", "\u20087", "\u20097", "\u200A7", "\u202F7",
"\u30007",
undefined, 1.5, true, false, {"test": 6}, NaN, +Infinity,
undefined, 1.5, "5%", true, false, {"test": 6}, NaN, +Infinity,
-Infinity, "\0",
{toString:function() {return 2;}, valueOf: null},
{valueOf:function() {return 3;}}],
@ -321,7 +321,7 @@ ReflectionTests.typeMap = {
"\u20007", "\u20017", "\u20027", "\u20037", "\u20047", "\u20057",
"\u20067", "\u20077", "\u20087", "\u20097", "\u200A7", "\u202F7",
"\u30007",
undefined, 1.5, true, false, {"test": 6}, NaN, +Infinity,
undefined, 1.5, "5%", true, false, {"test": 6}, NaN, +Infinity,
-Infinity, "\0",
{toString:function() {return 2;}, valueOf: null},
{valueOf:function() {return 3;}}],
@ -357,7 +357,7 @@ ReflectionTests.typeMap = {
"\u20007", "\u20017", "\u20027", "\u20037", "\u20047", "\u20057",
"\u20067", "\u20077", "\u20087", "\u20097", "\u200A7", "\u202F7",
"\u30007",
" " + binaryString + " foo ", undefined, 1.5, true, false,
" " + binaryString + " foo ", undefined, 1.5, "5%", true, false,
{"test": 6}, NaN, +Infinity, -Infinity, "\0",
{toString:function() {return 2;}, valueOf: null},
{valueOf:function() {return 3;}}],
@ -399,7 +399,7 @@ ReflectionTests.typeMap = {
"\u20007", "\u20017", "\u20027", "\u20037", "\u20047", "\u20057",
"\u20067", "\u20077", "\u20087", "\u20097", "\u200A7", "\u202F7",
"\u30007",
" " + binaryString + " foo ", undefined, 1.5, true, false,
" " + binaryString + " foo ", undefined, 1.5, "5%", true, false,
{"test": 6}, NaN, +Infinity, -Infinity, "\0",
{toString:function() {return 2;}, valueOf: null},
{valueOf:function() {return 3;}}],
@ -439,7 +439,7 @@ ReflectionTests.typeMap = {
"\u20007", "\u20017", "\u20027", "\u20037", "\u20047", "\u20057",
"\u20067", "\u20077", "\u20087", "\u20097", "\u200A7", "\u202F7",
"\u30007",
" " + binaryString + " foo ", undefined, 1.5, true, false,
" " + binaryString + " foo ", undefined, 1.5, "5%", true, false,
{"test": 6}, NaN, +Infinity, -Infinity, "\0",
{toString:function() {return 2;}, valueOf: null},
{valueOf:function() {return 3;}}],
@ -478,7 +478,7 @@ ReflectionTests.typeMap = {
"\u20007", "\u20017", "\u20027", "\u20037", "\u20047", "\u20057",
"\u20067", "\u20077", "\u20087", "\u20097", "\u200A7", "\u202F7",
"\u30007",
" " + binaryString + " foo ", undefined, 1.5, true, false,
" " + binaryString + " foo ", undefined, 1.5, "5%", true, false,
{"test": 6}, NaN, +Infinity, -Infinity, "\0",
{toString:function() {return 2;}, valueOf: null},
{valueOf:function() {return 3;}}],
@ -519,7 +519,7 @@ ReflectionTests.typeMap = {
"\u20007", "\u20017", "\u20027", "\u20037", "\u20047", "\u20057",
"\u20067", "\u20077", "\u20087", "\u20097", "\u200A7", "\u202F7",
"\u30007",
" " + binaryString + " foo ", undefined, 1.5, true, false,
" " + binaryString + " foo ", undefined, 1.5, "5%", true, false,
{"test": 6}, NaN, +Infinity, -Infinity, "\0",
{toString:function() {return 2;}, valueOf: null},
{valueOf:function() {return 3;}}],
@ -532,7 +532,7 @@ ReflectionTests.typeMap = {
null, null, null, null, null, null,
null,
// End leading whitespace tests
null, null, 1.5, null, null,
null, null, 1.5, 5, null, null,
null, null, null, null, null,
2, 3],
// I checked that ES ToString is well-defined for all of these (I