browser_browser_toolbox_l10n_buttons.js (3246B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // There are shutdown issues for which multiple rejections are left uncaught. 5 // See bug 1018184 for resolving these issues. 6 const { PromiseTestUtils } = ChromeUtils.importESModule( 7 "resource://testing-common/PromiseTestUtils.sys.mjs" 8 ); 9 PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/); 10 11 // On debug test machine, it takes about 50s to run the test. 12 requestLongerTimeout(4); 13 14 /** 15 * In the browser toolbox there are options to switch the language to the "bidi" and 16 * "accented" languages. These are useful for making sure the browser is correctly 17 * localized. This test opens the browser toolbox, and checks that these buttons 18 * work. 19 */ 20 add_task(async function () { 21 const ToolboxTask = await initBrowserToolboxTask(); 22 await ToolboxTask.importFunctions({ waitUntil, clickMeatballItem }); 23 24 is(getPseudoLocale(), "", "Starts out as empty"); 25 26 await ToolboxTask.spawn(null, () => clickMeatballItem("accented")); 27 is(getPseudoLocale(), "accented", "Enabled the accented pseudo-locale"); 28 29 await ToolboxTask.spawn(null, () => clickMeatballItem("accented")); 30 is(getPseudoLocale(), "", "Disabled the accented pseudo-locale."); 31 32 await ToolboxTask.spawn(null, () => clickMeatballItem("bidi")); 33 is(getPseudoLocale(), "bidi", "Enabled the bidi pseudo-locale."); 34 35 await ToolboxTask.spawn(null, () => clickMeatballItem("bidi")); 36 is(getPseudoLocale(), "", "Disabled the bidi pseudo-locale."); 37 38 await ToolboxTask.spawn(null, () => clickMeatballItem("bidi")); 39 is(getPseudoLocale(), "bidi", "Enabled the bidi before closing."); 40 41 await ToolboxTask.destroy(); 42 43 is(getPseudoLocale(), "", "After closing the pseudo-locale is disabled."); 44 }); 45 46 /** 47 * Return the pseudo-locale preference of the debuggee browser (not the browser toolbox). 48 * 49 * Another option for this test would be to test the text and layout of the 50 * browser directly, but this could be brittle. Checking the preference will 51 * hopefully provide adequate coverage. 52 */ 53 function getPseudoLocale() { 54 return Services.prefs.getCharPref("intl.l10n.pseudo"); 55 } 56 57 /** 58 * This function is a ToolboxTask and is cloned into the toolbox context. It opens the 59 * "meatball menu" in the browser toolbox, clicks one of the pseudo-locale 60 * options, and finally returns the pseudo-locale preference from the target browser. 61 * 62 * @param {"accented" | "bidi"} type 63 */ 64 async function clickMeatballItem(type) { 65 /* global gToolbox */ 66 67 const onPopupShown = new Promise(resolve => { 68 gToolbox.doc.addEventListener("popupshown", resolve, { once: true }); 69 }); 70 dump(`Opening the meatball menu in the browser toolbox.\n`); 71 gToolbox.doc.getElementById("toolbox-meatball-menu-button").click(); 72 await onPopupShown; 73 74 const menuItem = gToolbox.doc.getElementById( 75 "toolbox-meatball-menu-pseudo-locale-" + type 76 ); 77 dump(`Clicking the meatball menu item: "${type}".\n`); 78 const checked = menuItem.getAttribute("aria-checked"); 79 menuItem.click(); 80 81 dump( 82 "Wait for the new setting to be applied by waiting for the UI to be updated after the action is done\n" 83 ); 84 await waitUntil(() => menuItem.getAttribute("aria-checked") != checked); 85 }