tor-browser

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

edit-context-focus.tentative.html (1568B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>EditContext: The activation is synced with the associated element being focused or not</title>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/resources/testdriver.js"></script>
      8 <script src="/resources/testdriver-actions.js"></script>
      9 <script src="/resources/testdriver-vendor.js"></script>
     10 </head>
     11 <body>
     12 <div>Test</div>
     13 <button>Click</button>
     14 <input type="text" value="" />
     15 <script>
     16 promise_test(async () => {
     17  const div = document.querySelector('div');
     18  const editContext = new EditContext();
     19  let firedTextUpdate = false;
     20  editContext.addEventListener('textupdate', e => {
     21    firedTextUpdate = true;
     22    div.textContent = e.text;
     23  });
     24  div.editContext = editContext;
     25  div.focus();
     26  assert_equals(document.activeElement, div);
     27 
     28  const button = document.querySelector('button');
     29  const input = document.querySelector('input');
     30  button.addEventListener('focus', () => {
     31    input.focus();
     32  });
     33  await test_driver.click(button);
     34  // The focus is on the input element, editContext should be deactivated.
     35  assert_equals(document.activeElement, input);
     36 
     37  const key = 'A';
     38  await (new test_driver.Actions()
     39    .keyDown(key)
     40    .keyUp(key)
     41    .send());
     42  assert_false(firedTextUpdate);
     43  assert_equals(div.textContent, 'Test');
     44  assert_equals(input.value, key);
     45 }, `If an element with an associated EditContext loses focus, the EditContext is deactivated even when another focus change was triggered recursively.`);
     46 </script>
     47 </body>
     48 </html>