Bug 1447009: Ignore title if the element is not in the document. r?heycam
Turns out this was well specified, see the linked bits.
MozReview-Commit-ID: HjdbFS78Mwj
--- a/dom/base/nsStyleLinkElement.cpp
+++ b/dom/base/nsStyleLinkElement.cpp
@@ -85,18 +85,26 @@ nsStyleLinkElement::~nsStyleLinkElement(
nsStyleLinkElement::SetStyleSheet(nullptr);
}
void
nsStyleLinkElement::GetTitleAndMediaForElement(const Element& aSelf,
nsString& aTitle,
nsString& aMedia) const
{
- aSelf.GetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle);
- aTitle.CompressWhitespace();
+ // Only honor title as stylesheet name for elements in the document (that is,
+ // ignore for Shadow DOM), per [1] and [2]. See [3].
+ //
+ // [1]: https://html.spec.whatwg.org/#attr-link-title
+ // [2]: https://html.spec.whatwg.org/#attr-style-title
+ // [3]: https://github.com/w3c/webcomponents/issues/535
+ if (aSelf.IsInUncomposedDoc()) {
+ aSelf.GetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle);
+ aTitle.CompressWhitespace();
+ }
aSelf.GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
// The HTML5 spec is formulated in terms of the CSSOM spec, which specifies
// that media queries should be ASCII lowercased during serialization.
//
// FIXME(emilio): How does it matter? This is going to be parsed anyway, CSS
// should take care of serializing it properly.
nsContentUtils::ASCIIToLower(aMedia);
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -126650,16 +126650,28 @@
[
"/css/css-scoping/slotted-with-pseudo-element-ref.html",
"=="
]
],
{}
]
],
+ "css/css-scoping/stylesheet-title-001.html": [
+ [
+ "/css/css-scoping/stylesheet-title-001.html",
+ [
+ [
+ "/css/css-scoping/reference/green-box.html",
+ "=="
+ ]
+ ],
+ {}
+ ]
+ ],
"css/css-shapes/shape-outside/formatting-context/shape-outside-formatting-context.tentative.html": [
[
"/css/css-shapes/shape-outside/formatting-context/shape-outside-formatting-context.tentative.html",
[
[
"/css/css-shapes/shape-outside/formatting-context/reference/shape-outside-formatting-context-ref.html",
"=="
]
@@ -317675,16 +317687,22 @@
]
],
"css/css-scoping/slotted-slot.html": [
[
"/css/css-scoping/slotted-slot.html",
{}
]
],
+ "css/css-scoping/stylesheet-title-002.html": [
+ [
+ "/css/css-scoping/stylesheet-title-002.html",
+ {}
+ ]
+ ],
"css/css-scroll-anchoring/abspos-containing-block-outside-scroller.html": [
[
"/css/css-scroll-anchoring/abspos-containing-block-outside-scroller.html",
{}
]
],
"css/css-scroll-anchoring/abspos-contributes-to-static-parent-bounds.html": [
[
@@ -514754,16 +514772,24 @@
"css/css-scoping/slotted-with-pseudo-element-ref.html": [
"48561a3dff973b7ad1bfa9702461e50fd4a67c2d",
"support"
],
"css/css-scoping/slotted-with-pseudo-element.html": [
"27d36ba54623bbee2cdd09b7a9322873d5ab0011",
"reftest"
],
+ "css/css-scoping/stylesheet-title-001.html": [
+ "2e49b6d74d2021144444ca77e62acbc6aeffac2a",
+ "reftest"
+ ],
+ "css/css-scoping/stylesheet-title-002.html": [
+ "9e228381a0aa11c76568b8ec893ed6745581bbf9",
+ "testharness"
+ ],
"css/css-scroll-anchoring/README.md": [
"31205944cbcf321f7aa77e3bef0f8835cc7b6d13",
"support"
],
"css/css-scroll-anchoring/abspos-containing-block-outside-scroller.html": [
"d7a8e9904637c833d897b2e9c0da0a1628455670",
"testharness"
],
@@ -553639,17 +553665,17 @@
"40ab5636653dfd105738ab38e7d22316132eb630",
"testharness"
],
"dom/events/event-global.worker.js": [
"084a6f752edee6578113035fece6d0eb85a2fdf7",
"testharness"
],
"dom/events/relatedTarget.window.js": [
- "0426d2ecae3f3562be175e4364353d979365ed1c",
+ "3dd9ddfa4d8d584f6ddf6db52e4e9020491088d8",
"testharness"
],
"dom/historical.html": [
"291d078c4424d0491aeab7524d350eab7304f989",
"testharness"
],
"dom/interface-objects.html": [
"05963c8b0a839f3e07b5478d99fc034e4654b515",
@@ -579759,17 +579785,17 @@
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"support"
],
"html/webappapis/timers/evil-spec-example.html": [
"49fd55dbbf64c6973a0e76284c0e3d8b7bf0ef3c",
"testharness"
],
"html/webappapis/timers/missing-timeout-setinterval.any.js": [
- "79b4a278f0e35646cfdffeebf8f0523e2772bc9b",
+ "40ad74d6ed3719dcad2097246d74d49c87b989aa",
"testharness"
],
"html/webappapis/timers/negative-setinterval.html": [
"405046cab9cd15a88d57eace1f293ebdd7b1b3e2",
"testharness"
],
"html/webappapis/timers/negative-settimeout.html": [
"e5673e7cca2b006afd3e2e4e5dd3e56fb10efa4e",
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/css/css-scoping/stylesheet-title-001.html
@@ -0,0 +1,24 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>CSS Test: title attribute in stylesheets not in the document tree is ignored</title>
+<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
+<link rel="help" href="https://drafts.csswg.org/cssom/#preferred-css-style-sheet-set-name">
+<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-style-title">
+<link rel="help" href="https://github.com/w3c/webcomponents/issues/535">
+<link rel="match" href="reference/green-box.html">
+<p>Test passes if you see a single 100px by 100px green box below.</p>
+<div id="host"></div>
+<script>
+ host.attachShadow({ mode: "open" }).innerHTML = `
+ <style>
+ div { width: 100px; height: 100px; }
+ </style>
+ <style title="Foo">
+ div { background: purple }
+ </style>
+ <style title="Bar">
+ div { background: green }
+ </style>
+ <div></div>
+ `;
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/css/css-scoping/stylesheet-title-002.html
@@ -0,0 +1,29 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>CSS Test: title attribute in stylesheets not in the document tree is ignored</title>
+<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
+<link rel="help" href="https://drafts.csswg.org/cssom/#preferred-css-style-sheet-set-name">
+<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-style-title">
+<link rel="help" href="https://github.com/w3c/webcomponents/issues/535">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="host"></div>
+<script>
+test(function() {
+ host.attachShadow({ mode: "open" }).innerHTML = `
+ <style>
+ div { width: 100px; height: 100px; }
+ </style>
+ <style title="Foo">
+ div { background: purple }
+ </style>
+ <style title="Bar">
+ div { background: green }
+ </style>
+ <div></div>
+ `;
+ assert_equals(host.shadowRoot.styleSheets.length, 3);
+ for (let sheet of host.shadowRoot.styleSheets)
+ assert_equals(sheet.title, null);
+}, "Title attribute in stylesheets not in the document tree is ignored");
+</script>