tor-browser

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

test_bug551704.html (3878B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=551704
      5 -->
      6 <head>
      7  <title>Test for Bug 551704</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=551704">Mozilla Bug 551704</a>
     14 <p id="display"></p>
     15 <div id="content">
     16  <div id="preformatted" style="white-space: pre" contenteditable>a&#10;b</div>
     17  <div id="test1" contenteditable><br></div>
     18  <div id="test2" contenteditable>a<br></div>
     19  <div id="test3" contenteditable style="white-space: pre"><br></div>
     20  <div id="test4" contenteditable style="white-space: pre">a<br></div>
     21  <div id="test5" contenteditable></div>
     22  <div id="test6" contenteditable>a</div>
     23  <div id="test7" contenteditable style="white-space: pre"></div>
     24  <div id="test8" contenteditable style="white-space: pre">a</div>
     25 </div>
     26 <pre id="test">
     27 <script type="application/javascript">
     28 
     29 function testLineBreak(div, type, expectedText, expectedHTML, callback) {
     30  div.focus();
     31  getSelection().collapse(div, 0);
     32  type();
     33  is(div.innerHTML, expectedHTML, "The expected HTML after editing should be correct");
     34  requestAnimationFrame(function() {
     35    SimpleTest.waitForClipboard(expectedText,
     36      function() {
     37        getSelection().selectAllChildren(div);
     38        synthesizeKey("C", {accelKey: true});
     39      },
     40      function() {
     41        var t = document.createElement("textarea");
     42        document.body.appendChild(t);
     43        t.focus();
     44        synthesizeKey("V", {accelKey: true});
     45        is(t.value, expectedText, "The expected text should be copied to the clipboard");
     46        callback();
     47      },
     48      function() {
     49        SimpleTest.finish();
     50      }
     51    );
     52  });
     53 }
     54 
     55 function typeABCDEF() {
     56  sendString("a");
     57  typeBCDEF_chars();
     58 }
     59 
     60 function typeBCDEF() {
     61  synthesizeKey("KEY_ArrowRight");
     62  typeBCDEF_chars();
     63 }
     64 
     65 function typeBCDEF_chars() {
     66  sendString("bc");
     67  synthesizeKey("KEY_Enter");
     68  sendString("def");
     69 }
     70 
     71 /** Test for Bug 551704 */
     72 SimpleTest.waitForExplicitFinish();
     73 SimpleTest.waitForFocus(function() {
     74  document.execCommand("defaultParagraphSeparator", false, "div");
     75 
     76  var preformatted = document.getElementById("preformatted");
     77  is(preformatted.innerHTML, "a\nb", "No BR node should be injected for preformatted editable fields");
     78 
     79  var iframe = document.createElement("iframe");
     80  iframe.addEventListener("load", function() {
     81    var sel = iframe.contentWindow.getSelection();
     82    is(sel.rangeCount, 0, "There should be no range in the selection initially");
     83    iframe.contentDocument.designMode = "on";
     84    sel = iframe.contentWindow.getSelection();
     85    is(sel.rangeCount, 1, "There should be a single range in the selection after setting designMode");
     86    var range = sel.getRangeAt(0);
     87    ok(range.collapsed, "The range should be collapsed");
     88    is(range.startContainer, iframe.contentDocument.body.firstChild, "The range should start on the text");
     89    is(range.startOffset, 0, "The start offset should be zero");
     90 
     91    continueTest();
     92  });
     93  iframe.srcdoc = "foo";
     94  document.getElementById("content").appendChild(iframe);
     95 });
     96 
     97 function continueTest() {
     98  var divs = [];
     99  for (var i = 0; i < 8; ++i) {
    100    divs[i] = document.getElementById("test" + (i + 1));
    101  }
    102  var current = 0;
    103  function doNextTest() {
    104    if (current == divs.length) {
    105      SimpleTest.finish();
    106      return;
    107    }
    108    var div = divs[current++];
    109    let type;
    110    if (div.textContent == "a") {
    111      type = typeBCDEF;
    112    } else {
    113      type = typeABCDEF;
    114    }
    115    var expectedHTML = "<div>abc</div><div>def</div>";
    116    var expectedText = "abc\ndef";
    117    testLineBreak(div, type, expectedText, expectedHTML, doNextTest);
    118  }
    119 
    120  doNextTest();
    121 }
    122 
    123 </script>
    124 </pre>
    125 </body>
    126 </html>