tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

cdata-dir_auto.html (2470B)


      1 <!DOCTYPE html>
      2 <head>
      3    <meta charset="utf-8">
      4    <link rel="author" title="Vincent Hilla" href="mailto:vhilla@mozilla.com">
      5    <link rel="help" href="https://html.spec.whatwg.org/multipage/dom.html#the-directionality">
      6    <script src="/resources/testharness.js"></script>
      7    <script src="/resources/testharnessreport.js"></script>
      8 </head>
      9 <body>
     10    <div id="test1" dir="auto">
     11        <![CDATA[foo]]>اختبر
     12    </div>
     13 
     14    <iframe src="cdata-iframe.xhtml"></iframe>
     15 
     16    <script>
     17        function awaitMessage(msg) {
     18            return new Promise(res => {
     19                function waitAndRemove(e) {
     20                    if (e.data != msg)
     21                        return;
     22                    window.removeEventListener("message", waitAndRemove);
     23                    res();
     24                }
     25                window.addEventListener("message", waitAndRemove);
     26            });
     27        }
     28 
     29        const subframeLoaded = awaitMessage("subframe-loaded");
     30 
     31        async function createXHTMLCase(id) {
     32            await subframeLoaded;
     33 
     34            let iframe = document.querySelector("iframe");
     35            iframe.contentWindow.postMessage(id, "*");
     36 
     37            await awaitMessage(id);
     38 
     39            const doc = iframe.contentDocument;
     40            const div = doc.getElementById(id);
     41            const cdata = div.firstChild;
     42 
     43            return [div, cdata];
     44        }
     45 
     46        test(function() {
     47            const div = document.getElementById("test1");
     48            assert_true(div.matches(":dir(rtl)"));
     49        }, "Content of CDATA is ignored for dir=auto in html document");
     50 
     51        promise_test(async function() {
     52            let [div, cdata] = await createXHTMLCase(1);
     53            assert_true(div.matches(":dir(ltr)"));
     54        }, "Text in CDATASection is considered when determining auto directionality");
     55 
     56        promise_test(async function() {
     57            let [div, cdata] = await createXHTMLCase(2);
     58            assert_true(div.matches(":dir(ltr)"));
     59            cdata.remove();
     60            assert_true(div.matches(":dir(rtl)"));
     61        }, "Directionality is updated when removing CDATASection");
     62 
     63        promise_test(async function() {
     64            let [div, cdata] = await createXHTMLCase(3);
     65            assert_true(div.matches(":dir(ltr)"));
     66            cdata.textContent = "اختبر";
     67            assert_true(div.matches(":dir(rtl)"));
     68        }, "Directionality is updated when changing text of CDATASection");
     69    </script>
     70 </body>
     71 </html>