tor-browser

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

dispatchEvent.click.checkbox.html (2552B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title> MouseEvent: Default action and synthetic click event </title>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 </head>
      8 <body>
      9 <div id=log></div>
     10 
     11 <div style="display: none">
     12    <input type="checkbox" id="target">
     13    <button id="button"> Click Here </button>
     14 </div>
     15 
     16 <script>
     17    setup({explicit_done:true});
     18    var EVENT = "click";
     19    var TARGET = document.getElementById("target");
     20    var BUTTON = document.getElementById("button");
     21    var state;
     22 
     23    var description = "Test Description: " +
     24                      "MouseEvent: Default action is performed when a synthetic click event is dispatched on a checkbox element";
     25 
     26    BUTTON.addEventListener(EVENT, TestEvent, true);
     27    TARGET.addEventListener(EVENT, TestEvent, true);
     28 
     29    window.onload = function()
     30    {
     31        state = TARGET.checked;
     32        BUTTON.click();
     33    }
     34 
     35    function TestEvent(evt)
     36    {
     37        if (BUTTON == evt.target)
     38        {
     39            var e;
     40            test(function()
     41            {
     42                BUTTON.removeEventListener(EVENT, TestEvent, true);
     43 
     44                e = document.createEvent("MouseEvent");
     45                e.initMouseEvent(EVENT,  /* type */
     46                                 false,  /* bubbles */
     47                                 true,   /* cancelable */
     48                                 window, /* view */
     49                                 1,      /* detail */
     50                                 0,      /* screenX */
     51                                 0,      /* screenY */
     52                                 0,      /* clientX */
     53                                 0,      /* clientY */
     54                                 false,  /* ctrlKey */
     55                                 false,  /* altKey */
     56                                 false,  /* shiftKey */
     57                                 false,  /* metaKey */
     58                                 0,      /* button */
     59                                 null    /* relatedTarget */);
     60 
     61                assert_array_equals([TARGET.checked, e.type, e.bubbles], [state, EVENT, false]);
     62 
     63            }, "Checkbox state is unchanged before the synthetic click event is dispatched");
     64 
     65            TARGET.dispatchEvent(e);
     66        }
     67        else if (TARGET == evt.target)
     68        {
     69            test(function()
     70            {
     71                assert_array_equals([TARGET.checked, evt.type, evt.bubbles], [!state, EVENT, false]);
     72 
     73            }, description);
     74 
     75            done();
     76        }
     77    }
     78 </script>
     79 </body>
     80 </html>