chromium/third_party/blink/web_tests/wpt_internal/display-lock/css-content-visibility/accessibility/content-visibility-accessibility-003.html

<!doctype HTML>
<html>
<meta charset="utf8">
<title>Content Visibility: accessibility focus</title>
<link rel="author" title="Rakina Zata Amni" href="mailto:[email protected]">
<link rel="help" href="https://github.com/WICG/display-locking">
<meta name="assert" content="content-visibility auto subtrees are exposed by accessibility focus">

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

<div style="height:10000px;">
  spacer so that everything below will be offscreen (and won't get viewport-activated)
</div>
<div id="hidden" style="content-visibility: auto">
  foo
  <div id="child" tabindex="0">
    bar
  </div>
</div>

<script>
function axElementById(id) {
  return accessibilityController.accessibleElementById(id);
}

async_test((t) => {
  let axHidden = axElementById("hidden");
  // #hidden is locked, and thus is saved as an AXNodeObject instead of an AXLayoutObject,
  // and has 3 child nodes: "foo" text, "<newline>" text, and #child node.
  // Note that we have the separate <newline> text because it's an AXNodeObject and does
  // not do whitespace collapsing (though this might change in the future).
  t.step(() => { assert_equals(axHidden.childrenCount, 3, "Children count when locked"); });

  // Focus to #child. This will cause the element to be brought into the view,
  // since it is focusable even though it is locked by content-visibility (see
  // https://github.com/WICG/display-locking for details). When that is done,
  // the element will become unlocked and AXNodeObjects will be replaced with
  // AXLayoutObjects, causing <newline> to be collapsed, so we expect to see
  // two children.
  axElementById("child").takeFocus();
  // Wait for the next frame for the ax object to be recreated.
  requestAnimationFrame(() => {
    requestAnimationFrame(() => {
      let axHidden = axElementById("hidden");
      // Now #target is not locked, expect 2 children (no whitespace node).
      // This is the same as it would be if content-visibility had never been used.
      t.step(() => { assert_equals(axHidden.childrenCount, 2, "Children count after activation"); });
      t.done();
    });
  });
}, "Accessiblility focus causes activatable hidden tree to activate");
</script>