Commit 5ffd0694 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Form-associated custom elements: Update form submission logic

to match to the latest pull request [1].

- If the element has zero-length name attribute, it should not add an entry.
- The first argument of setFormValue() should be nullable, and the null
  value should add no entry.

[1] https://github.com/whatwg/html/pull/4383

Bug: 905922
Change-Id: I5bcacd633e43050e5065682043d126359bdeca7c
Reviewed-on: https://chromium-review.googlesource.com/c/1491051
Auto-Submit: Kent Tamura <tkent@chromium.org>
Commit-Queue: Hayato Ito <hayato@chromium.org>
Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635890}
parent 7ef39c6b
...@@ -225,14 +225,13 @@ void ElementInternals::AppendToFormData(FormData& form_data) { ...@@ -225,14 +225,13 @@ void ElementInternals::AppendToFormData(FormData& form_data) {
return; return;
const AtomicString& name = Target().FastGetAttribute(html_names::kNameAttr); const AtomicString& name = Target().FastGetAttribute(html_names::kNameAttr);
if (!entry_source_) { if (!entry_source_) {
if (name.IsNull()) if (name.IsEmpty())
return; return;
if (value_.IsFile()) if (value_.IsFile())
form_data.AppendFromElement(name, value_.GetAsFile()); form_data.AppendFromElement(name, value_.GetAsFile());
else if (value_.IsUSVString()) else if (value_.IsUSVString())
form_data.AppendFromElement(name, value_.GetAsUSVString()); form_data.AppendFromElement(name, value_.GetAsUSVString());
else // Append nothing for null value.
form_data.AppendFromElement(name, g_empty_string);
return; return;
} }
for (const auto& entry : entry_source_->Entries()) { for (const auto& entry : entry_source_->Entries()) {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
] ]
interface ElementInternals { interface ElementInternals {
// Attributes and operations for form-associated custom elements. // Attributes and operations for form-associated custom elements.
[RaisesException] void setFormValue(FormDataEntryValue value, optional FormData entrySource); [RaisesException] void setFormValue(FormDataEntryValue? value, optional FormData entrySource);
[RaisesException] readonly attribute HTMLFormElement? form; [RaisesException] readonly attribute HTMLFormElement? form;
......
...@@ -59,7 +59,7 @@ promise_test(t => { ...@@ -59,7 +59,7 @@ promise_test(t => {
'<iframe name="if1"></iframe>'; '<iframe name="if1"></iframe>';
$('my-control').value = 'value-ce1'; $('my-control').value = 'value-ce1';
return submitPromise(t).then(query => { return submitPromise(t).then(query => {
assert_equals(query, '?name-pd1=value-pd1&=value-ce1&name-pd2=value-pd2'); assert_equals(query, '?name-pd1=value-pd1&name-pd2=value-pd2');
}); });
}, 'Single value - empty name exists'); }, 'Single value - empty name exists');
...@@ -76,6 +76,19 @@ promise_test(t => { ...@@ -76,6 +76,19 @@ promise_test(t => {
}); });
}, 'Single value - Non-empty name exists'); }, 'Single value - Non-empty name exists');
promise_test(t => {
$('#container').innerHTML = '<form action="../../external/wpt/common/blank.html" target="if1">' +
'<input name=name-pd1 value="value-pd1">' +
'<my-control name="name-ce1"></my-control>' +
'<my-control name="name-ce2"></my-control>' +
'</form>' +
'<iframe name="if1"></iframe>';
$('my-control').value = null;
return submitPromise(t).then(query => {
assert_equals(query, '?name-pd1=value-pd1&name-ce2=');
});
}, 'Null value should submit nothing');
promise_test(t => { promise_test(t => {
$('#container').innerHTML = '<form action="../../external/wpt/common/blank.html" target="if1">' + $('#container').innerHTML = '<form action="../../external/wpt/common/blank.html" target="if1">' +
'<input name=name-pd1 value="value-pd1">' + '<input name=name-pd1 value="value-pd1">' +
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment