editor/libeditor/html/tests/test_bug442186.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=442186
     5 -->
     6 <head>
     7   <title>Test for Bug 442186</title>
     8   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    11 </head>
    12 <body>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=442186">Mozilla Bug 442186</a>
    14 <p id="display"></p>
    15 <div id="content">
    16   <h2> two &lt;div&gt; containers </h2>
    17   <section contenteditable id="test1">
    18     <div> First paragraph with some text. </div>
    19     <div> Second paragraph with some text. </div>
    20   </section>
    22   <h2> two paragraphs </h2>
    23   <section contenteditable id="test2">
    24     <p> First paragraph with some text. </p>
    25     <p> Second paragraph with some text. </p>
    26   </section>
    28   <h2> one text node, one paragraph </h2>
    29   <section contenteditable id="test3">
    30     First paragraph with some text.
    31     <p> Second paragraph with some text. </p>
    32   </section>
    33 </div>
    35 <pre id="test">
    36 <script type="application/javascript">
    38 /** Test for Bug 442186 **/
    39 SimpleTest.waitForExplicitFinish();
    40 SimpleTest.waitForFocus(runTests);
    42 function justify(textNode, pos) {
    43   if (!pos) pos = 10;
    45   // put the caret on the requested character
    46   var range = document.createRange();
    47   var sel = window.getSelection();
    48   range.setStart(textNode, pos);
    49   range.setEnd(textNode, pos);
    50   sel.addRange(range);
    52   // align
    53   document.execCommand("justifyright", false, null);
    54 }
    56 function runTests() {
    57   document.execCommand("stylewithcss", false, "true");
    59   const test1 = document.getElementById("test1");
    60   const test2 = document.getElementById("test2");
    61   const test3 = document.getElementById("test3");
    63   // #test1: two <div> containers
    64   const line1 = test1.querySelector("div").firstChild;
    65   test1.focus();
    66   justify(line1);
    67   is(test1.querySelectorAll("*").length, 2,
    68     "Aligning the first child should not create nor remove any element.");
    69   is(line1.parentNode.nodeName.toLowerCase(), "div",
    70     "Aligning the first <div> should not modify its node type.");
    71   is(line1.parentNode.style.textAlign, "right",
    72     "Aligning the first <div> should set a 'text-align: right' style rule.");
    74   // #test2: two paragraphs
    75   const line2 = test2.querySelector("p").firstChild;
    76   test2.focus();
    77   justify(line2);
    78   is(test2.querySelectorAll("*").length, 2,
    79     "Aligning the first child should not create nor remove any element.");
    80   is(line2.parentNode.nodeName.toLowerCase(), "p",
    81     "Aligning the first paragraph should not modify its node type.");
    82   is(line2.parentNode.style.textAlign, "right",
    83     "Aligning the first paragraph should set a 'text-align: right' style rule.");
    85   // #test3: one text node, two paragraphs
    86   const line3 = test3.firstChild;
    87   test3.focus();
    88   justify(line3);
    89   is(test3.querySelectorAll("*").length, 2,
    90     "Aligning the first child should create a block element.");
    91   is(line3.parentNode.nodeName.toLowerCase(), "div",
    92     "Aligning the first child should create a block element.");
    93   is(line3.parentNode.style.textAlign, "right",
    94     "Aligning the first line should set a 'text-align: right' style rule.");
    96   // done
    97   SimpleTest.finish();
    98 }
   100 </script>
   101 </pre>
   102 </body>
   103 </html>

mercurial