From d26c555e2a2fe0e10b9237e1ccf48d96665828c7 Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Sun, 23 Aug 2015 16:11:04 +1200 Subject: [PATCH 01/14] Adds support for input element's maxlength attr servo/servo#7320 servo/servo#7004 --- components/script/dom/htmlinputelement.rs | 34 +++++- components/script/dom/htmltextareaelement.rs | 4 +- .../dom/webidls/HTMLInputElement.webidl | 2 +- components/script/textinput.rs | 52 ++++++++- components/style/attr.rs | 10 +- tests/unit/script/textinput.rs | 107 +++++++++++++++++- 6 files changed, 196 insertions(+), 13 deletions(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 524f70e1288..554030c288a 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -8,8 +8,8 @@ use dom::attr::{Attr, AttrValue}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use dom::bindings::codegen::Bindings::HTMLInputElementBinding; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; +use dom::bindings::codegen::Bindings::HTMLInputElementBinding; use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods; use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; @@ -32,6 +32,7 @@ use msg::constellation_msg::ScriptMsg as ConstellationMsg; use selectors::states::*; use std::borrow::ToOwned; use std::cell::Cell; +use std::i32; use string_cache::Atom; use textinput::KeyReaction::{DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction}; use textinput::Lines::Single; @@ -116,7 +117,7 @@ impl HTMLInputElement { checked_changed: Cell::new(false), value_changed: Cell::new(false), size: Cell::new(DEFAULT_INPUT_SIZE), - textinput: DOMRefCell::new(TextInput::new(Single, DOMString::new(), chan)), + textinput: DOMRefCell::new(TextInput::new(Single, DOMString::new(), chan, None)), activation_state: DOMRefCell::new(InputActivationState::new()) } } @@ -337,6 +338,21 @@ impl HTMLInputElementMethods for HTMLInputElement { // https://html.spec.whatwg.org/multipage/#dom-input-formtarget make_setter!(SetFormTarget, "formtarget"); + // https://html.spec.whatwg.org/multipage/#dom-input-maxlength + fn MaxLength(&self) -> i32 { + match self.textinput.borrow().max_length { + Some(max_length) => max_length as i32, + None => i32::MAX + } + } + + // https://html.spec.whatwg.org/multipage/#dom-input-maxlength + fn SetMaxLength(&self, max_length: i32) { + if max_length > 0 { + self.textinput.borrow_mut().max_length = Some(max_length as usize) + } + } + // https://html.spec.whatwg.org/multipage/#dom-input-indeterminate fn Indeterminate(&self) -> bool { self.upcast::().get_state().contains(IN_INDETERMINATE_STATE) @@ -511,6 +527,7 @@ impl VirtualMethods for HTMLInputElement { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { self.super_type().unwrap().attribute_mutated(attr, mutation); + match attr.local_name() { &atom!("disabled") => { let disabled_state = match mutation { @@ -581,6 +598,18 @@ impl VirtualMethods for HTMLInputElement { self.radio_group_updated( mutation.new_value(attr).as_ref().map(|name| name.as_atom())); }, + &atom!("maxlength") => { + match *attr.value() { + AttrValue::Int(_, value) => { + if value < 0 { + self.textinput.borrow_mut().max_length = None + } else { + self.textinput.borrow_mut().max_length = Some(value as usize) + } + }, + _ => panic!("Expected an AttrValue::UInt"), + } + } &atom!("placeholder") => { // FIXME(ajeffrey): Should we do in-place mutation of the placeholder? let mut placeholder = self.placeholder.borrow_mut(); @@ -599,6 +628,7 @@ impl VirtualMethods for HTMLInputElement { &atom!("name") => AttrValue::from_atomic(value), &atom!("size") => AttrValue::from_limited_u32(value, DEFAULT_INPUT_SIZE), &atom!("type") => AttrValue::from_atomic(value), + &atom!("maxlength") => AttrValue::from_i32(value, i32::MAX), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index d4e1729f662..94057d4eee0 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -30,6 +30,7 @@ use script_task::ScriptTaskEventCategory::InputEvent; use script_task::{CommonScriptMsg, Runnable}; use selectors::states::*; use std::cell::Cell; +use std::i32; use string_cache::Atom; use textinput::{KeyReaction, Lines, TextInput}; use util::str::DOMString; @@ -89,6 +90,7 @@ impl<'a> RawLayoutHTMLTextAreaElementHelpers for &'a HTMLTextAreaElement { static DEFAULT_COLS: u32 = 20; static DEFAULT_ROWS: u32 = 2; +static DEFAULT_MAX_LENGTH: i32 = i32::MAX; impl HTMLTextAreaElement { fn new_inherited(localName: DOMString, @@ -99,7 +101,7 @@ impl HTMLTextAreaElement { htmlelement: HTMLElement::new_inherited_with_state(IN_ENABLED_STATE, localName, prefix, document), - textinput: DOMRefCell::new(TextInput::new(Lines::Multiple, DOMString::new(), chan)), + textinput: DOMRefCell::new(TextInput::new(Lines::Multiple, DOMString::new(), chan, None)), cols: Cell::new(DEFAULT_COLS), rows: Cell::new(DEFAULT_ROWS), value_changed: Cell::new(false), diff --git a/components/script/dom/webidls/HTMLInputElement.webidl b/components/script/dom/webidls/HTMLInputElement.webidl index a5472818afe..b2b7992f5e0 100644 --- a/components/script/dom/webidls/HTMLInputElement.webidl +++ b/components/script/dom/webidls/HTMLInputElement.webidl @@ -25,7 +25,7 @@ interface HTMLInputElement : HTMLElement { // attribute DOMString inputMode; //readonly attribute HTMLElement? list; // attribute DOMString max; - // attribute long maxLength; + attribute long maxLength; // attribute DOMString min; // attribute long minLength; // attribute boolean multiple; diff --git a/components/script/textinput.rs b/components/script/textinput.rs index aa970e27464..b5bd6421127 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -11,6 +11,7 @@ use msg::constellation_msg::{Key, KeyModifiers}; use std::borrow::ToOwned; use std::cmp::{max, min}; use std::default::Default; +use std::usize; use util::mem::HeapSizeOf; use util::str::DOMString; @@ -41,6 +42,7 @@ pub struct TextInput { multiline: bool, #[ignore_heap_size_of = "Can't easily measure this generic type"] clipboard_provider: T, + pub max_length: Option } /// Resulting action to be taken by the owner of a text input that is handling an event. @@ -107,13 +109,14 @@ fn is_printable_key(key: Key) -> bool { impl TextInput { /// Instantiate a new text input control - pub fn new(lines: Lines, initial: DOMString, clipboard_provider: T) -> TextInput { + pub fn new(lines: Lines, initial: DOMString, clipboard_provider: T, max_length: Option) -> TextInput { let mut i = TextInput { lines: vec!(), edit_point: Default::default(), selection_begin: None, multiline: lines == Lines::Multiple, - clipboard_provider: clipboard_provider + clipboard_provider: clipboard_provider, + max_length: max_length }; i.set_content(initial); i @@ -133,7 +136,7 @@ impl TextInput { } /// Insert a string at the current editing point - fn insert_string>(&mut self, s: S) { + pub fn insert_string>(&mut self, s: S) { if self.selection_begin.is_none() { self.selection_begin = Some(self.edit_point); } @@ -170,8 +173,40 @@ impl TextInput { }) } + fn selection_len(&self) -> usize { + if let Some((begin, end)) = self.get_sorted_selection() { + let prefix = &self.lines[begin.line][0..begin.index]; + let suffix = &self.lines[end.line][end.index..]; + let lines_prefix = &self.lines[..begin.line]; + let lines_suffix = &self.lines[end.line + 1..]; + + self.len() - (prefix.chars().count() + + suffix.chars().count() + + lines_prefix.iter().fold(0, |m, i| m + i.chars().count() + 1) + + lines_suffix.iter().fold(0, |m, i| m + i.chars().count() + 1)) + } else { + 0 + } + } + pub fn replace_selection(&mut self, insert: DOMString) { if let Some((begin, end)) = self.get_sorted_selection() { + let allowed_to_insert_count = if let Some(max_length) = self.max_length { + let len_after_selection_replaced = self.len() - self.selection_len(); + if len_after_selection_replaced > max_length { + // If, after deleting the selection, the len is still greater than the max + // length, then don't delete/insert anything + return + } + + max_length - len_after_selection_replaced + } else { + usize::MAX + }; + + let last_char_to_insert = min(allowed_to_insert_count, insert.chars().count()); + let chars_to_insert = (&insert[0 .. last_char_to_insert]).to_owned(); + self.clear_selection(); let new_lines = { @@ -181,13 +216,14 @@ impl TextInput { let lines_suffix = &self.lines[end.line + 1..]; let mut insert_lines = if self.multiline { - insert.split('\n').map(DOMString::from).collect() + chars_to_insert.split('\n').map(|s| DOMString::from(s.to_owned())).collect() } else { - vec!(insert) + vec!(DOMString::from(chars_to_insert)) }; // FIXME(ajeffrey): effecient append for DOMStrings let mut new_line = prefix.to_owned(); + new_line.push_str(&insert_lines[0]); insert_lines[0] = DOMString::from(new_line); @@ -434,6 +470,12 @@ impl TextInput { } } + pub fn len(&self) -> usize { + self.lines.iter().fold(0, |m, l| { + m + l.len() + 1 + }) - 1 + } + /// Get the current contents of the text input. Multiple lines are joined by \n. pub fn get_content(&self) -> DOMString { let mut content = "".to_owned(); diff --git a/components/style/attr.rs b/components/style/attr.rs index 625eeee3a5c..e50071e3b3f 100644 --- a/components/style/attr.rs +++ b/components/style/attr.rs @@ -5,7 +5,7 @@ use cssparser::RGBA; use std::ops::Deref; use string_cache::{Atom, Namespace}; -use util::str::{DOMString, LengthOrPercentageOrAuto, parse_unsigned_integer, parse_legacy_color, parse_length}; +use util::str::{DOMString, LengthOrPercentageOrAuto, parse_integer, parse_unsigned_integer, parse_legacy_color, parse_length}; use util::str::{split_html_space_chars, str_join}; use values::specified::{Length}; @@ -17,6 +17,7 @@ pub enum AttrValue { String(DOMString), TokenList(DOMString, Vec), UInt(DOMString, u32), + Int(DOMString, i32), Atom(Atom), Length(DOMString, Option), Color(DOMString, Option), @@ -52,6 +53,12 @@ impl AttrValue { AttrValue::UInt(string, result) } + // https://html.spec.whatwg.org/multipage/infrastructure.html#limited-to-only-non-negative-numbers + pub fn from_i32(string: DOMString, default: i32) -> AttrValue { + let result = parse_integer(string.chars()).unwrap_or(default); + AttrValue::Int(string, result) + } + // https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers-greater-than-zero pub fn from_limited_u32(string: DOMString, default: u32) -> AttrValue { let result = parse_unsigned_integer(string.chars()).unwrap_or(default); @@ -165,6 +172,7 @@ impl Deref for AttrValue { AttrValue::UInt(ref value, _) | AttrValue::Length(ref value, _) | AttrValue::Color(ref value, _) | + AttrValue::Int(ref value, _) | AttrValue::Dimension(ref value, _) => &value, AttrValue::Atom(ref value) => &value, } diff --git a/tests/unit/script/textinput.rs b/tests/unit/script/textinput.rs index 3d62f1f32ed..25ff3e827a0 100644 --- a/tests/unit/script/textinput.rs +++ b/tests/unit/script/textinput.rs @@ -13,11 +13,111 @@ use msg::constellation_msg::CONTROL; use msg::constellation_msg::SUPER; use msg::constellation_msg::{Key, KeyModifiers}; use script::clipboard_provider::DummyClipboardContext; -use script::textinput::{TextInput, Selection, Lines, Direction}; +use script::textinput::{TextInput, TextPoint, Selection, Lines, Direction}; use util::str::DOMString; fn text_input(lines: Lines, s: &str) -> TextInput { - TextInput::new(lines, DOMString::from(s), DummyClipboardContext::new("")) + TextInput::new(lines, DOMString::from(s), DummyClipboardContext::new(""), None) +} + +#[test] +fn test_textinput_when_inserting_multiple_lines_over_a_selection_respects_max_length() { + let mut textinput = TextInput::new( + Lines::Multiple, + DOMString::from("hello\nworld"), + DummyClipboardContext::new(""), + Some(17) + ); + + textinput.edit_point = TextPoint { line: 0, index: 1 }; + textinput.adjust_horizontal(3, Selection::Selected); + textinput.adjust_vertical(1, Selection::Selected); + + // Selection is now "hello\n + // ------ + // world" + // ---- + + textinput.insert_string("cruel\nterrible\nbad".to_string()); + + assert_eq!(textinput.get_content(), "hcruel\nterrible\nd"); +} + +#[test] +fn test_textinput_when_inserting_multiple_lines_still_respects_max_length() { + let mut textinput = TextInput::new( + Lines::Multiple, + DOMString::from("hello\nworld"), + DummyClipboardContext::new(""), + Some(17) + ); + + textinput.edit_point = TextPoint { line: 1, index: 0 }; + + textinput.insert_string("cruel\nterrible".to_string()); + + assert_eq!(textinput.get_content(), "hello\ncruel\nworld"); +} + +#[test] +fn test_textinput_when_content_is_already_longer_than_max_length_and_theres_no_selection_dont_insert_anything() { + let mut textinput = TextInput::new( + Lines::Single, + DOMString::from("abc"), + DummyClipboardContext::new(""), + Some(1) + ); + + textinput.insert_char('a'); + + assert_eq!(textinput.get_content(), "abc"); +} + +#[test] +fn test_multi_line_textinput_with_maxlength_doesnt_allow_appending_characters_when_input_spans_lines() { + let mut textinput = TextInput::new( + Lines::Multiple, + DOMString::from("abc\nd"), + DummyClipboardContext::new(""), + Some(5) + ); + + textinput.insert_char('a'); + + assert_eq!(textinput.get_content(), "abc\nd"); +} + +#[test] +fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_when_replacing_a_selection() { + let mut textinput = TextInput::new( + Lines::Single, + DOMString::from("abcde"), + DummyClipboardContext::new(""), + Some(5) + ); + + textinput.edit_point = TextPoint { line: 0, index: 1 }; + textinput.adjust_horizontal(3, Selection::Selected); + + // Selection is now "abcde" + // --- + + textinput.replace_selection(DOMString::from("too long")); + + assert_eq!(textinput.get_content(), "atooe"); +} + +#[test] +fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_after_max_length_is_reached() { + let mut textinput = TextInput::new( + Lines::Single, + DOMString::from("a"), + DummyClipboardContext::new(""), + Some(1) + ); + + textinput.insert_char('b'); + assert_eq!(textinput.get_content(), "a"); } #[test] @@ -199,7 +299,8 @@ fn test_clipboard_paste() { let mut textinput = TextInput::new(Lines::Single, DOMString::from("defg"), - DummyClipboardContext::new("abc")); + DummyClipboardContext::new("abc"), + None); assert_eq!(textinput.get_content(), "defg"); assert_eq!(textinput.edit_point.index, 0); textinput.handle_keydown_aux(Key::V, MODIFIERS); From eecdfdf6c17b71b03a9d6404d83de482880aa26c Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Tue, 1 Sep 2015 11:14:29 +1200 Subject: [PATCH 02/14] Makes int_getter macro, and uses -1 as default maxlength instead of maxint --- components/script/dom/element.rs | 21 ++++++++++++++++++++ components/script/dom/htmlinputelement.rs | 20 ++++++++++--------- components/script/dom/htmltextareaelement.rs | 2 -- components/script/dom/macros.rs | 19 ++++++++++++++++++ 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index e7d6a47076f..3cec88f148f 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1090,6 +1090,27 @@ impl Element { self.set_attribute(local_name, AttrValue::from_atomic_tokens(tokens)); } + pub fn get_int_attribute(&self, local_name: &Atom, default: i32) -> i32 { + // TODO: Is this assert necessary? + assert!(local_name.chars().all(|ch| { + !ch.is_ascii() || ch.to_ascii_lowercase() == ch + })); + let attribute = self.get_attribute(&ns!(""), local_name); + + match attribute { + Some(ref attribute) => { + match *attribute.r().value() { + AttrValue::Int(_, value) => value, + _ => panic!("Expected an AttrValue::Int: \ + implement parse_plain_attribute"), + } + } + None => default, + } + } + + // TODO: set_int_attribute(...) + pub fn get_uint_attribute(&self, local_name: &Atom, default: u32) -> u32 { assert!(local_name.chars().all(|ch| !ch.is_ascii() || ch.to_ascii_lowercase() == ch)); let attribute = self.get_attribute(&ns!(), local_name); diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 554030c288a..c23f73f3220 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -65,6 +65,7 @@ pub struct HTMLInputElement { placeholder: DOMRefCell, value_changed: Cell, size: Cell, + maxlength: Cell, #[ignore_heap_size_of = "#7193"] textinput: DOMRefCell>>, activation_state: DOMRefCell, @@ -104,6 +105,7 @@ impl InputActivationState { } static DEFAULT_INPUT_SIZE: u32 = 20; +static DEFAULT_MAX_LENGTH : i32 = -1; impl HTMLInputElement { fn new_inherited(localName: DOMString, prefix: Option, document: &Document) -> HTMLInputElement { @@ -116,6 +118,7 @@ impl HTMLInputElement { placeholder: DOMRefCell::new(DOMString::new()), checked_changed: Cell::new(false), value_changed: Cell::new(false), + maxlength: Cell::new(DEFAULT_MAX_LENGTH), size: Cell::new(DEFAULT_INPUT_SIZE), textinput: DOMRefCell::new(TextInput::new(Single, DOMString::new(), chan, None)), activation_state: DOMRefCell::new(InputActivationState::new()) @@ -339,17 +342,16 @@ impl HTMLInputElementMethods for HTMLInputElement { make_setter!(SetFormTarget, "formtarget"); // https://html.spec.whatwg.org/multipage/#dom-input-maxlength - fn MaxLength(&self) -> i32 { - match self.textinput.borrow().max_length { - Some(max_length) => max_length as i32, - None => i32::MAX - } - } + make_int_getter!(MaxLength, "maxlength", DEFAULT_MAX_LENGTH); // https://html.spec.whatwg.org/multipage/#dom-input-maxlength - fn SetMaxLength(&self, max_length: i32) { - if max_length > 0 { - self.textinput.borrow_mut().max_length = Some(max_length as usize) + fn SetMaxLength(&self, val: i32) { + self.maxlength.set(val); + + if val >= 0 { + self.textinput.borrow_mut().max_length = Some(val as usize) + } else { + self.textinput.borrow_mut().max_length = None } } diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 94057d4eee0..76d25092435 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -30,7 +30,6 @@ use script_task::ScriptTaskEventCategory::InputEvent; use script_task::{CommonScriptMsg, Runnable}; use selectors::states::*; use std::cell::Cell; -use std::i32; use string_cache::Atom; use textinput::{KeyReaction, Lines, TextInput}; use util::str::DOMString; @@ -90,7 +89,6 @@ impl<'a> RawLayoutHTMLTextAreaElementHelpers for &'a HTMLTextAreaElement { static DEFAULT_COLS: u32 = 20; static DEFAULT_ROWS: u32 = 2; -static DEFAULT_MAX_LENGTH: i32 = i32::MAX; impl HTMLTextAreaElement { fn new_inherited(localName: DOMString, diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 166b52d82d5..a292737ac47 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -26,6 +26,25 @@ macro_rules! make_bool_getter( ); ); +#[macro_export] +macro_rules! make_int_getter( + ($attr:ident, $htmlname:expr, $default:expr) => ( + fn $attr(&self) -> i32 { + use dom::bindings::codegen::InheritTypes::ElementCast; + use string_cache::Atom; + let element = ElementCast::from_ref(self); + // FIXME(pcwalton): Do this at compile time, not runtime. + element.get_int_attribute(&Atom::from_slice($htmlname), $default) + } + ); + ($attr:ident, $htmlname:expr) => { + make_int_getter!($attr, $htmlname, 0); + }; + ($attr:ident) => { + make_int_getter!($attr, to_lower!(stringify!($attr))); + } +); + #[macro_export] macro_rules! make_uint_getter( ($attr:ident, $htmlname:tt, $default:expr) => ( From 419a26e6192a31478302c310910f1ae8f6f5e3ae Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Tue, 1 Sep 2015 13:51:41 +1200 Subject: [PATCH 03/14] Adds a test for set_content to ignore max_length --- tests/unit/script/textinput.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/unit/script/textinput.rs b/tests/unit/script/textinput.rs index 25ff3e827a0..75a49c824dc 100644 --- a/tests/unit/script/textinput.rs +++ b/tests/unit/script/textinput.rs @@ -20,6 +20,16 @@ fn text_input(lines: Lines, s: &str) -> TextInput { TextInput::new(lines, DOMString::from(s), DummyClipboardContext::new(""), None) } +#[test] +fn test_set_content_ignores_max_length() { + let mut textinput = TextInput::new( + Lines::Single, "".to_owned(), DummyClipboardContext::new(""), Some(1) + ); + + textinput.set_content("mozilla rocks".to_owned()); + assert_eq!(textinput.get_content(), "mozilla rocks".to_owned()); +} + #[test] fn test_textinput_when_inserting_multiple_lines_over_a_selection_respects_max_length() { let mut textinput = TextInput::new( From 2ba1750c403e59556f667b163d5d2a90dd5f6dd6 Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Tue, 1 Dec 2015 20:40:37 +1100 Subject: [PATCH 04/14] Resolves long-running merge conflicts --- components/script/dom/element.rs | 2 +- components/script/dom/macros.rs | 17 +++++++---------- tests/unit/script/textinput.rs | 6 +++--- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 3cec88f148f..a5897ed80ac 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1095,7 +1095,7 @@ impl Element { assert!(local_name.chars().all(|ch| { !ch.is_ascii() || ch.to_ascii_lowercase() == ch })); - let attribute = self.get_attribute(&ns!(""), local_name); + let attribute = self.get_attribute(&ns!(), local_name); match attribute { Some(ref attribute) => { diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index a292737ac47..8029bb85b2f 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -28,21 +28,18 @@ macro_rules! make_bool_getter( #[macro_export] macro_rules! make_int_getter( - ($attr:ident, $htmlname:expr, $default:expr) => ( + ($attr:ident, $htmlname:tt, $default:expr) => ( fn $attr(&self) -> i32 { - use dom::bindings::codegen::InheritTypes::ElementCast; - use string_cache::Atom; - let element = ElementCast::from_ref(self); - // FIXME(pcwalton): Do this at compile time, not runtime. - element.get_int_attribute(&Atom::from_slice($htmlname), $default) + use dom::bindings::inheritance::Castable; + use dom::element::Element; + let element = self.upcast::(); + element.get_int_attribute(&atom!($htmlname), $default) } ); - ($attr:ident, $htmlname:expr) => { + + ($attr:ident, $htmlname:tt) => { make_int_getter!($attr, $htmlname, 0); }; - ($attr:ident) => { - make_int_getter!($attr, to_lower!(stringify!($attr))); - } ); #[macro_export] diff --git a/tests/unit/script/textinput.rs b/tests/unit/script/textinput.rs index 75a49c824dc..c5071f36090 100644 --- a/tests/unit/script/textinput.rs +++ b/tests/unit/script/textinput.rs @@ -23,11 +23,11 @@ fn text_input(lines: Lines, s: &str) -> TextInput { #[test] fn test_set_content_ignores_max_length() { let mut textinput = TextInput::new( - Lines::Single, "".to_owned(), DummyClipboardContext::new(""), Some(1) + Lines::Single, DOMString::from(""), DummyClipboardContext::new(""), Some(1) ); - textinput.set_content("mozilla rocks".to_owned()); - assert_eq!(textinput.get_content(), "mozilla rocks".to_owned()); + textinput.set_content(DOMString::from("mozilla rocks")); + assert_eq!(textinput.get_content(), DOMString::from("mozilla rocks")); } #[test] From 5450d49f5782edc941f925cb803255366529171e Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Sun, 13 Sep 2015 11:25:58 +1000 Subject: [PATCH 05/14] Removes failure expectations for input.maxLength WPT tests --- .../wpt/metadata/html/dom/interfaces.html.ini | 6 - .../html/dom/reflection-forms.html.ini | 183 ------------------ 2 files changed, 189 deletions(-) diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index a292516b1e5..c4a3f9fbaad 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -4860,9 +4860,6 @@ [HTMLInputElement interface: attribute max] expected: FAIL - [HTMLInputElement interface: attribute maxLength] - expected: FAIL - [HTMLInputElement interface: attribute min] expected: FAIL @@ -4983,9 +4980,6 @@ [HTMLInputElement interface: document.createElement("input") must inherit property "max" with the proper type (19)] expected: FAIL - [HTMLInputElement interface: document.createElement("input") must inherit property "maxLength" with the proper type (20)] - expected: FAIL - [HTMLInputElement interface: document.createElement("input") must inherit property "min" with the proper type (21)] expected: FAIL diff --git a/tests/wpt/metadata/html/dom/reflection-forms.html.ini b/tests/wpt/metadata/html/dom/reflection-forms.html.ini index 21effce681d..0084a038644 100644 --- a/tests/wpt/metadata/html/dom/reflection-forms.html.ini +++ b/tests/wpt/metadata/html/dom/reflection-forms.html.ini @@ -4977,189 +4977,6 @@ [input.max: IDL set to object "test-valueOf" followed by IDL get] expected: FAIL - [input.maxLength: typeof IDL attribute] - expected: FAIL - - [input.maxLength: IDL get with DOM attribute unset] - expected: FAIL - - [input.maxLength: setAttribute() to -2147483649 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to -2147483648 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to -36 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to -1 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to -0 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to 0 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to 1 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to 2147483647 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to 2147483648 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to 4294967295 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to 4294967296 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "-1" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "-0" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "0" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "1" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "\\t7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "\\v7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "\\f7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "\\n7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "\\r7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "
7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "
7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "᠎7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to " 7" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to undefined followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to 1.5 followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to true followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to false followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to object "[object Object\]" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to NaN followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to Infinity followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to -Infinity followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to "\\0" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to object "2" followed by IDL get] - expected: FAIL - - [input.maxLength: setAttribute() to object "3" followed by IDL get] - expected: FAIL - - [input.maxLength: IDL set to -2147483648 must throw INDEX_SIZE_ERR] - expected: FAIL - - [input.maxLength: IDL set to -36 must throw INDEX_SIZE_ERR] - expected: FAIL - - [input.maxLength: IDL set to -1 must throw INDEX_SIZE_ERR] - expected: FAIL - - [input.maxLength: IDL set to 0 followed by getAttribute()] - expected: FAIL - - [input.maxLength: IDL set to 1 followed by getAttribute()] - expected: FAIL - - [input.maxLength: IDL set to 2147483647 followed by getAttribute()] - expected: FAIL - [input.min: typeof IDL attribute] expected: FAIL From ecc7035de6f4a2de624b01aaaa2d269065703ced Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Sun, 13 Sep 2015 12:14:36 +1000 Subject: [PATCH 06/14] Correct the default max length --- components/script/dom/htmlinputelement.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index c23f73f3220..4ce74d29cde 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -630,7 +630,7 @@ impl VirtualMethods for HTMLInputElement { &atom!("name") => AttrValue::from_atomic(value), &atom!("size") => AttrValue::from_limited_u32(value, DEFAULT_INPUT_SIZE), &atom!("type") => AttrValue::from_atomic(value), - &atom!("maxlength") => AttrValue::from_i32(value, i32::MAX), + &atom!("maxlength") => AttrValue::from_limited_i32(value, DEFAULT_MAX_LENGTH), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } From 32627a475a17f8dd5c0e213de189f16de01ef835 Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Tue, 15 Sep 2015 21:22:30 +1200 Subject: [PATCH 07/14] Add maxlength manual test for input --- .../the-input-element/maxlength-manual.html | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength-manual.html diff --git a/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength-manual.html b/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength-manual.html new file mode 100644 index 00000000000..fdf6c264410 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength-manual.html @@ -0,0 +1,37 @@ + + + + + input max length + + + + + + + +
+

