<!DOCTYPE html>
<html>
<head>
<script>
if (window.testRunner) {
    testRunner.waitUntilDone();
    testRunner.dumpAsText();
}

function log(msg) {
    var div = document.createElement("div");
    div.appendChild(document.createTextNode(msg));
    document.getElementById("result").appendChild(div);
}

function done() {
    if (window.testRunner)
        testRunner.notifyDone();
}

window.onload = function () {
    log("Test begins");

    // The setTimeout handlers will get called after the
    // event listeners.
    postMessage("Message1", "*");
    postMessage("Message2", "*");
    postMessage("Message3", "*");
    setTimeout("log('setTimeout1')", 0);
    setTimeout("log('setTimeout2')", 0);
    setTimeout(done, 0);
    log("Events queued");
}

addEventListener("message", function (e) {
        log("Capture phase: " + e.data);
    }, true);
addEventListener("message", function (e) {
        log("Bubble phase: " + e.data);
    }, false);

document.addEventListener("message", function (e) {
        log("FAIL: Capture phase (document): " + e.data);
    }, true);
document.addEventListener("message", function (e) {
        log("FAIL: Bubble phase (document): " + e.data);
    }, false);
</script>
</head>
<body>
<div id="result">waiting...</div>
</body>
</html>
