tor-browser

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

setting-value-of-textcontrol-immediately-after-hidden.html (3779B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <meta name="variant" content="?editor=input&hide-target=editor">
      4 <meta name="variant" content="?editor=textarea&hide-target=editor">
      5 <meta name="variant" content="?editor=input&hide-target=parent">
      6 <meta name="variant" content="?editor=textarea&hide-target=parent">
      7 <title>Testing edit action in zombie editor</title>
      8 <script src=/resources/testharness.js></script>
      9 <script src=/resources/testharnessreport.js></script>
     10 <script src="/resources/testdriver.js"></script>
     11 <script src="/resources/testdriver-vendor.js"></script>
     12 <script src="/resources/testdriver-actions.js"></script>
     13 <body>
     14 <script>
     15 "use strict";
     16 
     17 const params = new URLSearchParams(location.search);
     18 
     19 /**
     20 * The expected results is based on Chrome 93.
     21 * The behavior is reasonable because JS API which does not require focus keeps
     22 * working even if it's hidden.
     23 */
     24 
     25 function init() {
     26  const div = document.createElement("div");
     27  const editor = document.createElement(params.get("editor"));
     28  const hideTarget = params.get("hide-target") == "editor" ? editor : div;
     29  editor.value = "default value";
     30  div.appendChild(editor);
     31  document.body.appendChild(div);
     32  return [ hideTarget, editor ];
     33 }
     34 
     35 function finalize(editor) {
     36  editor.blur();
     37  editor.parentNode.remove();
     38  document.body.getBoundingClientRect();
     39 }
     40 
     41 promise_test(async () => {
     42  await new Promise(resolve => addEventListener("load", resolve, {once: true}));
     43 }, "Wait for load event");
     44 
     45 promise_test(async () => {
     46  const [hideTarget, editor] = init();
     47  try {
     48    hideTarget.style.display = "none";
     49    editor.value = "new value";
     50    assert_equals(editor.value, "new value", "The value should be set properly");
     51  } finally {
     52    finalize(editor);
     53  }
     54 }, `<${params.get("editor")}>.value = "new value" (without focus)`);
     55 
     56 promise_test(async () => {
     57  const [hideTarget, editor] = init();
     58  try {
     59    editor.focus();
     60    hideTarget.style.display = "none";
     61    editor.value = "new value";
     62    assert_equals(editor.value, "new value", "The value should be set properly");
     63  } finally {
     64    finalize(editor);
     65  }
     66 }, `<${params.get("editor")}>.value = "new value" (with focus)`);
     67 
     68 promise_test(async () => {
     69  const [hideTarget, editor] = init();
     70  try {
     71    editor.focus();
     72    editor.blur();
     73    hideTarget.style.display = "none";
     74    editor.value = "new value";
     75    assert_equals(editor.value, "new value", "The value should be set properly");
     76  } finally {
     77    finalize(editor);
     78  }
     79 }, `<${params.get("editor")}>.value = "new value" (after blur)`);
     80 
     81 promise_test(async () => {
     82  const [hideTarget, editor] = init();
     83  try {
     84    hideTarget.style.display = "none";
     85    editor.setRangeText("new", 0, "default".length);
     86    assert_equals(editor.value, "new value", "The value should be set properly by setRangeText");
     87  } finally {
     88    finalize(editor);
     89  }
     90 }, `<${params.get("editor")}>.setRangeText("new", 0, "default".length) (without focus)`);
     91 
     92 promise_test(async () => {
     93  const [hideTarget, editor] = init();
     94  try {
     95    editor.focus();
     96    hideTarget.style.display = "none";
     97    editor.setRangeText("new", 0, "default".length);
     98    assert_equals(editor.value, "new value", "The value should be set properly by setRangeText");
     99  } finally {
    100    finalize(editor);
    101  }
    102 }, `<${params.get("editor")}>.setRangeText("new", 0, "default".length) (with focus)`);
    103 
    104 promise_test(async () => {
    105  const [hideTarget, editor] = init();
    106  try {
    107    editor.focus();
    108    editor.blur();
    109    hideTarget.style.display = "none";
    110    editor.setRangeText("new", 0, "default".length);
    111    assert_equals(editor.value, "new value", "The value should be set properly by setRangeText");
    112  } finally {
    113    finalize(editor);
    114  }
    115 }, `<${params.get("editor")}>.setRangeText("new", 0, "default".length) (after blur)`);
    116 
    117 </script>
    118 </body>