tor-browser

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

test_bug674558.html (8825B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=674558
      5 -->
      6 <head>
      7  <title>Test for Bug 674558</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/EventUtils.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=674558">Mozilla Bug 674558</a>
     14 <p id="display"></p>
     15 <div id="content">
     16 </div>
     17 <pre id="test">
     18 <script type="application/javascript">
     19 
     20 /** Test for Bug 674558 */
     21 SimpleTest.waitForExplicitFinish();
     22 
     23 SimpleTest.waitForFocus(startTest);
     24 
     25 function startTest() {
     26  function textAreaCtor() {
     27    return document.createElement("textarea");
     28  }
     29  var ctors = [textAreaCtor];
     30  ["text", "password", "search"].forEach(function(type) {
     31    ctors.push(function inputCtor() {
     32      var input = document.createElement("input");
     33      input.type = type;
     34      return input;
     35    });
     36  });
     37 
     38  for (var ctor in ctors) {
     39    test(ctors[ctor]);
     40  }
     41 
     42  SimpleTest.finish();
     43 }
     44 
     45 function test(ctor) {
     46  var elem = ctor();
     47  ok(true, "Testing " + name(elem));
     48 
     49  ok("selectionDirection" in elem, "elem should have the selectionDirection property");
     50 
     51  is(elem.selectionStart, elem.value.length, "Default value");
     52  is(elem.selectionEnd, elem.value.length, "Default value");
     53  is(elem.selectionDirection, "forward", "Default value");
     54 
     55  var content = document.getElementById("content");
     56  content.appendChild(elem);
     57 
     58  function flush() { document.body.clientWidth; }
     59  function hide() {
     60    content.style.display = "none";
     61    flush();
     62  }
     63  function show() {
     64    content.style.display = "";
     65    flush();
     66  }
     67 
     68  elem.value = "foobar";
     69 
     70  is(elem.selectionStart, elem.value.length, "Default value");
     71  is(elem.selectionEnd, elem.value.length, "Default value");
     72  is(elem.selectionDirection, "forward", "Default value");
     73 
     74  elem.setSelectionRange(1, 3);
     75  is(elem.selectionStart, 1, "Correct value");
     76  is(elem.selectionEnd, 3, "Correct value");
     77  is(elem.selectionDirection, "forward", "If not set, should default to forward");
     78 
     79  hide();
     80  is(elem.selectionStart, 1, "Value unchanged");
     81  is(elem.selectionEnd, 3, "Value unchanged");
     82  is(elem.selectionDirection, "forward", "Value unchanged");
     83 
     84  show();
     85  is(elem.selectionStart, 1, "Value unchanged");
     86  is(elem.selectionEnd, 3, "Value unchanged");
     87  is(elem.selectionDirection, "forward", "Value unchanged");
     88 
     89  // extend to right
     90  elem.focus();
     91  synthesizeKey("VK_RIGHT", {shiftKey: true});
     92 
     93  is(elem.selectionStart, 1, "Value unchanged");
     94  is(elem.selectionEnd, 4, "Correct value");
     95  is(elem.selectionDirection, "forward", "Still forward");
     96 
     97  hide();
     98  is(elem.selectionStart, 1, "Value unchanged");
     99  is(elem.selectionEnd, 4, "Value unchanged");
    100  is(elem.selectionDirection, "forward", "Value unchanged");
    101 
    102  show();
    103  is(elem.selectionStart, 1, "Value unchanged");
    104  is(elem.selectionEnd, 4, "Value unchanged");
    105  is(elem.selectionDirection, "forward", "Value unchanged");
    106 
    107  // change the direction
    108  elem.selectionDirection = "backward";
    109 
    110  is(elem.selectionStart, 1, "Value unchanged");
    111  is(elem.selectionEnd, 4, "Value unchanged");
    112  is(elem.selectionDirection, "backward", "Correct value");
    113 
    114  hide();
    115  is(elem.selectionStart, 1, "Value unchanged");
    116  is(elem.selectionEnd, 4, "Value unchanged");
    117  is(elem.selectionDirection, "backward", "Value unchanged");
    118 
    119  show();
    120  is(elem.selectionStart, 1, "Value unchanged");
    121  is(elem.selectionEnd, 4, "Value unchanged");
    122  is(elem.selectionDirection, "backward", "Value unchanged");
    123 
    124  // extend to right again
    125  synthesizeKey("VK_RIGHT", {shiftKey: true});
    126 
    127  is(elem.selectionStart, 2, "Correct value");
    128  is(elem.selectionEnd, 4, "Value unchanged");
    129  is(elem.selectionDirection, "backward", "Still backward");
    130 
    131  hide();
    132  is(elem.selectionStart, 2, "Value unchanged");
    133  is(elem.selectionEnd, 4, "Value unchanged");
    134  is(elem.selectionDirection, "backward", "Value unchanged");
    135 
    136  show();
    137  is(elem.selectionStart, 2, "Value unchanged");
    138  is(elem.selectionEnd, 4, "Value unchanged");
    139  is(elem.selectionDirection, "backward", "Value unchanged");
    140 
    141  elem.selectionEnd = 5;
    142 
    143  is(elem.selectionStart, 2, "Value unchanged");
    144  is(elem.selectionEnd, 5, "Correct value");
    145  is(elem.selectionDirection, "backward", "Still backward");
    146 
    147  hide();
    148  is(elem.selectionStart, 2, "Value unchanged");
    149  is(elem.selectionEnd, 5, "Value unchanged");
    150  is(elem.selectionDirection, "backward", "Value unchanged");
    151 
    152  show();
    153  is(elem.selectionStart, 2, "Value unchanged");
    154  is(elem.selectionEnd, 5, "Value unchanged");
    155  is(elem.selectionDirection, "backward", "Value unchanged");
    156 
    157  elem.selectionDirection = "none";
    158 
    159  is(elem.selectionStart, 2, "Value unchanged");
    160  is(elem.selectionEnd, 5, "Value unchanged");
    161  is(elem.selectionDirection, "forward", "none not supported");
    162 
    163  hide();
    164  is(elem.selectionStart, 2, "Value unchanged");
    165  is(elem.selectionEnd, 5, "Value unchanged");
    166  is(elem.selectionDirection, "forward", "Value unchanged");
    167 
    168  show();
    169  is(elem.selectionStart, 2, "Value unchanged");
    170  is(elem.selectionEnd, 5, "Value unchanged");
    171  is(elem.selectionDirection, "forward", "Value unchanged");
    172 
    173  elem.selectionDirection = "backward";
    174 
    175  is(elem.selectionStart, 2, "Value unchanged");
    176  is(elem.selectionEnd, 5, "Value unchanged");
    177  is(elem.selectionDirection, "backward", "Correct Value");
    178 
    179  hide();
    180  is(elem.selectionStart, 2, "Value unchanged");
    181  is(elem.selectionEnd, 5, "Value unchanged");
    182  is(elem.selectionDirection, "backward", "Value unchanged");
    183 
    184  show();
    185  is(elem.selectionStart, 2, "Value unchanged");
    186  is(elem.selectionEnd, 5, "Value unchanged");
    187  is(elem.selectionDirection, "backward", "Value unchanged");
    188 
    189  elem.selectionDirection = "invalid";
    190 
    191  is(elem.selectionStart, 2, "Value unchanged");
    192  is(elem.selectionEnd, 5, "Value unchanged");
    193  is(elem.selectionDirection, "forward", "Treated as none");
    194 
    195  hide();
    196  is(elem.selectionStart, 2, "Value unchanged");
    197  is(elem.selectionEnd, 5, "Value unchanged");
    198  is(elem.selectionDirection, "forward", "Value unchanged");
    199 
    200  show();
    201  is(elem.selectionStart, 2, "Value unchanged");
    202  is(elem.selectionEnd, 5, "Value unchanged");
    203  is(elem.selectionDirection, "forward", "Value unchanged");
    204 
    205  elem.selectionDirection = "backward";
    206 
    207  is(elem.selectionStart, 2, "Value unchanged");
    208  is(elem.selectionEnd, 5, "Value unchanged");
    209  is(elem.selectionDirection, "backward", "Correct Value");
    210 
    211  hide();
    212  is(elem.selectionStart, 2, "Value unchanged");
    213  is(elem.selectionEnd, 5, "Value unchanged");
    214  is(elem.selectionDirection, "backward", "Value unchanged");
    215 
    216  show();
    217  is(elem.selectionStart, 2, "Value unchanged");
    218  is(elem.selectionEnd, 5, "Value unchanged");
    219  is(elem.selectionDirection, "backward", "Value unchanged");
    220 
    221  elem.setSelectionRange(1, 4);
    222 
    223  is(elem.selectionStart, 1, "Correct value");
    224  is(elem.selectionEnd, 4, "Correct value");
    225  is(elem.selectionDirection, "forward", "Correct value");
    226 
    227  hide();
    228  is(elem.selectionStart, 1, "Value unchanged");
    229  is(elem.selectionEnd, 4, "Value unchanged");
    230  is(elem.selectionDirection, "forward", "Value unchanged");
    231 
    232  show();
    233  is(elem.selectionStart, 1, "Value unchanged");
    234  is(elem.selectionEnd, 4, "Value unchanged");
    235  is(elem.selectionDirection, "forward", "Value unchanged");
    236 
    237  elem.setSelectionRange(1, 1);
    238  synthesizeKey("VK_RIGHT", {shiftKey: true});
    239  synthesizeKey("VK_RIGHT", {shiftKey: true});
    240  synthesizeKey("VK_RIGHT", {shiftKey: true});
    241 
    242  is(elem.selectionStart, 1, "Correct value");
    243  is(elem.selectionEnd, 4, "Correct value");
    244  is(elem.selectionDirection, "forward", "Correct value");
    245 
    246  hide();
    247  is(elem.selectionStart, 1, "Value unchanged");
    248  is(elem.selectionEnd, 4, "Value unchanged");
    249  is(elem.selectionDirection, "forward", "Value unchanged");
    250 
    251  show();
    252  is(elem.selectionStart, 1, "Value unchanged");
    253  is(elem.selectionEnd, 4, "Value unchanged");
    254  is(elem.selectionDirection, "forward", "Value unchanged");
    255 
    256  elem.setSelectionRange(5, 5);
    257  synthesizeKey("VK_LEFT", {shiftKey: true});
    258  synthesizeKey("VK_LEFT", {shiftKey: true});
    259  synthesizeKey("VK_LEFT", {shiftKey: true});
    260 
    261  is(elem.selectionStart, 2, "Correct value");
    262  is(elem.selectionEnd, 5, "Correct value");
    263  is(elem.selectionDirection, "backward", "Correct value");
    264 
    265  hide();
    266  is(elem.selectionStart, 2, "Value unchanged");
    267  is(elem.selectionEnd, 5, "Value unchanged");
    268  is(elem.selectionDirection, "backward", "Value unchanged");
    269 
    270  show();
    271  is(elem.selectionStart, 2, "Value unchanged");
    272  is(elem.selectionEnd, 5, "Value unchanged");
    273  is(elem.selectionDirection, "backward", "Value unchanged");
    274 }
    275 
    276 function name(elem) {
    277  var tag = elem.localName;
    278  if (tag == "input") {
    279    tag += "[type=" + elem.type + "]";
    280  }
    281  return tag;
    282 }
    283 
    284 </script>
    285 </pre>
    286 </body>
    287 </html>