chromium/third_party/blink/web_tests/fast/events/message-channel-gc-3.html

<body>
<p>Test that MessagePort messages are delivered even if both ports are inaccessible from JS any more.</p>
<p>Should say PASS twice.</p>
<pre id=log></pre>
<script src="../../resources/gc.js"></script>
<script>

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

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

function test1()
{
    var channel = new MessageChannel;

    channel.port1.onmessage = function(evt) { log("PASS: message delivered. Port: " + evt.target); test2(); }
    channel.port2.postMessage("msg");

    channel = 0;
    gc();
}

function test2()
{
    var channel = new MessageChannel;

    channel.port2.close();

    channel = 0;
    gc();
    log("PASS: port closed.");
    if (window.testRunner)
        testRunner.notifyDone();
}

test1();

</script>
</body>