Type a letter anywhere into the input field (do not select any text, or otherwise manipulate the input)

+ + + + + + From 85b99f8ba45d0330b1d4a57161cf97c8b02b9dcd Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Wed, 2 Dec 2015 12:13:11 +1100 Subject: [PATCH 08/14] Fix typo in error message --- components/script/dom/htmlinputelement.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 4ce74d29cde..be02f62314b 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -609,7 +609,7 @@ impl VirtualMethods for HTMLInputElement { self.textinput.borrow_mut().max_length = Some(value as usize) } }, - _ => panic!("Expected an AttrValue::UInt"), + _ => panic!("Expected an AttrValue::Int"), } } &atom!("placeholder") => { From 6d1624f9d061e025df616ead4a21b44b7c1b326b Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Fri, 2 Oct 2015 10:50:18 +1000 Subject: [PATCH 09/14] Add additional WPT tests for maxlength parser set --- components/script/dom/htmlinputelement.rs | 1 - .../forms/the-input-element/maxlength.html | 61 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength.html diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index be02f62314b..19f5d53ef8b 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -32,7 +32,6 @@ use msg::constellation_msg::ScriptMsg as ConstellationMsg; use selectors::states::*; use std::borrow::ToOwned; use std::cell::Cell; -use std::i32; use string_cache::Atom; use textinput::KeyReaction::{DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction}; use textinput::Lines::Single; diff --git a/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength.html b/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength.html new file mode 100644 index 00000000000..59c97198be5 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength.html @@ -0,0 +1,61 @@ + + + + input max length + + + + + + + +

Text input element

+ +
+ + + + + +
+ +
+ + + + + From 51ca659f8a10e94f37538f5a062d567f89a70951 Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Thu, 8 Oct 2015 16:15:53 +1100 Subject: [PATCH 10/14] Add maxlength wpt to manifest --- tests/wpt/metadata/MANIFEST.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index c244304742d..67d9096c27f 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -18087,6 +18087,10 @@ "path": "html/semantics/forms/the-input-element/week.html", "url": "/html/semantics/forms/the-input-element/week.html" }, + { + "path": "html/semantics/forms/the-input-element/maxlength.html", + "url": "/html/semantics/forms/the-input-element/maxlength.html" + }, { "path": "html/semantics/forms/the-label-element/label-attributes.html", "url": "/html/semantics/forms/the-label-element/label-attributes.html" From 9668500e97eda6153a9e99da4e6ee665d6a794ff Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Wed, 2 Dec 2015 13:35:05 +1100 Subject: [PATCH 11/14] Makes setting negative values to maxLength throw an IndexSize exception --- components/script/dom/element.rs | 5 ++- components/script/dom/htmlinputelement.rs | 14 ++------ components/script/dom/macros.rs | 20 +++++++++++ .../dom/webidls/HTMLInputElement.webidl | 1 + components/style/attr.rs | 16 +++++++-- tests/unit/style/attr.rs | 33 +++++++++++++++++++ tests/unit/style/lib.rs | 1 + 7 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 tests/unit/style/attr.rs diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index a5897ed80ac..45fbe805b7a 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1109,7 +1109,10 @@ impl Element { } } - // TODO: set_int_attribute(...) + pub fn set_int_attribute(&self, local_name: &Atom, value: i32) { + assert!(&**local_name == local_name.to_ascii_lowercase()); + self.set_attribute(local_name, AttrValue::Int(DOMString::from(value.to_string()), value)); + } pub fn get_uint_attribute(&self, local_name: &Atom, default: u32) -> u32 { assert!(local_name.chars().all(|ch| !ch.is_ascii() || ch.to_ascii_lowercase() == ch)); diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 19f5d53ef8b..6cc4f9fdc69 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -8,8 +8,8 @@ use dom::attr::{Attr, AttrValue}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding; +use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods; use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; @@ -104,7 +104,7 @@ impl InputActivationState { } static DEFAULT_INPUT_SIZE: u32 = 20; -static DEFAULT_MAX_LENGTH : i32 = -1; +static DEFAULT_MAX_LENGTH: i32 = -1; impl HTMLInputElement { fn new_inherited(localName: DOMString, prefix: Option, document: &Document) -> HTMLInputElement { @@ -344,15 +344,7 @@ impl HTMLInputElementMethods for HTMLInputElement { make_int_getter!(MaxLength, "maxlength", DEFAULT_MAX_LENGTH); // https://html.spec.whatwg.org/multipage/#dom-input-maxlength - fn SetMaxLength(&self, val: i32) { - self.maxlength.set(val); - - if val >= 0 { - self.textinput.borrow_mut().max_length = Some(val as usize) - } else { - self.textinput.borrow_mut().max_length = None - } - } + make_limited_int_setter!(SetMaxLength, "maxlength", DEFAULT_MAX_LENGTH); // https://html.spec.whatwg.org/multipage/#dom-input-indeterminate fn Indeterminate(&self) -> bool { diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 8029bb85b2f..99b4e484752 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -26,6 +26,26 @@ macro_rules! make_bool_getter( ); ); +#[macro_export] +macro_rules! make_limited_int_setter( + ($attr:ident, $htmlname:tt, $default:expr) => ( + fn $attr(&self, value: i32) -> $crate::dom::bindings::error::ErrorResult { + use dom::bindings::inheritance::Castable; + use dom::element::Element; + + let value = if value < 0 { + return Err($crate::dom::bindings::error::Error::IndexSize); + } else { + value + }; + + let element = self.upcast::(); + element.set_int_attribute(&atom!($htmlname), value); + Ok(()) + } + ); +); + #[macro_export] macro_rules! make_int_getter( ($attr:ident, $htmlname:tt, $default:expr) => ( diff --git a/components/script/dom/webidls/HTMLInputElement.webidl b/components/script/dom/webidls/HTMLInputElement.webidl index b2b7992f5e0..274a10ce957 100644 --- a/components/script/dom/webidls/HTMLInputElement.webidl +++ b/components/script/dom/webidls/HTMLInputElement.webidl @@ -25,6 +25,7 @@ interface HTMLInputElement : HTMLElement { // attribute DOMString inputMode; //readonly attribute HTMLElement? list; // attribute DOMString max; + [SetterThrows] attribute long maxLength; // attribute DOMString min; // attribute long minLength; diff --git a/components/style/attr.rs b/components/style/attr.rs index e50071e3b3f..0569b235a9c 100644 --- a/components/style/attr.rs +++ b/components/style/attr.rs @@ -5,8 +5,8 @@ use cssparser::RGBA; use std::ops::Deref; use string_cache::{Atom, Namespace}; -use util::str::{DOMString, LengthOrPercentageOrAuto, parse_integer, parse_unsigned_integer, parse_legacy_color, parse_length}; -use util::str::{split_html_space_chars, str_join}; +use util::str::{DOMString, LengthOrPercentageOrAuto, parse_unsigned_integer, parse_legacy_color, parse_length}; +use util::str::{split_html_space_chars, str_join, parse_integer}; use values::specified::{Length}; // Duplicated from script::dom::values. @@ -53,12 +53,22 @@ impl AttrValue { AttrValue::UInt(string, result) } - // https://html.spec.whatwg.org/multipage/infrastructure.html#limited-to-only-non-negative-numbers pub fn from_i32(string: DOMString, default: i32) -> AttrValue { let result = parse_integer(string.chars()).unwrap_or(default); AttrValue::Int(string, result) } + // https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers + pub fn from_limited_i32(string: DOMString, default: i32) -> AttrValue { + let result = parse_integer(string.chars()).unwrap_or(default); + + if result < 0 { + AttrValue::Int(string, default) + } else { + AttrValue::Int(string, result) + } + } + // https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers-greater-than-zero pub fn from_limited_u32(string: DOMString, default: u32) -> AttrValue { let result = parse_unsigned_integer(string.chars()).unwrap_or(default); diff --git a/tests/unit/style/attr.rs b/tests/unit/style/attr.rs new file mode 100644 index 00000000000..d114b65af74 --- /dev/null +++ b/tests/unit/style/attr.rs @@ -0,0 +1,33 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use style::attr::AttrValue; +use util::str::DOMString; + +#[test] +fn test_from_limited_i32_should_be_default_when_less_than_0() { + let value = DOMString::from("-1"); + match AttrValue::from_limited_i32(value, 0) { + AttrValue::Int(_, 0) => (), + _ => panic!("expected an IndexSize error") + } +} + +#[test] +fn test_from_limited_i32_should_parse_a_uint_when_value_is_0_or_greater() { + match AttrValue::from_limited_i32(DOMString::from("1"), 0) { + AttrValue::Int(_, 1) => (), + _ => panic!("expected an successful parsing") + } +} + +#[test] +fn test_from_limited_i32_should_keep_parsed_value_when_not_an_int() { + match AttrValue::from_limited_i32(DOMString::from("parsed-value"), 0) { + AttrValue::Int(p, 0) => { + assert_eq!(p, DOMString::from("parsed_value")) + }, + _ => panic!("expected an successful parsing") + } +} diff --git a/tests/unit/style/lib.rs b/tests/unit/style/lib.rs index 4963607fb7c..a405d76108d 100644 --- a/tests/unit/style/lib.rs +++ b/tests/unit/style/lib.rs @@ -20,6 +20,7 @@ extern crate util; #[cfg(test)] mod stylesheets; #[cfg(test)] mod media_queries; #[cfg(test)] mod viewport; +#[cfg(test)] mod attr; #[cfg(test)] mod writing_modes { use style::properties::{INITIAL_VALUES, get_writing_mode}; From 7ba43913c2b7289d1120109d431741cac69eeac2 Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Wed, 2 Dec 2015 15:19:31 +1100 Subject: [PATCH 12/14] Uses `assert_throws` instead of explicit try/catch --- .../semantics/forms/the-input-element/maxlength.html | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength.html b/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength.html index 59c97198be5..8f0a2567d40 100644 --- a/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength.html +++ b/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/maxlength.html @@ -39,15 +39,9 @@ test( function() { - try { + assert_throws("INDEX_SIZE_ERR", function() { document.getElementById("assign-negative").maxLength = -5; - } catch (e) { - if (e.name == "IndexSizeError") { - return; - } - } - - throw new Error("expected IndexSizeError"); + }); }, "Assigning negative integer throws IndexSizeError"); test( From d375ac271d15a04cbc80cd1670af49ada1da38ed Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Wed, 2 Dec 2015 16:48:16 +1100 Subject: [PATCH 13/14] Fix manifest update --- tests/wpt/metadata/MANIFEST.json | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 67d9096c27f..c1facfac86e 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -18011,6 +18011,10 @@ "path": "html/semantics/forms/the-input-element/input-type-checkbox.html", "url": "/html/semantics/forms/the-input-element/input-type-checkbox.html" }, + { + "path": "html/semantics/forms/the-input-element/maxlength.html", + "url": "/html/semantics/forms/the-input-element/maxlength.html" + }, { "path": "html/semantics/forms/the-input-element/month.html", "url": "/html/semantics/forms/the-input-element/month.html" @@ -18087,10 +18091,6 @@ "path": "html/semantics/forms/the-input-element/week.html", "url": "/html/semantics/forms/the-input-element/week.html" }, - { - "path": "html/semantics/forms/the-input-element/maxlength.html", - "url": "/html/semantics/forms/the-input-element/maxlength.html" - }, { "path": "html/semantics/forms/the-label-element/label-attributes.html", "url": "/html/semantics/forms/the-label-element/label-attributes.html" @@ -30133,7 +30133,16 @@ }, "local_changes": { "deleted": [], - "items": {}, + "items": { + "manual": { + "html/semantics/forms/the-input-element/maxlength-manual.html": [ + { + "path": "html/semantics/forms/the-input-element/maxlength-manual.html", + "url": "/html/semantics/forms/the-input-element/maxlength-manual.html" + } + ] + } + }, "reftest_nodes": {} }, "reftest_nodes": { From 4befd2cfb0419a90efae391b1ecebb31c728bb6d Mon Sep 17 00:00:00 2001 From: Sam Gibson Date: Thu, 3 Dec 2015 14:10:25 +1100 Subject: [PATCH 14/14] Fixes typo in test literal --- tests/unit/style/attr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/style/attr.rs b/tests/unit/style/attr.rs index d114b65af74..7aca499beae 100644 --- a/tests/unit/style/attr.rs +++ b/tests/unit/style/attr.rs @@ -26,7 +26,7 @@ fn test_from_limited_i32_should_parse_a_uint_when_value_is_0_or_greater() { fn test_from_limited_i32_should_keep_parsed_value_when_not_an_int() { match AttrValue::from_limited_i32(DOMString::from("parsed-value"), 0) { AttrValue::Int(p, 0) => { - assert_eq!(p, DOMString::from("parsed_value")) + assert_eq!(p, DOMString::from("parsed-value")) }, _ => panic!("expected an successful parsing") }