tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

selection-not-application.html (3981B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <meta name=variant content="?default">
      4 <meta name=variant content="?week,month">
      5 <title>text field selection</title>
      6 <link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org">
      7 <link rel=help href="https://html.spec.whatwg.org/multipage/#textFieldSelection">
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 <div id="log"></div>
     11 <script>
     12  var nonApplicableTypes = ["hidden", "email", "datetime-local", "date", "time", "number", "range", "color", "checkbox", "radio", "file", "submit", "image", "reset", "button"];
     13  var applicableTypes = ["text", "search", "tel", "url", "password", "aninvalidtype", null];
     14 
     15  if (location.search !== "?default") {
     16    // For non default case, use the parameters passed in through query string
     17    // instead of nonApplicableTypes.
     18    nonApplicableTypes = location.search.substr(1).split(',');
     19  }
     20 
     21  nonApplicableTypes.forEach(function(type){
     22    var el = document.createElement("input");
     23    el.type = type;
     24 
     25    test(() => {
     26      assert_equals(el.selectionStart, null);
     27    }, `selectionStart on an input[type=${type}] returns null`);
     28 
     29    test(() => {
     30      assert_equals(el.selectionEnd, null);
     31    }, `selectionEnd on an input[type=${type}] returns null`);
     32 
     33    test(() => {
     34      assert_equals(el.selectionDirection, null);
     35    }, `selectionDirection on an input[type=${type}] returns null`);
     36 
     37    test(() => {
     38      assert_throws_dom("InvalidStateError", function(){
     39        el.selectionStart = 0;
     40      });
     41    }, `assigning selectionStart on an input[type=${type}] throws InvalidStateError`);
     42 
     43    test(() => {
     44      assert_throws_dom("InvalidStateError", function(){
     45        el.selectionEnd = 0;
     46      });
     47    }, `assigning selectionEnd on an input[type=${type}] throws InvalidStateError`);
     48 
     49    test(() => {
     50      assert_throws_dom("InvalidStateError", function(){
     51        el.selectionDirection = 'none';
     52      });
     53    }, `assigning selectionDirection on an input[type=${type}] throws InvalidStateError`);
     54 
     55    test(() => {
     56      assert_throws_dom("InvalidStateError", function(){
     57        el.setRangeText("foobar");
     58      });
     59    }, `setRangeText on an input[type=${type}] throws InvalidStateError`);
     60 
     61    test(() => {
     62      assert_throws_dom("InvalidStateError", function(){
     63        el.setSelectionRange(0, 1);
     64      });
     65    }, `setSelectionRange on an input[type=${type}] throws InvalidStateError`);
     66  });
     67 
     68  applicableTypes.forEach(function(type) {
     69    const el = document.createElement("input");
     70    if (type) {
     71      el.type = type;
     72    }
     73    const initialDirection = el.selectionDirection;
     74 
     75    test(() => {
     76      assert_equals(el.selectionStart, 0);
     77    }, `selectionStart on an input[type=${type}] returns a value`);
     78 
     79    test(() => {
     80      assert_equals(el.selectionEnd, 0);
     81    }, `selectionEnd on an input[type=${type}] returns a value`);
     82 
     83    test(() => {
     84      assert_in_array(el.selectionDirection, ["forward", "none"]);
     85    }, `selectionDirection on an input[type=${type}] returns a value`);
     86 
     87    test(() => {
     88      el.selectionDirection = "none";
     89      assert_equals(el.selectionDirection, initialDirection);
     90    }, `assigning selectionDirection "none" on an input[type=${type}] should give the initial direction`);
     91 
     92    test(() => {
     93      el.selectionStart = 1;
     94    }, `assigning selectionStart on an input[type=${type}] doesn't throw an exception`);
     95 
     96    test(() => {
     97      el.selectionEnd = 1;
     98    }, `assigning selectionEnd on an input[type=${type}] doesn't throw an exception`);
     99 
    100    test(() => {
    101      el.selectionDirection = "forward";
    102    }, `assigning selectionDirection on an input[type=${type}] doesn't throw an exception`);
    103 
    104    test(() => {
    105      el.setRangeText("foobar");
    106    }, `setRangeText on an input[type=${type}] doesn't throw an exception`);
    107 
    108    test(() => {
    109      el.setSelectionRange(0, 1);
    110    }, `setSelectionRange on an input[type=${type}] doesn't throw an exception`);
    111  });
    112 </script>