tor-browser

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

test_input_lastInteractiveValue.html (4519B)


      1 <!doctype html>
      2 <title>Test for HTMLInputElement.lastInteractiveValue</title>
      3 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      4 <script src="/tests/SimpleTest/EventUtils.js"></script>
      5 <script src="/tests/SimpleTest/NativeKeyCodes.js"></script>
      6 <link href="/tests/SimpleTest/test.css"/>
      7 <body>
      8 <script>
      9 const kIsMac = navigator.platform.indexOf("Mac") > -1;
     10 const kIsWin = navigator.platform.indexOf("Win") > -1;
     11 
     12 function getFreshInput() {
     13  let input = document.body.appendChild(document.createElement("input"));
     14  input.focus();
     15  return input;
     16 }
     17 
     18 // XXX This should be add_setup, but bug 1776589
     19 add_task(async function ensure_focus() {
     20  await SimpleTest.promiseFocus(window);
     21 });
     22 
     23 add_task(async function simple() {
     24  let input = getFreshInput();
     25 
     26  is(SpecialPowers.wrap(input).lastInteractiveValue, "", "Initial state");
     27 
     28  sendString("abc");
     29 
     30  is(input.value, "abc", ".value after interactive edit");
     31  is(SpecialPowers.wrap(input).lastInteractiveValue, "abc", ".lastInteractiveValue after interactive edit");
     32 
     33  input.value = "muahahaha";
     34  is(input.value, "muahahaha", ".value after script edit");
     35 
     36  is(SpecialPowers.wrap(input).lastInteractiveValue, "abc", ".lastInteractiveValue after script edit");
     37 });
     38 
     39 add_task(async function test_default_value() {
     40  let input = getFreshInput();
     41  input.defaultValue = "default value";
     42 
     43  is(input.value, "default value", ".defaultValue affects .value");
     44  is(SpecialPowers.wrap(input).lastInteractiveValue, "", "Default value is not interactive");
     45 
     46  sendString("abc");
     47 
     48  is(SpecialPowers.wrap(input).lastInteractiveValue, "default valueabc", "After interaction with default value");
     49 });
     50 
     51 // This happens in imdb.com login form.
     52 add_task(async function clone_after_interactive_edit() {
     53  let input = getFreshInput();
     54 
     55  sendString("abc");
     56 
     57  is(input.value, "abc", ".value after interactive edit");
     58  is(SpecialPowers.wrap(input).lastInteractiveValue, "abc", ".lastInteractiveValue after interactive edit");
     59 
     60  let clone = input.cloneNode(true);
     61  is(clone.value, "abc", ".value after clone");
     62  is(SpecialPowers.wrap(clone).lastInteractiveValue, "abc", ".lastInteractiveValue after clone");
     63 
     64  clone.type = "hidden";
     65 
     66  clone.value = "something random";
     67  is(SpecialPowers.wrap(clone).lastInteractiveValue, "", ".lastInteractiveValue after clone in non-text-input");
     68 });
     69 
     70 add_task(async function set_user_input() {
     71  let input = getFreshInput();
     72 
     73  input.value = "";
     74 
     75  SpecialPowers.wrap(input).setUserInput("abc");
     76 
     77  is(input.value, "abc", ".value after setUserInput edit");
     78  is(SpecialPowers.wrap(input).lastInteractiveValue, "abc", ".lastInteractiveValue after setUserInput");
     79 
     80  input.value = "foobar";
     81  is(SpecialPowers.wrap(input).lastInteractiveValue, "abc", ".lastInteractiveValue after script edit after setUserInput");
     82 });
     83 
     84 
     85 // TODO(emilio): Maybe execCommand shouldn't be considered interactive, but it
     86 // matches pre-existing behavior effectively.
     87 add_task(async function exec_command() {
     88  let input = getFreshInput();
     89 
     90  document.execCommand("insertText", false, "a");
     91 
     92  is(input.value, "a", ".value after execCommand edit");
     93 
     94  is(SpecialPowers.wrap(input).lastInteractiveValue, "a", ".lastInteractiveValue after execCommand");
     95 
     96  input.value = "foobar";
     97  is(SpecialPowers.wrap(input).lastInteractiveValue, "a", ".lastInteractiveValue after script edit after execCommand");
     98 });
     99 
    100 add_task(async function cut_paste() {
    101  if (true) {
    102    // TODO: the above condition should be if (!kIsMac && !kIsWin), but this
    103    // fails (intermittently?) in those platforms, see bug 1776838. Disable for
    104    // now.
    105    todo(false, "synthesizeNativeKey doesn't work elsewhere (yet)");
    106    return;
    107  }
    108 
    109  function doSynthesizeNativeKey(keyCode, modifiers, chars) {
    110    return new Promise((resolve, reject) => {
    111      if (!synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, keyCode, modifiers, chars, chars, resolve)) {
    112        reject(new Error("Couldn't synthesize native key"));
    113      }
    114    });
    115  }
    116 
    117  let input = getFreshInput();
    118 
    119  sendString("abc");
    120 
    121  input.select();
    122 
    123  is(SpecialPowers.wrap(input).lastInteractiveValue, "abc", ".lastInteractiveValue before cut");
    124 
    125  await doSynthesizeNativeKey(kIsMac ? MAC_VK_ANSI_X : WIN_VK_X, { accelKey: true }, "x");
    126 
    127  is(SpecialPowers.wrap(input).lastInteractiveValue, "", ".lastInteractiveValue after cut");
    128 
    129  await doSynthesizeNativeKey(kIsMac ? MAC_VK_ANSI_V : WIN_VK_V, { accelKey: true }, "v");
    130 
    131  is(SpecialPowers.wrap(input).lastInteractiveValue, "abc", ".lastInteractiveValue after paste");
    132 });
    133 
    134 </script>