<!DOCTYPE html>
<html><head>
<link rel="stylesheet" href="resources/redimport.css"/>
</head><body>
<div>Test for bug <a href="https://bugs.webkit.org/show_bug.cgi?id=56981">56981</a>: CSSStyleSheet#insertRule doesn't work well with imported stylesheets</div>
<div>You should see one PASS below.</div>
<div id="testArea"></div>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

var remainingTests = 20;

function test() {
    try {
        var testArea = document.getElementById("testArea");
        if (getComputedStyle(testArea).backgroundColor == "rgb(0, 128, 0)") {
            testArea.innerHTML = 'PASS';
            remainingTests = 0;
        } else {
            if (--remainingTests)
                testArea.innerHTML = 'FAIL, backgroundColor was ' + getComputedStyle(testArea).backgroundColor;
        }
    } catch (e) {
        testArea.innerHTML = 'FAIL, exception raised (' + e.message + ')';
        remainingTests = 0;
    }
    if (!remainingTests)
        window.setTimeout(test, 25);
    if (window.testRunner)
        testRunner.notifyDone();
}

function waitForSheetToFinishLoading()
{
    if (document.styleSheets.length && document.styleSheets[0].rules[1].styleSheet) {
        test();
        return;
    }

    window.setTimeout(waitForSheetToFinishLoading, 10)
}

window.onload = function() {
    document.styleSheets[0].insertRule('@import "green.css";', 1);

    // We need to wait some time to let the stylesheet load before testing.
    window.setTimeout(waitForSheetToFinishLoading, 10);
};
</script>
</body></html>
