// 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_serializer.h" #include <stddef.h> #include <stdint.h> #include <memory> #include "base/memory/raw_ptr.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/test/gtest_util.h" #include "testing/gmock/include/gmock/gmock-matchers.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/accessibility/ax_node.h" #include "ui/accessibility/ax_serializable_tree.h" #include "ui/accessibility/ax_tree_update.h" UnorderedElementsAre; namespace ui { BasicAXTreeSerializer; // The framework for these tests is that each test sets up |treedata0_| // and |treedata1_| and then calls GetTreeSerializer, which creates a // serializer for a tree that's initially in state |treedata0_|, but then // changes to state |treedata1_|. This allows each test to check the // updates created by AXTreeSerializer or unit-test its private // member functions. class AXTreeSerializerTest : public testing::Test { … }; void AXTreeSerializerTest::CreateTreeSerializer() { … } // In this test, one child is added to the root. Only the root and // new child should be added. TEST_F(AXTreeSerializerTest, UpdateContainsOnlyChangedNodes) { … } // When the root changes, the whole tree is updated, even if some of it // is unaffected. TEST_F(AXTreeSerializerTest, NewRootUpdatesEntireTree) { … } // When a node is reparented, the subtree including both the old parent // and new parent of the reparented node must be deleted and recreated. TEST_F(AXTreeSerializerTest, ReparentingUpdatesSubtree) { … } // When a node is reparented, the subtree including both the old parent // and new parent of the reparented node must be deleted and recreated. TEST_F(AXTreeSerializerTest, ReparentingUpdatesSubtree2) { … } // Similar to ReparentingUpdatesSubtree, except that InvalidateSubtree is // called on id=1 - we need to make sure that the reparenting is still // detected. TEST_F(AXTreeSerializerTest, ReparentingWithDirtySubtreeUpdates) { … } // A variant of AXTreeSource that does not serialize one particular id, // returning nullptr from methods that try to retrieve it. class AXTreeSourceWithInvalidId : public AXTreeSource<const AXNode*, AXTreeData*, AXNodeData> { … }; // Test that the serializer CHECKs when it finds invalid children. TEST(AXTreeSerializerInvalidDeathTest, InvalidChild) { … } // Test that we can set a maximum number of nodes to serialize. TEST_F(AXTreeSerializerTest, MaximumSerializedNodeCount) { … } #if defined(GTEST_HAS_DEATH_TEST) // If duplicate ids are encountered, it crashes via CHECK(false). TEST_F(AXTreeSerializerTest, DuplicateIdsCrashes) { … } #endif // If a tree serializer is reset, that means it doesn't know about // the state of the client tree anymore. The safest thing to do in // that circumstance is to force the client to clear everything. TEST_F(AXTreeSerializerTest, ResetUpdatesNodeIdToClear) { … } // Ensure that calling Reset doesn't cause any problems if // the root changes. TEST_F(AXTreeSerializerTest, ResetWorksWithNewRootId) { … } TEST_F(AXTreeSerializerTest, TestPartialSerialization) { … } } // namespace ui