Handle cases where selection API doesn't apply

The selection API only applies to certain <input> types:

https://html.spec.whatwg.org/multipage/#do-not-apply

This commit ensures that we handle that correctly.

Some notes:

1. TextControl::set_dom_selection_direction now calls
   set_selection_range(), which means that setting selectionDirection will
   now fire a selection event, as it should per the spec.

2. There is a test for the firing of the select event in
   tests/wpt/web-platform-tests/html/semantics/forms/textfieldselection/select-event.html,
   however the test did not run due to this syntax error:

   (pid:26017) "ERROR:script::dom::bindings::error: Error at http://web-platform.test:8000/html/semantics/forms/textfieldselection/select-event.html:50:11 missing = in const declaration"

   This happens due to the us of the "for (const foo of ...)" construct.
   Per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
   this should actually work, so it's somewhat unsatisfying to have to
   change the test.

4. If an <input>'s type is unset, it defaults to a text, and the
   selection API applies. Also, if an <input>'s type is set to an
   invalid value, it defaults to a text too. I've expanded the tests
   to account for this second case.
This commit is contained in:
Jon Leighton 2017-12-02 10:53:50 +01:00
parent e646471888
commit 71a013dd50
12 changed files with 372 additions and 114 deletions

View file

@ -1,23 +1,146 @@
[select-event.html]
type: testharness
[select() on textarea queues select event]
[textarea: select()]
expected: FAIL
[select() on input type text queues select event]
[textarea: select() a second time (must not fire select)]
expected: FAIL
[select() on input type search queues select event]
[textarea: selectionStart a second time (must not fire select)]
expected: FAIL
[select() on input type tel queues select event]
[textarea: selectionEnd a second time (must not fire select)]
expected: FAIL
[select() on input type url queues select event]
[textarea: selectionDirection a second time (must not fire select)]
expected: FAIL
[select() on input type password queues select event]
[textarea: setSelectionRange() a second time (must not fire select)]
expected: FAIL
[text field selection: select()]
[textarea: setRangeText()]
expected: FAIL
[textarea: setRangeText() a second time (must not fire select)]
expected: FAIL
[input type text: select()]
expected: FAIL
[input type text: select() a second time (must not fire select)]
expected: FAIL
[input type text: selectionStart a second time (must not fire select)]
expected: FAIL
[input type text: selectionEnd a second time (must not fire select)]
expected: FAIL
[input type text: selectionDirection a second time (must not fire select)]
expected: FAIL
[input type text: setSelectionRange() a second time (must not fire select)]
expected: FAIL
[input type text: setRangeText()]
expected: FAIL
[input type text: setRangeText() a second time (must not fire select)]
expected: FAIL
[input type search: select()]
expected: FAIL
[input type search: select() a second time (must not fire select)]
expected: FAIL
[input type search: selectionStart a second time (must not fire select)]
expected: FAIL
[input type search: selectionEnd a second time (must not fire select)]
expected: FAIL
[input type search: selectionDirection a second time (must not fire select)]
expected: FAIL
[input type search: setSelectionRange() a second time (must not fire select)]
expected: FAIL
[input type search: setRangeText()]
expected: FAIL
[input type search: setRangeText() a second time (must not fire select)]
expected: FAIL
[input type tel: select()]
expected: FAIL
[input type tel: select() a second time (must not fire select)]
expected: FAIL
[input type tel: selectionStart a second time (must not fire select)]
expected: FAIL
[input type tel: selectionEnd a second time (must not fire select)]
expected: FAIL
[input type tel: selectionDirection a second time (must not fire select)]
expected: FAIL
[input type tel: setSelectionRange() a second time (must not fire select)]
expected: FAIL
[input type tel: setRangeText()]
expected: FAIL
[input type tel: setRangeText() a second time (must not fire select)]
expected: FAIL
[input type url: select()]
expected: FAIL
[input type url: select() a second time (must not fire select)]
expected: FAIL
[input type url: selectionStart a second time (must not fire select)]
expected: FAIL
[input type url: selectionEnd a second time (must not fire select)]
expected: FAIL
[input type url: selectionDirection a second time (must not fire select)]
expected: FAIL
[input type url: setSelectionRange() a second time (must not fire select)]
expected: FAIL
[input type url: setRangeText()]
expected: FAIL
[input type url: setRangeText() a second time (must not fire select)]
expected: FAIL
[input type password: select()]
expected: FAIL
[input type password: select() a second time (must not fire select)]
expected: FAIL
[input type password: selectionStart a second time (must not fire select)]
expected: FAIL
[input type password: selectionEnd a second time (must not fire select)]
expected: FAIL
[input type password: selectionDirection a second time (must not fire select)]
expected: FAIL
[input type password: setSelectionRange() a second time (must not fire select)]
expected: FAIL
[input type password: setRangeText()]
expected: FAIL
[input type password: setRangeText() a second time (must not fire select)]
expected: FAIL

View file

@ -1,71 +1,74 @@
[selection-not-application.html]
type: testharness
[text field selection for the input hidden]
[setRangeText on an input[type=hidden\] throws InvalidStateError]
expected: FAIL
[text field selection for the input email]
[setRangeText on an input[type=email\] throws InvalidStateError]
expected: FAIL
[text field selection for the input datetime]
[setRangeText on an input[type=datetime-local\] throws InvalidStateError]
expected: FAIL
[text field selection for the input date]
[setRangeText on an input[type=date\] throws InvalidStateError]
expected: FAIL
[text field selection for the input month]
[setRangeText on an input[type=month\] throws InvalidStateError]
expected: FAIL
[text field selection for the input week]
[setRangeText on an input[type=week\] throws InvalidStateError]
expected: FAIL
[text field selection for the input time]
[setRangeText on an input[type=time\] throws InvalidStateError]
expected: FAIL
[text field selection for the input number]
[setRangeText on an input[type=number\] throws InvalidStateError]
expected: FAIL
[text field selection for the input range]
[setRangeText on an input[type=range\] throws InvalidStateError]
expected: FAIL
[text field selection for the input color]
[setRangeText on an input[type=color\] throws InvalidStateError]
expected: FAIL
[text field selection for the input checkbox]
[setRangeText on an input[type=checkbox\] throws InvalidStateError]
expected: FAIL
[text field selection for the input radio]
[setRangeText on an input[type=radio\] throws InvalidStateError]
expected: FAIL
[text field selection for the input file]
[setRangeText on an input[type=file\] throws InvalidStateError]
expected: FAIL
[text field selection for the input submit]
[setRangeText on an input[type=submit\] throws InvalidStateError]
expected: FAIL
[text field selection for the input image]
[setRangeText on an input[type=image\] throws InvalidStateError]
expected: FAIL
[text field selection for the input reset]
[setRangeText on an input[type=reset\] throws InvalidStateError]
expected: FAIL
[text field selection for the input button]
[setRangeText on an input[type=button\] throws InvalidStateError]
expected: FAIL
[text field selection for the input text]
[setRangeText on an input[type=text\] doesn't throw an exception]
expected: FAIL
[text field selection for the input search]
[setRangeText on an input[type=search\] doesn't throw an exception]
expected: FAIL
[text field selection for the input tel]
[setRangeText on an input[type=tel\] doesn't throw an exception]
expected: FAIL
[text field selection for the input url]
[setRangeText on an input[type=url\] doesn't throw an exception]
expected: FAIL
[text field selection for the input password]
[setRangeText on an input[type=password\] doesn't throw an exception]
expected: FAIL
[text field selection for the input datetime-local]
[setRangeText on an input[type=null\] doesn't throw an exception]
expected: FAIL
[setRangeText on an input[type=aninvalidtype\] doesn't throw an exception]
expected: FAIL