<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>

<script language="JavaScript">

function buildFrameset()
{
    if (window.testRunner) {
        testRunner.waitUntilDone();
        testRunner.dumpAsText();
        testRunner.dumpChildFramesAsText();
    }

    var outHTML="<frameset rows=\"33%, 33%, 33%\">"+
                "<frame src=\"\" name=\"topRow\">"+
                "<frame src=\"\" name=\"middleRow\">"+
                "<frame src=\"\" name=\"bottomRow\">"+
                "</frameset>";

    document.open("text/html","replace");
    document.write(outHTML);
    document.close();

    outHTML = "<html><head><scr" + "ipt language=\"JavaScript\" src=\"resources/frame-loading-via-document-write.js\">"+
              "</scr" + "ipt></head><body onLoad=\"clickAnchor(); top.frameLoaded();\"><table><tr><td>"+
              "<a href=\"resources/success.html\" target=\"topRow\" id=\"anchorLink\">Click me. If nothing loads above we have a problem.</a>"+
              "</td></tr></table></body></html>";

    frames['topRow'].document.open("text/html","replace");
    frames['topRow'].document.charset=document.charset;
    frames['topRow'].document.write(outHTML);
    frames['topRow'].document.close();

    var localImageLocation = "file:///tmp/LayoutTests/fast/dom/resources/abe.png";
    if (window.testRunner)
        localImageLocation = testRunner.pathToLocalResource(localImageLocation);

    // We check image loading via an onload handler on the <img> instead of the <body> because due to https://webkit.org/b/29615
    // the document onload may fire before the image has loaded.
    outHTML = "<html><head><scr" + "ipt language=\"JavaScript\" src=\"resources/frame-loading-via-document-write.js\">"+
              "</scr" + "ipt></head><body><table><tr><td>"+
              "<div id=\"result\"></div>"+
              "<img src=\"" + localImageLocation + "\" id=\"myImg\" onLoad=\"didImageLoad(); top.frameLoaded();\">"+
              "</td></tr></table></body></html>";

    frames['middleRow'].document.open("text/html","replace");
    frames['middleRow'].document.charset=document.charset;
    frames['middleRow'].document.write(outHTML);
    frames['middleRow'].document.close();

    outHTML = "<html><head><scr" + "ipt language=\"JavaScript\" src=\"resources/frame-loading-via-document-write.js\">"+
              "</scr" + "ipt></head><body><table><tr><td>"+
              "<div id=\"result\"></div>"+
              "<img src=\"resources/abe.png\" id=\"myImg\" onLoad=\"didImageLoad(); top.frameLoaded();\">"+
              "</td></tr></table></body></html>";

    frames['bottomRow'].document.open("text/html","replace");
    frames['bottomRow'].document.charset=document.charset;
    frames['bottomRow'].document.write(outHTML);
    frames['bottomRow'].document.close();
}

var frameLoadCounter = 3;

function frameLoaded()
{
    frameLoadCounter--;
    if (frameLoadCounter == 0 && window.testRunner)
        testRunner.notifyDone();
}

buildFrameset();

</script>
</head>

<body>
<p>JavaScript FAILED! you should not see this.</p>
</body>

</html>

