tor-browser

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

test_bug611182.html (2919B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=611182
      5 -->
      6 <head>
      7  <title>Test for Bug 611182</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/EventUtils.js"></script>
     10  <script src="/tests/SimpleTest/WindowSnapshot.js"></script>
     11  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=611182">Mozilla Bug 611182</a>
     15 <p id="display"></p>
     16 <div id="content">
     17  <iframe></iframe>
     18  <iframe id="ref" src="./file_bug611182.html"></iframe>
     19 </div>
     20 <pre id="test">
     21 <script type="application/javascript">
     22 
     23 /** Test for Bug 611182 */
     24 SimpleTest.waitForExplicitFinish();
     25 SimpleTest.waitForFocus(function() {
     26  var iframe = document.querySelector("iframe");
     27  var refElem = document.querySelector("#ref");
     28  var ref = snapshotWindow(refElem.contentWindow, false);
     29 
     30  function findTextNode(doc) {
     31    var body = doc.documentElement;
     32    var result = findTextNodeWorker(body);
     33    ok(result, "Failed to find the text node");
     34    return result;
     35  }
     36 
     37  function findTextNodeWorker(root) {
     38    if (root.isContentEditable) {
     39      root.focus();
     40    }
     41    for (var i = 0; i < root.childNodes.length; ++i) {
     42      var node = root.childNodes[i];
     43      if (node.nodeType == node.TEXT_NODE &&
     44          node.nodeValue == "fooz bar") {
     45        return node;
     46      }
     47      if (node.nodeType == node.ELEMENT_NODE) {
     48        node = findTextNodeWorker(node);
     49        if (node) {
     50          return node;
     51        }
     52      }
     53    }
     54    return null;
     55  }
     56 
     57  function testBackspace(src, callback) {
     58    ok(true, "Testing " + src);
     59    iframe.addEventListener("load", function() {
     60      var doc = iframe.contentDocument;
     61      var win = iframe.contentWindow;
     62      doc.body.setAttribute("spellcheck", "false");
     63 
     64      iframe.focus();
     65      var textNode = findTextNode(doc);
     66      var sel = win.getSelection();
     67      sel.collapse(textNode, 4);
     68      synthesizeKey("KEY_Backspace");
     69      is(textNode.textContent, "foo bar", "Backspace should work correctly");
     70 
     71      var snapshot = snapshotWindow(win, false);
     72      ok(compareSnapshots(snapshot, ref, true)[0],
     73         "No padding <br> element should exist in the document");
     74 
     75      callback();
     76    }, {once: true});
     77    iframe.src = src;
     78  }
     79 
     80  var totalTests = 0;
     81  var currentTest = 0;
     82  function runAllTests() {
     83    if (currentTest == totalTests) {
     84      SimpleTest.finish();
     85      return;
     86    }
     87    testBackspace("file_bug611182.sjs?" + currentTest, runAllTests);
     88    currentTest++;
     89  }
     90 
     91  // query total number of tests to be run from the server and
     92  // start running all tests.
     93  var myXHR = new XMLHttpRequest();
     94  myXHR.open("GET", "file_bug611182.sjs?queryTotalTests");
     95  myXHR.onload = function() {
     96    totalTests = myXHR.responseText;
     97    runAllTests();
     98  };
     99  myXHR.send();
    100 });
    101 
    102 </script>
    103 </pre>
    104 </body>
    105 </html>