chromium/third_party/blink/web_tests/loader/iframe-sync-loads.html

<body>
<pre id="log"></pre>
<script>
function log(msg) {
    document.getElementById("log").textContent += msg + "\n";
}

function getText(iframe) {
    return iframe.contentDocument.documentElement.textContent;
}

var testIndex = 0;

function runTest(name, testFunction) {
    var iframe = document.createElement('iframe');
    document.body.appendChild(iframe);

    var expectedText = "foo " + testIndex;
    iframe.onerror = function() {
        log(name + ' error ' + getText(iframe));
    }
    testFunction(iframe, expectedText);
    var resultText = getText(iframe);
    if (resultText == expectedText) {
        log(' sync : ' + name);
        iframe.parentNode.removeChild(iframe);
        nextTest();
    } else {
        iframe.onload = function() {
            log('ASYNC : ' + name);
            iframe.parentNode.removeChild(iframe);
            nextTest();
        }
    }
}

var tests = [
    { name: 'src = javascript:"content"', testFunction: function(iframe, expectedText) { iframe.src = 'javascript: "' + expectedText + '"'} },
    { name: 'src = data:text/html,content', testFunction: function(iframe, expectedText) { iframe.src = 'data:text/html,"' + expectedText + '"'} },
    { name: 'srcdoc = "content"', testFunction: function(iframe, expectedText) { iframe.src = 'data:text/html,"' + expectedText + '"'} },
];

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

function nextTest() {
    if (testIndex >= tests.length) {
        log("done");
        if (window.testRunner)
            testRunner.notifyDone();
        return;
    }
    var test = tests[testIndex++];
    runTest(test.name, test.testFunction);
}
nextTest();
</script>