- Revision
- 203018
- Author
- cdu...@apple.com
- Date
- 2016-07-08 19:24:27 -0700 (Fri, 08 Jul 2016)
Log Message
adoptNode() changes css class to lowercase for document loaded with XHR responseType = "document"
https://bugs.webkit.org/show_bug.cgi?id=159555
<rdar://problem/27252541>
Reviewed by Ryosuke Niwa.
Source/WebCore:
When adopting an Element from another document which has a different quirks mode,
case-sensitivity for id and class attributes differs and we need to correctly
update members such as ElementData::m_classNames or ElementData::m_idForStyleResolution.
To address the issue, have Element override didMoveToNewDocument() and call
attributeChanged() for id and class attributes.
Test: fast/dom/Document/adoptNode-quirks-mismatch.html
* dom/Element.cpp:
(WebCore::Element::didMoveToNewDocument):
* dom/Element.h:
LayoutTests:
Add test coverage for id and class attributes.
* fast/dom/Document/adoptNode-quirks-mismatch-expected.txt: Added.
* fast/dom/Document/adoptNode-quirks-mismatch.html: Added.
* fast/dom/Document/resources/document-quirks-class.html: Added.
* fast/dom/Document/resources/document-quirks-id.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (203017 => 203018)
--- trunk/LayoutTests/ChangeLog 2016-07-09 02:24:23 UTC (rev 203017)
+++ trunk/LayoutTests/ChangeLog 2016-07-09 02:24:27 UTC (rev 203018)
@@ -1,3 +1,18 @@
+2016-07-08 Chris Dumez <cdu...@apple.com>
+
+ adoptNode() changes css class to lowercase for document loaded with XHR responseType = "document"
+ https://bugs.webkit.org/show_bug.cgi?id=159555
+ <rdar://problem/27252541>
+
+ Reviewed by Ryosuke Niwa.
+
+ Add test coverage for id and class attributes.
+
+ * fast/dom/Document/adoptNode-quirks-mismatch-expected.txt: Added.
+ * fast/dom/Document/adoptNode-quirks-mismatch.html: Added.
+ * fast/dom/Document/resources/document-quirks-class.html: Added.
+ * fast/dom/Document/resources/document-quirks-id.html: Added.
+
2016-07-08 Daniel Bates <daba...@apple.com>
Setting table.tFoot or calling table.createTFoot() should append HTML tfont element to the end of the table
Added: trunk/LayoutTests/fast/dom/Document/adoptNode-quirks-mismatch-expected.txt (0 => 203018)
--- trunk/LayoutTests/fast/dom/Document/adoptNode-quirks-mismatch-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/adoptNode-quirks-mismatch-expected.txt 2016-07-09 02:24:27 UTC (rev 203018)
@@ -0,0 +1,14 @@
+Tests that Document.adoptNode() properly deals with the documents having a different quirks mode
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+MyClass
+
+MyId
+
+PASS window.getComputedStyle(container.lastChild).color is "rgb(0, 128, 0)"
+PASS window.getComputedStyle(container.lastChild).color is "rgb(0, 128, 0)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/Document/adoptNode-quirks-mismatch.html (0 => 203018)
--- trunk/LayoutTests/fast/dom/Document/adoptNode-quirks-mismatch.html (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/adoptNode-quirks-mismatch.html 2016-07-09 02:24:27 UTC (rev 203018)
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<style>
+
+.myClass, #myId
+{
+ color: green;
+ font-weight: bold;
+}
+
+.myclass, #myid
+{
+ color: red;
+ font-weight: bold;
+}
+
+.myclass::after, #myid::after
+{
+ content: " (this should have been green!)";
+}
+</style>
+</head>
+<body>
+<div id="description"></div>
+<div id="container"></div>
+<div id="console"></div>
+<script>
+description("Tests that Document.adoptNode() properly deals with the documents having a different quirks mode");
+jsTestIsAsync = true;
+
+var tests = ["resources/document-quirks-class.html", "resources/document-quirks-id.html"];
+var currentTest = -1;
+
+function documentLoaded()
+{
+ var parsedBodyChild = this.response.body.children[0];
+
+ var container = document.getElementById("container");
+ container.appendChild(document.adoptNode(parsedBodyChild));
+
+ shouldBeEqualToString("window.getComputedStyle(container.lastChild).color", "rgb(0, 128, 0)");
+
+ runNextTest();
+}
+
+function runNextTest()
+{
+ currentTest++;
+ if (currentTest >= tests.length) {
+ finishJSTest();
+ return;
+ }
+
+ var xhr = new XMLHttpRequest();
+ xhr.responseType = "document";
+ xhr.addEventListener("load", documentLoaded);
+ xhr.open("GET", tests[currentTest], true);
+
+ xhr.send();
+}
+
+runNextTest();
+</script>
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/fast/dom/Document/resources/document-quirks-class.html (0 => 203018)
--- trunk/LayoutTests/fast/dom/Document/resources/document-quirks-class.html (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/resources/document-quirks-class.html 2016-07-09 02:24:27 UTC (rev 203018)
@@ -0,0 +1,7 @@
+<html>
+<body>
+<div class="myClass">
+<p>MyClass</p>
+</div>
+</body>
+</html>
Added: trunk/LayoutTests/fast/dom/Document/resources/document-quirks-id.html (0 => 203018)
--- trunk/LayoutTests/fast/dom/Document/resources/document-quirks-id.html (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/resources/document-quirks-id.html 2016-07-09 02:24:27 UTC (rev 203018)
@@ -0,0 +1,7 @@
+<html>
+<body>
+<div id="myId">
+<p>MyId</p>
+</div>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (203017 => 203018)
--- trunk/Source/WebCore/ChangeLog 2016-07-09 02:24:23 UTC (rev 203017)
+++ trunk/Source/WebCore/ChangeLog 2016-07-09 02:24:27 UTC (rev 203018)
@@ -1,3 +1,24 @@
+2016-07-08 Chris Dumez <cdu...@apple.com>
+
+ adoptNode() changes css class to lowercase for document loaded with XHR responseType = "document"
+ https://bugs.webkit.org/show_bug.cgi?id=159555
+ <rdar://problem/27252541>
+
+ Reviewed by Ryosuke Niwa.
+
+ When adopting an Element from another document which has a different quirks mode,
+ case-sensitivity for id and class attributes differs and we need to correctly
+ update members such as ElementData::m_classNames or ElementData::m_idForStyleResolution.
+
+ To address the issue, have Element override didMoveToNewDocument() and call
+ attributeChanged() for id and class attributes.
+
+ Test: fast/dom/Document/adoptNode-quirks-mismatch.html
+
+ * dom/Element.cpp:
+ (WebCore::Element::didMoveToNewDocument):
+ * dom/Element.h:
+
2016-07-08 Daniel Bates <daba...@apple.com>
Cleanup: Remove use of PassRefPtr from class HTMLTableElement
Modified: trunk/Source/WebCore/dom/Element.cpp (203017 => 203018)
--- trunk/Source/WebCore/dom/Element.cpp 2016-07-09 02:24:23 UTC (rev 203017)
+++ trunk/Source/WebCore/dom/Element.cpp 2016-07-09 02:24:27 UTC (rev 203018)
@@ -1454,6 +1454,19 @@
{
}
+void Element::didMoveToNewDocument(Document* oldDocument)
+{
+ Node::didMoveToNewDocument(oldDocument);
+
+ if (oldDocument->inQuirksMode() && !document().inQuirksMode()) {
+ // ElementData::m_classNames or ElementData::m_idForStyleResolution have folded case, we need to update them.
+ if (hasID())
+ attributeChanged(idAttr, nullAtom, getIdAttribute());
+ if (hasClass())
+ attributeChanged(classAttr, nullAtom, getAttribute(classAttr));
+ }
+}
+
bool Element::hasAttributes() const
{
synchronizeAllAttributes();
Modified: trunk/Source/WebCore/dom/Element.h (203017 => 203018)
--- trunk/Source/WebCore/dom/Element.h 2016-07-09 02:24:23 UTC (rev 203017)
+++ trunk/Source/WebCore/dom/Element.h 2016-07-09 02:24:27 UTC (rev 203018)
@@ -537,6 +537,7 @@
void childrenChanged(const ChildChange&) override;
void removeAllEventListeners() final;
virtual void parserDidSetAttributes();
+ void didMoveToNewDocument(Document*) override;
void clearTabIndexExplicitlyIfNeeded();
void setTabIndexExplicitly(int);