/** Test for NavigatorLanguage **/ var actualLanguageChangesFromHandler = 0; var actualLanguageChangesFromAVL = 0; var expectedLanguageChanges = 0; var emptyLocale = SpecialPowers.Services.locale.webExposedLocales[0];
var currentTestIdx = 0; var tests = [];
function nextTest() {
currentTestIdx++;
if (currentTestIdx >= tests.length) {
SimpleTest.finish();
return;
}
tests[currentTestIdx]();
}
// Check that the API is there.
tests.push(function testAPIPresence() {
ok('language' in window.navigator);
ok('languages' in window.navigator);
ok('onlanguagechange' in window);
nextTest();
});
// Check that calling navigator.languages return the same array, unless there
// was a change.
tests.push(function testArrayCached() { var previous = navigator.languages;
is(navigator.languages, navigator.languages, "navigator.languages is cached");
is(navigator.languages, previous, "navigator.languages is cached");
window.onlanguagechange = function() {
isnot(navigator.languages, previous, "navigator.languages cached value was updated");
window.onlanguagechange = null;
// Test that event handler inside the <body> works as expected and that the
// event has the expected properties.
tests.push(function testEventProperties() {
document.body.setAttribute('onlanguagechange', "document.body.removeAttribute('onlanguagechange');" + "is(event.cancelable, false); is(event.bubbles, false);" + "nextTest();");
// Check that the returned values such as the behavior when the underlying
// languages change.
tests.push(function testBasicBehaviour() {
function checkIfDoneAndProceed() {
if (actualLanguageChangesFromHandler == actualLanguageChangesFromAVL) {
if (genEvents.next().done) {
window.onlanguagechange = null;
window.removeEventListener('languagechange', languageChangeAVL);
nextTest();
}
}
}
window.onlanguagechange = function() {
actualLanguageChangesFromHandler++;
checkIfDoneAndProceed();
}
function languageChangeAVL() {
actualLanguageChangesFromAVL++;
checkIfDoneAndProceed();
}
window.addEventListener('languagechange', languageChangeAVL);
function* testEvents() {
for (var i = 0; i < testValues.length; ++i) { var data = testValues[i];
setTimeout(function(d) {
SpecialPowers.pushPrefEnv({"set": [['intl.accept_languages', d.accept_languages]]});
}, 0, data);
expectedLanguageChanges++;
yield undefined;
var genEvents = testEvents();
genEvents.next();
});
// Check that the languagechange event isn't sent twice if the preference
// is set to the same value.
tests.push(function testOnlyFireIfRealChange() {
function* changeLanguage() {
setTimeout(function() {
SpecialPowers.pushPrefEnv({"set": [['intl.accept_languages', 'fr-CA']]});
});
yield undefined;
setTimeout(function() {
// Twice the same change, should fire only one event.
SpecialPowers.pushPrefEnv({"set": [['intl.accept_languages', 'fr-CA']]});
setTimeout(function() {
// A real change to tell the test it should now count how many changes were
// received until now.
SpecialPowers.pushPrefEnv({"set": [['intl.accept_languages', 'fr-FR']]});
});
});
yield undefined;
}
if (navigator.language == 'fr-CA') {
doubleEventCount++;
}
genChanges.next();
}
genChanges.next();
});
// Check that there is no crash when a change happen after a window listening
// to them is killed.
tests.push(function testThatAddingAnEventDoesNotHaveSideEffects() { varframe = document.createElement('iframe'); frame.srcdoc = '<script>window.onlanguagechange=function(){}<\/script>';
document.body.appendChild(frame);
SpecialPowers.exactGC(function() {
// This should not crash.
SpecialPowers.pushPrefEnv({"set": [['intl.accept_languages', 'en-GB']]}, nextTest);
});
}
});
// There is one test using document.body.
addLoadEvent(function() {
tests[0]();
});
</script>
</body>
</html>
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet am 2026-04-29)
¤
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.