<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <title>Yomichan Manual Tests</title>
        <link rel="icon" type="image/gif" href="data:image/gif;base64,R0lGODlhEAAQAKEBAAAAAP///////////yH5BAEKAAIALAAAAAAQABAAAAImFI6Zpt0B4YkS0TCpq07xbmEgcGVRUpLaI46ZG7ppalY0jDCwUAAAOw==">
        <link rel="stylesheet" href="test-stylesheet.css">
        <script src="test-document2-script.js"></script>
    </head>
    <style id="container-styles">
.container {
    width: 100%;
    height: 200px;
    border: 1px solid #d8d8d8;
    position: relative;
    box-sizing: border-box;
}
.container-inner {
    background-color: #f8f8f8;
    padding: 0.5em;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
}
    </style>
<body>

    <h1>Yomichan Manual Tests</h1>
    <y-description>Manual tests involving fullscreen elements, &lt;iframe&gt;s, and shadow DOMs.</y-description>

    <y-test>
        <y-description>Standard content.</y-description>
        <div class="fullscreen-element container"><div class="container-inner">
            <div>
                ありがとう
            </div>
            <div>
                <a href="#" class="fullscreen-link">Toggle fullscreen</a>
            </div>
        </div></div>
    </y-test>

    <y-test data-shadow-mode="open">
        <y-description>Content inside of an open shadow DOM.</y-description>
        <div class="template-content-container"></div>
        <template>
            <link rel="stylesheet" href="test-stylesheet.css">
            <div class="fullscreen-element container"><div class="container-inner">
                <div>
                    ありがとう
                </div>
                <div>
                    <a href="#" class="fullscreen-link">Toggle fullscreen</a>
                </div>
            </div></div>
        </template>
    </y-test>

    <y-test data-shadow-mode="closed">
        <y-description>Content inside of a closed shadow DOM.</y-description>
        <div class="template-content-container"></div>
        <template>
            <link rel="stylesheet" href="test-stylesheet.css">
            <div class="fullscreen-element container"><div class="container-inner">
                <div>
                    ありがとう
                </div>
                <div>
                    <a href="#" class="fullscreen-link">Toggle fullscreen</a>
                </div>
            </div></div>
        </template>
    </y-test>

    <y-test>
        <y-description>&lt;iframe&gt; element.</y-description>
        <iframe src="test-document2-frame1.html" allowfullscreen="true" class="container"></iframe>
    </y-test>

    <y-test data-shadow-mode="open">
        <y-description>&lt;iframe&gt; element inside of an open shadow DOM.</y-description>
        <div class="template-content-container"></div>
        <template>
            <iframe src="test-document2-frame1.html" allowfullscreen="true" class="container"></iframe>
        </template>
    </y-test>

    <y-test data-shadow-mode="closed">
        <y-description>&lt;iframe&gt; element inside of a closed shadow DOM.</y-description>
        <div class="template-content-container"></div>
        <template>
            <iframe src="test-document2-frame1.html" allowfullscreen="true" class="container"></iframe>
        </template>
    </y-test>

    <y-test>
        <y-description>&lt;iframe&gt; element with data URL.</y-description>
        <iframe id="iframe-with-data-url" src="data:text/html;base64,PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCiAgICA8aGVhZD4NCiAgICAgICAgPG1ldGEgY2hhcnNldD0iVVRGLTgiPg0KICAgICAgICA8bWV0YSBuYW1lPSJ2aWV3cG9ydCIgY29udGVudD0id2lkdGg9ZGV2aWNlLXdpZHRoLGluaXRpYWwtc2NhbGU9MSIgLz4NCiAgICAgICAgPHRpdGxlPllvbWljaGFuIFRlc3RzPC90aXRsZT4NCiAgICAgICAgPHNjcmlwdD4NCmZ1bmN0aW9uIHRvZ2dsZUZ1bGxzY3JlZW4oZWxlbWVudCkgew0KICAgIGlmIChnZXRGdWxsc2NyZWVuRWxlbWVudCgpKSB7DQogICAgICAgIGV4aXRGdWxsc2NyZWVuKCk7DQogICAgfSBlbHNlIHsNCiAgICAgICAgcmVxdWVzdEZ1bGxzY3JlZW4oZWxlbWVudCk7DQogICAgfQ0KfQ0KDQpmdW5jdGlvbiBzZXR1cChjb250YWluZXIsIGZ1bGxzY3JlZW5FbGVtZW50PW51bGwpIHsNCiAgICBjb25zdCBmdWxsc2NyZWVuTGluayA9IGNvbnRhaW5lci5xdWVyeVNlbGVjdG9yKCcuZnVsbHNjcmVlbi1saW5rJyk7DQogICAgaWYgKGZ1bGxzY3JlZW5MaW5rICE9PSBudWxsKSB7DQogICAgICAgIGlmI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Go44GGDQo8L2Rpdj4NCjxkaXY+DQogICAgPGEgaHJlZj0iIyIgY2xhc3M9ImZ1bGxzY3JlZW4tbGluayI+VG9nZ2xlIGZ1bGxzY3JlZW48L2E+DQogICAgPHNjcmlwdD5zZXR1cChkb2N1bWVudC5ib2R5LCBkb2N1bWVudC5ib2R5KTs8L3NjcmlwdD4NCjwvZGl2Pg0KPC9kaXY+PC9ib2R5Pg0KPC9odG1sPg==" allowfullscreen="true" class="container"></iframe>
    </y-test>

    <y-test>
        <y-description>&lt;iframe&gt; element with blob URL.</y-description>
        <iframe id="iframe-with-blob-url" allowfullscreen="true" class="container"></iframe>
    </y-test>

    <y-test>
        <y-description>SVG &lt;img&gt;.</y-description>
        <img src="test-document2-frame2.svg" class="container" alt="">
    </y-test>

    <y-test>
        <y-description>SVG &lt;object&gt;.</y-description>
        <object data="test-document2-frame2.svg" type="image/svg+xml" class="container"></object>
    </y-test>

    <y-test>
        <y-description>SVG &lt;embed&gt;.</y-description>
        <embed type="image/svg+xml" src="test-document2-frame2.svg" class="container">
    </y-test>

    <y-test>
        <y-description>SVG &lt;iframe&gt;.</y-description>
        <iframe src="test-document2-frame2.svg" allowfullscreen="true" class="container"></iframe>
    </y-test>

    <y-test>
        <y-description>SVG &lt;svg&gt;.</y-description>
        <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="container" style="background-color: #f8f8f8;" focusable="false">
            <text
                x="7"
                y="12"
                style="
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                font-size: 14px;
                fill: #000000;
                dominant-baseline: hanging;"
            >
                ありがとう
            </text>
        </svg>
    </y-test>


    <script>
(() => {
    function stringToTypedArray(string) {
        const array = new Uint8Array(string.length);
        for (let i = 0; i < string.length; ++i) {
            array[i] = string.charCodeAt(i);
        }
        return array;
    }

    function dataUrlToBlob(dataUrl) {
        let [, type, isBase64, data] = /^data:([^;]*);(base64,)?([\w\W]*)$/.exec(dataUrl);
        data = (
            isBase64 ?
            new TextDecoder().decode(stringToTypedArray(atob(data))) :
            data
        );
        return new Blob([data], {type});
    }

    for (const element of document.querySelectorAll('y-test')) {
        setup(element);
    }

    const iframeWithDataUrl = document.querySelector('#iframe-with-data-url');
    const iframeWithBlobUrl = document.querySelector('#iframe-with-blob-url');
    iframeWithBlobUrl.src = URL.createObjectURL(dataUrlToBlob(iframeWithDataUrl.src));
})();
    </script>

</body>
</html>