Skip to content

Truly independent web browser

2.8 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<style>
    body { margin: 0; font: 20px/30px monospace; }
    textarea { display: block; font: inherit; width: 600px; height: 30px; padding: 0; border: 0; resize: none; }
    div { width: 600px; }
</style>
<textarea id="area">one wrod two</textarea>
<div id="editable" contenteditable>three lernagain four</div>
<span id="probe">xxxxxxxxxx</span>
<script>
    promiseTest(async () => {
        const probe = document.getElementById("probe");
        const characterWidth = probe.getBoundingClientRect().width / 10;
        probe.remove();
        const clickAt = (x, y, button = 0) => {
            internals.mouseDown(x, y, 1, button);
            internals.mouseUp(x, y, button);
        };
        const pointInTextControl = (element, index) => {
            const rect = element.getBoundingClientRect();
            return [rect.left + (index + 0.5) * characterWidth, rect.top + 15];
        };
        const pointInText = (text, index) => {
            const range = document.createRange();
            range.setStart(text, index);
            range.setEnd(text, index + 1);
            const rect = range.getBoundingClientRect();
            return [rect.left + rect.width / 2, rect.top + rect.height / 2];
        };
        const leaveField = () => document.activeElement.blur();
        const ranges = node => internals.spellingErrorRanges(node) || "(none)";

        // Focus coming back to the field checks its text again, and the menu action follows before that check's
        // answer, which was worked out while the word was still misspelled.
        const area = document.getElementById("area");
        clickAt(...pointInTextControl(area, 0));
        await internals.spellCheckSettled();
        println(`area flagged: ${ranges(area)}`);
        clickAt(...pointInTextControl(area, 5), 2);
        leaveField();
        clickAt(...pointInTextControl(area, 0));
        println(`menu on wrod: ${await internals.activateSpellingMenuItem("ignore")}`);
        await internals.spellCheckSettled();
        println(`area flagged after ignore: ${ranges(area)}`);

        // Learn Spelling reaches every tab, so this word is one no other test uses.
        const editable = document.getElementById("editable");
        leaveField();
        clickAt(...pointInText(editable.firstChild, 0));
        await internals.spellCheckSettled();
        println(`editable flagged: ${ranges(editable.firstChild)}`);
        clickAt(...pointInText(editable.firstChild, 8), 2);
        leaveField();
        clickAt(...pointInText(editable.firstChild, 0));
        println(`menu on lernagain: ${await internals.activateSpellingMenuItem("learn")}`);
        await internals.spellCheckSettled();
        println(`editable flagged after learn: ${ranges(editable.firstChild)}`);
    });
</script>