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

Impressum test_contextmenu_chorded_buttons.html   Sprache: HTML

 
 products/Sources/formale Sprachen/C/Firefox/widget/tests/test_contextmenu_chorded_buttons.html


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test PointerEvent.buttons of `contextmenu`</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
"use strict";

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
  let contextMenuEvent;
  // Using native mouse button state may be unstable. Try some times until getting expected result.
  for (let i = 0; i < 10; i++) {
    const promiseContextMenu = new Promise(resolve => {
      addEventListener("contextmenu", resolve, { once: true, capture: true });
    });
    info("synthesizing mousemove to the clicking position...");
    await promiseNativeMouseEvent({
      type: "mousemove",
      target: document.body,
      offsetX: 10,
      offsetY: 10,
    });
    info("synthesizing primary button down...");
    await promiseNativeMouseEvent({
      type: "mousedown",
      target: document.body,
      offsetX: 10,
      offsetY: 10,
      button: 0,
    });
    info("synthesizing middle button down...");
    await promiseNativeMouseEvent({
      type: "mousedown",
      target: document.body,
      offsetX: 10,
      offsetY: 10,
      button: 1,
    });
    info("synthesizing right click...");
    await promiseNativeMouseEvent({
      type: "click",
      target: document.body,
      offsetX: 10,
      offsetY: 10,
      button: 2,
    });
    info("synthesizing primary button up...");
    await promiseNativeMouseEvent({
      type: "mouseup",
      target: document.body,
      offsetX: 10,
      offsetY: 10,
      button: 0,
    });
    info("synthesizing middle button up...");
    await promiseNativeMouseEvent({
      type: "mouseup",
      target: document.body,
      offsetX: 10,
      offsetY: 10,
      button: 1,
    });

    info("waiting for contextmenu event...");
    contextMenuEvent = await promiseContextMenu;

    const promiseContextMenuClosed = new Promise(resolve => {
      addEventListener("keyup", resolve, {once: true});
      synthesizeKey("KEY_Escape");
    });
    info("waiting for closing contextmenu...");
    await promiseContextMenuClosed;

    // It depends on the platform whether the context menu opens before/after
    // mouseup of the secondary mouse button.  Therefore, we should ignore
    // 2 of `.buttons` of `contextmenu`.
    if ((contextMenuEvent?.buttons & ~2) == (1 | 4)) {
      break;
    }
    info(`Retrying due to: ${
      !contextMenuEvent ? "no `contextmenu` event" : `unexpected buttons, ${contextMenuEvent.buttons}`
    }`);
  }

  // See above comment for the reason why we ignore 2 of `.buttons` of `contextmenu`.
  is(
    contextMenuEvent?.buttons & ~2,
    (1 | 4),
    "buttons of contextmenu event should indicate that the primary button and the middle button is pressed"
  );

  SimpleTest.finish();
});
</script>
</head>
</html>

100%


¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet)  ¤

*© 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 ist noch experimentell.