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

Quelle  browser_Finder_sound.js   Sprache: JAVA

 
/* Any copyright is dedicated to the Public Domain.
   https://creativecommons.org/publicdomain/zero/1.0/ */


"use strict";

var MockSound = SpecialPowers.MockSound;

add_setup(() => {
  MockSound.init();
  registerCleanupFunction(() => MockSound.cleanup());
});

add_task(async function test_notfound_sound() {
  const url =
    "data:text/html;base64," + btoa('');
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);

  let finder = tab.linkedBrowser.finder;
  let listener = {
    onFindResult() {
      ok(false"callback wasn't replaced");
    },
  };
  finder.addResultListener(listener);

  let promiseFind, findResult;

  function waitForFind() {
    return new Promise(resolve => {
      listener.onFindResult = resolve;
    });
  }

  const steps = [
    ["foo""FIND_FOUND", []],
    ["fox""FIND_NOTFOUND", []], // silent if searchString has not increased its length
    ["foxx""FIND_NOTFOUND", ["beep"]],
  ];

  for (let index = 0; index < steps.length; index++) {
    const [searchString, result, expectedPlayed] = steps[index];
    MockSound.reset();
    promiseFind = waitForFind();
    finder.fastFind(searchString, falsefalse);
    findResult = await promiseFind;
    is(
      findResult.result,
      Ci.nsITypeAheadFind[result],
      `Step ${index + 1}, find "${searchString}"`
    );
    SimpleTest.isDeeply(
      MockSound.played,
      expectedPlayed,
      `Step ${index + 1}, Not-found sound`
    );
  }

  // Extra step for testing entireWord
  finder.entireWord = true;

  MockSound.reset();
  promiseFind = waitForFind();
  finder.fastFind("foxxx"falsefalse);
  findResult = await promiseFind;
  is(
    findResult.result,
    Ci.nsITypeAheadFind.FIND_NOTFOUND,
    'String "foxxx" not found'
  );
  SimpleTest.isDeeply(MockSound.played, [], "No sound when entireWord is on");

  gBrowser.removeTab(tab);
});

add_task(async function test_wrapped_sound() {
  const url =
    "data:text/html;base64," +
    btoa('');
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);

  await SpecialPowers.pushPrefEnv({
    set: [["accessibility.typeaheadfind.wrappedSoundURL""beep"]],
  });

  let finder = tab.linkedBrowser.finder;
  let listener = {
    onFindResult() {
      ok(false"callback wasn't replaced");
    },
  };
  finder.addResultListener(listener);

  let promiseFind, findResult;

  function waitForFind() {
    return new Promise(resolve => {
      listener.onFindResult = resolve;
    });
  }

  MockSound.reset();
  promiseFind = waitForFind();
  finder.fastFind("foo"falsefalse);
  findResult = await promiseFind;

  promiseFind = waitForFind();
  finder.findAgain("foo"falsefalsefalse);
  findResult = await promiseFind;

  is(findResult.result, Ci.nsITypeAheadFind.FIND_FOUND, 'Find "foo" 2 times');
  SimpleTest.isDeeply(
    MockSound.played,
    [],
    "No sound played for first 2 finds"
  );

  // 3rd find will trigger "wrapped"
  promiseFind = waitForFind();
  finder.findAgain("foo"falsefalsefalse);
  findResult = await promiseFind;
  is(
    findResult.result,
    Ci.nsITypeAheadFind.FIND_WRAPPED,
    'Find "foo" 3rd time'
  );
  SimpleTest.isDeeply(MockSound.played, ["beep"], '"beep" for wrapped event');

  gBrowser.removeTab(tab);
});

add_task(async function test_notfound_sound_in_remote_findbar() {
  const url = "about:about";
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);

  let finder = tab.linkedBrowser.finder;
  let listener = {
    onFindResult() {
      ok(false"callback wasn't replaced");
    },
  };
  finder.addResultListener(listener);

  let promiseFind, findResult;

  function waitForFind() {
    return new Promise(resolve => {
      listener.onFindResult = resolve;
    });
  }

  const steps = [
    ["config""FIND_FOUND", []],
    ["confoo""FIND_NOTFOUND", []], // silent if searchString has not increased its length
    ["confool""FIND_NOTFOUND", ["beep"]],
  ];

  for (let index = 0; index < steps.length; index++) {
    const [searchString, result, expectedPlayed] = steps[index];
    MockSound.reset();
    promiseFind = waitForFind();
    finder.fastFind(searchString, falsefalse);
    findResult = await promiseFind;
    is(
      findResult.result,
      Ci.nsITypeAheadFind[result],
      `Step ${index + 1}, find "${searchString}"`
    );
    SimpleTest.isDeeply(
      MockSound.played,
      expectedPlayed,
      `Step ${index + 1}, Not-found sound for ${searchString}`
    );
  }

  // Extra step for testing entireWord
  finder.entireWord = true;

  MockSound.reset();
  promiseFind = waitForFind();
  finder.fastFind("confoobar"falsefalse);
  findResult = await promiseFind;
  is(
    findResult.result,
    Ci.nsITypeAheadFind.FIND_NOTFOUND,
    'String "confoobar" not found'
  );
  SimpleTest.isDeeply(MockSound.played, [], "No sound when entireWord is on");

  gBrowser.removeTab(tab);
});

add_task(async function test_wrapped_sound_in_remote_findbar() {
  const url = kFixtureBaseURL + "file_FinderSample.html";
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);

  await SpecialPowers.pushPrefEnv({
    set: [["accessibility.typeaheadfind.wrappedSoundURL""beep"]],
  });

  let finder = tab.linkedBrowser.finder;
  let listener = {
    onFindResult() {
      ok(false"callback wasn't replaced");
    },
  };
  finder.addResultListener(listener);

  let promiseFind, findResult;

  function waitForFind() {
    return new Promise(resolve => {
      listener.onFindResult = resolve;
    });
  }

  MockSound.reset();
  promiseFind = waitForFind();
  finder.fastFind("Roland"falsefalse);
  findResult = await promiseFind;

  promiseFind = waitForFind();
  finder.findAgain("Roland"falsefalsefalse);
  findResult = await promiseFind;

  // Known: "Roland" appears in <body> 2 times
  is(
    findResult.result,
    Ci.nsITypeAheadFind.FIND_FOUND,
    'Find "Roland" 2 times'
  );
  SimpleTest.isDeeply(
    MockSound.played,
    [],
    "No sound played for first 2 finds"
  );

  // 3rd find will trigger "wrapped"
  promiseFind = waitForFind();
  finder.findAgain("Roland"falsefalsefalse);
  findResult = await promiseFind;
  is(
    findResult.result,
    Ci.nsITypeAheadFind.FIND_WRAPPED,
    'Find "Roland" 3rd time'
  );
  SimpleTest.isDeeply(MockSound.played, ["beep"], '"beep" for wrapped event');

  gBrowser.removeTab(tab);
});

Messung V0.5
C=97 H=90 G=93

¤ Dauer der Verarbeitung: 0.1 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 und die Messung sind noch experimentell.