https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 9f7520e98307e7c61ad3a39b6dc1a2d1ecf96b75 authored by Anne van Kesteren on 13 September 2016, 09:05:52 UTC
Test for specific cross-origin object exceptions
Tip revision: 9f7520e
selection-not-application.html
<!DOCTYPE html>
<meta charset=utf-8>
<title>text field selection</title>
<link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org">
<link rel=help href="https://html.spec.whatwg.org/multipage/#textFieldSelection">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
  var types = ["hidden", "email", "datetime", "date", "month", "week", "time", "number", "range", "color", "checkbox", "radio", "file", "submit", "image", "reset", "button"]; //types for which the API doesn't apply
  var types2 = ["text", "search", "tel", "url", "password"]; //types for which the API applies

  types.forEach(function(type){
    test(function(){
      var el = document.createElement("input");
      el.type = type;
      assert_throws("InvalidStateError", function(){
        el.selectionStart;
      });
      assert_throws("InvalidStateError", function(){
        el.selectionEnd;
      });
      assert_throws("InvalidStateError", function(){
        el.selectionDirection;
      });
      assert_throws("InvalidStateError", function(){
        el.setRangeText("foobar");
      });
      assert_throws("InvalidStateError", function(){
        el.setSelectionRange(0, 1);
      });
    }, "text field selection for the input " + type);
  });

  types2.forEach(function(type) {
    test(function() {
      var el = document.createElement("input");
      el.type = type;
      assert_equals(el.selectionStart, 0);
      assert_equals(el.selectionEnd, 0);
      el.selectionStart = 1;
      el.selectionEnd = 1;
      el.selectionDirection = "forward";
      el.setRangeText("foobar");
      el.setSelectionRange(0, 1);
    }, "text field selection for the input " + type);
  });
</script>
back to top