<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[197012] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/197012">197012</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2016-02-23 21:15:44 -0800 (Tue, 23 Feb 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Align our implementation of Range.createContextualFragment with the specification
https://bugs.webkit.org/show_bug.cgi?id=154627

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline as one more check is passing.

* web-platform-tests/dom/nodes/Node-contains-xhtml-expected.txt:

Source/WebCore:

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):

LayoutTests:

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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsdomnodesNodecontainsxhtmlexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-contains-xhtml-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomRangecpp">trunk/Source/WebCore/dom/Range.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfrombodylessdocumentrangeexpectedtxt">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfrombodylessdocumentrangehtml">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range.html</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdetachedtextnoderangeexpectedtxt">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdetachedtextnoderangehtml">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range.html</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdocumentfragmentrangeexpectedtxt">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdocumentfragmentrangehtml">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range.html</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdocumentrangeexpectedtxt">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdocumentrangehtml">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range.html</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromxhtmldocumentrangeexpectedtxt">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromxhtmldocumentrangexhtml">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range.xhtml</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentscriptnotranexpectedtxt">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentscriptnotranhtml">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran.html</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentscriptunmarkalreadystartedexpectedtxt">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentscriptunmarkalreadystartedhtml">trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (197011 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-02-24 04:39:29 UTC (rev 197011)
+++ trunk/LayoutTests/ChangeLog        2016-02-24 05:15:44 UTC (rev 197012)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2016-02-23  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        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.
+
</ins><span class="cx"> 2016-02-23  Dean Jackson  &lt;dino@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WebGL] iOS doesn't respect the alpha:false context creation attribute
</span></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfrombodylessdocumentrangeexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range-expected.txt (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+Test of createContextualFragment from a Range whose context is an HTML document without a body. If the test succeeds you will see the word &quot;PASS&quot; below.
+
+PASS
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfrombodylessdocumentrangehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-bodyless-document-range.html (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;p&gt;Test of createContextualFragment from a Range whose context is an HTML document without a body. If the test succeeds you will see the word &quot;PASS&quot; below.&lt;/p&gt;
+&lt;p id=&quot;result&quot;&gt;&lt;/p&gt;
+&lt;script&gt;
+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('&lt;p id=&quot;fragment&quot;&gt;Inserted fragment&lt;/p&gt;');
+div.appendChild(fragment);
+var p = doc.getElementById('fragment');
+
+var result = document.getElementById('result');
+result.textContent = (p &amp;&amp; p.parentElement === div &amp;&amp; p.namespaceURI === 'http://www.w3.org/1999/xhtml') ? 'PASS' : 'FAIL';
+&lt;/script&gt;
+
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdetachedtextnoderangeexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range-expected.txt (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+Test of createContextualFragment from a Range whose context is a detached text node. If the test succeeds you will see the word &quot;PASS&quot; below.
+
+PASS
+
+Inserted fragment
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdetachedtextnoderangehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-detached-text-node-range.html (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;p&gt;Test of createContextualFragment from a Range whose context is a detached text node. If the test succeeds you will see the word &quot;PASS&quot; below.&lt;/p&gt;
+&lt;p id=&quot;result&quot;&gt;&lt;/p&gt;
+&lt;script&gt;
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var textNode = document.createTextNode(&quot;Text node without an element parent&quot;);
+var range = document.createRange();
+range.setStart(textNode, 0);
+var fragment = range.createContextualFragment('&lt;p id=&quot;fragment&quot;&gt;Inserted fragment&lt;/p&gt;');
+document.body.appendChild(fragment);
+var p = document.getElementById('fragment');
+
+var result = document.getElementById('result');
+result.textContent = (p &amp;&amp; p.parentElement === document.body &amp;&amp; p.namespaceURI === 'http://www.w3.org/1999/xhtml') ? 'PASS' : 'FAIL';
+&lt;/script&gt;
+
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdocumentfragmentrangeexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range-expected.txt (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+Test of createContextualFragment from a Range whose container is a DocumentFragment. If the test succeeds you will see the word &quot;PASS&quot; below.
+
+PASS
+
+Inserted fragment
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdocumentfragmentrangehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-fragment-range.html (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,17 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;p&gt;Test of createContextualFragment from a Range whose container is a DocumentFragment. If the test succeeds you will see the word &quot;PASS&quot; below.&lt;/p&gt;
+&lt;p id=&quot;result&quot;&gt;&lt;/p&gt;
+&lt;script&gt;
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var contextFragment = document.createDocumentFragment();
+var range = document.createRange();
+range.setStart(contextFragment, 0);
+var fragment = range.createContextualFragment('&lt;p id=&quot;fragment&quot;&gt;Inserted fragment&lt;/p&gt;');
+document.body.appendChild(fragment);
+var p = document.getElementById('fragment');
+
+var result = document.getElementById('result');
+result.textContent = (p &amp;&amp; p.parentElement === document.body &amp;&amp; p.namespaceURI === 'http://www.w3.org/1999/xhtml') ? 'PASS' : 'FAIL';
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdocumentrangeexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range-expected.txt (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+Test of createContextualFragment from a Range whose context is a document. If the test succeeds you will see the word &quot;PASS&quot; below.
+
+PASS
+
+Inserted fragment
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromdocumentrangehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-document-range.html (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;p&gt;Test of createContextualFragment from a Range whose context is a document. If the test succeeds you will see the word &quot;PASS&quot; below.&lt;/p&gt;
+&lt;p id=&quot;result&quot;&gt;&lt;/p&gt;
+&lt;script&gt;
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var range = document.createRange();
+var fragment = range.createContextualFragment('&lt;p id=&quot;fragment&quot;&gt;Inserted fragment&lt;/p&gt;');
+document.body.appendChild(fragment);
+var p = document.getElementById('fragment');
+
+var result = document.getElementById('result');
+result.textContent = (p &amp;&amp; p.parentElement === document.body &amp;&amp; p.namespaceURI === 'http://www.w3.org/1999/xhtml') ? 'PASS' : 'FAIL';
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromxhtmldocumentrangeexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range-expected.txt (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+Test of createContextualFragment from a Range whose context is an XHTML document. If the test succeeds you will see the word &quot;PASS&quot; below.
+
+PASS
+
+Inserted fragment
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentfromxhtmldocumentrangexhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-from-xhtml-document-range.xhtml (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+&lt;?xml version=&quot;1.0&quot;?&gt;
+&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
+&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
+&lt;head&gt;
+  &lt;title&gt;createContextualFragment from &amp;lt;html&amp;gt; element range in XHTML document.&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;p&gt;Test of createContextualFragment from a Range whose context is an XHTML document. If the test succeeds you will see the word &quot;PASS&quot; below.&lt;/p&gt;
+&lt;p id=&quot;result&quot;&gt;&lt;/p&gt;
+&lt;script&gt;
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var range = document.createRange();
+var fragment = range.createContextualFragment('&amp;lt;p id=&quot;frag&quot;&gt;Inserted fragment&amp;lt;/p&gt;');
+document.body.appendChild(fragment);
+var p = document.getElementById('frag');
+
+var result = document.getElementById('result');
+result.textContent = (p &amp;amp;&amp;amp; p.parentElement === document.body &amp;amp;&amp;amp; p.namespaceURI === 'http://www.w3.org/1999/xhtml') ? 'PASS' : 'FAIL';
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentscriptnotranexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran-expected.txt (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+Tests createContextualFragment does not execute scripts immediately. You should see PASS below:
+
+PASS
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentscriptnotranhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-not-ran.html (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+&lt;p&gt;Tests createContextualFragment does not execute scripts immediately. You should see PASS below:&lt;/p&gt;
+&lt;div id=&quot;test&quot;&gt;&lt;/div&gt;
+&lt;script&gt;
+var range = document.createRange();
+var node = document.getElementById(&quot;test&quot;);
+var count = 0;
+range.selectNodeContents(node);
+range.createContextualFragment(&quot;&lt;script&gt; count++; &lt;/script&quot; + &quot;&gt;&quot;);
+node.textContent = !count ? 'PASS' : 'FAIL - expected no execution but executed ' + count + ' times';
+
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentscriptunmarkalreadystartedexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started-expected.txt (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+Tests createContextualFragment does not mark scripts elements it parsed as already started. You should see PASS below:
+
+PASS
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedblinkfastdomRangecreatecontextualfragmentscriptunmarkalreadystartedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/blink/fast/dom/Range/create-contextual-fragment-script-unmark-already-started.html (0 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+&lt;p&gt;Tests createContextualFragment does not mark scripts elements it parsed as already started. You should see PASS below:&lt;/p&gt;
+&lt;div id=&quot;test&quot;&gt;&lt;/div&gt;
+&lt;script&gt;
+var range = document.createRange();
+var node = document.getElementById(&quot;test&quot;);
+var count = 0;
+range.selectNodeContents(node);
+node.appendChild(range.createContextualFragment(&quot;&lt;script&gt; count++; &lt;/script&quot; + &quot;&gt;&quot;));
+node.textContent = count == 1 ? 'PASS' : 'FAIL - expected one execution but executed ' + count + ' times';
+
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (197011 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-02-23  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        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:
+
</ins><span class="cx"> 2016-02-22  Youenn Fablet  &lt;youenn.fablet@crf.canon.fr&gt;
</span><span class="cx"> 
</span><span class="cx">         Binding generator should support key value iterable
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsdomnodesNodecontainsxhtmlexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Node-contains-xhtml-expected.txt (197011 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -8,6 +8,6 @@
</span><span class="cx"> PASS contains with a button 
</span><span class="cx"> PASS contains with a text node 
</span><span class="cx"> PASS contains with a processing instruction 
</span><del>-FAIL contains with a document fragment NotSupportedError: DOM Exception 9
</del><ins>+PASS contains with a document fragment 
</ins><span class="cx"> PASS contaibs with another document 
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (197011 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2016-02-23  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        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):
+
</ins><span class="cx"> 2016-02-23  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Xcode] Linker errors display mangled names, but no longer should
</span></span></pre></div>
<a id="trunkSourceWebCoredomRangecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Range.cpp (197011 => 197012)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -31,7 +31,10 @@
</span><span class="cx"> #include &quot;Event.h&quot;
</span><span class="cx"> #include &quot;Frame.h&quot;
</span><span class="cx"> #include &quot;FrameView.h&quot;
</span><ins>+#include &quot;HTMLBodyElement.h&quot;
+#include &quot;HTMLDocument.h&quot;
</ins><span class="cx"> #include &quot;HTMLElement.h&quot;
</span><ins>+#include &quot;HTMLHtmlElement.h&quot;
</ins><span class="cx"> #include &quot;HTMLNames.h&quot;
</span><span class="cx"> #include &quot;NodeTraversal.h&quot;
</span><span class="cx"> #include &quot;NodeWithIndex.h&quot;
</span><span class="lines">@@ -919,15 +922,26 @@
</span><span class="cx">     return plainText(this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+// https://w3c.github.io/DOM-Parsing/#widl-Range-createContextualFragment-DocumentFragment-DOMString-fragment
</ins><span class="cx"> RefPtr&lt;DocumentFragment&gt; Range::createContextualFragment(const String&amp; markup, ExceptionCode&amp; ec)
</span><span class="cx"> {
</span><del>-    Node* element = startContainer().isElementNode() ? &amp;startContainer() : startContainer().parentNode();
-    if (!element || !element-&gt;isHTMLElement()) {
</del><ins>+    Node&amp; node = startContainer();
+    RefPtr&lt;Element&gt; element;
+    if (is&lt;Document&gt;(node) || is&lt;DocumentFragment&gt;(node))
+        element = nullptr;
+    else if (is&lt;Element&gt;(node))
+        element = &amp;downcast&lt;Element&gt;(node);
+    else
+        element = node.parentElement();
+
+    if (!element || (is&lt;HTMLDocument&gt;(element-&gt;document()) &amp;&amp; is&lt;HTMLHtmlElement&gt;(*element)))
+        element = HTMLBodyElement::create(node.document());
+    else if (!is&lt;HTMLElement&gt;(*element)) {
</ins><span class="cx">         ec = NOT_SUPPORTED_ERR;
</span><span class="cx">         return nullptr;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    return WebCore::createContextualFragment(markup, downcast&lt;HTMLElement&gt;(element), AllowScriptingContentAndDoNotMarkAlreadyStarted, ec);
</del><ins>+    return WebCore::createContextualFragment(markup, downcast&lt;HTMLElement&gt;(element.get()), AllowScriptingContentAndDoNotMarkAlreadyStarted, ec);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>