<!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>[206332] 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/206332">206332</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2016-09-23 14:46:27 -0700 (Fri, 23 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Align HTMLLabelElement.prototype.form with the HTML specification
https://bugs.webkit.org/show_bug.cgi?id=162369

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline several W3C tests now that more checks are passing.

* web-platform-tests/html/semantics/forms/form-control-infrastructure/form-expected.txt:
* web-platform-tests/html/semantics/forms/the-label-element/label-attributes-expected.txt:

Source/WebCore:

Align HTMLLabelElement.prototype.form with the HTML specification:
- https://html.spec.whatwg.org/#dom-label-form

In particular, the following behavior changes:
- We now return null if the label element has no labeled control.
- We now return the form element instead of returning null if
  the label element is outside the form but its labeled control
  is inside the form.

Firefox and Chrome match the specification.

No new tests, rebaselined existing tests.

* html/HTMLLabelElement.cpp:
(WebCore::HTMLLabelElement::form):
* html/HTMLLabelElement.h:

LayoutTests:

Update existing tests to reflect behavior change. I have verified
that Firefox and Chrome were failing those tests.

* fast/dom/HTMLLabelElement/form/test1.html:
* fast/forms/form-attribute-expected.txt:
* fast/forms/form-attribute-nonexistence-form-id-expected.txt:
* fast/forms/form-attribute-nonexistence-form-id.html:
* fast/forms/form-attribute.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastdomHTMLLabelElementformtest1html">trunk/LayoutTests/fast/dom/HTMLLabelElement/form/test1.html</a></li>
<li><a href="#trunkLayoutTestsfastformsformattributeexpectedtxt">trunk/LayoutTests/fast/forms/form-attribute-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastformsformattributenonexistenceformidexpectedtxt">trunk/LayoutTests/fast/forms/form-attribute-nonexistence-form-id-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastformsformattributenonexistenceformidhtml">trunk/LayoutTests/fast/forms/form-attribute-nonexistence-form-id.html</a></li>
<li><a href="#trunkLayoutTestsfastformsformattributehtml">trunk/LayoutTests/fast/forms/form-attribute.html</a></li>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestshtmlsemanticsformsformcontrolinfrastructureformexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-control-infrastructure/form-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestshtmlsemanticsformsthelabelelementlabelattributesexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-label-element/label-attributes-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformiossimulatorimportedw3cwebplatformtestshtmlsemanticsformsformcontrolinfrastructureformexpectedtxt">trunk/LayoutTests/platform/ios-simulator/imported/w3c/web-platform-tests/html/semantics/forms/form-control-infrastructure/form-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLLabelElementcpp">trunk/Source/WebCore/html/HTMLLabelElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLLabelElementh">trunk/Source/WebCore/html/HTMLLabelElement.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/LayoutTests/ChangeLog        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2016-09-23  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Align HTMLLabelElement.prototype.form with the HTML specification
+        https://bugs.webkit.org/show_bug.cgi?id=162369
+
+        Reviewed by Ryosuke Niwa.
+
+        Update existing tests to reflect behavior change. I have verified
+        that Firefox and Chrome were failing those tests.
+
+        * fast/dom/HTMLLabelElement/form/test1.html:
+        * fast/forms/form-attribute-expected.txt:
+        * fast/forms/form-attribute-nonexistence-form-id-expected.txt:
+        * fast/forms/form-attribute-nonexistence-form-id.html:
+        * fast/forms/form-attribute.html:
+
</ins><span class="cx"> 2016-09-23  Ryan Haddad  &lt;ryanhaddad@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Temporarily skipping media/media-source/media-source-duplicate-seeked.html on mac.
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomHTMLLabelElementformtest1html"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/HTMLLabelElement/form/test1.html (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/HTMLLabelElement/form/test1.html        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/LayoutTests/fast/dom/HTMLLabelElement/form/test1.html        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -17,7 +17,7 @@
</span><span class="cx">         
</span><span class="cx">             form = document.getElementById(&quot;form&quot;);
</span><span class="cx">             
</span><del>-            if(labelInsideForm.form == form)
</del><ins>+            if(labelInsideForm.form == null)
</ins><span class="cx">                 print(&quot;Passed&quot;);
</span><span class="cx">             else
</span><span class="cx">                 print(&quot;Failed&quot;);
</span></span></pre></div>
<a id="trunkLayoutTestsfastformsformattributeexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/forms/form-attribute-expected.txt (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/forms/form-attribute-expected.txt        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/LayoutTests/fast/forms/form-attribute-expected.txt        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -8,7 +8,7 @@
</span><span class="cx"> PASS document.getElementsByTagName(&quot;fieldset&quot;)[0].form is owner
</span><span class="cx"> PASS document.getElementsByTagName(&quot;input&quot;)[0].form is owner
</span><span class="cx"> PASS document.getElementsByTagName(&quot;keygen&quot;)[0].form is owner
</span><del>-PASS document.getElementsByTagName(&quot;label&quot;)[0].form is owner
</del><ins>+PASS document.getElementsByTagName(&quot;label&quot;)[0].form is null
</ins><span class="cx"> PASS document.getElementsByTagName(&quot;object&quot;)[0].form is owner
</span><span class="cx"> PASS document.getElementsByTagName(&quot;output&quot;)[0].form is owner
</span><span class="cx"> PASS document.getElementsByTagName(&quot;select&quot;)[0].form is owner
</span><span class="lines">@@ -22,9 +22,9 @@
</span><span class="cx"> PASS inputElement1.form is owner
</span><span class="cx"> PASS inputElement2.form is owner
</span><span class="cx"> PASS inputElement3.form is owner
</span><del>-PASS labelElement1.form is owner
-PASS labelElement2.form is owner
-PASS labelElement3.form is owner
</del><ins>+PASS labelElement1.form is null
+PASS labelElement2.form is null
+PASS labelElement3.form is null
</ins><span class="cx"> 
</span><span class="cx"> - Ensures that the form attribute points the form owner even if the form element is nested another form element.
</span><span class="cx"> NOTE: It seems that nesting form elements is not allowed so we ensure each form-associated elements associate with the outmost form element.
</span><span class="lines">@@ -31,15 +31,13 @@
</span><span class="cx"> PASS inputElement1.form is owner
</span><span class="cx"> PASS inputElement2.form is owner
</span><span class="cx"> PASS inputElement3.form is owner
</span><del>-PASS labelElement1.form is owner
-PASS labelElement2.form is owner
-PASS labelElement3.form is owner
</del><ins>+PASS labelElement1.form is null
+PASS labelElement2.form is null
+PASS labelElement3.form is null
</ins><span class="cx"> 
</span><span class="cx"> - Ensures whether the form owner is set correctly when the value of form attribute of a form-associated element changed.
</span><span class="cx"> PASS inputElement.form is form1
</span><span class="cx"> PASS inputElement.form is form2
</span><del>-PASS labelElement.form is form1
-PASS labelElement.form is form2
</del><span class="cx"> PASS objectElement.form is form1
</span><span class="cx"> PASS objectElement.form is form2
</span><span class="cx"> 
</span><span class="lines">@@ -47,9 +45,6 @@
</span><span class="cx"> PASS inputElement.form is null
</span><span class="cx"> PASS inputElement.form is owner
</span><span class="cx"> PASS inputElement.form is null
</span><del>-PASS labelElement.form is null
-PASS labelElement.form is owner
-PASS labelElement.form is null
</del><span class="cx"> PASS objectElement.form is null
</span><span class="cx"> PASS objectElement.form is owner
</span><span class="cx"> PASS objectElement.form is null
</span><span class="lines">@@ -58,11 +53,8 @@
</span><span class="cx"> PASS owner.name is &quot;firstOwner&quot;
</span><span class="cx"> PASS owner.name is &quot;secondOwner&quot;
</span><span class="cx"> PASS inputElement.form is owner
</span><del>-PASS labelElement.form is owner
</del><span class="cx"> PASS inputElement.form is null
</span><del>-PASS labelElement.form is null
</del><span class="cx"> PASS inputElement.form is owner
</span><del>-PASS labelElement.form is owner
</del><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsfastformsformattributenonexistenceformidexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/forms/form-attribute-nonexistence-form-id-expected.txt (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/forms/form-attribute-nonexistence-form-id-expected.txt        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/LayoutTests/fast/forms/form-attribute-nonexistence-form-id-expected.txt        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -6,8 +6,8 @@
</span><span class="cx"> label1 label2
</span><span class="cx"> PASS inputShouldHaveForm.form is form
</span><span class="cx"> PASS inputShouldNotHaveForm.form is null
</span><del>-PASS labelShouldHaveForm.form is form
-PASS labelShouldNotHaveForm.form is null
</del><ins>+PASS labelWithoutForm.form is null
+PASS labelWithInvalidForm.form is null
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsfastformsformattributenonexistenceformidhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/forms/form-attribute-nonexistence-form-id.html (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/forms/form-attribute-nonexistence-form-id.html        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/LayoutTests/fast/forms/form-attribute-nonexistence-form-id.html        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -18,12 +18,12 @@
</span><span class="cx"> var form = document.getElementById('form');
</span><span class="cx"> var inputShouldHaveForm = document.getElementById('input1');
</span><span class="cx"> var inputShouldNotHaveForm = document.getElementById('input2');
</span><del>-var labelShouldHaveForm = document.getElementById('label1');
-var labelShouldNotHaveForm = document.getElementById('label2');
</del><ins>+var labelWithoutForm = document.getElementById('label1');
+var labelWithInvalidForm = document.getElementById('label2');
</ins><span class="cx"> shouldBe('inputShouldHaveForm.form', 'form');
</span><span class="cx"> shouldBeNull('inputShouldNotHaveForm.form');
</span><del>-shouldBe('labelShouldHaveForm.form', 'form');
-shouldBeNull('labelShouldNotHaveForm.form');
</del><ins>+shouldBeNull('labelWithoutForm.form');
+shouldBeNull('labelWithInvalidForm.form');
</ins><span class="cx"> &lt;/script&gt;
</span><span class="cx"> &lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
</span><span class="cx"> &lt;/body&gt;
</span></span></pre></div>
<a id="trunkLayoutTestsfastformsformattributehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/forms/form-attribute.html (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/forms/form-attribute.html        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/LayoutTests/fast/forms/form-attribute.html        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -18,7 +18,7 @@
</span><span class="cx">     '&lt;fieldset name=victim form=owner /&gt;' +
</span><span class="cx">     '&lt;input name=victim form=owner /&gt;' +
</span><span class="cx">     '&lt;keygen name=victim form=owner /&gt;' +
</span><del>-    '&lt;label name=victim form=owner /&gt;' +
</del><ins>+    '&lt;label name=victim form=owner&gt;&lt;/label&gt;' +
</ins><span class="cx">     '&lt;object name=victim form=owner&gt;&lt;/object&gt;' +
</span><span class="cx">     '&lt;output name=victim form=owner /&gt;' +
</span><span class="cx">     '&lt;select name=victim form=owner /&gt;' +
</span><span class="lines">@@ -29,7 +29,7 @@
</span><span class="cx"> shouldBe('document.getElementsByTagName(&quot;fieldset&quot;)[0].form', 'owner');
</span><span class="cx"> shouldBe('document.getElementsByTagName(&quot;input&quot;)[0].form', 'owner');
</span><span class="cx"> shouldBe('document.getElementsByTagName(&quot;keygen&quot;)[0].form', 'owner');
</span><del>-shouldBe('document.getElementsByTagName(&quot;label&quot;)[0].form', 'owner');
</del><ins>+shouldBeNull('document.getElementsByTagName(&quot;label&quot;)[0].form');
</ins><span class="cx"> shouldBe('document.getElementsByTagName(&quot;object&quot;)[0].form', 'owner');
</span><span class="cx"> shouldBe('document.getElementsByTagName(&quot;output&quot;)[0].form', 'owner');
</span><span class="cx"> shouldBe('document.getElementsByTagName(&quot;select&quot;)[0].form', 'owner');
</span><span class="lines">@@ -40,7 +40,7 @@
</span><span class="cx"> container.innerHTML = '&lt;form id=owner&gt;&lt;/form&gt;' +
</span><span class="cx">     '&lt;form id=shouldNotBeOwner&gt;' +
</span><span class="cx">     '    &lt;input id=inputElement name=victim form=owner /&gt;' +
</span><del>-    '    &lt;label id=labelElement name=victim form=owner /&gt;' +
</del><ins>+    '    &lt;label id=labelElement name=victim for=inputElement /&gt;' +
</ins><span class="cx">     '&lt;/form&gt;';
</span><span class="cx"> owner = document.getElementById('owner');
</span><span class="cx"> var inputElement = document.getElementById('inputElement');
</span><span class="lines">@@ -69,9 +69,9 @@
</span><span class="cx"> shouldBe('inputElement1.form', 'owner');
</span><span class="cx"> shouldBe('inputElement2.form', 'owner');
</span><span class="cx"> shouldBe('inputElement3.form', 'owner');
</span><del>-shouldBe('labelElement1.form', 'owner');
-shouldBe('labelElement2.form', 'owner');
-shouldBe('labelElement3.form', 'owner');
</del><ins>+shouldBeNull('labelElement1.form');
+shouldBeNull('labelElement2.form');
+shouldBeNull('labelElement3.form');
</ins><span class="cx"> 
</span><span class="cx"> debug('');
</span><span class="cx"> debug('- Ensures that the form attribute points the form owner even if the form element is nested another form element.');
</span><span class="lines">@@ -96,9 +96,9 @@
</span><span class="cx"> shouldBe('inputElement1.form', 'owner');
</span><span class="cx"> shouldBe('inputElement2.form', 'owner');
</span><span class="cx"> shouldBe('inputElement3.form', 'owner');
</span><del>-shouldBe('labelElement1.form', 'owner');
-shouldBe('labelElement2.form', 'owner');
-shouldBe('labelElement3.form', 'owner');
</del><ins>+shouldBeNull('labelElement1.form');
+shouldBeNull('labelElement2.form');
+shouldBeNull('labelElement3.form');
</ins><span class="cx"> 
</span><span class="cx"> debug('');
</span><span class="cx"> debug('- Ensures whether the form owner is set correctly when the value of form attribute of a form-associated element changed.');
</span><span class="lines">@@ -105,7 +105,6 @@
</span><span class="cx"> container.innerHTML = '&lt;form id=form1&gt;&lt;/form&gt;' +
</span><span class="cx">     '&lt;form id=form2&gt;&lt;/form&gt;' +
</span><span class="cx">     '&lt;input id=inputElement name=victim form=form1 /&gt;' +
</span><del>-    '&lt;label id=labelElement name=victim form=form1 /&gt;' +
</del><span class="cx">     '&lt;object id=objectElement name=victim form=form1&gt;&lt;/object&gt;';
</span><span class="cx"> var form1 = document.getElementById('form1');
</span><span class="cx"> var form2 = document.getElementById('form2');
</span><span class="lines">@@ -114,12 +113,6 @@
</span><span class="cx"> inputElement.attributes['form'].value = 'form2';
</span><span class="cx"> shouldBe('inputElement.form', 'form2');
</span><span class="cx"> 
</span><del>-// HTMLabelElement has its own implementation of formAttr processing and so needs its own test.
-labelElement = document.getElementById('labelElement');
-shouldBe('labelElement.form', 'form1');
-labelElement.attributes['form'].value = 'form2';
-shouldBe('labelElement.form', 'form2');
-
</del><span class="cx"> // HTMLObjectElement has its own implementation of formAttr processing and so needs its own test.
</span><span class="cx"> objectElement = document.getElementById('objectElement');
</span><span class="cx"> shouldBe('objectElement.form', 'form1');
</span><span class="lines">@@ -130,7 +123,6 @@
</span><span class="cx"> debug('- Ensures whether the form owner is set correctly when the value of form attribute is added/removed.');
</span><span class="cx"> container.innerHTML = '&lt;form id=owner name=firstOwner&gt;&lt;/form&gt;' +
</span><span class="cx">     '&lt;input id=inputElement name=victim /&gt;' +
</span><del>-    '&lt;label id=labelElement name=victim /&gt;' +
</del><span class="cx">     '&lt;object id=objectElement name=victim&gt;&lt;/object&gt;';
</span><span class="cx"> owner = document.getElementById('owner');
</span><span class="cx"> inputElement = document.getElementById('inputElement');
</span><span class="lines">@@ -141,14 +133,6 @@
</span><span class="cx"> inputElement.removeAttribute('form');
</span><span class="cx"> shouldBe('inputElement.form', 'null');
</span><span class="cx"> 
</span><del>-// HTMLLabelElement has its own implementation of formAttr processing and so needs its own test.
-labelElement = document.getElementById('labelElement');
-shouldBe('labelElement.form', 'null');
-labelElement.setAttribute('form', 'owner');
-shouldBe('labelElement.form', 'owner');
-labelElement.removeAttribute('form');
-shouldBe('labelElement.form', 'null');
-
</del><span class="cx"> // HTMLObjectElement has its own implementation of formAttr processing and so needs its own test.
</span><span class="cx"> objectElement = document.getElementById('objectElement');
</span><span class="cx"> shouldBe('objectElement.form', 'null');
</span><span class="lines">@@ -161,23 +145,18 @@
</span><span class="cx"> debug('- Ensures whether the form owner is set correctly when the form owner is added/removed.');
</span><span class="cx"> container.innerHTML = '&lt;form id=owner name=firstOwner&gt;&lt;/form&gt;' +
</span><span class="cx">     '&lt;form id=owner name=secondOwner&gt;&lt;/form&gt;' +
</span><del>-    '&lt;input id=inputElement name=victim form=owner /&gt;' +
-    '&lt;label id=labelElement name=victim form=owner /&gt;';
</del><ins>+    '&lt;input id=inputElement name=victim form=owner /&gt;';
</ins><span class="cx"> owner = document.getElementById('owner');
</span><span class="cx"> shouldBeEqualToString('owner.name', 'firstOwner');
</span><span class="cx"> inputElement = document.getElementById('inputElement');
</span><del>-labelElement = document.getElementById('labelElement');
</del><span class="cx"> container.removeChild(owner);
</span><span class="cx"> owner = document.getElementById('owner');
</span><span class="cx"> shouldBeEqualToString('owner.name', 'secondOwner');
</span><span class="cx"> shouldBe('inputElement.form', 'owner');
</span><del>-shouldBe('labelElement.form', 'owner');
</del><span class="cx"> container.removeChild(owner);
</span><span class="cx"> shouldBe('inputElement.form', 'null');
</span><del>-shouldBe('labelElement.form', 'null');
</del><span class="cx"> container.appendChild(owner);
</span><span class="cx"> shouldBe('inputElement.form', 'owner');
</span><del>-shouldBe('labelElement.form', 'owner');
</del><span class="cx"> &lt;/script&gt;
</span><span class="cx"> &lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
</span><span class="cx"> &lt;/body&gt;
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/LayoutTests/imported/w3c/ChangeLog        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -1,5 +1,17 @@
</span><span class="cx"> 2016-09-23  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Align HTMLLabelElement.prototype.form with the HTML specification
+        https://bugs.webkit.org/show_bug.cgi?id=162369
+
+        Reviewed by Ryosuke Niwa.
+
+        Rebaseline several W3C tests now that more checks are passing.
+
+        * web-platform-tests/html/semantics/forms/form-control-infrastructure/form-expected.txt:
+        * web-platform-tests/html/semantics/forms/the-label-element/label-attributes-expected.txt:
+
+2016-09-23  Chris Dumez  &lt;cdumez@apple.com&gt;
+
</ins><span class="cx">         document.title getter does not strip / collapse the right whitespace characters
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=162468
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestshtmlsemanticsformsformcontrolinfrastructureformexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-control-infrastructure/form-expected.txt (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-control-infrastructure/form-expected.txt        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-control-infrastructure/form-expected.txt        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -7,24 +7,18 @@
</span><span class="cx"> PASS output.form 
</span><span class="cx"> PASS select.form 
</span><span class="cx"> PASS textarea.form 
</span><del>-FAIL label.form assert_equals: label.form expected null but got Element node &lt;form id=&quot;form&quot;&gt;
-&lt;p&gt;&lt;button id=&quot;button&quot;&gt;button&lt;/button&gt;
-&lt;...
-FAIL label-form.form assert_equals: label.form expected null but got Element node &lt;form id=&quot;form&quot;&gt;
-&lt;p&gt;&lt;button id=&quot;button&quot;&gt;button&lt;/button&gt;
-&lt;...
-FAIL label-form-form2.form assert_equals: label.form expected null but got Element node &lt;form id=&quot;form2&quot;&gt;&lt;/form&gt;
</del><ins>+PASS label.form 
+PASS label-form.form 
+PASS label-form-form2.form 
</ins><span class="cx"> PASS label-with-control.form 
</span><span class="cx"> PASS label-for.form 
</span><span class="cx"> FAIL label-with-progress.form assert_equals: Sanity check: label.control.form expected (object) null but got (undefined) undefined
</span><span class="cx"> FAIL label-with-meter.form assert_equals: Sanity check: label.control.form expected (object) null but got (undefined) undefined
</span><del>-FAIL label-for-control-form-in-form.form assert_equals: label.form expected Element node &lt;form id=&quot;form2&quot;&gt;&lt;/form&gt; but got Element node &lt;form id=&quot;form&quot;&gt;
-&lt;p&gt;&lt;button id=&quot;button&quot;&gt;button&lt;/button&gt;
-&lt;...
-FAIL label-for-control-form.form assert_equals: label.form expected Element node &lt;form id=&quot;form2&quot;&gt;&lt;/form&gt; but got null
</del><ins>+PASS label-for-control-form-in-form.form 
+PASS label-for-control-form.form 
</ins><span class="cx"> PASS label-in-table.form 
</span><del>-FAIL label-in-table-with-control.form assert_equals: label.form expected Element node &lt;form id=&quot;form3&quot;&gt;&lt;/form&gt; but got null
-FAIL label-in-table-for.form assert_equals: label.form expected Element node &lt;form id=&quot;form3&quot;&gt;&lt;/form&gt; but got null
</del><ins>+PASS label-in-table-with-control.form 
+PASS label-in-table-for.form 
</ins><span class="cx"> button
</span><span class="cx"> 
</span><span class="cx"> fieldset
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestshtmlsemanticsformsthelabelelementlabelattributesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-label-element/label-attributes-expected.txt (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-label-element/label-attributes-expected.txt        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-label-element/label-attributes-expected.txt        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -9,9 +9,7 @@
</span><span class="cx"> PASS A form control has an implicit label. 
</span><span class="cx"> PASS A form control has no label 1. 
</span><span class="cx"> PASS A form control has no label 2. 
</span><del>-FAIL A label in a form without a control assert_equals: The 'form' property for a label should return null if label.control is null. expected null but got Element node &lt;form id=&quot;fm&quot; style=&quot;display:none&quot;&gt;
-  &lt;label id=&quot;lbl0&quot; fo...
-FAIL A label outside a form with a control inside the form assert_equals: The 'form' property for a label should return label.control.form. expected Element node &lt;form id=&quot;fm&quot; style=&quot;display:none&quot;&gt;
-  &lt;label id=&quot;lbl0&quot; fo... but got null
</del><ins>+PASS A label in a form without a control 
+PASS A label outside a form with a control inside the form 
</ins><span class="cx"> PASS A label's htmlFor attribute must reflect the for content attribute 
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsplatformiossimulatorimportedw3cwebplatformtestshtmlsemanticsformsformcontrolinfrastructureformexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/ios-simulator/imported/w3c/web-platform-tests/html/semantics/forms/form-control-infrastructure/form-expected.txt (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/ios-simulator/imported/w3c/web-platform-tests/html/semantics/forms/form-control-infrastructure/form-expected.txt        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/LayoutTests/platform/ios-simulator/imported/w3c/web-platform-tests/html/semantics/forms/form-control-infrastructure/form-expected.txt        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -7,24 +7,18 @@
</span><span class="cx"> PASS output.form 
</span><span class="cx"> PASS select.form 
</span><span class="cx"> PASS textarea.form 
</span><del>-FAIL label.form assert_equals: label.form expected null but got Element node &lt;form id=&quot;form&quot;&gt;
-&lt;p&gt;&lt;button id=&quot;button&quot;&gt;button&lt;/button&gt;
-&lt;...
-FAIL label-form.form assert_equals: label.form expected null but got Element node &lt;form id=&quot;form&quot;&gt;
-&lt;p&gt;&lt;button id=&quot;button&quot;&gt;button&lt;/button&gt;
-&lt;...
-FAIL label-form-form2.form assert_equals: label.form expected null but got Element node &lt;form id=&quot;form2&quot;&gt;&lt;/form&gt;
</del><ins>+PASS label.form 
+PASS label-form.form 
+PASS label-form-form2.form 
</ins><span class="cx"> PASS label-with-control.form 
</span><span class="cx"> PASS label-for.form 
</span><span class="cx"> FAIL label-with-progress.form assert_equals: Sanity check: label.control.form expected (object) null but got (undefined) undefined
</span><span class="cx"> FAIL label-with-meter.form assert_equals: Sanity check: label.control.form expected (object) null but got (undefined) undefined
</span><del>-FAIL label-for-control-form-in-form.form assert_equals: label.form expected Element node &lt;form id=&quot;form2&quot;&gt;&lt;/form&gt; but got Element node &lt;form id=&quot;form&quot;&gt;
-&lt;p&gt;&lt;button id=&quot;button&quot;&gt;button&lt;/button&gt;
-&lt;...
-FAIL label-for-control-form.form assert_equals: label.form expected Element node &lt;form id=&quot;form2&quot;&gt;&lt;/form&gt; but got null
</del><ins>+PASS label-for-control-form-in-form.form 
+PASS label-for-control-form.form 
</ins><span class="cx"> PASS label-in-table.form 
</span><del>-FAIL label-in-table-with-control.form assert_equals: label.form expected Element node &lt;form id=&quot;form3&quot;&gt;&lt;/form&gt; but got null
-FAIL label-in-table-for.form assert_equals: label.form expected Element node &lt;form id=&quot;form3&quot;&gt;&lt;/form&gt; but got null
</del><ins>+PASS label-in-table-with-control.form 
+PASS label-in-table-for.form 
</ins><span class="cx"> button
</span><span class="cx"> 
</span><span class="cx"> fieldset
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/Source/WebCore/ChangeLog        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-09-23  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Align HTMLLabelElement.prototype.form with the HTML specification
+        https://bugs.webkit.org/show_bug.cgi?id=162369
+
+        Reviewed by Ryosuke Niwa.
+
+        Align HTMLLabelElement.prototype.form with the HTML specification:
+        - https://html.spec.whatwg.org/#dom-label-form
+
+        In particular, the following behavior changes:
+        - We now return null if the label element has no labeled control.
+        - We now return the form element instead of returning null if
+          the label element is outside the form but its labeled control
+          is inside the form.
+
+        Firefox and Chrome match the specification.
+
+        No new tests, rebaselined existing tests.
+
+        * html/HTMLLabelElement.cpp:
+        (WebCore::HTMLLabelElement::form):
+        * html/HTMLLabelElement.h:
+
</ins><span class="cx"> 2016-09-23  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Refactor URLParser
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLLabelElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLLabelElement.cpp (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLLabelElement.cpp        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/Source/WebCore/html/HTMLLabelElement.cpp        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> #include &quot;Event.h&quot;
</span><span class="cx"> #include &quot;EventNames.h&quot;
</span><span class="cx"> #include &quot;FormAssociatedElement.h&quot;
</span><ins>+#include &quot;HTMLFormControlElement.h&quot;
</ins><span class="cx"> #include &quot;HTMLNames.h&quot;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -79,9 +80,13 @@
</span><span class="cx">     return inDocument() ? firstElementWithIdIfLabelable(treeScope(), controlId) : nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-HTMLFormElement* HTMLLabelElement::form() const
</del><ins>+HTMLFormElement* HTMLLabelElement::form()
</ins><span class="cx"> {
</span><del>-    return FormAssociatedElement::findAssociatedForm(this, 0);
</del><ins>+    auto* labeledControl = control();
+    if (!labeledControl)
+        return nullptr;
+
+    return is&lt;HTMLFormControlElement&gt;(*labeledControl) ? downcast&lt;HTMLFormControlElement&gt;(*labeledControl).form() : nullptr;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLLabelElement::setActive(bool down, bool pause)
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLLabelElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLLabelElement.h (206331 => 206332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLLabelElement.h        2016-09-23 21:20:19 UTC (rev 206331)
+++ trunk/Source/WebCore/html/HTMLLabelElement.h        2016-09-23 21:46:27 UTC (rev 206332)
</span><span class="lines">@@ -32,7 +32,7 @@
</span><span class="cx">     static Ref&lt;HTMLLabelElement&gt; create(const QualifiedName&amp;, Document&amp;);
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT LabelableElement* control();
</span><del>-    WEBCORE_EXPORT HTMLFormElement* form() const;
</del><ins>+    WEBCORE_EXPORT HTMLFormElement* form();
</ins><span class="cx"> 
</span><span class="cx">     bool willRespondToMouseClickEvents() final;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>