summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/interaction/focus/the-autofocus-attribute/document-with-fragment-top.html
blob: f2d2aaae609c1c573c47f7dd11d2135a1fd0e20f (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
30
31
32
33
34
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>

<iframe src="resources/frame-with-autofocus-element.html#top"></iframe>

<script>
'use strict';

promise_test(async () => {
  await waitForLoad(window);
  const iframe = document.querySelector('iframe');
  await waitUntilStableAutofocusState();
  assert_equals(document.activeElement, iframe,
      'Autofocus elements in iframes should be focused.');
  const doc = iframe.contentDocument;
  assert_true(!doc.querySelector(':target'));

  let input = document.createElement('input');
  input.autofocus = true;
  document.body.appendChild(input);
  await waitUntilStableAutofocusState();
  assert_not_equals(document.activeElement, input);
}, 'Autofocus elements in iframed documents with "top" fragments should work.');

promise_test(async () => {
  let w = window.open('resources/frame-with-autofocus-element.html#top');
  await waitForLoad(w);
  await waitUntilStableAutofocusState(w);
  assert_not_equals(w.document.activeElement, w.document.body);
  w.close();
}, 'Autofocus elements in top-level browsing context\'s documents with "top" fragments should work.');
</script>