<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.messagePort.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.messagePort = 0;
    }
    channel = 0;
    channel2 = 0;
    gc();
}

test1();

</script>
</body>
