chromium/ui/accessibility/ax_tree_unittest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/accessibility/ax_tree.h"

#include "base/containers/contains.h"
#include "base/test/metrics/histogram_tester.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/accessibility/ax_enum_util.h"
#include "ui/accessibility/ax_node.h"
#include "ui/accessibility/ax_serializable_tree.h"
#include "ui/accessibility/ax_tree_observer.h"
#include "ui/accessibility/ax_tree_serializer.h"

namespace ui {

namespace {

std::string IntVectorToString(const std::vector<int>& items) {}

std::string GetBoundsAsString(const AXTree& tree, int32_t id) {}

std::string GetUnclippedBoundsAsString(const AXTree& tree, int32_t id) {}

bool IsNodeOffscreen(const AXTree& tree, int32_t id) {}

void AssertReverseRelationFor(ax::mojom::IntListAttribute relation) {}

class TestAXTreeObserver final : public AXTreeObserver {};

// UTF encodings that are tested by the `AXTreeTestWithMultipleUTFEncodings`
// parameterized tests.
enum class TestEncoding {};

// Fixture for a test that needs to run multiple times with different UTF
// encodings. For example, once with UTF8 encoding and once with UTF16.
class AXTreeTestWithMultipleUTFEncodings
    : public ::testing::TestWithParam<TestEncoding> {};

}  // namespace

ElementsAre;

// A macro for testing that a std::optional has both a value and that its value
// is set to a particular expectation.
#define EXPECT_OPTIONAL_EQ(expected, actual)

TEST(AXTreeTest, SerializeSimpleAXTree) {}

TEST(AXTreeTest, SerializeAXTreeUpdate) {}

TEST(AXTreeTest, LeaveOrphanedDeletedSubtreeFails) {}

TEST(AXTreeTest, LeaveOrphanedNewChildFails) {}

TEST(AXTreeTest, DuplicateChildIdFails) {}

TEST(AXTreeTest, InvalidReparentingFails) {}

TEST(AXTreeTest, NoReparentingOfRootIfNoNewRoot) {}

TEST(AXTreeTest, NoReparentingIfOnlyRemovedAndChangedNotReAdded) {}

// Tests a fringe scenario that may happen if multiple AXTreeUpdates are merged.
// Make sure that when a node is reparented then removed from the tree
// that it notifies OnNodeDeleted rather than OnNodeReparented.
TEST(AXTreeTest, NoReparentingIfRemovedMultipleTimesAndNotInFinalTree) {}

// Tests a fringe scenario that may happen if multiple AXTreeUpdates are merged.
// Make sure that when a node is reparented multiple times and exists in the
// final tree that it notifies OnNodeReparented rather than OnNodeDeleted.
TEST(AXTreeTest, ReparentIfRemovedMultipleTimesButExistsInFinalTree) {}

TEST(AXTreeTest, ReparentRootIfRootChanged) {}

TEST(AXTreeTest, ImplicitChildrenDelete) {}

TEST(AXTreeTest, IndexInParentAfterReorder) {}

TEST(AXTreeTest, IndexInParentAfterReorderIgnoredNode) {}

TEST(AXTreeTest, ImplicitAttributeDelete) {}

TEST(AXTreeTest, TreeObserverIsCalled) {}

TEST(AXTreeTest, TreeObserverIsCalledForTreeDataChanges) {}

TEST(AXTreeTest, ReparentingDoesNotTriggerNodeCreated) {}

TEST(AXTreeTest, MultipleIgnoredChangesDoesNotBreakCache) {}

TEST(AXTreeTest, NodeToClearUpdatesParentUnignoredCount) {}

TEST(AXTreeTest, TreeObserverIsNotCalledForReparenting) {}

// https://crbug.com/1359080
// UAF caught by ax_tree_fuzzer
TEST(AXTreeTest, DISABLED_BogusAXTree) {}

// UAF caught by ax_tree_fuzzer
TEST(AXTreeTest, BogusAXTree2) {}

// UAF caught by ax_tree_fuzzer
TEST(AXTreeTest, BogusAXTree3) {}

TEST(AXTreeTest, RoleAndStateChangeCallbacks) {}

TEST(AXTreeTest, AttributeChangeCallbacks) {}

TEST(AXTreeTest, IntListChangeCallbacks) {}

// Create a very simple tree and make sure that we can get the bounds of
// any node.
TEST(AXTreeTest, GetBoundsBasic) {}

// If a node doesn't specify its location but at least one child does have
// a location, its computed bounds should be the union of all child bounds.
TEST(AXTreeTest, EmptyNodeBoundsIsUnionOfChildren) {}

// If a node doesn't specify its location but at least one child does have
// a location, it will be offscreen if all of its children are offscreen.
TEST(AXTreeTest, EmptyNodeNotOffscreenEvenIfAllChildrenOffscreen) {}

// Test that getting the bounds of a node works when there's a transform.
TEST(AXTreeTest, GetBoundsWithTransform) {}

// Test that getting the bounds of a node that's inside a container
// works correctly.
TEST(AXTreeTest, GetBoundsWithContainerId) {}

// Test that getting the bounds of a node that's inside a scrolling container
// works correctly.
TEST(AXTreeTest, GetBoundsWithScrolling) {}

// When a node has zero size, we try to get the bounds from an ancestor.
TEST(AXTreeTest, GetBoundsOfNodeWithZeroSize) {}

TEST(AXTreeTest, GetBoundsEmptyBoundsInheritsFromParent) {}

TEST(AXTreeTest, GetBoundsCropsChildToRoot) {}

TEST(AXTreeTest, GetBoundsSetsOffscreenIfClipsChildren) {}

TEST(AXTreeTest, GetBoundsUpdatesOffscreen) {}

TEST(AXTreeTest, IntReverseRelations) {}

TEST(AXTreeTest, IntListReverseRelations) {}

TEST(AXTreeTest, DeletingNodeUpdatesReverseRelations) {}

TEST(AXTreeTest, ReverseRelationsDoNotKeepGrowing) {}

TEST(AXTreeTest, SkipIgnoredNodes) {}

TEST(AXTreeTest, CachedUnignoredValues) {}

TEST(AXTreeTest, TestRecursionUnignoredChildCount) {}

TEST(AXTreeTest, NullUnignoredChildren) {}

TEST(AXTreeTest, UnignoredChildIteratorIncrementDecrementPastEnd) {}

TEST(AXTreeTest, UnignoredChildIteratorIgnoredContainerSiblings) {}

TEST(AXTreeTest, UnignoredChildIterator) {}

TEST(AXTreeTest, UnignoredAccessors) {}

TEST(AXTreeTest, UnignoredNextPreviousChild) {}

TEST(AXTreeTest, GetSiblingsNoIgnored) {}

TEST(AXTreeTest, GetUnignoredSiblingsChildrenPromoted) {}

TEST(AXTreeTest, GetUnignoredSiblingsIgnoredChildSkipped) {}

TEST(AXTreeTest, GetUnignoredSiblingIgnoredParentIrrelevant) {}

TEST(AXTreeTest, GetUnignoredSiblingsAllIgnored) {}

TEST(AXTreeTest, GetUnignoredSiblingsNestedIgnored) {}

TEST(AXTreeTest, GetChildrenOrSiblings) {}

TEST(AXTreeTest, ChildTreeIds) {}

TEST_P(AXTreeTestWithMultipleUTFEncodings, ComputedNodeData) {}

INSTANTIATE_TEST_SUITE_P();

// Tests GetPosInSet and GetSetSize return the assigned int attribute values.
TEST(AXTreeTest, SetSizePosInSetAssigned) {}

// Tests that PosInSet and SetSize can be calculated if not assigned.
TEST(AXTreeTest, SetSizePosInSetUnassigned) {}

// Tests that PosInSet and SetSize can be calculated for TreeGrid rows if not
// assigned.
TEST(AXTreeTest, SetSizePosInSetInTreeGridUnassigned) {}

// Tests PosInSet can be calculated if unassigned, and SetSize can be
// assigned on the outerlying ordered set.
TEST(AXTreeTest, SetSizeAssignedOnContainer) {}

// Tests GetPosInSet and GetSetSize on a list containing various roles.
// Roles for items and associated ordered set should match up.
TEST(AXTreeTest, SetSizePosInSetDiverseList) {}

// Tests GetPosInSet and GetSetSize on a nested list.
TEST(AXTreeTest, SetSizePosInSetNestedList) {}

// Tests PosInSet can be calculated if one item specifies PosInSet, but
// other assignments are missing.
TEST(AXTreeTest, PosInSetMissing) {}

// A more difficult test that involves missing PosInSet and SetSize values.
TEST(AXTreeTest, SetSizePosInSetMissingDifficult) {}

// Tests that code overwrites decreasing SetSize assignments to largest of
// assigned values.
TEST(AXTreeTest, SetSizeDecreasing) {}

// Tests that code overwrites decreasing PosInSet values.
TEST(AXTreeTest, PosInSetDecreasing) {}

// Tests that code overwrites duplicate PosInSet values. Note this case is
// tricky; an update to the second element causes an update to the third
// element.
TEST(AXTreeTest, PosInSetDuplicates) {}

// Tests GetPosInSet and GetSetSize when some list items are nested in a generic
// container.
TEST(AXTreeTest, SetSizePosInSetNestedContainer) {}

// Tests GetSetSize and GetPosInSet are correct, even when list items change.
// Tests that previously calculated values are not used after tree is updated.
TEST(AXTreeTest, SetSizePosInSetDeleteItem) {}

// Tests GetSetSize and GetPosInSet are correct, even when list items change.
// This test adds an item to the front of a list, which invalidates previously
// calculated PosInSet and SetSize values. Tests that old values are not
// used after tree is updated.
TEST(AXTreeTest, SetSizePosInSetAddItem) {}

// Tests that the outerlying ordered set reports a SetSize. Ordered sets
// should not report a PosInSet value other than 0, since they are not
// considered to be items within a set (even when nested).
TEST(AXTreeTest, OrderedSetReportsSetSize) {}

// Tests GetPosInSet and GetSetSize code on invalid input.
TEST(AXTreeTest, SetSizePosInSetInvalid) {}

// Tests GetPosInSet and GetSetSize code on kRadioButtons. Radio buttons
// behave differently than other item-like elements; most notably, they do not
// need to be contained within an ordered set to report a PosInSet or SetSize.
TEST(AXTreeTest, SetSizePosInSetRadioButtons) {}

// Tests GetPosInSet and GetSetSize on a list that includes radio buttons.
// Note that radio buttons do not contribute to the SetSize of the outerlying
// list.
TEST(AXTreeTest, SetSizePosInSetRadioButtonsInList) {}

// Tests GetPosInSet and GetSetSize on a flat tree representation. According
// to the tree representation, the three elements are siblings. However,
// due to the presence of the kHierarchicalLevel attribute, they all belong
// to different sets.
TEST(AXTreeTest, SetSizePosInSetFlatTree) {}

// Tests GetPosInSet and GetSetSize on a flat tree representation, where only
// the level is specified.
TEST(AXTreeTest, SetSizePosInSetFlatTreeLevelsOnly) {}

// Tests that GetPosInSet and GetSetSize work while a tree is being
// unserialized.
TEST(AXTreeTest, SetSizePosInSetSubtreeDeleted) {}

// Tests that GetPosInSet and GetSetSize work when there are ignored nodes.
TEST(AXTreeTest, SetSizePosInSetIgnoredItem) {}

// Tests that kPopUpButtons are assigned the SetSize of the wrapped
// kMenuListPopup, if one is present.
TEST(AXTreeTest, SetSizePosInSetPopUpButtonAndSelect) {}

// Tests that PosInSet and SetSize are still correctly calculated when there
// are nodes with role of kUnknown layered between items and ordered set.
TEST(AXTreeTest, SetSizePosInSetUnkown) {}

TEST(AXTreeTest, SetSizePosInSetMenuItemValidChildOfMenuListPopup) {}

TEST(AXTreeTest, SetSizePostInSetListBoxOptionWithGroup) {}

TEST(AXTreeTest, SetSizePosInSetGroup) {}

TEST(AXTreeTest, SetSizePosInSetHidden) {}

// Tests that we get the correct PosInSet and SetSize values when using an
// aria-controls relationship.
TEST(AXTreeTest, SetSizePosInSetControls) {}

// Tests GetPosInSet and GetSetSize return the assigned int attribute values
// when a pop-up button is a leaf node.
TEST(AXTreeTest, SetSizePosInSetLeafPopUpButton) {}

TEST(AXTreeTest, OnNodeWillBeDeletedHasValidUnignoredParent) {}

TEST(AXTreeTest, OnNodeHasBeenDeleted) {}

// Tests a fringe scenario that may happen if multiple AXTreeUpdates are merged.
// Make sure that we correctly Unserialize if a newly created node is deleted,
// and possibly recreated later.
TEST(AXTreeTest, SingleUpdateDeletesNewlyCreatedChildNode) {}

// Tests a fringe scenario that may happen if multiple AXTreeUpdates are merged.
// Make sure that we correctly Unserialize if a node is reparented multiple
// times.
TEST(AXTreeTest, SingleUpdateReparentsNodeMultipleTimes) {}

// Tests a fringe scenario that may happen if multiple AXTreeUpdates are merged.
// Make sure that we correctly Unserialize if a newly created node toggles its
// ignored state.
TEST(AXTreeTest, SingleUpdateIgnoresNewlyCreatedUnignoredChildNode) {}

// Tests a fringe scenario that may happen if multiple AXTreeUpdates are merged.
// Make sure that we correctly Unserialize if a newly created node toggles its
// ignored state.
TEST(AXTreeTest, SingleUpdateTogglesIgnoredStateAfterCreatingNode) {}

// Tests a fringe scenario that may happen if multiple AXTreeUpdates are merged.
// Make sure that we correctly Unserialize if a node toggles its ignored state
// and is then removed from the tree.
TEST(AXTreeTest, SingleUpdateTogglesIgnoredStateBeforeDestroyingNode) {}

// Tests that the IsInListMarker() method returns true if the current node is a
// list marker or if it's a descendant node of a list marker.
TEST(AXTreeTest, TestIsInListMarker) {}

TEST(AXTreeTest, UpdateFromOutOfSyncTree) {}

TEST(AXTreeTest, UnserializeErrors) {}

}  // namespace ui