<!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>[190174] 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/190174">190174</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2015-09-23 09:21:33 -0700 (Wed, 23 Sep 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Range's setStartBefore() / setStartAfter() / setEndBefore() / setEndAfter() do not match the specification
https://bugs.webkit.org/show_bug.cgi?id=149490

Reviewed by Andreas Kling.

LayoutTests/imported/w3c:

Rebaseline several W3C DOM tests now that more checks are passing.

* web-platform-tests/dom/ranges/Range-selectNode-expected.txt:
* web-platform-tests/dom/ranges/Range-surroundContents-expected.txt:

Source/WebCore:

Range's setStartBefore() / setStartAfter() / setEndBefore() / setEndAfter()
behavior do not match the DOM specification:
- https://dom.spec.whatwg.org/#dom-range-setstartbefore
- https://dom.spec.whatwg.org/#dom-range-setstartafter
- https://dom.spec.whatwg.org/#dom-range-setendbefore
- https://dom.spec.whatwg.org/#dom-range-setendafter

In particular, instead of step 2:
&quot;If parent is null, throw an InvalidNodeTypeError exception.&quot;

Our implementation was doing more checks and throwing exceptions in cases
that the specification does not say we should. We were calling
checkNodeBA() which had restrictions on both the node type and its
root type. This is now replaced by a simple null check on the parent,
as per the specification.

Firefox's behavior matches the specification.

No new tests, already covered by existing tests.

* dom/Range.cpp:
(WebCore::Range::setStartAfter):
(WebCore::Range::setEndBefore):
(WebCore::Range::setEndAfter):
(WebCore::Range::setStartBefore):
(WebCore::Range::cloneRange): Deleted.
(WebCore::Range::selectNode): Deleted.
(WebCore::Range::selectNodeContents): Deleted.
(WebCore::Range::absoluteTextRects): Deleted.
* dom/Range.h:

LayoutTests:

Update test that expected an assertion in a case where we no longer
throw. I checked that Firefox does not throw in this case either.

