tor-browser

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

test_input_time_key_events.html (6367B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1288591
      5 -->
      6 <head>
      7  <title>Test key events for time control</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  <meta charset="UTF-8">
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1288591">Mozilla Bug 1288591</a>
     15 <p id="display"></p>
     16 <div id="content">
     17  <input id="input" type="time">
     18 </div>
     19 <pre id="test">
     20 <script type="application/javascript">
     21 
     22 SimpleTest.waitForExplicitFinish();
     23 SimpleTest.waitForFocus(function() {
     24  test();
     25  SimpleTest.finish();
     26 });
     27 
     28 var testData = [
     29  /**
     30   * keys: keys to send to the input element.
     31   * initialVal: initial value set to the input element.
     32   * expectedVal: expected value of the input element after sending the keys.
     33   */
     34  {
     35    // Type 16 in the hour field will automatically change time to 4PM in 12-hour clock
     36    keys: ["16"],
     37    initialVal: "01:00",
     38    expectedVal: "16:00"
     39  },
     40  {
     41    // Type 00 in hour field will automatically convert to 12AM in 12-hour clock
     42    keys: ["00"],
     43    initialVal: "03:00",
     44    expectedVal: "00:00"
     45  },
     46  {
     47    // Type hour > 23 such as 24 will automatically convert to 2
     48    keys: ["24"],
     49    initialVal: "04:00",
     50    expectedVal: "02:00"
     51  },
     52  {
     53    // Type 1030 and select AM.
     54    keys: ["1030"],
     55    initialVal: "",
     56    expectedVal: "10:30"
     57  },
     58  {
     59    // Type 3 in the hour field will automatically advance to the minute field.
     60    keys: ["330"],
     61    initialVal: "",
     62    expectedVal: "03:30"
     63  },
     64  {
     65    // Type 5 in the hour field will automatically advance to the minute field.
     66    // Type 7 in the minute field will automatically advance to the AM/PM field.
     67    keys: ["57"],
     68    initialVal: "",
     69    expectedVal: "05:07"
     70  },
     71  {
     72    // Advance to AM/PM field and change to PM.
     73    keys: ["KEY_Tab", "KEY_Tab", "KEY_ArrowDown"],
     74    initialVal: "10:30",
     75    expectedVal: "22:30"
     76  },
     77  {
     78    // Right key should do the same thing as TAB key.
     79    keys: ["KEY_ArrowRight", "KEY_ArrowRight", "KEY_ArrowDown"],
     80    initialVal: "10:30",
     81    expectedVal: "22:30"
     82  },
     83  {
     84    // Advance to minute field then back to hour field and decrement.
     85    keys: ["KEY_ArrowRight", "KEY_ArrowLeft", "KEY_ArrowDown"],
     86    initialVal: "10:30",
     87    expectedVal: "09:30"
     88  },
     89  {
     90    // Focus starts on the first field, hour in this case, and increment.
     91    keys: ["KEY_ArrowUp"],
     92    initialVal: "16:00",
     93    expectedVal: "17:00"
     94  },
     95  {
     96    // Advance to minute field and decrement.
     97    keys: ["KEY_Tab", "KEY_ArrowDown"],
     98    initialVal: "16:00",
     99    expectedVal: "16:59"
    100  },
    101  {
    102    // Advance to minute field and increment.
    103    keys: ["KEY_Tab", "KEY_ArrowUp"],
    104    initialVal: "16:59",
    105    expectedVal: "16:00"
    106  },
    107  {
    108    // PageUp on hour field increments hour by 3.
    109    keys: ["KEY_PageUp"],
    110    initialVal: "05:00",
    111    expectedVal: "08:00"
    112  },
    113  {
    114    // PageDown on hour field decrements hour by 3.
    115    keys: ["KEY_PageDown"],
    116    initialVal: "05:00",
    117    expectedVal: "02:00"
    118  },
    119  {
    120    // PageUp on minute field increments minute by 10.
    121    keys: ["KEY_Tab", "KEY_PageUp"],
    122    initialVal: "14:00",
    123    expectedVal: "14:10"
    124  },
    125  {
    126    // PageDown on minute field decrements minute by 10.
    127    keys: ["KEY_Tab", "KEY_PageDown"],
    128    initialVal: "14:00",
    129    expectedVal: "14:50"
    130  },
    131  {
    132    // Home key on hour field sets it to the minimum hour, which is 1 in 12-hour
    133    // clock.
    134    keys: ["KEY_Home"],
    135    initialVal: "03:10",
    136    expectedVal: "01:10"
    137  },
    138  {
    139    // End key on hour field sets it to the maximum hour, which is 12PM in 12-hour
    140    // clock.
    141    keys: ["KEY_End"],
    142    initialVal: "03:10",
    143    expectedVal: "12:10"
    144  },
    145  {
    146    // Home key on minute field sets it to the minimum minute, which is 0.
    147    keys: ["KEY_Tab", "KEY_Home"],
    148    initialVal: "19:30",
    149    expectedVal: "19:00"
    150  },
    151  {
    152    // End key on minute field sets it to the minimum minute, which is 59.
    153    keys: ["KEY_Tab", "KEY_End"],
    154    initialVal: "19:30",
    155    expectedVal: "19:59"
    156  },
    157  // Second field will show up when needed.
    158  {
    159    // PageUp on second field increments second by 10.
    160    keys: ["KEY_Tab", "KEY_Tab", "KEY_PageUp"],
    161    initialVal: "08:10:10",
    162    expectedVal: "08:10:20"
    163  },
    164  {
    165    // PageDown on second field increments second by 10.
    166    keys: ["KEY_Tab", "KEY_Tab", "KEY_PageDown"],
    167    initialVal: "08:10:10",
    168    expectedVal: "08:10:00"
    169  },
    170  {
    171    // Home key on second field sets it to the minimum second, which is 0.
    172    keys: ["KEY_Tab", "KEY_Tab", "KEY_Home"],
    173    initialVal: "16:00:30",
    174    expectedVal: "16:00:00"
    175  },
    176  {
    177    // End key on second field sets it to the minimum second, which is 59.
    178    keys: ["KEY_Tab", "KEY_Tab", "KEY_End"],
    179    initialVal: "16:00:30",
    180    expectedVal: "16:00:59"
    181  },
    182  {
    183    // Incomplete value maps to empty .value.
    184    keys: ["1"],
    185    initialVal: "",
    186    expectedVal: ""
    187  },
    188  {
    189    keys: ["160"],
    190    initialVal: "",
    191    expectedVal: "",
    192    expectedValOnBlur: "16:00",
    193  },
    194 ];
    195 
    196 function sendKeys(aKeys, aElem) {
    197  for (let i = 0; i < aKeys.length; i++) {
    198    // Force layout flush between keys to ensure focus is correct.
    199    // This shouldn't be necessary; bug 1450219 tracks this.
    200    aElem.clientTop;
    201    let key = aKeys[i];
    202    if (key.startsWith("KEY_")) {
    203      synthesizeKey(key);
    204    } else {
    205      sendString(key);
    206    }
    207  }
    208 }
    209 
    210 function test() {
    211  var elem = document.getElementById("input");
    212 
    213  for (let { keys, initialVal, expectedVal, expectedValOnBlur } of testData) {
    214    elem.focus();
    215    elem.value = initialVal;
    216    sendKeys(keys, elem);
    217    is(elem.value, expectedVal,
    218       "Test with " + keys + ", result should be " + expectedVal + " before blur");
    219    let sawBlur = [false, false];
    220    for (let capture of [false, true]) {
    221      elem.addEventListener("blur", function() {
    222        sawBlur[capture ? 0 : 1] = true;
    223        is(elem.value, expectedValOnBlur || expectedVal,
    224           `Test with ${keys}, result should be correct on blur (capture=${capture})`);
    225      }, { once: true, capture });
    226    }
    227    elem.blur();
    228    ok(sawBlur[0], "Should've seen the blur event (non-capture)");
    229    ok(sawBlur[1], "Should've seen the blur event (capture)");
    230    elem.value = "";
    231  }
    232 }
    233 
    234 </script>
    235 </pre>
    236 </body>
    237 </html>