Commit 42a73985 authored by Stephen Sigwart's avatar Stephen Sigwart Committed by Commit Bot

Added additional number input validation tests.

Bug: 365196
Change-Id: I71f74169589ac768f8c8299c9683ec82be2eb9b5
Cq-Do-Not-Cancel-Tryjobs: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2331518
Commit-Queue: Stephen Sigwart <ssigwart@gmail.com>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797984}
parent 5c606c3c
...@@ -709,6 +709,22 @@ void HTMLInputElement::setSelectionRangeForBinding( ...@@ -709,6 +709,22 @@ void HTMLInputElement::setSelectionRangeForBinding(
TextControlElement::setSelectionRangeForBinding(start, end, direction); TextControlElement::setSelectionRangeForBinding(start, end, direction);
} }
// This function can be used to allow tests to set the selection
// range for Number inputs, which do not support the ordinary
// selection API.
void HTMLInputElement::SetSelectionRangeForTesting(
unsigned start,
unsigned end,
ExceptionState& exception_state) {
if (FormControlType() != input_type_names::kNumber) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
"The input element's type ('" +
input_type_->FormControlType() +
"') is not a number input.");
}
TextControlElement::setSelectionRangeForBinding(start, end);
}
void HTMLInputElement::AccessKeyAction(bool send_mouse_events) { void HTMLInputElement::AccessKeyAction(bool send_mouse_events) {
input_type_view_->AccessKeyAction(send_mouse_events); input_type_view_->AccessKeyAction(send_mouse_events);
} }
......
...@@ -196,6 +196,12 @@ class CORE_EXPORT HTMLInputElement ...@@ -196,6 +196,12 @@ class CORE_EXPORT HTMLInputElement
unsigned end, unsigned end,
const String& direction, const String& direction,
ExceptionState&); ExceptionState&);
// This function can be used to allow tests to set the selection
// range for Number inputs, which do not support the ordinary
// selection API.
void SetSelectionRangeForTesting(unsigned start,
unsigned end,
ExceptionState&);
bool LayoutObjectIsNeeded(const ComputedStyle&) const final; bool LayoutObjectIsNeeded(const ComputedStyle&) const final;
LayoutObject* CreateLayoutObject(const ComputedStyle&, LegacyLayout) override; LayoutObject* CreateLayoutObject(const ComputedStyle&, LegacyLayout) override;
......
...@@ -1476,6 +1476,23 @@ void Internals::setAutofilled(Element* element, ...@@ -1476,6 +1476,23 @@ void Internals::setAutofilled(Element* element,
enabled ? WebAutofillState::kAutofilled : WebAutofillState::kNotFilled); enabled ? WebAutofillState::kAutofilled : WebAutofillState::kNotFilled);
} }
void Internals::setSelectionRangeForNumberType(
Element* input_element,
uint32_t start,
uint32_t end,
ExceptionState& exception_state) {
DCHECK(input_element);
auto* html_input_element = DynamicTo<HTMLInputElement>(input_element);
if (!html_input_element) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidNodeTypeError,
"The element provided is not an input element.");
return;
}
html_input_element->SetSelectionRangeForTesting(start, end, exception_state);
}
Range* Internals::rangeFromLocationAndLength(Element* scope, Range* Internals::rangeFromLocationAndLength(Element* scope,
int range_location, int range_location,
int range_length) { int range_length) {
......
...@@ -237,6 +237,10 @@ class Internals final : public ScriptWrappable { ...@@ -237,6 +237,10 @@ class Internals final : public ScriptWrappable {
void setAutofilledValue(Element*, const String&, ExceptionState&); void setAutofilledValue(Element*, const String&, ExceptionState&);
void setEditingValue(Element* input_element, const String&, ExceptionState&); void setEditingValue(Element* input_element, const String&, ExceptionState&);
void setAutofilled(Element*, bool enabled, ExceptionState&); void setAutofilled(Element*, bool enabled, ExceptionState&);
void setSelectionRangeForNumberType(Element* input_element,
uint32_t start,
uint32_t end,
ExceptionState&);
Range* rangeFromLocationAndLength(Element* scope, Range* rangeFromLocationAndLength(Element* scope,
int range_location, int range_location,
......
...@@ -130,6 +130,7 @@ ...@@ -130,6 +130,7 @@
[RaisesException] void setAutofilledValue(Element inputElement, DOMString value); [RaisesException] void setAutofilledValue(Element inputElement, DOMString value);
[RaisesException] void setEditingValue(Element inputElement, DOMString value); [RaisesException] void setEditingValue(Element inputElement, DOMString value);
[RaisesException] void setAutofilled(Element inputElement, boolean enabled); [RaisesException] void setAutofilled(Element inputElement, boolean enabled);
[RaisesException] void setSelectionRangeForNumberType(Element inputElement, unsigned long start, unsigned long end);
Range rangeFromLocationAndLength(Element scope, long rangeLocation, long rangeLength); Range rangeFromLocationAndLength(Element scope, long rangeLocation, long rangeLength);
unsigned long locationFromRange(Element scope, Range range); unsigned long locationFromRange(Element scope, Range range);
......
...@@ -293,9 +293,9 @@ void Locale::SetLocaleData(const Vector<String, kDecimalSymbolsSize>& symbols, ...@@ -293,9 +293,9 @@ void Locale::SetLocaleData(const Vector<String, kDecimalSymbolsSize>& symbols,
// zero length positive prefix. // zero length positive prefix.
uses_single_char_number_filtering_ = false; uses_single_char_number_filtering_ = false;
if (decimal_symbols_[kDecimalSeparatorIndex].length() == 1 && if (decimal_symbols_[kDecimalSeparatorIndex].length() == 1 &&
(positive_prefix_.length() == 0 || positive_prefix_.length() == 1) && positive_prefix_.length() <= 1 && negative_prefix_.length() == 1 &&
negative_prefix_.length() == 1 && positive_suffix_.length() == 0 && positive_suffix_.length() == 0 && negative_suffix_.length() == 0 &&
negative_suffix_.length() == 0) { !IsRTL()) {
uses_single_char_number_filtering_ = true; uses_single_char_number_filtering_ = true;
for (wtf_size_t i = 0; i <= 9; ++i) { for (wtf_size_t i = 0; i <= 9; ++i) {
if (decimal_symbols_[i].length() != 1) { if (decimal_symbols_[i].length() != 1) {
......
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