tor-browser

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

auxclick_event.html (3528B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <meta charset="utf-8">
      5    <title>Clicking with primary vs non-primary buttons</title>
      6    <link rel="help" href="https://wicg.github.io/auxclick/">
      7    <script src="/resources/testharness.js"></script>
      8    <script src="/resources/testharnessreport.js"></script>
      9    <script src="/resources/testdriver.js"></script>
     10    <script src="/resources/testdriver-actions.js"></script>
     11    <script src="/resources/testdriver-vendor.js"></script>
     12    <style>
     13 #target {
     14  background-color: green;
     15  height: 200px;
     16  width: 200px;
     17 }
     18    </style>
     19  </head>
     20  <body>
     21    <h1>Clicking with primary vs non-primary buttons</h1>
     22    <p>Double-click on the green box with a non-primary button. When using mouse any button other than the left button is non-primary. If a "PASS" result appears, the test passes; otherwise, it fails.</p>
     23    <div id="target"></div>
     24    <script>
     25    var test_auxclick = async_test("auxclick event sequence received.");
     26    var actions_promise;
     27    var target = document.querySelector('#target');
     28    document.addEventListener('contextmenu', event => { event.preventDefault(); });
     29    ['click', 'dblclick'].forEach(eventName => {
     30        target.addEventListener(eventName, () => {
     31            test_auxclick.step(() => {
     32                assert_unreached(eventName + ' event should not be dispatched for non-primary buttons.');
     33            });
     34        });
     35        document.addEventListener(eventName, () => {
     36            test_auxclick.step(() => {
     37                assert_unreached('document should not receive ' + eventName + ' for non-primary buttons.');
     38            });
     39        }, true);
     40    });
     41    var click_count = 0;
     42    var events = [];
     43    ['mousedown', 'mouseup'].forEach(eventName => {
     44        target.addEventListener(eventName, event => {
     45            events.push(event.type);
     46        });
     47    });
     48    target.addEventListener('auxclick', event => {
     49        events.push(event.type);
     50        click_count++;
     51        if (click_count==1) {
     52           test (() => {
     53               assert_equals(event.detail, click_count, 'detail attribute of auxclick should be the click count.');
     54           }, "First auxclick should have detail=1 indicating the fire click");
     55        } else {
     56           test (() => {
     57               assert_equals(event.detail, click_count, 'detail attribute of auxclick should be the click count.');
     58           }, "Second auxclick should have detail=2 indicating the fire click");
     59            test_auxclick.step(() => {
     60                assert_array_equals(events, ['mousedown', 'mouseup', 'auxclick', 'mousedown', 'mouseup', 'auxclick'],
     61                    'There should be two auxclick events for a non-primary button double click each preceded by one mousemove and one mouseup');
     62                assert_equals(event.detail, click_count, 'detail attribute of auxclick should be the click count.');
     63            });
     64            // Make sure the test finishes after all the input actions are completed.
     65            actions_promise.then( () => {
     66                test_auxclick.done();
     67            });
     68        }
     69    });
     70 
     71    // Inject mouse double click events.
     72    var actions = new test_driver.Actions();
     73    actions_promise = actions.pointerMove(0, 0, {origin: target})
     74           .pointerDown({button: actions.ButtonType.MIDDLE})
     75           .pointerUp({button: actions.ButtonType.MIDDLE})
     76           .pointerDown({button: actions.ButtonType.MIDDLE})
     77           .pointerUp({button: actions.ButtonType.MIDDLE})
     78           .send();
     79    </script>
     80  </body>
     81 </html>