Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/editor/libeditor/tests/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 11 kB image not shown  

SSL test_replace_text.html   Interaktion und
PortierbarkeitHTML

 
 products/Sources/formale Sprachen/C/Firefox/editor/libeditor/tests/test_replace_text.html


<!DOCTYPE html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1149826
-->

<html>
<head>
<title>Test for replaceText</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>

<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1149826">Mozilla Bug 1149826</a><br>
<input type="text"><br>
<textarea></textarea>
<div contenteditable></div>

<script>
const gDOMWindowUtils = _getDOMWindowUtils(window);
const Ci = SpecialPowers.Ci;
const IS_WIN = navigator.platform.indexOf("Win") == 0;

async function testReplaceText(INPUT_TESTS, TEXTAREA_TESTS, CONTENTEDITABLE_TESTS, aPreventSetSelection) {
  await SimpleTest.promiseFocus();

  const flags = aPreventSetSelection ?
    Ci.nsIDOMWindowUtils.CONTENT_COMMAND_FLAG_PREVENT_SET_SELECTION :
    0;

  const input = document.querySelector("input");
  input.focus();
  await new Promise(resolve => SimpleTest.executeSoon(resolve));

  info("for ");

  for (const TEST of INPUT_TESTS) {
    input.value = TEST.before.value;
    input.selectionStart = TEST.before.start;
    input.selectionEnd = TEST.before.end;
    await new Promise(resolve => SimpleTest.executeSoon(resolve));

    input.addEventListener("beforeinput", e => {
      is(e.inputType, "insertReplacementText",
         "inputType in input must be insertReplacementText by replaceText");
      is(input.selectionStart, TEST.before.start,
         "Before inputReplacementText, start offset is valid");
      is(input.selectionEnd, TEST.before.end,
         "Before inputReplacementText, end offset is valid");
    }, { once: true } );

    const promiseAfterOnInput =
      new Promise(resolve => input.addEventListener("input", e => {
        is(e.inputType, "insertReplacementText",
           "inputType must be insertReplacementText by replaceText");
        resolve();
      }, { once: true } ));
    gDOMWindowUtils.sendContentCommandEvent(
      "replaceText",
      null,
      TEST.replace.value,
      TEST.replace.start,
      TEST.replace.src,
      flags
    );
    await promiseAfterOnInput

    is(input.value, TEST.after.value,
       "replaceText in input replaces inner text");
    is(input.selectionStart, TEST.after.start,
       "replaceText in input sets expected selection start");
    is(input.selectionEnd, TEST.after.end,
       "replaceText in input sets expected selection end");
  }

  const textarea = document.querySelector("textarea");
  textarea.focus();
  await new Promise(resolve => SimpleTest.executeSoon(resolve));

  info("for