<script>
    if (window.testRunner) {
        testRunner.dumpAsText();
    }

    function log(m)
    {
        var results = document.getElementById('results');
        results.innerHTML += m + '<br>';
    }

    function shouldBe(aDescription, a, b)
    {
        if (a === b) {
            log("PASS: " + aDescription + " should be '" + b + "' and is.");
        } else {
            log("FAIL: " + aDescription + " should be '" + b + "' but instead is '" + a + "'.");
        }
    }

    function dispatchCustomEvent(name, value)
    {
        var ev = document.createEvent("CustomEvent");
        ev.initCustomEvent(name, true, false, value);
        document.dispatchEvent(ev);
    }

    function runTests()
    {
        addEventListener("blah", function() {
            shouldBe("arguments[0].detail.result of the CustomEvent", arguments[0].detail.result, "success");
        }, false);
        addEventListener("blah2", function() {
            shouldBe("arguments[0].detail of the CustomEvent", arguments[0].detail, "success");
        }, false);

        dispatchCustomEvent("blah", { result: "success" });
        dispatchCustomEvent("blah2", "success");
    }
</script>

<body onload="runTests()">
    <div id="results"></div>
</body>
</html>
