tor-browser

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

test_bug1248459.html (1577B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1248459
      5 -->
      6 <head>
      7  <title>Test for Bug 1248459</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 <input id="input" value="foo">
     14 <div id="div">bar</div>
     15 <script type="application/javascript">
     16 
     17 /** Test for Bug 1248459 */
     18 /**
     19 * The bug occurs when a piece of text outside of the editor's root element is
     20 * somehow selected when the editor is focused. In the bug's case, it's the
     21 * placeholder anonymous div that's selected. In this test's case, it's a
     22 * document div that's selected.
     23 */
     24 SimpleTest.waitForExplicitFinish();
     25 
     26 SimpleTest.waitForFocus(function() {
     27  var div = document.getElementById("div");
     28  var input = document.getElementById("input");
     29 
     30  input.appendChild(div);
     31  input.focus();
     32 
     33  var editor = SpecialPowers.wrap(input).editor;
     34  var sel = editor.selection;
     35 
     36  sel.selectAllChildren(editor.rootElement);
     37  var result = synthesizeQuerySelectedText();
     38 
     39  ok(result.succeeded, "Query selected text should succeed");
     40  is(result.offset, 0, "Selected text should be at offset 0");
     41  is(result.text, "foo", "Selected text should match");
     42 
     43  var range = document.createRange();
     44  range.selectNode(div);
     45 
     46  sel.removeAllRanges();
     47  sel.addRange(range);
     48 
     49  result = synthesizeQuerySelectedText();
     50 
     51  ok(!result.succeeded, "Query out-of-bounds selection should fail");
     52 
     53  SimpleTest.finish();
     54 });
     55 
     56 </script>
     57 </body>
     58 </html>