chromium/third_party/blink/web_tests/accessibility/in-page-link-target.html

<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>

<div id="main">
  <a id="anchor1" href="#emptyAnchor">Empty anchor</a>
  <a id="anchor2" href="#anchorWithContent">Anchor with content</a>
  <a id="anchor3" href="#anchorWithID">Anchor with ID</a>
  <a id="anchor4" href="#emptySpan">Empty span</a>
  <a id="anchor5" href="#spanWithContent">Span with content</a>
  <a id="anchor6" href="#paragraphWithContent">Paragraph with content</a>

  <p><a name="emptyAnchor"></a>After empty anchor</p>
  <p><a name="anchorWithContent">Anchor with content</a></p>
  <p><a id="anchorWithID">Anchor with ID</a></p>
  <p><span id="emptySpan"></span>After empty span</span></p>
  <p><span id="spanWithContent">Span with content</span></p>
  <p id="paragraphWithContent">Paragraph with content</p>
</div>

<script>
test(function() {
  var anchor = accessibilityController.accessibleElementById('anchor1');
  assert_not_equals(anchor, undefined);
  var target = anchor.inPageLinkTarget;
  assert_not_equals(target, undefined);
  // AXGenericContainer because this is how the "a" tag is marked in the AX tree
  // when it's a target and not a link.
  assert_equals(target.role, 'AXRole: AXGenericContainer');
  assert_equals(target.name, '');
}, 'Test finding the target when it is an empty anchor.');

test(function() {
  var anchor = accessibilityController.accessibleElementById('anchor2');
  assert_not_equals(anchor, undefined);
  var target = anchor.inPageLinkTarget;
  assert_not_equals(target, undefined);
  // AXGenericContainer because this is how the "a" tag is marked in the AX tree
  // when it's a target and not a link.
  assert_equals(target.role, 'AXRole: AXGenericContainer');
}, 'Test finding the target when it is an anchor with content.');

test(function() {
  var anchor = accessibilityController.accessibleElementById('anchor3');
  assert_not_equals(anchor, undefined);
  var target = anchor.inPageLinkTarget;
  assert_not_equals(target, undefined);
  // AXGenericContainer because this is how the "a" tag is marked in the AX tree
  // when it's a target and not a link.
  assert_equals(target.role, 'AXRole: AXGenericContainer');
}, 'Test finding the target when it is an anchor with ID.');

test(function() {
  var anchor = accessibilityController.accessibleElementById('anchor4');
  assert_not_equals(anchor, undefined);
  var target = anchor.inPageLinkTarget;
  assert_not_equals(target, undefined);
  assert_equals(target.role, 'AXRole: AXGenericContainer');
  assert_equals(target.name, '');
}, 'Test finding the target when it is an empty span.');

test(function() {
  var anchor = accessibilityController.accessibleElementById('anchor5');
  assert_not_equals(anchor, undefined);
  var target = anchor.inPageLinkTarget;
  assert_not_equals(target, undefined);
  assert_equals(target.role, 'AXRole: AXGenericContainer');
  var child = target.childAtIndex(0);
  assert_not_equals(child, undefined);
  assert_equals(child.role, 'AXRole: AXStaticText');
  assert_equals(child.name, 'Span with content');
}, 'Test finding the target when it is a span with content.');

test(function() {
  var anchor = accessibilityController.accessibleElementById('anchor6');
  assert_not_equals(anchor, undefined);
  var target = anchor.inPageLinkTarget;
  assert_not_equals(target, undefined);
  assert_equals(target.role, 'AXRole: AXParagraph');
}, 'Test finding the target when it is a paragraph.');
</script>