Bug 1389421 - Support nonce IDL property; r=ckerschb,smaug

We already support the actual functionality, but nobody added support
for the IDL property to the .webidl file.

Also added <style nonce> to the web-platform-tests reflection tests,
since nobody updated that to the current spec either.

This does not add support for .nonce to SVGScriptElement, because I
couldn't find any standard that specified it.  I updated the wpt tests
to expect .nonce to work on HTMLScriptElement but not SVGScriptElement.

MozReview-Commit-ID: F1K7WMfMoDi

--HG--
extra : rebase_source : 247c63b63446dc0d60062bb9d9c61228c379b989
This commit is contained in:
Aryeh Gregor 2017-08-21 14:49:44 +03:00
Родитель 078e5787ea
Коммит 1b3b415680
17 изменённых файлов: 38 добавлений и 250 удалений

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

@ -107,6 +107,14 @@ public:
SetHTMLAttr(nsGkAtoms::rel, aRel, aRv);
}
nsDOMTokenList* RelList();
void GetNonce(nsAString& aNonce) const
{
GetHTMLAttr(nsGkAtoms::nonce, aNonce);
}
void SetNonce(const nsAString& aNonce, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::nonce, aNonce, aRv);
}
// XPCOM GetMedia is fine.
void SetMedia(const nsAString& aMedia, ErrorResult& aRv)
{

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

@ -81,6 +81,14 @@ public:
{
SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin, aCrossOrigin, aError);
}
void GetNonce(nsAString& aNonce) const
{
GetHTMLAttr(nsGkAtoms::nonce, aNonce);
}
void SetNonce(const nsAString& aNonce, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::nonce, aNonce, aRv);
}
void GetIntegrity(nsAString& aIntegrity)
{
GetHTMLAttr(nsGkAtoms::integrity, aIntegrity);

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

@ -62,6 +62,14 @@ public:
bool Disabled();
void SetDisabled(bool aDisabled);
void GetNonce(nsAString& aNonce) const
{
GetHTMLAttr(nsGkAtoms::nonce, aNonce);
}
void SetNonce(const nsAString& aNonce, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::nonce, aNonce, aRv);
}
void SetMedia(const nsAString& aMedia, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::media, aMedia, aError);

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

