<!DOCTYPE html>
<html>
<head>
<title>Mutating accesskey attribute</title>
<script src="../../resources/js-test.js"></script>
</head>
</head>
<body>
<script>
description('Access key should work after accesskey attribute is mutated. To test this manually, press &lt;alt&gt;+a, &lt;alt&gt;+b and &lt;alt&gt;+c keys in this order (on Mac OS X, press &lt;Ctrl&gt;+&lt;Opt&gt; instead of &lt;alt&gt;).');

window.jsTestIsAsync = true;

function pressKey(key)
{
    if (navigator.userAgent.search(/\bMac OS X\b/) !== -1)
        modifiers = ["ctrlKey", "altKey"];
    else
        modifiers = ["altKey"];

    if (window.eventSender)
        eventSender.keyDown(key, modifiers);
}

document.addEventListener("DOMContentLoaded", function () {
    var input = document.createElement('input');
    input.accessKey = 'a';
    input.onfocus = function () {
        testPassed('Pressing the "a" access key triggered a focus event.');
        input.blur();
        input.accessKey = 'b';
        input.onfocus = function () {
            testPassed('Pressing the "b" access key triggered a focus event.');
            input.blur();
            input.setAttribute('accesskey', 'c');
            input.onfocus = function () {
                testPassed('Pressing the "c" access key triggered a focus event.');
                document.body.removeChild(input);
                finishJSTest();
            };
            pressKey('c');
        };
        pressKey('b');
    };
    document.body.appendChild(input);
    pressKey('a');
});
</script>
</body>
</html>
