<!DOCTYPE HTML>
<html>
<head>
<title>Test declared after harness completion</title>
</head>
<body>
<div id="log"></div>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<p>This test simulates an automated test running scenario, where the test
results emitted by testharness.js may be interpreted after some delay. It is
intended to demonstrate that in such cases, any additional tests which are
executed during that delay are <em>not</em> included in the dataset.</p>

<p>Although these "late" tests are likely an indication of a mistake in test
design, they cannot be detected deterministically, so in the interest of
stability, they should be silently tolerated.</p>
<script>
async_test(function(t) {
    var source = [
        "<div id='log'></div>",
        "<script src='/resources/testharness.js'></" + "script>",
        "<script src='/resources/testharnessreport.js'></" + "script>",
        "<script>",
        "parent.childReady(window);",
        "setup({ explicit_done: true });",
        "test(function() {}, 'acceptable test');",
        "onload = function() {",
        "  done();",
        "  test(function() {}, 'this test is late and should be ignored');",
        "};",
        "</" + "script>"
    ].join("\n");
    var iframe = document.createElement("iframe");

    document.body.appendChild(iframe);
    window.childReady = t.step_func(function(childWindow) {
        childWindow.add_completion_callback(t.step_func(function(tests, status) {
            t.step_timeout(t.step_func(function() {
                assert_equals(tests.length, 1);
                assert_equals(tests[0].name, "acceptable test");
                assert_equals(status.status, status.OK);
                t.done();
            }), 0);
        }));
    });

    iframe.contentDocument.open();
    iframe.contentDocument.write(source);
    iframe.contentDocument.close();
});
</script>
</body>
</html>