@ -26,6 +26,8 @@ interface HTMLLinkElement : HTMLElement {
readonly attribute DOMTokenList relList;
[CEReactions, SetterThrows, Pure]
attribute DOMString media;
[CEReactions, SetterThrows, Pure]
attribute DOMString nonce;
[CEReactions, SetterThrows, Pure]
attribute DOMString hreflang;
[CEReactions, SetterThrows, Pure]

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

@ -26,6 +26,10 @@ interface HTMLScriptElement : HTMLElement {
attribute DOMString? crossOrigin;
[CEReactions, SetterThrows]
attribute DOMString text;
[CEReactions, SetterThrows, Pure]
attribute DOMString nonce;
[CEReactions, SetterThrows, Pure]
attribute DOMString integrity;
};
// http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
@ -35,9 +39,3 @@ partial interface HTMLScriptElement {
[CEReactions, SetterThrows]
attribute DOMString htmlFor;
};
// https://w3c.github.io/webappsec/specs/subresourceintegrity/#htmlscriptelement-1
partial interface HTMLScriptElement {
[CEReactions, SetterThrows]
attribute DOMString integrity;
};

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

@ -15,6 +15,8 @@ interface HTMLStyleElement : HTMLElement {
[CEReactions, SetterThrows, Pure]
attribute DOMString media;
[CEReactions, SetterThrows, Pure]
attribute DOMString nonce;
[CEReactions, SetterThrows, Pure]
attribute DOMString type;
[SetterThrows, Pure, Pref="layout.css.scoped-style.enabled"]
attribute boolean scoped;

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

@ -1,29 +1,8 @@
[script-nonces-hidden-meta.tentative.html]
type: testharness
[Reading 'nonce' content attribute and IDL attribute.]
expected: FAIL
[Cloned node retains nonce.]
expected: FAIL
[Cloned node retains nonce when inserted.]
expected: FAIL
[Writing 'nonce' content attribute.]
expected: FAIL
[Document-written script's nonce value.]
expected: FAIL
[createElement.nonce.]
expected: FAIL
[setAttribute('nonce') overwrites '.nonce' upon insertion.]
expected: FAIL
[createElement.setAttribute.]
expected: FAIL
[Nonces leak via CSS side-channels.]
expected: FAIL

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

@ -9,9 +9,6 @@
[Cloned node retains nonce when inserted.]
expected: FAIL
[Writing 'nonce' content attribute.]
expected: FAIL
[Document-written script's nonce value.]
expected: FAIL

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

@ -15,9 +15,6 @@
[Document-written script's nonce value.]
expected: FAIL
[createElement.setAttribute.]
expected: FAIL
[Nonces don't leak via CSS side-channels.]
expected: FAIL

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

@ -2677,12 +2677,6 @@
[HTMLElement interface: document.createElement("noscript") must inherit property "onmousewheel" with the proper type (58)]
expected: FAIL
[HTMLStyleElement interface: attribute nonce]
expected: FAIL
[HTMLStyleElement interface: document.createElement("style") must inherit property "nonce" with the proper type (1)]
expected: FAIL
[HTMLMediaElement interface: document.createElement("video") must inherit property "audioTracks" with the proper type (38)]
expected: FAIL
@ -3001,12 +2995,6 @@
[HTMLElement interface: document.createElement("noscript") must inherit property "onmousewheel" with the proper type (59)]
expected: FAIL
[HTMLLinkElement interface: attribute nonce]
expected: FAIL
[HTMLLinkElement interface: document.createElement("link") must inherit property "nonce" with the proper type (5)]
expected: FAIL
[HTMLIFrameElement interface: attribute allowUserMedia]
expected: FAIL
@ -3256,15 +3244,9 @@
[HTMLScriptElement interface: attribute noModule]
expected: FAIL
[HTMLScriptElement interface: attribute nonce]
expected: FAIL
[HTMLScriptElement interface: document.createElement("script") must inherit property "noModule" with the proper type (2)]
expected: FAIL
[HTMLScriptElement interface: document.createElement("script") must inherit property "nonce" with the proper type (8)]
expected: FAIL
[HTMLElement interface: document.createElement("noscript") must inherit property "forceSpellCheck" with the proper type (15)]
expected: FAIL
@ -3289,9 +3271,6 @@
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "styleSheets" with the proper type (29)]
expected: FAIL
[HTMLLinkElement interface: document.createElement("link") must inherit property "nonce" with the proper type (6)]
expected: FAIL
[HTMLBodyElement interface: attribute onmessageerror]
expected: FAIL

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

@ -36,102 +36,6 @@
[style.tabIndex: setAttribute() to object "3" followed by IDL get]
expected: FAIL
[link.nonce: typeof IDL attribute]
expected: FAIL
[link.nonce: IDL get with DOM attribute unset]
expected: FAIL
[link.nonce: setAttribute() to ""]
expected: FAIL
[link.nonce: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo "]
expected: FAIL
[link.nonce: setAttribute() to undefined]
expected: FAIL
[link.nonce: setAttribute() to 7]
expected: FAIL
[link.nonce: setAttribute() to 1.5]
expected: FAIL
[link.nonce: setAttribute() to true]
expected: FAIL
[link.nonce: setAttribute() to false]
expected: FAIL
[link.nonce: setAttribute() to object "[object Object\]"]
expected: FAIL
[link.nonce: setAttribute() to NaN]
expected: FAIL
[link.nonce: setAttribute() to Infinity]
expected: FAIL
[link.nonce: setAttribute() to -Infinity]
expected: FAIL
[link.nonce: setAttribute() to "\\0"]
expected: FAIL
[link.nonce: setAttribute() to null]
expected: FAIL
[link.nonce: setAttribute() to object "test-toString"]
expected: FAIL
[link.nonce: setAttribute() to object "test-valueOf"]
expected: FAIL
[link.nonce: IDL set to ""]
expected: FAIL
[link.nonce: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo "]
expected: FAIL
[link.nonce: IDL set to undefined]
expected: FAIL
[link.nonce: IDL set to 7]
expected: FAIL
[link.nonce: IDL set to 1.5]
expected: FAIL
[link.nonce: IDL set to true]
expected: FAIL
[link.nonce: IDL set to false]
expected: FAIL
[link.nonce: IDL set to object "[object Object\]"]
expected: FAIL
[link.nonce: IDL set to NaN]
expected: FAIL
[link.nonce: IDL set to Infinity]
expected: FAIL
[link.nonce: IDL set to -Infinity]
expected: FAIL
[link.nonce: IDL set to "\\0"]
expected: FAIL
[link.nonce: IDL set to null]
expected: FAIL
[link.nonce: IDL set to object "test-toString"]
expected: FAIL
[link.nonce: IDL set to object "test-valueOf"]
expected: FAIL
[link.as: setAttribute() to "document"]
expected: FAIL

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

@ -604,102 +604,6 @@
[menuitem.default: IDL set to object "test-valueOf"]
expected: FAIL
[script.nonce: typeof IDL attribute]
expected: FAIL
[script.nonce: IDL get with DOM attribute unset]
expected: FAIL
[script.nonce: setAttribute() to ""]
expected: FAIL
[script.nonce: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo "]
expected: FAIL
[script.nonce: setAttribute() to undefined]
expected: FAIL
[script.nonce: setAttribute() to 7]
expected: FAIL
[script.nonce: setAttribute() to 1.5]
expected: FAIL
[script.nonce: setAttribute() to true]
expected: FAIL
[script.nonce: setAttribute() to false]
expected: FAIL
[script.nonce: setAttribute() to object "[object Object\]"]
expected: FAIL
[script.nonce: setAttribute() to NaN]
expected: FAIL
[script.nonce: setAttribute() to Infinity]
expected: FAIL
[script.nonce: setAttribute() to -Infinity]
expected: FAIL
[script.nonce: setAttribute() to "\\0"]
expected: FAIL
[script.nonce: setAttribute() to null]
expected: FAIL
[script.nonce: setAttribute() to object "test-toString"]
expected: FAIL
[script.nonce: setAttribute() to object "test-valueOf"]
expected: FAIL
[script.nonce: IDL set to ""]
expected: FAIL
[script.nonce: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo "]
expected: FAIL
[script.nonce: IDL set to undefined]
expected: FAIL
[script.nonce: IDL set to 7]
expected: FAIL
[script.nonce: IDL set to 1.5]
expected: FAIL
[script.nonce: IDL set to true]
expected: FAIL
[script.nonce: IDL set to false]
expected: FAIL
[script.nonce: IDL set to object "[object Object\]"]
expected: FAIL
[script.nonce: IDL set to NaN]
expected: FAIL
[script.nonce: IDL set to Infinity]
expected: FAIL
[script.nonce: IDL set to -Infinity]
expected: FAIL
[script.nonce: IDL set to "\\0"]
expected: FAIL
[script.nonce: IDL set to null]
expected: FAIL
[script.nonce: IDL set to object "test-toString"]
expected: FAIL
[script.nonce: IDL set to object "test-valueOf"]
expected: FAIL
[script.noModule: typeof IDL attribute]
expected: FAIL

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

@ -53,7 +53,7 @@
test(t => {
script.nonce = 'bar';
assert_equals(script.nonce, 'bar');
assert_equals(script.getAttribute('nonce'), 'foo');
assert_equals(script.getAttribute('nonce'), 'bar');
}, "Writing 'nonce' IDL attribute.");
// Fragment parser.

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

@ -54,7 +54,7 @@
test(t => {
script.nonce = 'bar';
assert_equals(script.nonce, 'bar');
assert_equals(script.getAttribute('nonce'), 'foo');
assert_equals(script.getAttribute('nonce'), 'bar');
}, "Writing 'nonce' IDL attribute.");
// Fragment parser.

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

@ -52,7 +52,7 @@
assert_equals(script.nonce, 'abc');
}, "Writing 'nonce' content attribute.");
// Set the IDL attribute to 'bar'
// Set the IDL attribute to 'bar' (doesn't work on SVGScriptElement)
test(t => {
script.nonce = 'bar';
assert_equals(script.nonce, 'bar');

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

@ -73,7 +73,8 @@
// Create node.
test(t => {
var s = document.createElement('svg');
var innerScript = document.createElement('script');
var innerScript = document.createElementNS('http://www.w3.org/2000/svg',
'script');
innerScript.innerText = script.innerText;
innerScript.nonce = 'abc';
s.appendChild(innerScript);

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

@ -55,6 +55,7 @@ var metadataElements = {
},
style: {
media: "string",
nonce: "string",
type: "string",
},
};