mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #13762 - frewsxcv:select-reset, r=Manishearth
Implement "reset algorithm" for `<select>`. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13762) <!-- Reviewable:end -->
This commit is contained in:
commit
28be83bd9a
4 changed files with 31 additions and 7 deletions
|
@ -634,8 +634,7 @@ impl HTMLFormElement {
|
|||
// {}
|
||||
//}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) => {
|
||||
// Unimplemented
|
||||
{}
|
||||
child.downcast::<HTMLSelectElement>().unwrap().reset();
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
|
||||
child.downcast::<HTMLTextAreaElement>().unwrap().reset();
|
||||
|
|
|
@ -84,6 +84,16 @@ impl HTMLSelectElement {
|
|||
HTMLSelectElementBinding::Wrap)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#the-select-element:concept-form-reset-control
|
||||
pub fn reset(&self) {
|
||||
let node = self.upcast::<Node>();
|
||||
for opt in node.traverse_preorder().filter_map(Root::downcast::<HTMLOptionElement>) {
|
||||
opt.set_selectedness(opt.DefaultSelected());
|
||||
opt.set_dirtiness(false);
|
||||
}
|
||||
self.ask_for_reset();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#ask-for-a-reset
|
||||
pub fn ask_for_reset(&self) {
|
||||
if self.Multiple() {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
[reset-form.html]
|
||||
type: testharness
|
||||
[Resetting the form by calling the reset() method]
|
||||
[Resetting <output> by calling the reset() method]
|
||||
expected: FAIL
|
||||
|
||||
[Resetting the form by clicking the button in reset status]
|
||||
[Resetting <output> by clicking the button in reset status]
|
||||
expected: FAIL
|
||||
|
||||
[Resetting the form by clicking the input in reset status]
|
||||
[Resetting <output> by clicking the input in reset status]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -87,10 +87,25 @@ function runTest(reset, description) {
|
|||
assert_false(document.getElementById("rd2").checked, "The checked attribute of the input element in radio should be false.");
|
||||
assert_true(document.getElementById("cb1").checked, "The checked attribute of the input element in checkbox should be true.");
|
||||
assert_false(document.getElementById("cb2").checked, "The checked attribute of the input element in checkbox should be false.");
|
||||
}, "Resetting <input> " + description);
|
||||
|
||||
test(function() {
|
||||
setPreconditions("Setting preconditions for resetting " + description);
|
||||
reset();
|
||||
assert_equals(document.getElementById("ta").value, document.getElementById("ta").textContent, "The value attribute of the textarea element should be reset.");
|
||||
assert_equals(document.getElementById("ta").value, "abc", "The value attribute of the textarea element should be 'abc'.");
|
||||
}, "Resetting <textarea> " + description);
|
||||
|
||||
test(function() {
|
||||
setPreconditions("Setting preconditions for resetting " + description);
|
||||
reset();
|
||||
assert_equals(document.getElementById("opt").textContent, document.getElementById("opt").defaultValue, "The textContent of the output element should be reset.");
|
||||
assert_equals(document.getElementById("opt").textContent, "abc", "The textContent of the output element should be 'abc'.");
|
||||
}, "Resetting <output> " + description);
|
||||
|
||||
test(function() {
|
||||
setPreconditions("Setting preconditions for resetting " + description);
|
||||
reset();
|
||||
assert_true(document.getElementById("slt1").options[0].selected, "The first option in the select element should be selected.");
|
||||
assert_false(document.getElementById("slt1").options[1].selected, "The second option in the select element should not be selected.");
|
||||
assert_false(document.getElementById("slt2").options[0].selected, "The first option in the select element should not be selected.");
|
||||
|
@ -98,8 +113,8 @@ function runTest(reset, description) {
|
|||
assert_false(document.getElementById("slt3").options[0].selected, "The first option in the select element with multiple attribute should not be selected.");
|
||||
assert_true(document.getElementById("slt3").options[1].selected, "The second option in the select element with multiple attribute should be selected.");
|
||||
assert_true(document.getElementById("slt3").options[2].selected, "The third option in the select element with multiple attribute should be selected.");
|
||||
}, "Resetting <select> " + description);
|
||||
//TODO: The keygen reset algorithm
|
||||
}, "Resetting the form " + description);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue