<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>

window._test_hasPaintRects = false;
window._test_hasPaintRectsObserver = setInterval(() => {
    let paintRectsCount = window.internals.inspectorPaintRectCount();

    // Exact paint rect counts may vary, so only check if there are paint rects.
    if (!!paintRectsCount != window._test_hasPaintRects) {
        window._test_hasPaintRects = !!paintRectsCount;
        TestPage.dispatchEventToFrontend("TestHasPaintRectsDidChange");
    }
}, 0);

function test()
{
    // Because adding test results to the page also causes painting (of the new result elements) we need to defer adding
    // results to the page until we are between test cases.
    let deferredTestResults = [];

    const inspectorTestOriginalAddResult = InspectorTest.addResult.bind(InspectorTest);
    InspectorTest.addResult = function(result) {
        deferredTestResults.push(result);
    }

    function writeDeferredTestOutputToPage() {
        for (let result of deferredTestResults)
            inspectorTestOriginalAddResult(result);
        deferredTestResults = [];
    }

    async function expectHasPaintRectsDidChangeTo(expected) {
        await InspectorTest.awaitEvent("TestHasPaintRectsDidChange");
        await expectHasPaintRects(expected);
    }

    async function expectHasPaintRects(expected) {
        let hasPaintRects = await InspectorTest.evaluateInPage(`window._test_hasPaintRects`);
        InspectorTest.expectEqual(hasPaintRects, expected, `Should ${expected ? "" : "not "}have paint rects displayed.`);
    }

    async function setup() {
        await PageAgent.setShowPaintRects(false);

        // Existing paint rects still need to fade out, so it isn't safe to assume we will immediately have zero paint
        // rects visible.
        if (!(await InspectorTest.evaluateInPage(`window._test_hasPaintRects`)))
            return;
        await InspectorTest.awaitEvent("TestHasPaintRectsDidChange");
    }

    async function teardown() {
        writeDeferredTestOutputToPage();
    }

    let suite = InspectorTest.createAsyncSuite("Page.setShowPaintRects");

    suite.addTestCase({
        name: "Page.setShowPaintRects.Enabled",
        description: "Test that paint rects are correctly created and removed while enabled.",
        setup,
        teardown,
        async test() {
            await PageAgent.setShowPaintRects(true);
            await expectHasPaintRects(false);

            let hasPaintRectsPromise = expectHasPaintRectsDidChangeTo(true);

            await InspectorTest.evaluateInPage(`document.getElementById("test").style.backgroundColor = "papayawhip"`);
            await hasPaintRectsPromise;
            await expectHasPaintRectsDidChangeTo(false);
        }
    });

    suite.addTestCase({
        name: "Page.setShowPaintRects.Disabled",
        description: "Test that paint rects are not created while disabled.",
        setup,
        teardown,
        async test() {
            await PageAgent.setShowPaintRects(false);
            await expectHasPaintRects(false);

            let hasPaintRectsDidChange = Promise.race([
                InspectorTest.awaitEvent("TestHasPaintRectsDidChange").then(() => true),
                new Promise((resolve) => { setTimeout(resolve, 500, false); }),
            ]);

            await InspectorTest.evaluateInPage(`document.getElementById("test").style.backgroundColor = "rebeccapurple"`);
            InspectorTest.expectFalse(await hasPaintRectsDidChange, `Should not have had any paint rects displayed.`);
        }
    });

    suite.runTestCasesAndFinish();
}
</script>
<style>
#test {
    width: 100px;
    height: 100px;
    background-color: gainsboro;
}
</style>
</head>
<body onload="runTest()">
<p>Tests for the Page.setShowPaintRects.</p>
<div id="test"></div>
</body>
</html>
