/* 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"; /* import-globals-from ../../mochitest/attributes.js */ loadScripts({ name: "attributes.js", dir: MOCHITESTS_DIR }); add_setup(async function () { await SpecialPowers.pushPrefEnv({ set: [["dom.headingoffset.enabled", true]], }); }); // Test basic heading levels (h1-h6) addAccessibleTask( `

heading 1

heading 2

heading 3

heading 4

heading 5
heading 6
`, async function testBasicHeadingLevels(browser, docAcc) { let getAcc = id => findAccessibleChildByID(docAcc, id); testGroupAttrs(getAcc("h1"), 0, 0, 1); testGroupAttrs(getAcc("h2"), 0, 0, 2); testGroupAttrs(getAcc("h3"), 0, 0, 3); testGroupAttrs(getAcc("h4"), 0, 0, 4); testGroupAttrs(getAcc("h5"), 0, 0, 5); testGroupAttrs(getAcc("h6"), 0, 0, 6); }, { chrome: true, topLevel: true, iframe: true, remoteIframe: true, } ); // Test headingoffset attribute on container addAccessibleTask( `

heading 1 (now level 2)

heading 2 (now level 3)

heading 3 (now level 4)

`, async function testHeadingoffsetOnContainer(browser, docAcc) { let getAcc = id => findAccessibleChildByID(docAcc, id); testGroupAttrs(getAcc("h1"), 0, 0, 2); testGroupAttrs(getAcc("h2"), 0, 0, 3); testGroupAttrs(getAcc("h3"), 0, 0, 4); }, { chrome: true, topLevel: true, iframe: true, remoteIframe: true, } ); // Test nested headingoffset attributes addAccessibleTask( `

heading 1 (level 2)

heading 1 (level 4)

heading 2 (level 5)

`, async function testNestedHeadingoffset(browser, docAcc) { let getAcc = id => findAccessibleChildByID(docAcc, id); testGroupAttrs(getAcc("h1-outer"), 0, 0, 2); testGroupAttrs(getAcc("h1-inner"), 0, 0, 4); testGroupAttrs(getAcc("h2-inner"), 0, 0, 5); }, { chrome: true, topLevel: true, iframe: true, remoteIframe: true, } ); // Test headingreset attribute addAccessibleTask( `

heading 1 (level 3)

heading 1 (level 1, reset)

heading 2 (level 2, reset)

`, async function testHeadingreset(browser, docAcc) { let getAcc = id => findAccessibleChildByID(docAcc, id); testGroupAttrs(getAcc("h1-offset"), 0, 0, 3); testGroupAttrs(getAcc("h1-reset"), 0, 0, 1); testGroupAttrs(getAcc("h2-reset"), 0, 0, 2); }, { chrome: true, topLevel: true, iframe: true, remoteIframe: true, } ); // Test headingreset directly on heading element addAccessibleTask( `

heading 1 (level 4)

heading 1 (level 1, self reset)

`, async function testHeadingresetDirectOnHeading(browser, docAcc) { let getAcc = id => findAccessibleChildByID(docAcc, id); testGroupAttrs(getAcc("h1-offset"), 0, 0, 4); testGroupAttrs(getAcc("h1-self-reset"), 0, 0, 1); }, { chrome: true, topLevel: true, iframe: true, remoteIframe: true, } ); // Test headingoffset directly on heading element addAccessibleTask( `

heading 1 (level 3)

heading 2 (level 5)

`, async function testHeadingoffsetDirectOnHeading(browser, docAcc) { let getAcc = id => findAccessibleChildByID(docAcc, id); testGroupAttrs(getAcc("h1-self"), 0, 0, 3); testGroupAttrs(getAcc("h2-self"), 0, 0, 5); }, { chrome: true, topLevel: true, iframe: true, remoteIframe: true, } ); // Test heading level clamping to 9 addAccessibleTask( `

heading 1 (level 9)

heading 2 (level 9, clamped)

heading 6 (level 9, clamped)
`, async function testHeadingoffsetClamping(browser, docAcc) { let getAcc = id => findAccessibleChildByID(docAcc, id); testGroupAttrs(getAcc("h1-clamp"), 0, 0, 9); testGroupAttrs(getAcc("h2-clamp"), 0, 0, 9); testGroupAttrs(getAcc("h6-clamp"), 0, 0, 9); }, { chrome: true, topLevel: true, iframe: true, remoteIframe: true, } ); // Test negative headingoffset clamped to 0 addAccessibleTask( `

heading 1 (level 1)

heading 3 (level 3)

`, async function testHeadingoffsetNegative(browser, docAcc) { let getAcc = id => findAccessibleChildByID(docAcc, id); testGroupAttrs(getAcc("h1-neg"), 0, 0, 1); testGroupAttrs(getAcc("h3-neg"), 0, 0, 3); }, { chrome: true, topLevel: true, iframe: true, remoteIframe: true, } ); // Test headingoffset with headingreset on the same element addAccessibleTask( `

heading (level 3)

heading (level 4)

`, async function testHeadingoffsetWithReset(browser, docAcc) { let getAcc = id => findAccessibleChildByID(docAcc, id); testGroupAttrs(getAcc("h1-both"), 0, 0, 3); testGroupAttrs(getAcc("h2-both"), 0, 0, 4); }, { chrome: true, topLevel: true, iframe: true, remoteIframe: true, } ); // Test headingoffset with mutations addAccessibleTask( `

heading (level 4)

heading (level 5)

`, async function testHeadingoffsetMutations(browser, docAcc) { let getAcc = id => findAccessibleChildByID(docAcc, id); testGroupAttrs(getAcc("h1"), 0, 0, 4); testGroupAttrs(getAcc("h2"), 0, 0, 5); info("Mutate headingoffset"); await invokeSetAttribute(browser, "root", "headingoffset", "5"); await untilCacheIs( () => { const level = {}; getAcc("h1").groupPosition(level, {}, {}); return level.value; }, 6, "level changed to 6" ); await untilCacheIs( () => { const level = {}; getAcc("h2").groupPosition(level, {}, {}); return level.value; }, 7, "level changed to 7" ); }, { chrome: true, topLevel: true, iframe: true, remoteIframe: true, } );