tor-browser

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

test_bug442186.html (3248B)


      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 src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script 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>
     21 
     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>
     27 
     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>
     34 
     35 <pre id="test">
     36 <script type="application/javascript">
     37 
     38 /** Test for Bug 442186 */
     39 SimpleTest.waitForExplicitFinish();
     40 SimpleTest.waitForFocus(runTests);
     41 
     42 function justify(textNode, pos) {
     43  if (!pos) pos = 10;
     44 
     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);
     51 
     52  // align
     53  document.execCommand("justifyright", false, null);
     54 }
     55 
     56 function runTests() {
     57  document.execCommand("stylewithcss", false, "true");
     58 
     59  const test1 = document.getElementById("test1");
     60  const test2 = document.getElementById("test2");
     61  const test3 = document.getElementById("test3");
     62 
     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.");
     73 
     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.");
     84 
     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.");
     95 
     96  // done
     97  SimpleTest.finish();
     98 }
     99 
    100 </script>
    101 </pre>
    102 </body>
    103 </html>