tor-browser

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

fire-selectionchange-event-on-textcontrol-element-on-pressing-backspace.html (1882B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Test selectionchange event fired on Text Control element</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/resources/testdriver.js"></script>
      7 <script src="/resources/testdriver-vendor.js"></script>
      8 
      9 <input id="input" type="text" value="hello">
     10 
     11 <script>
     12    const element = document.querySelector("input");
     13    const events_on_document = [];
     14    document.addEventListener("selectionchange", ev => {
     15        events_on_document.push(ev);
     16    });
     17 
     18    const events_on_input = [];
     19    element.addEventListener("selectionchange", ev => {
     20        events_on_input.push(ev);
     21    });
     22 
     23    promise_test(async () => {
     24        element.focus();
     25        element.setSelectionRange(5, 5);
     26        await new Promise(resolve => step_timeout(resolve, 500));
     27        events_on_document.length = 0;
     28        events_on_input.length = 0;
     29 
     30        assert_equals(element.selectionStart, 5, "selectionStart before pressing backspace key");
     31        assert_equals(element.selectionEnd, 5, "selectionEnd before pressing backspace key");
     32 
     33        await new test_driver.send_keys(element, "\uE003");
     34 
     35        assert_equals(element.selectionStart, 4, "selectionStart after pressing backspace key");
     36        assert_equals(element.selectionEnd, 4, "selectionEnd after pressing backspace key");
     37 
     38        // Waits a short time to allow any events to be processed.
     39        await new Promise(resolve => step_timeout(resolve, 500));
     40        assert_equals(events_on_input.length, 1);
     41 
     42        //selectionchange event fired on a text control should bubble to the document
     43        assert_equals(events_on_document[0].target, element, "Event target should be the input element");
     44        assert_equals(events_on_document.length, 1);
     45 
     46    }, "selectionchange event fired on an input element");
     47 </script>