<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="../../resources/accessibility-helper.js"></script>
</head>
<body>

<ul id="tree" role="tree" tabindex="0">
    <li id="treeitem1" role="treeitem"></li>
    <li id="treeitem2" role="treeitem"></li>
    <li id="treeitem3" role="treeitem">
        <button>Button inside treeitem3</button>
    </li>
</ul>

<div id="group" role="group">
    <li id="treeitem4" role="treeitem">
        <button>Button inside treeitem4</button>
    </li>
</div>

<script>
    var testOutput = "This test ensures that tree and treeitem objects report the most up-to-date children and rows after dynamic page changes.\n\n";

    function verifyChildren(id) {
        const axElement = accessibilityController.accessibleElementById(id);
        if (!axElement)
            return;

        const childrenCount = axElement.childrenCount;
        testOutput += `#${id} childrenCount: ${childrenCount}\n`;
        for (let i = 0; i < childrenCount; i++)
            testOutput += `    child: ${axElement.childAtIndex(i).role}\n`;
    }

    function verifyTreeRows() {
        const axElement = accessibilityController.accessibleElementById("tree");
        if (!axElement)
            return;

        const rowCount = axElement.rowCount;
        testOutput += `#tree rowCount: ${rowCount}\n`;
        for (let i = 0; i < rowCount; i++) {
            const row = axElement.rowAtIndex(i);
            testOutput += `    row ${i}: ${row.role}, #${row.domIdentifier}\n`;
        }
    }

    if (window.accessibilityController) {
        window.jsTestIsAsync = true;
        verifyChildren("treeitem1");
        verifyChildren("treeitem2");
        verifyTreeRows();

        let button = document.createElement("button");
        button.innerHTML = "Button inside treeitem1";
        document.getElementById("treeitem1").appendChild(button);

        testOutput += "\nAdding content to #treeitem1 and #treeitem2.\n\n";
        document.getElementById("treeitem2").appendChild(document.getElementById("treeitem3"));
        document.getElementById("treeitem2").appendChild(document.getElementById("group"));
        setTimeout(async function() {
            let firstDisclosedRow, secondDisclosedRow;
            await waitFor(() => {
                const treeitem1 = accessibilityController.accessibleElementById("treeitem1");
                if (!treeitem1 || treeitem1.childrenCount !== 1)
                    return false;
                const treeitem2 = accessibilityController.accessibleElementById("treeitem2");
                firstDisclosedRow = treeitem2.disclosedRowAtIndex(0);
                secondDisclosedRow = treeitem2.disclosedRowAtIndex(1);
                return firstDisclosedRow && secondDisclosedRow;
            });
            verifyChildren("treeitem1");
            // We added a group and treeitem to #treeitem2, neither of which should show up as a child (but should be considered when computing disclosed rows).
            verifyChildren("treeitem2");
            testOutput += `#treeitem2 had disclosed row #${firstDisclosedRow.domIdentifier}\n`;
            testOutput += `#treeitem2 had disclosed row #${secondDisclosedRow.domIdentifier}\n`;
            verifyTreeRows();

            debug(testOutput);
            finishJSTest();
        }, 0);
    }
</script>
</body>
</html>

