Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge r183436 - Form control may be associated with the wrong HTML Fo…
…rm element after form id change https://bugs.webkit.org/show_bug.cgi?id=133456 <rdar://problem/17095055> Reviewed by Andy Estes. Source/WebCore: Fixes an issue where a form control may be associated with the wrong HTML Form element after the id of the HTML Form element associated with the form control is changed when there is more than one HTML Form element with the same id in the document. Specifically, a form control that has an HTML form attribute value X will always be associated with some HTML Form element f where f.id = X regardless of whether f.id is subsequently changed. Tests: fast/forms/change-form-id-to-be-unique-then-submit-form.html fast/forms/change-form-id-to-be-unique.html * dom/Element.cpp: (WebCore::Element::attributeChanged): Notify observers when the id of an element changed. (WebCore::Element::updateId): Added parameter NotifyObservers (defaults to NotifyObservers::Yes), as to whether we should notify observers of the id change. (WebCore::Element::updateIdForTreeScope): Ditto. (WebCore::Element::willModifyAttribute): Do not notify observers of the id change immediately. As indicated by the name of this method, we plan to modify the DOM attribute id of the element, but we have not actually modified it when this method is called. Instead we will notify observers in Element::attributeChanged(), which is called after the DOM attribute id is modified. (WebCore::Element::cloneAttributesFromElement): Ditto. * dom/Element.h: Defined enum class NotifyObservers. * dom/TreeScope.cpp: (WebCore::TreeScope::addElementById): Added boolean parameter notifyObservers (defaults to true) as to whether we should dispatch a notification to all observers. (WebCore::TreeScope::removeElementById): Ditto. * dom/TreeScope.h: LayoutTests: Add tests to ensure that we associate the correct HTML Form element with a <select> after changing the id of its associated HTML form element. * fast/forms/change-form-id-to-be-unique-expected.txt: Added. * fast/forms/change-form-id-to-be-unique-then-submit-form-expected.txt: Added. * fast/forms/change-form-id-to-be-unique-then-submit-form.html: Added. * fast/forms/change-form-id-to-be-unique.html: Added.
- Loading branch information
1 parent
80b7d6c
commit 8431ec4
Showing
10 changed files
with
148 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
LayoutTests/fast/forms/change-form-id-to-be-unique-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PASS did not cause an assertion failure. |
4 changes: 4 additions & 0 deletions
4
LayoutTests/fast/forms/change-form-id-to-be-unique-then-submit-form-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This tests that we submit the form element associated with id "a" after changing the id of one of the <form id="a">s in a document that contains two such HTML Form elements. | ||
|
||
PASS submitted second <form>. | ||
|
45 changes: 45 additions & 0 deletions
45
LayoutTests/fast/forms/change-form-id-to-be-unique-then-submit-form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style> | ||
#test-container { visibility: hidden; } | ||
</style> | ||
<script> | ||
if (window.testRunner) { | ||
testRunner.dumpAsText(); | ||
testRunner.waitUntilDone(); | ||
} | ||
|
||
function logMessageAndDone(message) | ||
{ | ||
document.getElementById("console").textContent = message; | ||
if (window.testRunner) | ||
testRunner.notifyDone(); | ||
} | ||
|
||
function runTest() | ||
{ | ||
var search = document.location.search; | ||
if (search === "?submitted=secondFormElement") | ||
logMessageAndDone("PASS submitted second <form>."); | ||
else if (search === "?submitted=firstFormElement") | ||
logMessageAndDone("FAIL should have submitted second <form>, but submitted first <form>."); | ||
else { | ||
document.getElementById("a").id = "y"; // Changes the id of the first <form> (traversing the DOM from top-to-bottom). | ||
document.getElementById("submit").click(); | ||
} | ||
} | ||
|
||
window.onload = runTest; | ||
</script> | ||
</head> | ||
<body> | ||
<p>This tests that we submit the form element associated with id "a" after changing the id of one of the <form id="a">s in a document that contains two such HTML Form elements.</p> | ||
<div id="console"></div> | ||
<div id="test-container"> | ||
<form id="a"><input type="hidden" name="submitted" value="firstFormElement"></form> | ||
<form id="a"><input type="hidden" name="submitted" value="secondFormElement"></form> | ||
<input id="submit" type="submit" form="a" value="Submit"> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script> | ||
if (window.testRunner) | ||
testRunner.dumpAsText(); | ||
</script> | ||
</head> | ||
<body onload="document.body.removeChild(document.getElementById('x'));"> | ||
<p>PASS did not cause an assertion failure.</p> | ||
<div id="x"> | ||
<form id="a"></form> | ||
<form id="a"> | ||
<select form="a"></select> | ||
</form> | ||
</div> | ||
<script> | ||
document.getElementById("a").setAttribute("id", "y"); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters