Sync web-platform-tests up to revision a5b95cb31914507088a4eda16f7674bbc6f3313f
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / html / semantics / forms / textfieldselection / selection-not-application.html
1 <!DOCTYPE html>
2 <meta charset=utf-8>
3 <title>text field selection</title>
4 <link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org">
5 <link rel=help href="https://html.spec.whatwg.org/multipage/#textFieldSelection">
6 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
8 <div id="log"></div>
9 <script>
10   var types = ["hidden", "email", "datetime-local", "date", "month", "week", "time", "number", "range", "color", "checkbox", "radio", "file", "submit", "image", "reset", "button"]; //types for which the API doesn't apply
11   var types2 = ["text", "search", "tel", "url", "password"]; //types for which the API applies
12
13   types.forEach(function(type){
14     test(function(){
15       var el = document.createElement("input");
16       el.type = type;
17       assert_equals(el.selectionStart, null);
18       assert_equals(el.selectionEnd, null);
19       assert_equals(el.selectionDirection, null);
20       assert_throws("InvalidStateError", function(){
21         el.selectionStart = 0;
22       });
23       assert_throws("InvalidStateError", function(){
24         el.selectionEnd = 0;
25       });
26       assert_throws("InvalidStateError", function(){
27         el.selectionDirection = 'none';
28       });
29       assert_throws("InvalidStateError", function(){
30         el.setRangeText("foobar");
31       });
32       assert_throws("InvalidStateError", function(){
33         el.setSelectionRange(0, 1);
34       });
35     }, "text field selection for the input " + type);
36   });
37
38   types2.forEach(function(type) {
39     test(function() {
40       var el = document.createElement("input");
41       el.type = type;
42       assert_equals(el.selectionStart, 0);
43       assert_equals(el.selectionEnd, 0);
44       el.selectionStart = 1;
45       el.selectionEnd = 1;
46       el.selectionDirection = "forward";
47       el.setRangeText("foobar");
48       el.setSelectionRange(0, 1);
49     }, "text field selection for the input " + type);
50   });
51 </script>