tor-browser

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

test_slotted_text_click.html (2033B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>Bug 1481500: click / activation on text activates the slot it's assigned to</title>
      4 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      5 <script src="/tests/SimpleTest/EventUtils.js"></script>
      6 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
      7 <script>
      8 function generateLotsOfText() {
      9  let text = "Some text. ";
     10  for (let i = 0; i < 10; ++i)
     11    text += text;
     12  return text;
     13 }
     14 
     15 function runTests() {
     16  let iframe = document.createElement('iframe');
     17  document.body.appendChild(iframe);
     18  iframe.onload = () => frameLoaded(iframe);
     19  iframe.width = "350"
     20  iframe.height = "350"
     21  iframe.srcdoc =
     22    `<div id="host">${generateLotsOfText()}</div>`
     23 }
     24 
     25 function frameLoaded(iframe) {
     26  let host = iframe.contentDocument.getElementById('host');
     27 
     28  host.attachShadow({ mode: 'open' }).innerHTML = `
     29    <style>
     30      :host {
     31        width: 300px;
     32        height: 300px;
     33        overflow: hidden;
     34      }
     35    </style>
     36    <slot></slot>
     37  `;
     38 
     39  let slot = host.shadowRoot.querySelector('slot');
     40  let mousedownFired = false;
     41  let mouseupFired = false;
     42  slot.addEventListener('mousedown', function() {
     43    ok(true, "Mousedown should fire on the slot when clicking on text");
     44    mousedownFired = true;
     45  });
     46 
     47  slot.addEventListener('click', function() {
     48    ok(true, "Click should target the slot");
     49    ok(mousedownFired, "mousedown should've fired");
     50    ok(mouseupFired, "click should've fired");
     51    SimpleTest.finish();
     52  });
     53 
     54  slot.addEventListener('mouseup', function() {
     55    // FIXME: When we fix bug 1481517, this check should move to the mousedown listener.
     56    ok(this.matches(":active"), "Slot should become active");
     57    mouseupFired = true;
     58  });
     59 
     60  requestAnimationFrame(() => {
     61    requestAnimationFrame(() => {
     62      synthesizeMouseAtPoint(150, 150, { type: "mousedown" });
     63      synthesizeMouseAtPoint(150, 150, { type: "mouseup" });
     64    });
     65  });
     66 }
     67 
     68 SimpleTest.waitForExplicitFinish();
     69 window.onload = () => {
     70  SimpleTest.waitForFocus(runTests);
     71 };
     72 </script>