Diff
Modified: trunk/LayoutTests/ChangeLog (197011 => 197012)
--- trunk/LayoutTests/ChangeLog 2016-02-24 04:39:29 UTC (rev 197011)
+++ trunk/LayoutTests/ChangeLog 2016-02-24 05:15:44 UTC (rev 197012)
@@ -1,3 +1,28 @@
+2016-02-23 Chris Dumez <[email protected]>
+
+ Align our implementation of Range.createContextualFragment with the specification
+ https://bugs.webkit.org/show_bug.cgi?id=154627
+
+ Reviewed by Ryosuke Niwa.
+
+ Import some more layout tests from blink to improve coverage for
+ Range.createContextualFragment().
+
+ * imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range-expected.txt: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range.html: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range-expected.txt: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range.html: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range-expected.txt: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range.html: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range-expected.txt: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range.html: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range-expected.txt: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range.xhtml: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran-expected.txt: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran.html: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started-expected.txt: Added.
+ * imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started.html: Added.
+
2016-02-23 Dean Jackson <[email protected]>
[WebGL] iOS doesn't respect the alpha:false context creation attribute
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range-expected.txt (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range-expected.txt 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,3 @@
+Test of createContextualFragment from a Range whose context is an HTML document without a body. If the test succeeds you will see the word "PASS" below.
+
+PASS
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range.html (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range.html (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range.html 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<p>Test of createContextualFragment from a Range whose context is an HTML document without a body. If the test succeeds you will see the word "PASS" below.</p>
+<p id="result"></p>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+var doc = document.implementation.createHTMLDocument();
+var div = doc.createElement('div');
+doc.replaceChild(div, doc.documentElement);
+
+var range = doc.createRange();
+var fragment = range.createContextualFragment('<p id="fragment">Inserted fragment</p>');
+div.appendChild(fragment);
+var p = doc.getElementById('fragment');
+
+var result = document.getElementById('result');
+result.textContent = (p && p.parentElement === div && p.namespaceURI === 'http://www.w3.org/1999/xhtml') ? 'PASS' : 'FAIL';
+</script>
+
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range-expected.txt (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range-expected.txt 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,5 @@
+Test of createContextualFragment from a Range whose context is a detached text node. If the test succeeds you will see the word "PASS" below.
+
+PASS
+
+Inserted fragment
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range.html (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range.html (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range.html 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<p>Test of createContextualFragment from a Range whose context is a detached text node. If the test succeeds you will see the word "PASS" below.</p>
+<p id="result"></p>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+var textNode = document.createTextNode("Text node without an element parent");
+var range = document.createRange();
+range.setStart(textNode, 0);
+var fragment = range.createContextualFragment('<p id="fragment">Inserted fragment</p>');
+document.body.appendChild(fragment);
+var p = document.getElementById('fragment');
+
+var result = document.getElementById('result');
+result.textContent = (p && p.parentElement === document.body && p.namespaceURI === 'http://www.w3.org/1999/xhtml') ? 'PASS' : 'FAIL';
+</script>
+
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range-expected.txt (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range-expected.txt 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,5 @@
+Test of createContextualFragment from a Range whose container is a DocumentFragment. If the test succeeds you will see the word "PASS" below.
+
+PASS
+
+Inserted fragment
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range.html (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range.html (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range.html 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<p>Test of createContextualFragment from a Range whose container is a DocumentFragment. If the test succeeds you will see the word "PASS" below.</p>
+<p id="result"></p>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+var contextFragment = document.createDocumentFragment();
+var range = document.createRange();
+range.setStart(contextFragment, 0);
+var fragment = range.createContextualFragment('<p id="fragment">Inserted fragment</p>');
+document.body.appendChild(fragment);
+var p = document.getElementById('fragment');
+
+var result = document.getElementById('result');
+result.textContent = (p && p.parentElement === document.body && p.namespaceURI === 'http://www.w3.org/1999/xhtml') ? 'PASS' : 'FAIL';
+</script>
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range-expected.txt (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range-expected.txt 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,5 @@
+Test of createContextualFragment from a Range whose context is a document. If the test succeeds you will see the word "PASS" below.
+
+PASS
+
+Inserted fragment
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range.html (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range.html (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range.html 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<p>Test of createContextualFragment from a Range whose context is a document. If the test succeeds you will see the word "PASS" below.</p>
+<p id="result"></p>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+var range = document.createRange();
+var fragment = range.createContextualFragment('<p id="fragment">Inserted fragment</p>');
+document.body.appendChild(fragment);
+var p = document.getElementById('fragment');
+
+var result = document.getElementById('result');
+result.textContent = (p && p.parentElement === document.body && p.namespaceURI === 'http://www.w3.org/1999/xhtml') ? 'PASS' : 'FAIL';
+</script>
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range-expected.txt (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range-expected.txt 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,5 @@
+Test of createContextualFragment from a Range whose context is an XHTML document. If the test succeeds you will see the word "PASS" below.
+
+PASS
+
+Inserted fragment
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range.xhtml (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range.xhtml (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range.xhtml 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>createContextualFragment from <html> element range in XHTML document.</title>
+</head>
+<body>
+<p>Test of createContextualFragment from a Range whose context is an XHTML document. If the test succeeds you will see the word "PASS" below.</p>
+<p id="result"></p>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+var range = document.createRange();
+var fragment = range.createContextualFragment('<p id="frag">Inserted fragment</p>');
+document.body.appendChild(fragment);
+var p = document.getElementById('frag');
+
+var result = document.getElementById('result');
+result.textContent = (p && p.parentElement === document.body && p.namespaceURI === 'http://www.w3.org/1999/xhtml') ? 'PASS' : 'FAIL';
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran-expected.txt (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran-expected.txt 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,3 @@
+Tests createContextualFragment does not execute scripts immediately. You should see PASS below:
+
+PASS
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran.html (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran.html (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran.html 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>Tests createContextualFragment does not execute scripts immediately. You should see PASS below:</p>
+<div id="test"></div>
+<script>
+var range = document.createRange();
+var node = document.getElementById("test");
+var count = 0;
+range.selectNodeContents(node);
+range.createContextualFragment("<script> count++; </script" + ">");
+node.textContent = !count ? 'PASS' : 'FAIL - expected no execution but executed ' + count + ' times';
+
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started-expected.txt (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started-expected.txt 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,3 @@
+Tests createContextualFragment does not mark scripts elements it parsed as already started. You should see PASS below:
+
+PASS
Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started.html (0 => 197012)
--- trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started.html (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started.html 2016-02-24 05:15:44 UTC (rev 197012)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>Tests createContextualFragment does not mark scripts elements it parsed as already started. You should see PASS below:</p>
+<div id="test"></div>
+<script>
+var range = document.createRange();
+var node = document.getElementById("test");
+var count = 0;
+range.selectNodeContents(node);
+node.appendChild(range.createContextualFragment("<script> count++; </script" + ">"));
+node.textContent = count == 1 ? 'PASS' : 'FAIL - expected one execution but executed ' + count + ' times';
+
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+</script>
+</body>
+</html>
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (197011 => 197012)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2016-02-24 04:39:29 UTC (rev 197011)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2016-02-24 05:15:44 UTC (rev 197012)
@@ -1,3 +1,14 @@
+2016-02-23 Chris Dumez <[email protected]>
+
+ Align our implementation of Range.createContextualFragment with the specification
+ https://bugs.webkit.org/show_bug.cgi?id=154627
+
+ Reviewed by Ryosuke Niwa.
+
+ Rebaseline as one more check is passing.
+
+ * web-platform-tests/dom/nodes/Node-contains-xhtml-expected.txt:
+
2016-02-22 Youenn Fablet <[email protected]>
Binding generator should support key value iterable
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-contains-xhtml-expected.txt (197011 => 197012)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-contains-xhtml-expected.txt 2016-02-24 04:39:29 UTC (rev 197011)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-contains-xhtml-expected.txt 2016-02-24 05:15:44 UTC (rev 197012)
@@ -8,6 +8,6 @@
PASS contains with a button
PASS contains with a text node
PASS contains with a processing instruction
-FAIL contains with a document fragment NotSupportedError: DOM Exception 9
+PASS contains with a document fragment
PASS contaibs with another document
Modified: trunk/Source/WebCore/ChangeLog (197011 => 197012)
--- trunk/Source/WebCore/ChangeLog 2016-02-24 04:39:29 UTC (rev 197011)
+++ trunk/Source/WebCore/ChangeLog 2016-02-24 05:15:44 UTC (rev 197012)
@@ -1,3 +1,31 @@
+2016-02-23 Chris Dumez <[email protected]>
+
+ Align our implementation of Range.createContextualFragment with the specification
+ https://bugs.webkit.org/show_bug.cgi?id=154627
+
+ Reviewed by Ryosuke Niwa.
+
+ Align our implementation of Range.createContextualFragment with the
+ specification:
+ - https://w3c.github.io/DOM-Parsing/#widl-Range-createContextualFragment-DocumentFragment-DOMString-fragment
+
+ In particular, if the Range's start node is a Document / DocumentFragment,
+ we now create a new HTMLBodyElement and use it as context element, instead
+ of throwing an exception.
+
+ This also aligns our behavior with Firefox and Chrome.
+
+ Tests: imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range.html
+ imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range.html
+ imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range.html
+ imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range.html
+ imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range.xhtml
+ imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran.html
+ imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started.html
+
+ * dom/Range.cpp:
+ (WebCore::Range::createContextualFragment):
+
2016-02-23 Dan Bernstein <[email protected]>
[Xcode] Linker errors display mangled names, but no longer should
Modified: trunk/Source/WebCore/dom/Range.cpp (197011 => 197012)
--- trunk/Source/WebCore/dom/Range.cpp 2016-02-24 04:39:29 UTC (rev 197011)
+++ trunk/Source/WebCore/dom/Range.cpp 2016-02-24 05:15:44 UTC (rev 197012)
@@ -31,7 +31,10 @@
#include "Event.h"
#include "Frame.h"
#include "FrameView.h"
+#include "HTMLBodyElement.h"
+#include "HTMLDocument.h"
#include "HTMLElement.h"
+#include "HTMLHtmlElement.h"
#include "HTMLNames.h"
#include "NodeTraversal.h"
#include "NodeWithIndex.h"
@@ -919,15 +922,26 @@
return plainText(this);
}
+// https://w3c.github.io/DOM-Parsing/#widl-Range-createContextualFragment-DocumentFragment-DOMString-fragment
RefPtr<DocumentFragment> Range::createContextualFragment(const String& markup, ExceptionCode& ec)
{
- Node* element = startContainer().isElementNode() ? &startContainer() : startContainer().parentNode();
- if (!element || !element->isHTMLElement()) {
+ Node& node = startContainer();
+ RefPtr<Element> element;
+ if (is<Document>(node) || is<DocumentFragment>(node))
+ element = nullptr;
+ else if (is<Element>(node))
+ element = &downcast<Element>(node);
+ else
+ element = node.parentElement();
+
+ if (!element || (is<HTMLDocument>(element->document()) && is<HTMLHtmlElement>(*element)))
+ element = HTMLBodyElement::create(node.document());
+ else if (!is<HTMLElement>(*element)) {
ec = NOT_SUPPORTED_ERR;
return nullptr;
}
- return WebCore::createContextualFragment(markup, downcast<HTMLElement>(element), AllowScriptingContentAndDoNotMarkAlreadyStarted, ec);
+ return WebCore::createContextualFragment(markup, downcast<HTMLElement>(element.get()), AllowScriptingContentAndDoNotMarkAlreadyStarted, ec);
}