Skip to content

Commit

Permalink
Added additional number input validation tests.
Browse files Browse the repository at this point in the history
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: Kent Tamura <tkent@chromium.org>
Reviewed-by: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797984}
  • Loading branch information
ssigwart authored and Commit Bot committed Aug 14, 2020
1 parent 5c606c3 commit 42a7398
Show file tree
Hide file tree
Showing 8 changed files with 423 additions and 85 deletions.
16 changes: 16 additions & 0 deletions third_party/blink/renderer/core/html/forms/html_input_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,22 @@ void HTMLInputElement::setSelectionRangeForBinding(
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) {
input_type_view_->AccessKeyAction(send_mouse_events);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ class CORE_EXPORT HTMLInputElement
unsigned end,
const String& direction,
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;
LayoutObject* CreateLayoutObject(const ComputedStyle&, LegacyLayout) override;
Expand Down
17 changes: 17 additions & 0 deletions third_party/blink/renderer/core/testing/internals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,23 @@ void Internals::setAutofilled(Element* element,
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,
int range_location,
int range_length) {
Expand Down
4 changes: 4 additions & 0 deletions third_party/blink/renderer/core/testing/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ class Internals final : public ScriptWrappable {
void setAutofilledValue(Element*, const String&, ExceptionState&);
void setEditingValue(Element* input_element, const String&, ExceptionState&);
void setAutofilled(Element*, bool enabled, ExceptionState&);
void setSelectionRangeForNumberType(Element* input_element,
uint32_t start,
uint32_t end,
ExceptionState&);

Range* rangeFromLocationAndLength(Element* scope,
int range_location,
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/core/testing/internals.idl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
[RaisesException] void setAutofilledValue(Element inputElement, DOMString value);
[RaisesException] void setEditingValue(Element inputElement, DOMString value);
[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);
unsigned long locationFromRange(Element scope, Range range);
Expand Down
6 changes: 3 additions & 3 deletions third_party/blink/renderer/platform/text/platform_locale.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ void Locale::SetLocaleData(const Vector<String, kDecimalSymbolsSize>& symbols,
// zero length positive prefix.
uses_single_char_number_filtering_ = false;
if (decimal_symbols_[kDecimalSeparatorIndex].length() == 1 &&
(positive_prefix_.length() == 0 || positive_prefix_.length() == 1) &&
negative_prefix_.length() == 1 && positive_suffix_.length() == 0 &&
negative_suffix_.length() == 0) {
positive_prefix_.length() <= 1 && negative_prefix_.length() == 1 &&
positive_suffix_.length() == 0 && negative_suffix_.length() == 0 &&
!IsRTL()) {
uses_single_char_number_filtering_ = true;
for (wtf_size_t i = 0; i <= 9; ++i) {
if (decimal_symbols_[i].length() != 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,186 @@
Arabic number input should accept ASCII digits and Arabic digits, and reject others.
PASS displayValueForKeyInput(arabicInput, "123.4") is "123.4"
PASS displayValueForKeyInput(arabicInput, "1.23E+19") is "1.23E+19"
PASS displayValueForKeyInput(arabicInput, "1.23e-1") is "1.23e-1"
PASS displayValueForKeyInput(arabicInput, "١٩٠") is "١٩٠"
PASS displayValueForKeyInput(arabicInput, "acdef") is "e"
PASS 123.4 is 123.4
PASS displayValueForKeyInput(input_ar, "123.4", "", 123.4) is "123.4"
PASS 1.23E+19 is 12300000000000000000
PASS displayValueForKeyInput(input_ar, "1.23E+19", "", 12300000000000000000) is "1.23E+19"
PASS 1.23e-1 is 0.123
PASS displayValueForKeyInput(input_ar, "1.23e-1", "", 0.123) is "1.23e-1"
PASS 190 is 190
PASS displayValueForKeyInput(input_ar, "١٩٠", "", 190) is "١٩٠"
PASS is undefined.
PASS displayValueForKeyInput(input_ar, "acdef", "", undefined) is "e"


French number input should accept ASCII digits, comma, and full stop.
PASS displayValueForKeyInput(frenchInput, "1234.56") is "1234.56"
FAIL displayValueForKeyInput(frenchInput, "1234,56") should be 1234.56. Was 1234,56.
PASS 1234.56 is 1234.56
PASS displayValueForKeyInput(input_fr, "1234.56", "", 1234.56) is "1234.56"
PASS 1234.56 is 1234.56
PASS displayValueForKeyInput(input_fr, "1234,56", "", 1234.56) is "1234,56"


English number input should accept ASCII digits and full stop, and no comma.
PASS displayValueForKeyInput(englishInput, "1234.56") is "1234.56"
PASS displayValueForKeyInput(englishInput, "-1234,56") is "-123456"
PASS displayValueForKeyInput(englishInput, " 1234.56 ") is "1234.56"
PASS displayValueForKeyInput(englishInput, "123,456,789E+10") is "123456789E+10"
PASS displayValueForKeyInput(englishInput, ".", "1|e2") is "1.e2"
PASS displayValueForKeyInput(englishInput, ".", "1e2|") is "1e2"
PASS displayValueForKeyInput(englishInput, ".", "|-12") is "-12"
PASS displayValueForKeyInput(englishInput, ".", "|1e-12") is ".1e-12"
PASS displayValueForKeyInput(englishInput, "e", "12|34") is "12e34"
PASS displayValueForKeyInput(englishInput, "e", "12|3e4") is "123e4"
PASS displayValueForKeyInput(englishInput, "e", "123|.4") is "123.4"
PASS displayValueForKeyInput(englishInput, "e", "12.3|4") is "12.3e4"
PASS displayValueForKeyInput(englishInput, "+", "12|34") is "12+34"
PASS displayValueForKeyInput(englishInput, "+", "-1|2e-34") is "-12e-34"
PASS displayValueForKeyInput(englishInput, "+", "|1234") is "+1234"
PASS displayValueForKeyInput(englishInput, "-", "123e|4") is "123e-4"
PASS displayValueForKeyInput(englishInput, "-", "1|23e4") is "123e4"
PASS displayValueForKeyInput(englishInput, "-", "123e4|") is "123e4"
PASS displayValueForKeyInput(englishInput, "9", "|-1") is "-1"
PASS displayValueForKeyInput(englishInput, "9", "-|1") is "-91"
PASS displayValueForKeyInput(englishInput, "9", "1e|+2") is "1e+2"
PASS displayValueForKeyInput(englishInput, "9", "1e+|2") is "1e+92"
PASS displayValueForKeyInput(englishInput, " abcdef ") is "e"
PASS displayValueForKeyInput(englishInput, "+1-2") is "+1-2"
PASS displayValueForKeyInput(englishInput, "+1-2+2-3") is "+1-223"
PASS displayValueForKeyInput(englishInput, "0-123-123+123") is "0-123-123123"
PASS displayValueForKeyInput(englishInput, "10e123123e1231233e") is "10e1231231231233"
PASS displayValueForKeyInput(englishInput, "1e2eee") is "1e2"
PASS displayValueForKeyInput(englishInput, "1e1e1e1e") is "1e111"
PASS 1234.56 is 1234.56
PASS displayValueForKeyInput(input_en, "1234.56", "", 1234.56) is "1234.56"
PASS -123456 is -123456
PASS displayValueForKeyInput(input_en, "-1234,56", "", -123456) is "-123456"
PASS 1234.56 is 1234.56
PASS displayValueForKeyInput(input_en, " 1234.56 ", "", 1234.56) is "1234.56"
PASS window.getSelection().toString() is "-1-1"
PASS -1e-1 is -0.1
PASS displayValueForKeyInput(input_en, "e", "-1|-1", -0.1) is "-1e-1"


Test all locales.
PASS 123456789E+10 is 1234567890000000000
PASS displayValueForKeyInput(input_en, "123,456,789E+10", "", 1234567890000000000) is "123456789E+10"
PASS window.getSelection().toString() is "1e2"
PASS 1.e2 is 100
PASS displayValueForKeyInput(input_fr, ".", "1|e2", 100) is "1.e2"
PASS window.getSelection().toString() is "1e2"
PASS 1.e2 is 100
PASS displayValueForKeyInput(input_en, ".", "1|e2", 100) is "1.e2"
PASS window.getSelection().toString() is "1e2"
PASS 1e2 is 100
PASS displayValueForKeyInput(input_fr, ",", "1e2|", 100) is "1e2"
PASS window.getSelection().toString() is "1e2"
PASS 1e2 is 100
PASS displayValueForKeyInput(input_en, ".", "1e2|", 100) is "1e2"
PASS window.getSelection().toString() is "-12"
PASS -12 is -12
PASS displayValueForKeyInput(input_fr, ",", "|-12", -12) is "-12"
PASS window.getSelection().toString() is "-12"
PASS -12 is -12
PASS displayValueForKeyInput(input_en, ".", "|-12", -12) is "-12"
PASS window.getSelection().toString() is "1e-12"
PASS .1e-12 is 1e-13
PASS displayValueForKeyInput(input_fr, ".", "|1e-12", 1e-13) is ".1e-12"
PASS window.getSelection().toString() is "1e-12"
PASS .1e-12 is 1e-13
PASS displayValueForKeyInput(input_en, ".", "|1e-12", 1e-13) is ".1e-12"
PASS window.getSelection().toString() is "3412"
PASS 34e12 is 34000000000000
PASS displayValueForKeyInput(input_fr, "e", "34|12", 34000000000000) is "34e12"
PASS window.getSelection().toString() is "3412"
PASS 34e12 is 34000000000000
PASS displayValueForKeyInput(input_en, "e", "34|12", 34000000000000) is "34e12"
PASS window.getSelection().toString() is "123e4"
PASS 123e4 is 1230000
PASS displayValueForKeyInput(input_fr, "e", "12|3e4", 1230000) is "123e4"
PASS window.getSelection().toString() is "123e4"
PASS 123e4 is 1230000
PASS displayValueForKeyInput(input_en, "e", "12|3e4", 1230000) is "123e4"
PASS window.getSelection().toString() is "123,4"
PASS 123.4 is 123.4
PASS displayValueForKeyInput(input_fr, "e", "123|,4", 123.4) is "123,4"
PASS window.getSelection().toString() is "123.4"
PASS 123.4 is 123.4
PASS displayValueForKeyInput(input_en, "e", "123|.4", 123.4) is "123.4"
PASS window.getSelection().toString() is "12.34"
PASS 12.3e4 is 123000
PASS displayValueForKeyInput(input_fr, "e", "12.3|4", 123000) is "12.3e4"
PASS window.getSelection().toString() is "12.34"
PASS 12.3e4 is 123000
PASS displayValueForKeyInput(input_en, "e", "12.3|4", 123000) is "12.3e4"
PASS window.getSelection().toString() is "١٢٣٤"
PASS is undefined.
PASS displayValueForKeyInput(input_ar, "+", "١٢|٣٤", undefined) is "١٢+٣٤"
PASS window.getSelection().toString() is "1234"
PASS is undefined.
PASS displayValueForKeyInput(input_fr, "+", "12|34", undefined) is "12+34"
PASS window.getSelection().toString() is "1234"
PASS is undefined.
PASS displayValueForKeyInput(input_en, "+", "12|34", undefined) is "12+34"
PASS window.getSelection().toString() is "-34e-12"
PASS -34e-12 is -3.4e-11
PASS displayValueForKeyInput(input_fr, "+", "-3|4e-12", -3.4e-11) is "-34e-12"
PASS window.getSelection().toString() is "-34e-12"
PASS -34e-12 is -3.4e-11
PASS displayValueForKeyInput(input_en, "+", "-3|4e-12", -3.4e-11) is "-34e-12"
PASS window.getSelection().toString() is "١٢٣٤"
PASS 1234 is 1234
PASS displayValueForKeyInput(input_ar, "+", "|١٢٣٤", 1234) is "+١٢٣٤"
PASS window.getSelection().toString() is "1234"
PASS 1234 is 1234
PASS displayValueForKeyInput(input_fr, "+", "|1234", 1234) is "+1234"
PASS window.getSelection().toString() is "1234"
PASS 1234 is 1234
PASS displayValueForKeyInput(input_en, "+", "|1234", 1234) is "+1234"
PASS window.getSelection().toString() is "123e4"
PASS 123e-4 is 0.0123
PASS displayValueForKeyInput(input_fr, "-", "123e|4", 0.0123) is "123e-4"
PASS window.getSelection().toString() is "123e4"
PASS 123e-4 is 0.0123
PASS displayValueForKeyInput(input_en, "-", "123e|4", 0.0123) is "123e-4"
PASS window.getSelection().toString() is "123e4"
PASS 123e4 is 1230000
PASS displayValueForKeyInput(input_fr, "-", "1|23e4", 1230000) is "123e4"
PASS window.getSelection().toString() is "123e4"
PASS 123e4 is 1230000
PASS displayValueForKeyInput(input_en, "-", "1|23e4", 1230000) is "123e4"
PASS window.getSelection().toString() is "123e4"
PASS 123e4 is 1230000
PASS displayValueForKeyInput(input_fr, "-", "123e4|", 1230000) is "123e4"
PASS window.getSelection().toString() is "123e4"
PASS 123e4 is 1230000
PASS displayValueForKeyInput(input_en, "-", "123e4|", 1230000) is "123e4"
PASS window.getSelection().toString() is "-1"
PASS -1 is -1
PASS displayValueForKeyInput(input_fr, "9", "|-1", -1) is "-1"
PASS window.getSelection().toString() is "-1"
PASS -1 is -1
PASS displayValueForKeyInput(input_en, "9", "|-1", -1) is "-1"
PASS window.getSelection().toString() is "-1"
PASS -91 is -91
PASS displayValueForKeyInput(input_fr, "9", "-|1", -91) is "-91"
PASS window.getSelection().toString() is "-1"
PASS -91 is -91
PASS displayValueForKeyInput(input_en, "9", "-|1", -91) is "-91"
PASS window.getSelection().toString() is "1e+2"
PASS 1e+2 is 100
PASS displayValueForKeyInput(input_fr, "9", "1e|+2", 100) is "1e+2"
PASS window.getSelection().toString() is "1e+2"
PASS 1e+2 is 100
PASS displayValueForKeyInput(input_en, "9", "1e|+2", 100) is "1e+2"
PASS window.getSelection().toString() is "1e+2"
PASS 1e+12 is 1000000000000
PASS displayValueForKeyInput(input_fr, "1", "1e+|2", 1000000000000) is "1e+12"
PASS window.getSelection().toString() is "1e+2"
PASS 1e+12 is 1000000000000
PASS displayValueForKeyInput(input_en, "1", "1e+|2", 1000000000000) is "1e+12"
PASS is undefined.
PASS displayValueForKeyInput(input_fr, " abcdef ", "", undefined) is "e"
PASS is undefined.
PASS displayValueForKeyInput(input_en, " abcdef ", "", undefined) is "e"
PASS is undefined.
PASS displayValueForKeyInput(input_ar, "+١-٢", "", undefined) is "+١-٢"
PASS is undefined.
PASS displayValueForKeyInput(input_fr, "+1-2", "", undefined) is "+1-2"
PASS is undefined.
PASS displayValueForKeyInput(input_en, "+1-2", "", undefined) is "+1-2"
PASS is undefined.
PASS displayValueForKeyInput(input_ar, "+١-٢+٢-٣", "", undefined) is "+١-٢+٢-٣"
PASS is undefined.
PASS displayValueForKeyInput(input_fr, "+1-2+2-3", "", undefined) is "+1-223"
PASS is undefined.
PASS displayValueForKeyInput(input_en, "+1-2+2-3", "", undefined) is "+1-223"
PASS is undefined.
PASS displayValueForKeyInput(input_ar, "٠-١٢٣-١٢٣+١٢٣", "", undefined) is "٠-١٢٣-١٢٣+١٢٣"
PASS is undefined.
PASS displayValueForKeyInput(input_fr, "0-123-123+123", "", undefined) is "0-123-123123"
PASS is undefined.
PASS displayValueForKeyInput(input_en, "0-123-123+123", "", undefined) is "0-123-123123"
PASS is undefined.
PASS displayValueForKeyInput(input_fr, "10e123123e1231233e", "", undefined) is "10e1231231231233"
PASS is undefined.
PASS displayValueForKeyInput(input_en, "10e123123e1231233e", "", undefined) is "10e1231231231233"
PASS 1e2 is 100
PASS displayValueForKeyInput(input_fr, "1e2eee", "", 100) is "1e2"
PASS 1e2 is 100
PASS displayValueForKeyInput(input_en, "1e2eee", "", 100) is "1e2"
PASS 1e11 is 100000000000
PASS displayValueForKeyInput(input_fr, "1e1e1e", "", 100000000000) is "1e11"
PASS 1e11 is 100000000000
PASS displayValueForKeyInput(input_en, "1e1e1e", "", 100000000000) is "1e11"
PASS successfullyParsed is true

TEST COMPLETE
Expand Down
Loading

0 comments on commit 42a7398

Please sign in to comment.