<!DOCTYPE HTML>
<html>
<head>
    <style>iframe { display: none; }</style>
    <script src="../resources/js-test-pre.js"></script>
    <script>
    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    function waitFor(element, type) {
        return new Promise(resolve => {
            element.addEventListener(type, event => {
                resolve(event);
            }, { once: true });
        });
    }

    window.addEventListener('load', async event => {
        try {
            let attributeFilter = attribute => { return attribute.name !== 'data-enabled'; };
            let attributeMap = attribute => {
                if (attribute.value === '')
                    return attribute.name;
                if (attribute.name === 'src')
                    return `${attribute.name}="${attribute.value.substring(0, 10)}..."`;
                return `${attribute.name}="${attribute.value}"`;
            }

            for (var frame of document.querySelectorAll('iframe')) {
                frame.contentWindow.postMessage(["eval", 'parent.postMessage(document.webkitFullscreenEnabled, "*")'], "*");
                let messageEvent = await waitFor(window, 'message');
                let expectedMessage = frame.getAttribute('data-enabled');
                let frameAttributes = Array.prototype.filter.call(frame.attributes, attributeFilter).map(attributeMap);
                let testDescription = `iframe with ${ frameAttributes.join(', ') } should have document.webkitFullscreenEnabled === ${ expectedMessage }`;
                if (String(messageEvent.data) === expectedMessage)
                    testPassed(`${testDescription}.`);
                else
                    testFailed(`${testDescription}, was ${ messageEvent.data }`);
            }
        } catch(e) {
            testFailed(`Should not throw. Threw exception ${ e }.`)
        }
        if (window.testRunner)
            testRunner.notifyDone();
    });
    </script>
</head>
<body>
    <iframe data-enabled="false" src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe data-enabled="true" src="../resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen" data-enabled="true" src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen" data-enabled="true" src="../resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen *" data-enabled="true" src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen *" data-enabled="true" src="../resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'none'" data-enabled="false" src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'none'" data-enabled="false" src="../resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'self'" data-enabled="false" src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'self'" data-enabled="true" src="../resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen http://localhost:8000" data-enabled="true" src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen http://localhost:8000" data-enabled="false" src="../resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allowfullscreen data-enabled="true"  src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allowfullscreen data-enabled="true" src="../resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'none'" allowfullscreen data-enabled="false" src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'none'" allowfullscreen data-enabled="false" src="../resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'self'" allowfullscreen data-enabled="false" src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'self'" allowfullscreen data-enabled="true" src="../resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe webkitallowfullscreen data-enabled="true" src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe webkitallowfullscreen data-enabled="true" src="../resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'none'" webkitallowfullscreen data-enabled="false" src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'none'" webkitallowfullscreen data-enabled="false" src="../resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'self'" webkitallowfullscreen data-enabled="false" src="http://localhost:8000/resources/pointer-lock/inner-iframe.html"></iframe>
    <iframe allow="fullscreen 'self'" webkitallowfullscreen data-enabled="true" src="../resources/pointer-lock/inner-iframe.html"></iframe>
</body>
