<html>
<head>
    <script>
    function focusElementAndPressTabKey(el)
    {
        el.focus();
        if (window.eventSender)
            eventSender.keyDown("\t");
    }

    function test() {

        if (window.testRunner)
            testRunner.dumpAsText();

        var el = document.getElementById('ta');

        // Test that default setting is to cycle through elements.
        // This tab key press should not insert a tab.
        focusElementAndPressTabKey(el);
        if (el.value != "")
            return;

        if (window.testRunner)
            testRunner.setTabKeyCyclesThroughElements(false);

        // Test that activating the setting causes a tab character insertion.
        focusElementAndPressTabKey(el);
        if (el.value != "\t")
            return;

        // Set this preference so the tab key will actually insert a tab character- like in Mail.
        if (window.testRunner)
            testRunner.setTabKeyCyclesThroughElements(true);

        // Test that deactivating the setting prevents a tab insertion.
        el.value = "";
        focusElementAndPressTabKey(el);
        if (el.value != "")
            return;

        res.innerHTML = "Test Passed";
    }
    </script>
</head>

<body onload="test()">
    This tests that you can insert a tab in a WebKit app that allows tab insertion<br>
    <textarea id="ta"></textarea><br>
    <div id="res">Test Failed</div>
</body>
</html>
