<body>
<p>Test that MessagePort messages are delivered even if both ports are in transit (cloned).</p>
<p>Should say PASS twice.</p>
<pre id=log></pre>
<script>
function gc()
{
    if (window.GCController)
        return GCController.collect();

    for (var i = 0; i < 10000; i++) { // force garbage collection (FF requires about 9K allocations before a collect)
        var s = new String("abc");
    }
}

function log(message)
{
    document.getElementById("log").innerHTML += message + "<br>";
}

if (window.layoutTestController) {
    layoutTestController.dumpAsText();
    layoutTestController.waitUntilDone();
}

function test1()
{
    var channel = new MessageChannel;
    var channel2 = new MessageChannel;
    channel.port1.postMessage("msg1");
    channel2.port1.postMessage("", [channel.port1]);
    channel2.port2.postMessage("", [channel.port2]);
    channel2.port2.onmessage = channel2.port1.onmessage = function(evt) {
        evt.ports[0].onmessage = function(event) {
            if (event.data == "msg1") {
                log("PASS: Received message to cloned port.");
                this.postMessage("msg2");
                gc();
            } else if (event.data == "msg2") {
                log("PASS: Received message from cloned port.");
                gc();
                if (window.layoutTestController)
                    layoutTestController.notifyDone();
            } else {
                log("FAIL: Received unknown message: " + event.data);
            }
        }
        evt.ports[0] = 0;
    }
    channel = 0;
    channel2 = 0;
    gc();
}

test1();

</script>
</body>
