<!DOCTYPE html>

<script src="../../resources/js-test-pre.js"></script>

<div id="container">
    <div id="inside">
        <iframe id="frame1" name="frame1" srcdoc="frame1"></iframe>
        <iframe id="frame2" name="frame2" srcdoc="frame2"></iframe>
    </div>
</div>

<script>
description('Reparented sibling frames from unload handlers should load.');

var jsTestIsAsync = true;
var count = 2;
var container = document.getElementById('container');
var inside = document.getElementById('inside');
var frame1 = document.getElementById('frame1');
var frame2 = document.getElementById('frame2');

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

function runTest()
{
    if (--count) return;
    // Wait until all frame disconnection calls are complete to ensure inDocument
    // frames remain loaded.
    setTimeout(function() {
        shouldNotBe('frame1.contentDocument', 'null');
        shouldNotBe('frame2.contentDocument', 'null');
        finishJSTest();
    }, 0);
}

onload = function() {
    inside.appendChild(frame1);
    inside.appendChild(frame2);

    frame1.contentWindow.onunload = function() {
        frame1.onload = runTest;
        frame2.onload = runTest;
        document.body.appendChild(inside);
    };

    container.parentNode.removeChild(container);
};
</script>

<script src="../../resources/js-test-post.js"></script>
