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 7 kB image not shown  

Quelle  test_bug525389.html   Sprache: HTML

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


<!DOCTYPE HTML>
<html><head>
<title>Test for bug 525389</title>
<style src="/tests/SimpleTest/test.css" type="text/css"></style>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>

<script class="testbody" type="application/javascript">

  var utils = SpecialPowers.getDOMWindowUtils(window);
  var Cc = SpecialPowers.Cc;
  var Ci = SpecialPowers.Ci;

function getLoadContext() {
  return SpecialPowers.wrap(window).docShell.QueryInterface(Ci.nsILoadContext);
}

async function runTest() {
  var pasteCount = 0;
  var pasteFunc = function() { pasteCount++; };

  function verifyContent(s) {
    var e = document.getElementById("i1");
    var doc = e.contentDocument;
    if (navigator.platform.includes("Win")) {
      // On Windows ignore \n which got left over from the removal of the fragment tags
      // <html><body>\n<!--StartFragment--> and <!--EndFragment-->\n</body>\n</html>.
      is(doc.body.innerHTML.replace(/\n/g, ""), s, "");
    } else {
      is(doc.body.innerHTML, s, "");
    }
  }

  function pasteInto(trans, html, target_id) {
    var e = document.getElementById("i1");
    var doc = e.contentDocument;
    doc.designMode = "on";
    doc.body.innerHTML = html;
    doc.defaultView.focus();
    if (target_id)
      e = doc.getElementById(target_id);
    else
      e = doc.body;
    var selection = doc.defaultView.getSelection();
    selection.removeAllRanges();
    selection.selectAllChildren(e);
    selection.collapseToEnd();

    pasteCount = 0;
    e.addEventListener("paste", pasteFunc);
    utils.sendContentCommandEvent("pasteTransferable", trans);
    e.removeEventListener("paste", pasteFunc);

    return e;
  }

  function getTransferableFromClipboard(asHTML) {
    var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
    trans.init(getLoadContext());
    if (asHTML) {
      trans.addDataFlavor("text/html");
    } else {
      trans.addDataFlavor("text/plain");
    }
    var clip = SpecialPowers.Services.clipboard;
    clip.getData(trans, Ci.nsIClipboard.kGlobalClipboard, SpecialPowers.wrap(window).browsingContext.currentWindowContext);
    return trans;
  }

  // Commented out as the test for it below is also commented out.
  // function makeTransferable(s, asHTML, target_id) {
  //   var e = document.getElementById("i2");
  //   var doc = e.contentDocument;
  //   if (asHTML) {
  //     doc.body.innerHTML = s;
  //   } else {
  //     var text = doc.createTextNode(s);
  //     doc.body.appendChild(text);
  //   }
  //   doc.designMode = "on";
  //   doc.defaultView.focus();
  //   var selection = doc.defaultView.getSelection();
  //   selection.removeAllRanges();
  //   if (!target_id) {
  //     selection.selectAllChildren(doc.body);
  //   } else {
  //     var range = document.createRange();
  //     range.selectNode(doc.getElementById(target_id));
  //     selection.addRange(range);
  //   }
  //
  //   // We cannot use plain strings, we have to use nsSupportsString.
  //   var supportsStringClass = SpecialPowers.Components.classes["@mozilla.org/supports-string;1"];
  //   var ssData = supportsStringClass.createInstance(Ci.nsISupportsString);
  //
  //   // Create the transferable.
  //   var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
  //   trans.init(getLoadContext());
  //
  //   // Add the data to the transferable.
  //   if (asHTML) {
  //     trans.addDataFlavor("text/html");
  //     ssData.data = doc.body.innerHTML;
  //     trans.setTransferData("text/html", ssData);
  //   } else {
  //     trans.addDataFlavor("text/plain");
  //     ssData.data = doc.body.innerHTML;
  //     trans.setTransferData("text/plain", ssData);
  //   }
  //
  //   return trans;
  // }

  async function copyToClipBoard(s, asHTML, target_id) {
    var e = document.getElementById("i2");
    var doc = e.contentDocument;
    if (asHTML) {
      doc.body.innerHTML = s;
    } else {
      var text = doc.createTextNode(s);
      doc.body.appendChild(text);
    }
    doc.designMode = "on";
    doc.defaultView.focus();
    var selection = doc.defaultView.getSelection();
    selection.removeAllRanges();
    if (!target_id) {
      selection.selectAllChildren(doc.body);
    } else {
      var range = document.createRange();
      range.selectNode(doc.getElementById(target_id));
      selection.addRange(range);
    }

    await SimpleTest.promiseClipboardChange(() => true,
      () => { SpecialPowers.wrap(doc).execCommand("copy", false, null); });

    return e;
  }

  await copyToClipBoard("HelloKitty", true);
  var trans = getTransferableFromClipboard(true);
  pasteInto(trans, "");
  verifyContent("HelloKitty");
  is(pasteCount, 1, "paste event was not triggered");

  // this test is not working out exactly like the clipboard test
  // has to do with generating the nsITransferable above
  // trans = makeTransferable('HelloKitty', true);
  // pasteInto(trans, '');
  // verifyContent('HelloKitty');

  await copyToClipBoard("
Hello Kitty
HelloKitty"
, true);
  trans = getTransferableFromClipboard(true);
  pasteInto(trans, '
  1. X
'
"paste_here");
  verifyContent('
  1. X
    Hello Kitty
    HelloKitty
'
);
  is(pasteCount, 1, "paste event was not triggered");

// The following test doesn't do what I expected, because the special handling
// of IsList nodes in nsHTMLEditor::InsertHTMLWithContext simply removes
// non-list/item children.  See bug 481177.
//  await copyToClipBoard("
  1. Hello Kitty
  2. Hello
"
, true);
//  pasteInto('
  1. X
'
,"paste_here");
//  verifyContent('
  1. X
  2. Hello Kitty
  3. Hello
'
);

  await copyToClipBoard("
Kitty
Hello"
, true);
  trans = getTransferableFromClipboard(true);
  pasteInto(trans, '
Hello 
'
"paste_here");
  verifyContent('
Hello KittyHello
'
);
  is(pasteCount, 1, "paste event was not triggered");

  await copyToClipBoard('123', true);
  trans = getTransferableFromClipboard(true);
  pasteInto(trans, '
'
"paste_here");
  verifyContent('
123
'
);
  is(pasteCount, 1, "paste event was not triggered");

  // test that we can preventDefault pastes
  pasteFunc = function(event) { event.preventDefault(); return false; };
  await copyToClipBoard("
Kitty
Hello"
, true);
  trans = getTransferableFromClipboard(true);
  pasteInto(trans, '
Hello 
'
"paste_here");
  verifyContent('
Hello 
'
);
  is(pasteCount, 0, "paste event was triggered");
}

SimpleTest.waitForExplicitFinish();
addLoadEvent(() => {
  add_task(async function test_copy() {
    await runTest();
  });
});

</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=525389">Mozilla Bug 525389</a>
<p id="display"></p>

<pre id="test">
</pre>

<iframe id="i1" width="200" height="100" src="about:blank"></iframe><br>
<iframe id="i2" width="200" height="100" src="about:blank"></iframe><br>

</body>
</html>

Messung V0.5
C=100 H=100 G=100

¤ Dauer der Verarbeitung: 0.7 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.