mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Implement minlength for text inputs
This commit is contained in:
parent
7c0dfd07ad
commit
2cb5adf6c6
8 changed files with 113 additions and 78 deletions
|
@ -17,13 +17,18 @@ use script::dom::bindings::str::DOMString;
|
|||
use script::textinput::{TextInput, TextPoint, Selection, Lines, Direction, SelectionDirection};
|
||||
|
||||
fn text_input(lines: Lines, s: &str) -> TextInput<DummyClipboardContext> {
|
||||
TextInput::new(lines, DOMString::from(s), DummyClipboardContext::new(""), None, SelectionDirection::None)
|
||||
TextInput::new(lines,
|
||||
DOMString::from(s),
|
||||
DummyClipboardContext::new(""),
|
||||
None,
|
||||
None,
|
||||
SelectionDirection::None)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_content_ignores_max_length() {
|
||||
let mut textinput = TextInput::new(
|
||||
Lines::Single, DOMString::from(""), DummyClipboardContext::new(""), Some(1), SelectionDirection::None
|
||||
Lines::Single, DOMString::from(""), DummyClipboardContext::new(""), Some(1), None, SelectionDirection::None
|
||||
);
|
||||
|
||||
textinput.set_content(DOMString::from("mozilla rocks"));
|
||||
|
@ -37,6 +42,7 @@ fn test_textinput_when_inserting_multiple_lines_over_a_selection_respects_max_le
|
|||
DOMString::from("hello\nworld"),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(17),
|
||||
None,
|
||||
SelectionDirection::None,
|
||||
);
|
||||
|
||||
|
@ -61,6 +67,7 @@ fn test_textinput_when_inserting_multiple_lines_still_respects_max_length() {
|
|||
DOMString::from("hello\nworld"),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(17),
|
||||
None,
|
||||
SelectionDirection::None
|
||||
);
|
||||
|
||||
|
@ -78,6 +85,7 @@ fn test_textinput_when_content_is_already_longer_than_max_length_and_theres_no_s
|
|||
DOMString::from("abc"),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(1),
|
||||
None,
|
||||
SelectionDirection::None,
|
||||
);
|
||||
|
||||
|
@ -93,6 +101,7 @@ fn test_multi_line_textinput_with_maxlength_doesnt_allow_appending_characters_wh
|
|||
DOMString::from("abc\nd"),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(5),
|
||||
None,
|
||||
SelectionDirection::None,
|
||||
);
|
||||
|
||||
|
@ -108,6 +117,7 @@ fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_
|
|||
DOMString::from("abcde"),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(5),
|
||||
None,
|
||||
SelectionDirection::None,
|
||||
);
|
||||
|
||||
|
@ -129,6 +139,7 @@ fn test_single_line_textinput_with_max_length_multibyte() {
|
|||
DOMString::from(""),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(2),
|
||||
None,
|
||||
SelectionDirection::None,
|
||||
);
|
||||
|
||||
|
@ -147,6 +158,7 @@ fn test_single_line_textinput_with_max_length_multi_code_unit() {
|
|||
DOMString::from(""),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(3),
|
||||
None,
|
||||
SelectionDirection::None,
|
||||
);
|
||||
|
||||
|
@ -167,6 +179,7 @@ fn test_single_line_textinput_with_max_length_inside_char() {
|
|||
DOMString::from("\u{10437}"),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(1),
|
||||
None,
|
||||
SelectionDirection::None,
|
||||
);
|
||||
|
||||
|
@ -181,6 +194,7 @@ fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_
|
|||
DOMString::from("a"),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(1),
|
||||
None,
|
||||
SelectionDirection::None,
|
||||
);
|
||||
|
||||
|
@ -398,6 +412,7 @@ fn test_clipboard_paste() {
|
|||
DOMString::from("defg"),
|
||||
DummyClipboardContext::new("abc"),
|
||||
None,
|
||||
None,
|
||||
SelectionDirection::None);
|
||||
assert_eq!(textinput.get_content(), "defg");
|
||||
assert_eq!(textinput.edit_point.index, 0);
|
||||
|
|
|
@ -37499,6 +37499,12 @@
|
|||
"path": "dom/lists/DOMTokenList-Iterable.html",
|
||||
"url": "/dom/lists/DOMTokenList-Iterable.html"
|
||||
}
|
||||
],
|
||||
"html/semantics/forms/the-input-element/minlength.html": [
|
||||
{
|
||||
"path": "html/semantics/forms/the-input-element/minlength.html",
|
||||
"url": "/html/semantics/forms/the-input-element/minlength.html"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -3555,9 +3555,6 @@
|
|||
[HTMLInputElement interface: attribute list]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: attribute minLength]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: attribute valueAsDate]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -3627,9 +3624,6 @@
|
|||
[HTMLInputElement interface: document.createElement("input") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: document.createElement("input") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: document.createElement("input") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -6906,9 +6900,6 @@
|
|||
[HTMLInputElement interface: createInput("text") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("text") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("text") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -6993,9 +6984,6 @@
|
|||
[HTMLInputElement interface: createInput("hidden") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("hidden") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("hidden") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -7080,9 +7068,6 @@
|
|||
[HTMLInputElement interface: createInput("search") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("search") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("search") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -7167,9 +7152,6 @@
|
|||
[HTMLInputElement interface: createInput("tel") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("tel") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("tel") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -7254,9 +7236,6 @@
|
|||
[HTMLInputElement interface: createInput("url") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("url") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("url") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -7341,9 +7320,6 @@
|
|||
[HTMLInputElement interface: createInput("email") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("email") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("email") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -7428,9 +7404,6 @@
|
|||
[HTMLInputElement interface: createInput("password") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("password") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("password") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -7515,9 +7488,6 @@
|
|||
[HTMLInputElement interface: createInput("date") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("date") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("date") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -7602,9 +7572,6 @@
|
|||
[HTMLInputElement interface: createInput("month") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("month") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("month") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -7689,9 +7656,6 @@
|
|||
[HTMLInputElement interface: createInput("week") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("week") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("week") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -7776,9 +7740,6 @@
|
|||
[HTMLInputElement interface: createInput("time") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("time") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("time") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -7863,9 +7824,6 @@
|
|||
[HTMLInputElement interface: createInput("datetime-local") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("datetime-local") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("datetime-local") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -7950,9 +7908,6 @@
|
|||
[HTMLInputElement interface: createInput("number") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("number") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("number") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -8037,9 +7992,6 @@
|
|||
[HTMLInputElement interface: createInput("range") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("range") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("range") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -8124,9 +8076,6 @@
|
|||
[HTMLInputElement interface: createInput("color") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("color") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("color") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -8211,9 +8160,6 @@
|
|||
[HTMLInputElement interface: createInput("checkbox") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("checkbox") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("checkbox") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -8298,9 +8244,6 @@
|
|||
[HTMLInputElement interface: createInput("radio") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("radio") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("radio") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -8388,9 +8331,6 @@
|
|||
[HTMLInputElement interface: createInput("file") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("file") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("file") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -8475,9 +8415,6 @@
|
|||
[HTMLInputElement interface: createInput("submit") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("submit") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("submit") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -8562,9 +8499,6 @@
|
|||
[HTMLInputElement interface: createInput("image") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("image") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("image") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -8649,9 +8583,6 @@
|
|||
[HTMLInputElement interface: createInput("reset") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("reset") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("reset") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -8736,9 +8667,6 @@
|
|||
[HTMLInputElement interface: createInput("button") must inherit property "list" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("button") must inherit property "minLength" with the proper type (22)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("button") must inherit property "valueAsDate" with the proper type (35)]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>input min length</title>
|
||||
<link rel="author" title="Taryn Hill" href="mailto:Phrohdoh@gmail.com">
|
||||
<link rel=help href="https://html.spec.whatwg.org/multipage/forms.html#the-minlength-and-minlength-attributes">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Text input element</h1>
|
||||
|
||||
<div style="display: none">
|
||||
<input id="none" />
|
||||
<input id="negative" minlength=-5 />
|
||||
<input id="non-numeric" minlength="not-a-number" />
|
||||
<input id="assign-negative" />
|
||||
<input id="assign-non-numeric" />
|
||||
</div>
|
||||
|
||||
<div id="log"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
test(
|
||||
function() {
|
||||
assert_equals(document.getElementById("none").minLength, -1);
|
||||
}, "Unset minlength is -1");
|
||||
|
||||
test(
|
||||
function() {
|
||||
assert_equals(document.getElementById("negative").minLength, -1);
|
||||
}, "Negative minlength is always -1");
|
||||
|
||||
test(
|
||||
function() {
|
||||
assert_equals(document.getElementById("non-numeric").minLength, -1);
|
||||
}, "Non-numeric minlength is -1");
|
||||
|
||||
test(
|
||||
function() {
|
||||
assert_throws("INDEX_SIZE_ERR", function() {
|
||||
document.getElementById("assign-negative").minLength = -5;
|
||||
});
|
||||
}, "Assigning negative integer throws IndexSizeError");
|
||||
|
||||
test(
|
||||
function() {
|
||||
document.getElementById("assign-non-numeric").minLength = "not-a-number";
|
||||
assert_equals(document.getElementById("assign-non-numeric").minLength, 0);
|
||||
}, "Assigning non-numeric to minlength sets minlength to 0");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue