Files
tubestation/toolkit/modules/tests/browser/browser_FinderSound.js
bootleq 521c33ff8a Bug 1905331 - Add test for findbar sound, r=NeilDeakin,pdfjs-reviewers,robwu
Add `MockSound` to replace nsISound in test. Allow us to track play
calls by additional exposed `played` array.

Add `resetSound` to FinderSound module, this is mainly for tests to
clear the internal gSound cache and ensure MockSound can mock it.

Differential Revision: https://phabricator.services.mozilla.com/D215306
2024-10-03 16:09:29 +00:00

62 lines
1.5 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
https://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const kEnabledPref = "accessibility.typeaheadfind.enablesound";
const kSoundURLPref = "accessibility.typeaheadfind.soundURL";
const kClassicSoundURL = "chrome://global/content/notfound.wav";
const { resetSound, playNotFoundSound } = ChromeUtils.importESModule(
"resource://gre/modules/FinderSound.sys.mjs"
);
const MockSound = SpecialPowers.MockSound;
add_setup(() => {
MockSound.init();
resetSound();
registerCleanupFunction(() => MockSound.cleanup());
});
add_task(async function test_notfound_sound_with_preferences() {
await SpecialPowers.pushPrefEnv({
set: [[kSoundURLPref, "beep"]],
});
MockSound.reset();
playNotFoundSound();
SimpleTest.isDeeply(MockSound.played, ["beep"], '"beep" notfound sound');
await SpecialPowers.pushPrefEnv({
set: [[kSoundURLPref, "default"]],
});
MockSound.reset();
playNotFoundSound();
SimpleTest.isDeeply(
MockSound.played,
[`(uri)${kClassicSoundURL}`],
'"default" notfound sound is a bulit-in wav'
);
await SpecialPowers.pushPrefEnv({
set: [[kSoundURLPref, ""]],
});
MockSound.reset();
playNotFoundSound();
SimpleTest.isDeeply(
MockSound.played,
[],
"Empty notfound sound plays nothing"
);
await SpecialPowers.pushPrefEnv({
set: [
[kSoundURLPref, "beep"],
[kEnabledPref, false],
],
});
MockSound.reset();
playNotFoundSound();
SimpleTest.isDeeply(MockSound.played, [], "Disable sound completely");
});