/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; const VALUE_CHANGE_EVENT = "object:property-change:accessible-value"; function getValuetext(id) { return runPython( `findByDomId(doc, "${id}").get_attributes().get("valuetext")` ); } /** * Call mutate and wait for an AT-SPI accessible-value property change event on * the Accessible with the given DOM id. */ async function mutateAndWaitForValueChange(id, mutate) { await runPython(` global onValueChange onValueChange = WaitForEvent("${VALUE_CHANGE_EVENT}", "${id}") `); await mutate(); await runPython(` onValueChange.wait() `); } /** * Test valuetext on a slider. */ addAccessibleTask( `
`, async function testSlider(browser) { await runPython(` global doc doc = getDoc() `); is(await getValuetext("slider"), "30", "slider has correct valuetext"); info("Changing aria-valuenow"); await mutateAndWaitForValueChange("slider", () => invokeSetAttribute(browser, "slider", "aria-valuenow", "40") ); is(await getValuetext("slider"), "40", "slider has correct valuetext"); info("Adding aria-valuetext"); await mutateAndWaitForValueChange("slider", () => invokeSetAttribute(browser, "slider", "aria-valuetext", "40%") ); is(await getValuetext("slider"), "40%", "slider has correct valuetext"); info("Changing aria-valuetext"); await mutateAndWaitForValueChange("slider", () => invokeSetAttribute(browser, "slider", "aria-valuetext", "50%") ); is(await getValuetext("slider"), "50%", "slider has correct valuetext"); } ); /** * Test valuetext on a select element. */ addAccessibleTask( ` `, async function testSelect(browser) { await runPython(` global doc doc = getDoc() `); is(await getValuetext("select"), "a", "select has correct valuetext"); info("Selecting b"); await mutateAndWaitForValueChange("select", () => invokeContentTask(browser, [], () => { content.document.getElementById("select").selectedIndex = 1; }) ); is(await getValuetext("select"), "b", "select has correct valuetext"); info("Changing select to a list box"); const shown = waitForEvent(EVENT_SHOW, "select"); await invokeSetAttribute(browser, "select", "size", "2"); await shown; is(await getValuetext("select"), null, "list box has no valuetext"); } ); /** * Test valuetext on an ARIA combobox. */ addAccessibleTask( `