summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/interaction/focus/the-autofocus-attribute/autofocus-dialog.html
blob: 08a0913f42ff91f62af9b19e8c9a3959b63caffa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#the-autofocus-attribute">
<link rel='author' href='mailto:masonf@chromium.org'>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>

<body>
<script>
promise_test(async t => {
  let w = window.open('/common/blank.html');
  await waitForLoad(w);
  t.add_cleanup(() => { w.close(); });
  w.document.body.innerHTML = '<dialog><div tabindex=0 autofocus></dialog><input autofocus>';
  await waitUntilStableAutofocusState(w);
  assert_equals(w.document.activeElement.tagName, 'INPUT');
}, '<dialog> can contain autofocus, without stopping page autofocus content from working');

promise_test(async t => {
  let w = window.open('/common/blank.html');
  await waitForLoad(w);
  t.add_cleanup(() => { w.close(); });
  w.document.body.innerHTML = '<dialog><div tabindex=0 autofocus></dialog><input autofocus>';
  await waitUntilStableAutofocusState(w);
  w.document.querySelector('dialog').show();
  assert_equals(w.document.activeElement.tagName, 'DIV');
}, '<dialog>-contained autofocus element gets focused when the dialog is shown');
</script>