- Revision
- 279814
- Author
- [email protected]
- Date
- 2021-07-10 21:16:05 -0700 (Sat, 10 Jul 2021)
Log Message
document.readyState should be "complete" after calling DOMParser.parseFromString()
https://bugs.webkit.org/show_bug.cgi?id=227846
Reviewed by Ryosuke Niwa.
LayoutTests/imported/w3c:
Rebaseline WPT test that is now passing.
* web-platform-tests/domparsing/xmldomparser-expected.txt:
Source/WebCore:
document.readyState should be "complete" after calling DOMParser.parseFromString().
This is causing the following WPT test to fail in WebKit:
http://wpt.live/domparsing/xmldomparser.html
Both Gecko and Blink report the correct readyState here.
No new tests, rebaselined existing test.
* dom/Document.cpp:
(WebCore::Document::explicitClose):
explicitClose() normally calls checkCompleted() which calls FrameLoader::checkCompleted(),
which ends up setting the document's ready state to "complete" and then calling
Document::implicitClose(). However, when the document has no frame (which is the case
for a document just created via DOMParser.parseFromString()), we would call
Document::implicitClose() directly, since we don't have a FrameLoader. As a result,
the document's ready state would stay "interactive". To address the issue, we now set
the document's ready state to "complete" before calling implicitClose(), similarly to
what FrameLoader::checkCompleted() would have done.
Modified Paths
Added Paths
Diff
Added: trunk/LayoutTests/fast/dom/Document/createdDocument-readyState-expected.txt (0 => 279814)
--- trunk/LayoutTests/fast/dom/Document/createdDocument-readyState-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/createdDocument-readyState-expected.txt 2021-07-11 04:16:05 UTC (rev 279814)
@@ -0,0 +1,19 @@
+Tests document.readyState() for documents created by _javascript_
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+htmlDocument = document.implementation.createHTMLDocument()
+PASS htmlDocument.readyState is "loading"
+htmlDocument.close()
+PASS htmlDocument.readyState is "complete"
+xhtmlDocument = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null)
+PASS xhtmlDocument.readyState is "complete"
+svgDocument = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg', null)
+PASS svgDocument.readyState is "complete"
+xmlDocument = (new DOMParser()).parseFromString('', 'text/xml')
+PASS xmlDocument.readyState is "complete"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/Document/createdDocument-readyState.html (0 => 279814)
--- trunk/LayoutTests/fast/dom/Document/createdDocument-readyState.html (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/createdDocument-readyState.html 2021-07-11 04:16:05 UTC (rev 279814)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Tests document.readyState() for documents created by _javascript_");
+
+evalAndLog("htmlDocument = document.implementation.createHTMLDocument()");
+shouldBeEqualToString("htmlDocument.readyState", "loading"); // WebKit and Blink say "loading", Gecko says "complete".
+evalAndLog("htmlDocument.close()");
+shouldBeEqualToString("htmlDocument.readyState", "complete");
+
+evalAndLog("xhtmlDocument = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null)");
+shouldBeEqualToString("xhtmlDocument.readyState", "complete");
+
+evalAndLog("svgDocument = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg', null)");
+shouldBeEqualToString("svgDocument.readyState", "complete");
+
+evalAndLog("xmlDocument = (new DOMParser()).parseFromString('<html></html>', 'text/xml')");
+shouldBeEqualToString("xmlDocument.readyState", "complete");
+</script>
+</html>
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (279813 => 279814)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-07-11 01:27:40 UTC (rev 279813)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-07-11 04:16:05 UTC (rev 279814)
@@ -1,3 +1,14 @@
+2021-07-10 Chris Dumez <[email protected]>
+
+ document.readyState should be "complete" after calling DOMParser.parseFromString()
+ https://bugs.webkit.org/show_bug.cgi?id=227846
+
+ Reviewed by Ryosuke Niwa.
+
+ Rebaseline WPT test that is now passing.
+
+ * web-platform-tests/domparsing/xmldomparser-expected.txt:
+
2021-07-10 Commit Queue <[email protected]>
Unreviewed, reverting r279803.
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/domparsing/xmldomparser-expected.txt (279813 => 279814)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/domparsing/xmldomparser-expected.txt 2021-07-11 01:27:40 UTC (rev 279813)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/domparsing/xmldomparser-expected.txt 2021-07-11 04:16:05 UTC (rev 279814)
@@ -1,3 +1,3 @@
-FAIL XML Dom Parse readyState Test assert_equals: expected "complete" but got "interactive"
+PASS XML Dom Parse readyState Test
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/responsexml-document-properties-expected.txt (279813 => 279814)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/responsexml-document-properties-expected.txt 2021-07-11 01:27:40 UTC (rev 279813)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/responsexml-document-properties-expected.txt 2021-07-11 04:16:05 UTC (rev 279814)
@@ -6,7 +6,7 @@
PASS referrer
PASS title
PASS contentType
-FAIL readyState assert_equals: expected "complete" but got "interactive"
+PASS readyState
PASS location
PASS defaultView
PASS body
Modified: trunk/Source/WebCore/ChangeLog (279813 => 279814)
--- trunk/Source/WebCore/ChangeLog 2021-07-11 01:27:40 UTC (rev 279813)
+++ trunk/Source/WebCore/ChangeLog 2021-07-11 04:16:05 UTC (rev 279814)
@@ -1,3 +1,30 @@
+2021-07-10 Chris Dumez <[email protected]>
+
+ document.readyState should be "complete" after calling DOMParser.parseFromString()
+ https://bugs.webkit.org/show_bug.cgi?id=227846
+
+ Reviewed by Ryosuke Niwa.
+
+ document.readyState should be "complete" after calling DOMParser.parseFromString().
+
+ This is causing the following WPT test to fail in WebKit:
+ http://wpt.live/domparsing/xmldomparser.html
+
+ Both Gecko and Blink report the correct readyState here.
+
+ No new tests, rebaselined existing test.
+
+ * dom/Document.cpp:
+ (WebCore::Document::explicitClose):
+ explicitClose() normally calls checkCompleted() which calls FrameLoader::checkCompleted(),
+ which ends up setting the document's ready state to "complete" and then calling
+ Document::implicitClose(). However, when the document has no frame (which is the case
+ for a document just created via DOMParser.parseFromString()), we would call
+ Document::implicitClose() directly, since we don't have a FrameLoader. As a result,
+ the document's ready state would stay "interactive". To address the issue, we now set
+ the document's ready state to "complete" before calling implicitClose(), similarly to
+ what FrameLoader::checkCompleted() would have done.
+
2021-07-10 Commit Queue <[email protected]>
Unreviewed, reverting r279803.
Modified: trunk/Source/WebCore/dom/Document.cpp (279813 => 279814)
--- trunk/Source/WebCore/dom/Document.cpp 2021-07-11 01:27:40 UTC (rev 279813)
+++ trunk/Source/WebCore/dom/Document.cpp 2021-07-11 04:16:05 UTC (rev 279814)
@@ -1395,8 +1395,10 @@
}
m_readyState = readyState;
- dispatchEvent(Event::create(eventNames().readystatechangeEvent, Event::CanBubble::No, Event::IsCancelable::No));
+ if (m_frame)
+ dispatchEvent(Event::create(eventNames().readystatechangeEvent, Event::CanBubble::No, Event::IsCancelable::No));
+
if (settings().suppressesIncrementalRendering())
setVisualUpdatesAllowed(readyState);
}
@@ -3103,6 +3105,7 @@
// Because we have no frame, we don't know if all loading has completed,
// so we just call implicitClose() immediately. FIXME: This might fire
// the load event prematurely <http://bugs.webkit.org/show_bug.cgi?id=14568>.
+ setReadyState(Complete);
implicitClose();
return;
}