tor-browser

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

dialog-closedby-start-open.html (3069B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <meta name="timeout" content="long">
      4 <link rel=help href="https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-light-dismiss">
      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 <script src="../../popovers/resources/popover-utils.js"></script>
     11 
     12 <dialog id=test1 open closedby="any"></dialog>
     13 
     14 <script>
     15 const ESC = '\uE00C';
     16 promise_test(async (t) => {
     17  const dialog = document.querySelector('dialog#test1');
     18  assert_true(dialog.open);
     19  assert_true(dialog.matches('[open]'));
     20  await new test_driver.send_keys(document.documentElement,ESC);
     21  assert_false(dialog.open);
     22  assert_false(dialog.matches('[open]'));
     23  dialog.showModal();
     24  assert_true(dialog.open);
     25  assert_true(dialog.matches('[open]'));
     26  await new test_driver.send_keys(document.documentElement,ESC);
     27  assert_false(dialog.open);
     28  assert_false(dialog.matches('[open]'));
     29 }, `Dialogs that start open and have closedby should still function`);
     30 </script>
     31 
     32 <dl>
     33  <dt contenteditable></dt>
     34  <dialog id=test2 open></dialog>
     35 </dl>
     36 
     37 <script>
     38 promise_test(async (t) => {
     39  // This test case is pulled from `dialog-closewatcher-crash.html`. It is
     40  // constructed such that this happens:
     41  //  1. The dialog `open` attribute is removed, which (depending on whether
     42  //     https://github.com/whatwg/html/pull/10124 behavior is happening) calls
     43  //     the close() steps.
     44  //  2. the last step of close() is to restore focus to the previously-focused
     45  //     element.
     46  //  3. Changing focus triggers the `focusin` event, which calls `showModal()`.
     47  //  4. In showModal(), the dialog is again made modal, re-constructing the
     48  //     close watcher and re-setting the `open` attribute.
     49  //  5. The call to close() ends.
     50  // After all of this, if things are working, the ESC key should still cause
     51  // the dialog to be closed.
     52  const dialog = document.querySelector('dialog#test2');
     53  const controller = new AbortController();
     54  document.querySelector('dl').addEventListener("focusin", () => {
     55    dialog.showModal();
     56  },{signal:controller.signal});
     57  // This will trigger the focus-the-previous-element behavior, which will fire
     58  // the `focusin` event.
     59  dialog.open = false;
     60  await new Promise(resolve => {
     61    document.defaultView.requestIdleCallback(() => {
     62      window.getSelection().addRange(document.createRange());
     63      dialog.close();
     64      resolve();
     65    });
     66  });
     67  assert_true(dialog.open);
     68  assert_true(dialog.matches('[open]'));
     69  // Stop re-running showModal(), so we can check that the dialog closes with ESC:
     70  controller.abort();
     71  await test_driver.send_keys(document.documentElement,ESC);
     72  assert_false(dialog.open,'ESC should still work');
     73  assert_false(dialog.matches('[open]'));
     74 }, `Opening and closing a dialog during the dialog focus fixup should still leave closedby functional`);
     75 </script>