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

Quelle  browser_mouseout_notification_panel.js   Sprache: JAVA

 
"use strict";

async function showNotification(aBrowser, aId) {
  info(`Show notification ${aId}`);
  let promise = BrowserTestUtils.waitForEvent(
    PopupNotifications.panel,
    "popupshown"
  );
  let notification = PopupNotifications.show(
    aBrowser /* browser */,
    "test-notification-" + aId /* id */,
    aId + ": Will you allow <> to perform this action?" /* message */,
    null /* anchorID */,
    {
      label: "Main Action",
      accessKey: "M",
      callback: () => {},
    } /* mainAction */,
    [
      {
        label: "Secondary Action",
        accessKey: "S",
        callback: () => {},
      },
    ] /* secondaryActions */
  );
  await promise;

  let rect = PopupNotifications.panel.getBoundingClientRect();
  return { notification, rect };
}

function waitForMouseEvent(aType, aElement) {
  return new Promise(resolve => {
    aElement.addEventListener(
      aType,
      e => {
        resolve({
          screenX: e.screenX,
          screenY: e.screenY,
          clientX: e.clientX,
          clientY: e.clientY,
        });
      },
      { once: true }
    );
  });
}

function waitForRemoteMouseEvent(aType, aBrowser) {
  return SpecialPowers.spawn(aBrowser, [aType], async aType => {
    return new Promise(
      resolve => {
        content.document.addEventListener(aType, e => {
          resolve({
            screenX: e.screenX,
            screenY: e.screenY,
            clientX: e.clientX,
            clientY: e.clientY,
          });
        });
      },
      { once: true }
    );
  });
}

function executeSoonRemote(aBrowser) {
  return SpecialPowers.spawn(aBrowser, [], () => {
    return new Promise(resolve => {
      SpecialPowers.executeSoon(resolve);
    });
  });
}

function synthesizeMouseAtCenter(aRect) {
  EventUtils.synthesizeMouseAtPoint(
    aRect.left + aRect.width / 2,
    aRect.top + aRect.height / 2,
    {
      type: "mousemove",
    }
  );
}

let notificationRect;

add_setup(async function init() {
  ok(PopupNotifications, "PopupNotifications object exists");
  ok(PopupNotifications.panel, "PopupNotifications panel exists");

  await SpecialPowers.pushPrefEnv({
    set: [
      ["test.events.async.enabled"true],
      // This test aims to synthesize mousemove events at specific times, so
      // disable the automatically synthesized mousemove events during reflow.
      ["layout.reflow.synthMouseMove"false],
    ],
  });

  info(`Show notification to get its size and position`);
  let { notification, rect } = await showNotification(
    gBrowser.selectedBrowser,
    "Test#Init"
  );
  PopupNotifications.remove(notification);
  notificationRect = rect;
});

add_task(async function test_mouseout_chrome() {
  await BrowserTestUtils.withNewTab("about:blank", async browser => {
    info(`Generate mousemove event on browser`);
    let mousemovePromise = waitForMouseEvent("mousemove", browser);
    synthesizeMouseAtCenter(notificationRect);
    let mousemoveCoordinate = await mousemovePromise;
    info(`mousemove event: ${JSON.stringify(mousemoveCoordinate)}`);

    info(`Showing notification should generate mouseout event on browser`);
    let mouseoutPromise = waitForMouseEvent("mouseout", browser);
    let { notification } = await showNotification(browser, "Test#Chrome");
    synthesizeMouseAtCenter(notificationRect);
    let mouseoutCoordinate = await mouseoutPromise;
    info(`mouseout event: ${JSON.stringify(mouseoutCoordinate)}`);

    SimpleTest.isDeeply(
      mouseoutCoordinate,
      mousemoveCoordinate,
      "Test event coordinate"
    );
    info(`Remove notification`);
    PopupNotifications.remove(notification);
  });
});

add_task(async function test_mouseout_content() {
  await BrowserTestUtils.withNewTab("about:blank", async browser => {
    info(`Generate mousemove event on content`);
    let mousemovePromise = waitForRemoteMouseEvent("mousemove", browser);
    // Ensure the event listener is registered in remote before synthesizing mouse event.
    await executeSoonRemote(browser);
    synthesizeMouseAtCenter(notificationRect);
    let mousemoveCoordinate = await mousemovePromise;
    info(`mousemove event on content: ${JSON.stringify(mousemoveCoordinate)}`);

    info(`Showing notification should generate mouseout event on content`);
    let mouseoutPromise = waitForRemoteMouseEvent("mouseout", browser);
    // Ensure the event listener is registered in remote before showing notification.
    await executeSoonRemote(browser);
    let { notification } = await showNotification(browser, "Test#Content");
    synthesizeMouseAtCenter(notificationRect);
    let mouseoutCoordinate = await mouseoutPromise;
    info(`remote mouseout event: ${JSON.stringify(mouseoutCoordinate)}`);

    SimpleTest.isDeeply(
      mouseoutCoordinate,
      mousemoveCoordinate,
      "Test event coordinate"
    );
    info(`Remove notification`);
    PopupNotifications.remove(notification);
  });
});

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

¤ Dauer der Verarbeitung: 0.3 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.