* fast/dom/Range/range-exceptions-expected.txt:
* fast/dom/Range/script-tests/range-exceptions.js:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastdomRangerangeexceptionsexpectedtxt">trunk/LayoutTests/fast/dom/Range/range-exceptions-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomRangescripttestsrangeexceptionsjs">trunk/LayoutTests/fast/dom/Range/script-tests/range-exceptions.js</a></li>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsdomrangesRangeselectNodeexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-selectNode-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsdomrangesRangesurroundContentsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-surroundContents-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>
<li><a href="#trunkSourceWebCoredomRangeh">trunk/Source/WebCore/dom/Range.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (190173 => 190174)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-09-23 16:06:00 UTC (rev 190173)
+++ trunk/LayoutTests/ChangeLog        2015-09-23 16:21:33 UTC (rev 190174)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2015-09-23  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Range's setStartBefore() / setStartAfter() / setEndBefore() / setEndAfter() do not match the specification
+        https://bugs.webkit.org/show_bug.cgi?id=149490
+
+        Reviewed by Andreas Kling.
+
+        Update test that expected an assertion in a case where we no longer
+        throw. I checked that Firefox does not throw in this case either.
+
+        * fast/dom/Range/range-exceptions-expected.txt:
+        * fast/dom/Range/script-tests/range-exceptions.js:
+
</ins><span class="cx"> 2015-09-23  Commit Queue  &lt;commit-queue@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r190168.
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomRangerangeexceptionsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/Range/range-exceptions-expected.txt (190173 => 190174)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Range/range-exceptions-expected.txt        2015-09-23 16:06:00 UTC (rev 190173)
+++ trunk/LayoutTests/fast/dom/Range/range-exceptions-expected.txt        2015-09-23 16:21:33 UTC (rev 190174)
</span><span class="lines">@@ -4,8 +4,6 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> PASS node.innerHTML is '&lt;bar&gt;AB&lt;moo&gt;C&lt;/moo&gt;DE&lt;/bar&gt;'
</span><del>-PASS foo.outerHTML is '&lt;foo&gt;&lt;/foo&gt;'
-PASS range.surroundContents(foo) threw exception Error: InvalidNodeTypeError: DOM Exception 24.
</del><span class="cx"> PASS r.surroundContents(document.createElement('a')) threw exception Error: InvalidStateError: DOM Exception 11.
</span><span class="cx"> PASS r.surroundContents(document.createElement('a')) threw exception Error: HierarchyRequestError: DOM Exception 3.
</span><span class="cx"> PASS successfullyParsed is true
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomRangescripttestsrangeexceptionsjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/Range/script-tests/range-exceptions.js (190173 => 190174)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Range/script-tests/range-exceptions.js        2015-09-23 16:06:00 UTC (rev 190173)
+++ trunk/LayoutTests/fast/dom/Range/script-tests/range-exceptions.js        2015-09-23 16:21:33 UTC (rev 190174)
</span><span class="lines">@@ -6,12 +6,6 @@
</span><span class="cx"> var node = document.createElement(&quot;DIV&quot;);
</span><span class="cx"> node.innerHTML = &quot;&lt;BAR&gt;AB&lt;MOO&gt;C&lt;/MOO&gt;DE&lt;/BAR&gt;&quot;;
</span><span class="cx"> shouldBe(&quot;node.innerHTML&quot;, &quot;'&lt;bar&gt;AB&lt;moo&gt;C&lt;/moo&gt;DE&lt;/bar&gt;'&quot;);
</span><del>-var range = document.createRange();
-range.setStart(node.firstChild, 1);
-range.setEnd(node.firstChild, 2);
-var foo = document.createElement(&quot;FOO&quot;);
-shouldBe(&quot;foo.outerHTML&quot;, &quot;'&lt;foo&gt;&lt;/foo&gt;'&quot;);
-shouldThrow(&quot;range.surroundContents(foo)&quot;);
</del><span class="cx"> 
</span><span class="cx"> // Ensure that we throw BAD_BOUNDARYPOINTS_ERR when trying to split a comment
</span><span class="cx"> // (non-text but character-offset node). (Test adapted from Acid3.)
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (190173 => 190174)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog        2015-09-23 16:06:00 UTC (rev 190173)
+++ trunk/LayoutTests/imported/w3c/ChangeLog        2015-09-23 16:21:33 UTC (rev 190174)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2015-09-23  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Range's setStartBefore() / setStartAfter() / setEndBefore() / setEndAfter() do not match the specification
+        https://bugs.webkit.org/show_bug.cgi?id=149490
+
+        Reviewed by Andreas Kling.
+
+        Rebaseline several W3C DOM tests now that more checks are passing.
+
+        * web-platform-tests/dom/ranges/Range-selectNode-expected.txt:
+        * web-platform-tests/dom/ranges/Range-surroundContents-expected.txt:
+
</ins><span class="cx"> 2015-09-22  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Event fired on a detached node does not bubble up
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsdomrangesRangeselectNodeexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-selectNode-expected.txt (190173 => 190174)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-selectNode-expected.txt        2015-09-23 16:06:00 UTC (rev 190173)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-selectNode-expected.txt        2015-09-23 16:21:33 UTC (rev 190174)
</span><span class="lines">@@ -183,22 +183,22 @@
</span><span class="cx"> PASS  detached div in current doc: div node, foreign doc's range, type 1 
</span><span class="cx"> PASS  detached div in current doc: div node, XML doc's range, type 1 
</span><span class="cx"> PASS  detached div in current doc: div node, detached range, type 1 
</span><del>-FAIL ** detached div in current doc: p node, current doc's range, type 1 InvalidNodeTypeError: DOM Exception 24
-FAIL ** detached div in current doc: p node, foreign doc's range, type 1 InvalidNodeTypeError: DOM Exception 24
-FAIL ** detached div in current doc: p node, XML doc's range, type 1 InvalidNodeTypeError: DOM Exception 24
-FAIL ** detached div in current doc: p node, detached range, type 1 InvalidNodeTypeError: DOM Exception 24
-FAIL **** detached div in current doc: #text node, current doc's range, type 3 InvalidNodeTypeError: DOM Exception 24
-FAIL **** detached div in current doc: #text node, foreign doc's range, type 3 InvalidNodeTypeError: DOM Exception 24
-FAIL **** detached div in current doc: #text node, XML doc's range, type 3 InvalidNodeTypeError: DOM Exception 24
-FAIL **** detached div in current doc: #text node, detached range, type 3 InvalidNodeTypeError: DOM Exception 24
-FAIL ** detached div in current doc: p node, current doc's range, type 1 InvalidNodeTypeError: DOM Exception 24
-FAIL ** detached div in current doc: p node, foreign doc's range, type 1 InvalidNodeTypeError: DOM Exception 24
-FAIL ** detached div in current doc: p node, XML doc's range, type 1 InvalidNodeTypeError: DOM Exception 24
-FAIL ** detached div in current doc: p node, detached range, type 1 InvalidNodeTypeError: DOM Exception 24
-FAIL **** detached div in current doc: #text node, current doc's range, type 3 InvalidNodeTypeError: DOM Exception 24
-FAIL **** detached div in current doc: #text node, foreign doc's range, type 3 InvalidNodeTypeError: DOM Exception 24
-FAIL **** detached div in current doc: #text node, XML doc's range, type 3 InvalidNodeTypeError: DOM Exception 24
-FAIL **** detached div in current doc: #text node, detached range, type 3 InvalidNodeTypeError: DOM Exception 24
</del><ins>+PASS ** detached div in current doc: p node, current doc's range, type 1 
+PASS ** detached div in current doc: p node, foreign doc's range, type 1 
+PASS ** detached div in current doc: p node, XML doc's range, type 1 
+PASS ** detached div in current doc: p node, detached range, type 1 
+PASS **** detached div in current doc: #text node, current doc's range, type 3 
+PASS **** detached div in current doc: #text node, foreign doc's range, type 3 
+PASS **** detached div in current doc: #text node, XML doc's range, type 3 
+PASS **** detached div in current doc: #text node, detached range, type 3 
+PASS ** detached div in current doc: p node, current doc's range, type 1 
+PASS ** detached div in current doc: p node, foreign doc's range, type 1 
+PASS ** detached div in current doc: p node, XML doc's range, type 1 
+PASS ** detached div in current doc: p node, detached range, type 1 
+PASS **** detached div in current doc: #text node, current doc's range, type 3 
+PASS **** detached div in current doc: #text node, foreign doc's range, type 3 
+PASS **** detached div in current doc: #text node, XML doc's range, type 3 
+PASS **** detached div in current doc: #text node, detached range, type 3 
</ins><span class="cx"> PASS  #document node, current doc's range, type 9 
</span><span class="cx"> PASS  #document node, foreign doc's range, type 9 
</span><span class="cx"> PASS  #document node, XML doc's range, type 9 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsdomrangesRangesurroundContentsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-surroundContents-expected.txt (190173 => 190174)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-surroundContents-expected.txt        2015-09-23 16:06:00 UTC (rev 190173)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-surroundContents-expected.txt        2015-09-23 16:21:33 UTC (rev 190174)
</span><span class="lines">@@ -293,14 +293,14 @@
</span><span class="cx"> PASS 5,20: resulting range position for range [paras[1].firstChild, 2, paras[1].firstChild, 9], node doctype 
</span><span class="cx"> PASS 5,21: resulting DOM for range [paras[1].firstChild, 2, paras[1].firstChild, 9], node foreignDoctype 
</span><span class="cx"> PASS 5,21: resulting range position for range [paras[1].firstChild, 2, paras[1].firstChild, 9], node foreignDoctype 
</span><del>-FAIL 6,0: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node paras[0] InvalidNodeTypeError: DOM Exception 24
-FAIL 6,0: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node paras[0] assert_equals: Unexpected startOffset after surroundContents() expected 1 but got 0
</del><ins>+PASS 6,0: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node paras[0] 
+PASS 6,0: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node paras[0] 
</ins><span class="cx"> PASS 6,1: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node paras[0].firstChild 
</span><span class="cx"> FAIL 6,1: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node paras[0].firstChild assert_equals: Unexpected endOffset after surroundContents() expected 2 but got 0
</span><span class="cx"> PASS 6,2: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node paras[1].firstChild 
</span><span class="cx"> FAIL 6,2: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node paras[1].firstChild assert_equals: Unexpected endOffset after surroundContents() expected 2 but got 0
</span><del>-FAIL 6,3: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignPara1 InvalidNodeTypeError: DOM Exception 24
-FAIL 6,3: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignPara1 assert_equals: Unexpected startOffset after surroundContents() expected 1 but got 0
</del><ins>+PASS 6,3: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignPara1 
+PASS 6,3: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignPara1 
</ins><span class="cx"> PASS 6,4: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignPara1.firstChild 
</span><span class="cx"> FAIL 6,4: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignPara1.firstChild assert_equals: Unexpected endOffset after surroundContents() expected 2 but got 0
</span><span class="cx"> FAIL 6,5: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node detachedPara1 assert_true: First differing node: expected Element node &lt;p&gt;Wxyzabcd&lt;/p&gt;, got Text node &quot;Opqrstuv&quot; [Actual and expected mismatch for range's tree root.  ] expected true got false
</span><span class="lines">@@ -313,12 +313,12 @@
</span><span class="cx"> FAIL 6,8: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node detachedDiv assert_unreached: DOMs were not equal but we couldn't figure out why Reached unreachable code
</span><span class="cx"> PASS 6,9: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignDoc 
</span><span class="cx"> PASS 6,9: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignDoc 
</span><del>-FAIL 6,10: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignPara2 InvalidNodeTypeError: DOM Exception 24
-FAIL 6,10: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignPara2 assert_equals: Unexpected startOffset after surroundContents() expected 1 but got 0
</del><ins>+PASS 6,10: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignPara2 
+PASS 6,10: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignPara2 
</ins><span class="cx"> PASS 6,11: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node xmlDoc 
</span><span class="cx"> PASS 6,11: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node xmlDoc 
</span><del>-FAIL 6,12: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node xmlElement InvalidNodeTypeError: DOM Exception 24
-FAIL 6,12: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node xmlElement assert_equals: Unexpected startOffset after surroundContents() expected 1 but got 0
</del><ins>+PASS 6,12: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node xmlElement 
+PASS 6,12: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node xmlElement 
</ins><span class="cx"> PASS 6,13: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node detachedTextNode 
</span><span class="cx"> FAIL 6,13: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node detachedTextNode assert_equals: Unexpected endOffset after surroundContents() expected 2 but got 0
</span><span class="cx"> PASS 6,14: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignTextNode 
</span><span class="lines">@@ -337,14 +337,14 @@
</span><span class="cx"> PASS 6,20: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node doctype 
</span><span class="cx"> PASS 6,21: resulting DOM for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignDoctype 
</span><span class="cx"> PASS 6,21: resulting range position for range [detachedPara1.firstChild, 0, detachedPara1.firstChild, 0], node foreignDoctype 
</span><del>-FAIL 7,0: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node paras[0] InvalidNodeTypeError: DOM Exception 24
-FAIL 7,0: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node paras[0] assert_equals: Unexpected startOffset after surroundContents() expected 1 but got 2
</del><ins>+PASS 7,0: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node paras[0] 
+PASS 7,0: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node paras[0] 
</ins><span class="cx"> PASS 7,1: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node paras[0].firstChild 
</span><span class="cx"> PASS 7,1: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node paras[0].firstChild 
</span><span class="cx"> PASS 7,2: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node paras[1].firstChild 
</span><span class="cx"> PASS 7,2: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node paras[1].firstChild 
</span><del>-FAIL 7,3: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignPara1 InvalidNodeTypeError: DOM Exception 24
-FAIL 7,3: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignPara1 assert_equals: Unexpected startOffset after surroundContents() expected 1 but got 2
</del><ins>+PASS 7,3: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignPara1 
+PASS 7,3: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignPara1 
</ins><span class="cx"> PASS 7,4: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignPara1.firstChild 
</span><span class="cx"> PASS 7,4: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignPara1.firstChild 
</span><span class="cx"> FAIL 7,5: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node detachedPara1 assert_true: First differing node: expected Element node &lt;p&gt;Wxyzabcd&lt;/p&gt;, got Text node &quot;Opqrstuv&quot; [Actual and expected mismatch for range's tree root.  ] expected true got false
</span><span class="lines">@@ -357,12 +357,12 @@
</span><span class="cx"> FAIL 7,8: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node detachedDiv assert_unreached: DOMs were not equal but we couldn't figure out why Reached unreachable code
</span><span class="cx"> PASS 7,9: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignDoc 
</span><span class="cx"> PASS 7,9: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignDoc 
</span><del>-FAIL 7,10: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignPara2 InvalidNodeTypeError: DOM Exception 24
-FAIL 7,10: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignPara2 assert_equals: Unexpected startOffset after surroundContents() expected 1 but got 2
</del><ins>+PASS 7,10: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignPara2 
+PASS 7,10: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignPara2 
</ins><span class="cx"> PASS 7,11: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node xmlDoc 
</span><span class="cx"> PASS 7,11: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node xmlDoc 
</span><del>-FAIL 7,12: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node xmlElement InvalidNodeTypeError: DOM Exception 24
-FAIL 7,12: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node xmlElement assert_equals: Unexpected startOffset after surroundContents() expected 1 but got 2
</del><ins>+PASS 7,12: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node xmlElement 
+PASS 7,12: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node xmlElement 
</ins><span class="cx"> PASS 7,13: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node detachedTextNode 
</span><span class="cx"> PASS 7,13: resulting range position for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node detachedTextNode 
</span><span class="cx"> PASS 7,14: resulting DOM for range [detachedPara1.firstChild, 2, detachedPara1.firstChild, 8], node foreignTextNode 
</span><span class="lines">@@ -781,13 +781,13 @@
</span><span class="cx"> PASS 16,20: resulting range position for range [paras[0], 0, paras[0], 1], node doctype 
</span><span class="cx"> PASS 16,21: resulting DOM for range [paras[0], 0, paras[0], 1], node foreignDoctype 
</span><span class="cx"> PASS 16,21: resulting range position for range [paras[0], 0, paras[0], 1], node foreignDoctype 
</span><del>-FAIL 17,0: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node paras[0] InvalidNodeTypeError: DOM Exception 24
</del><ins>+PASS 17,0: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node paras[0] 
</ins><span class="cx"> PASS 17,0: resulting range position for range [detachedPara1, 0, detachedPara1, 1], node paras[0] 
</span><span class="cx"> PASS 17,1: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node paras[0].firstChild 
</span><span class="cx"> PASS 17,1: resulting range position for range [detachedPara1, 0, detachedPara1, 1], node paras[0].firstChild 
</span><span class="cx"> PASS 17,2: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node paras[1].firstChild 
</span><span class="cx"> PASS 17,2: resulting range position for range [detachedPara1, 0, detachedPara1, 1], node paras[1].firstChild 
</span><del>-FAIL 17,3: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node foreignPara1 InvalidNodeTypeError: DOM Exception 24
</del><ins>+PASS 17,3: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node foreignPara1 
</ins><span class="cx"> PASS 17,3: resulting range position for range [detachedPara1, 0, detachedPara1, 1], node foreignPara1 
</span><span class="cx"> PASS 17,4: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node foreignPara1.firstChild 
</span><span class="cx"> PASS 17,4: resulting range position for range [detachedPara1, 0, detachedPara1, 1], node foreignPara1.firstChild 
</span><span class="lines">@@ -801,11 +801,11 @@
</span><span class="cx"> FAIL 17,8: resulting range position for range [detachedPara1, 0, detachedPara1, 1], node detachedDiv assert_unreached: DOMs were not equal but we couldn't figure out why Reached unreachable code
</span><span class="cx"> PASS 17,9: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node foreignDoc 
</span><span class="cx"> PASS 17,9: resulting range position for range [detachedPara1, 0, detachedPara1, 1], node foreignDoc 
</span><del>-FAIL 17,10: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node foreignPara2 InvalidNodeTypeError: DOM Exception 24
</del><ins>+PASS 17,10: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node foreignPara2 
</ins><span class="cx"> PASS 17,10: resulting range position for range [detachedPara1, 0, detachedPara1, 1], node foreignPara2 
</span><span class="cx"> PASS 17,11: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node xmlDoc 
</span><span class="cx"> PASS 17,11: resulting range position for range [detachedPara1, 0, detachedPara1, 1], node xmlDoc 
</span><del>-FAIL 17,12: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node xmlElement InvalidNodeTypeError: DOM Exception 24
</del><ins>+PASS 17,12: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node xmlElement 
</ins><span class="cx"> PASS 17,12: resulting range position for range [detachedPara1, 0, detachedPara1, 1], node xmlElement 
</span><span class="cx"> PASS 17,13: resulting DOM for range [detachedPara1, 0, detachedPara1, 1], node detachedTextNode 
</span><span class="cx"> PASS 17,13: resulting range position for range [detachedPara1, 0, detachedPara1, 1], node detachedTextNode 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (190173 => 190174)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-09-23 16:06:00 UTC (rev 190173)
+++ trunk/Source/WebCore/ChangeLog        2015-09-23 16:21:33 UTC (rev 190174)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2015-09-23  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Range's setStartBefore() / setStartAfter() / setEndBefore() / setEndAfter() do not match the specification
+        https://bugs.webkit.org/show_bug.cgi?id=149490
+
+        Reviewed by Andreas Kling.
+
+        Range's setStartBefore() / setStartAfter() / setEndBefore() / setEndAfter()
+        behavior do not match the DOM specification:
+        - https://dom.spec.whatwg.org/#dom-range-setstartbefore
+        - https://dom.spec.whatwg.org/#dom-range-setstartafter
+        - https://dom.spec.whatwg.org/#dom-range-setendbefore
+        - https://dom.spec.whatwg.org/#dom-range-setendafter
+
+        In particular, instead of step 2:
+        &quot;If parent is null, throw an InvalidNodeTypeError exception.&quot;
+
+        Our implementation was doing more checks and throwing exceptions in cases
+        that the specification does not say we should. We were calling
+        checkNodeBA() which had restrictions on both the node type and its
+        root type. This is now replaced by a simple null check on the parent,
+        as per the specification.
+
+        Firefox's behavior matches the specification.
+
+        No new tests, already covered by existing tests.
+
+        * dom/Range.cpp:
+        (WebCore::Range::setStartAfter):
+        (WebCore::Range::setEndBefore):
+        (WebCore::Range::setEndAfter):
+        (WebCore::Range::setStartBefore):
+        (WebCore::Range::cloneRange): Deleted.
+        (WebCore::Range::selectNode): Deleted.
+        (WebCore::Range::selectNodeContents): Deleted.
+        (WebCore::Range::absoluteTextRects): Deleted.
+        * dom/Range.h:
+
</ins><span class="cx"> 2015-09-23  Commit Queue  &lt;commit-queue@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r190168.
</span></span></pre></div>
<a id="trunkSourceWebCoredomRangecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Range.cpp (190173 => 190174)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Range.cpp        2015-09-23 16:06:00 UTC (rev 190173)
+++ trunk/Source/WebCore/dom/Range.cpp        2015-09-23 16:21:33 UTC (rev 190174)
</span><span class="lines">@@ -1018,49 +1018,6 @@
</span><span class="cx">     return nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Range::checkNodeBA(Node* n, ExceptionCode&amp; ec) const
-{
-    // INVALID_NODE_TYPE_ERR: Raised if the root container of refNode is not an
-    // Attr, Document, DocumentFragment or ShadowRoot node, or part of a SVG shadow DOM tree,
-    // or if refNode is a Document, DocumentFragment, ShadowRoot, Attr, or Entity node.
-
-    switch (n-&gt;nodeType()) {
-        case Node::ATTRIBUTE_NODE:
-        case Node::DOCUMENT_FRAGMENT_NODE:
-        case Node::DOCUMENT_NODE:
-            ec = INVALID_NODE_TYPE_ERR;
-            return;
-        case Node::CDATA_SECTION_NODE:
-        case Node::COMMENT_NODE:
-        case Node::DOCUMENT_TYPE_NODE:
-        case Node::ELEMENT_NODE:
-        case Node::PROCESSING_INSTRUCTION_NODE:
-        case Node::TEXT_NODE:
-        case Node::XPATH_NAMESPACE_NODE:
-            break;
-    }
-
-    Node* root = n;
-    while (ContainerNode* parent = root-&gt;parentNode())
-        root = parent;
-
-    switch (root-&gt;nodeType()) {
-        case Node::ATTRIBUTE_NODE:
-        case Node::DOCUMENT_NODE:
-        case Node::DOCUMENT_FRAGMENT_NODE:
-            break;
-        case Node::CDATA_SECTION_NODE:
-        case Node::COMMENT_NODE:
-        case Node::DOCUMENT_TYPE_NODE:
-        case Node::ELEMENT_NODE:
-        case Node::PROCESSING_INSTRUCTION_NODE:
-        case Node::TEXT_NODE:
-        case Node::XPATH_NAMESPACE_NODE:
-            ec = INVALID_NODE_TYPE_ERR;
-            return;
-    }
-}
-
</del><span class="cx"> Ref&lt;Range&gt; Range::cloneRange() const
</span><span class="cx"> {
</span><span class="cx">     return Range::create(ownerDocument(), &amp;startContainer(), m_start.offset(), &amp;endContainer(), m_end.offset());
</span><span class="lines">@@ -1073,10 +1030,10 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    ec = 0;
-    checkNodeBA(refNode, ec);
-    if (ec)
</del><ins>+    if (!refNode-&gt;parentNode()) {
+        ec = INVALID_NODE_TYPE_ERR;
</ins><span class="cx">         return;
</span><ins>+    }
</ins><span class="cx"> 
</span><span class="cx">     setStart(refNode-&gt;parentNode(), refNode-&gt;computeNodeIndex() + 1, ec);
</span><span class="cx"> }
</span><span class="lines">@@ -1088,10 +1045,10 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    ec = 0;
-    checkNodeBA(refNode, ec);
-    if (ec)
</del><ins>+    if (!refNode-&gt;parentNode()) {
+        ec = INVALID_NODE_TYPE_ERR;
</ins><span class="cx">         return;
</span><ins>+    }
</ins><span class="cx"> 
</span><span class="cx">     setEnd(refNode-&gt;parentNode(), refNode-&gt;computeNodeIndex(), ec);
</span><span class="cx"> }
</span><span class="lines">@@ -1103,10 +1060,10 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    ec = 0;
-    checkNodeBA(refNode, ec);
-    if (ec)
</del><ins>+    if (!refNode-&gt;parentNode()) {
+        ec = INVALID_NODE_TYPE_ERR;
</ins><span class="cx">         return;
</span><ins>+    }
</ins><span class="cx"> 
</span><span class="cx">     setEnd(refNode-&gt;parentNode(), refNode-&gt;computeNodeIndex() + 1, ec);
</span><span class="cx"> }
</span><span class="lines">@@ -1265,10 +1222,10 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    ec = 0;
-    checkNodeBA(refNode, ec);
-    if (ec)
</del><ins>+    if (!refNode-&gt;parentNode()) {
+        ec = INVALID_NODE_TYPE_ERR;
</ins><span class="cx">         return;
</span><ins>+    }
</ins><span class="cx"> 
</span><span class="cx">     setStart(refNode-&gt;parentNode(), refNode-&gt;computeNodeIndex(), ec);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoredomRangeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Range.h (190173 => 190174)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Range.h        2015-09-23 16:06:00 UTC (rev 190173)
+++ trunk/Source/WebCore/dom/Range.h        2015-09-23 16:21:33 UTC (rev 190174)
</span><span class="lines">@@ -160,7 +160,6 @@
</span><span class="cx">     void setDocument(Document&amp;);
</span><span class="cx"> 
</span><span class="cx">     Node* checkNodeWOffset(Node*, int offset, ExceptionCode&amp;) const;
</span><del>-    void checkNodeBA(Node*, ExceptionCode&amp;) const;
</del><span class="cx"> 
</span><span class="cx">     enum ActionType { Delete, Extract, Clone };
</span><span class="cx">     RefPtr&lt;DocumentFragment&gt; processContents(ActionType, ExceptionCode&amp;);
</span></span></pre>
</div>
</div>

</body>
</html>