This source file includes following definitions.
- CreateTreeSerializer
- TEST_F
- TEST_F
- TEST_F
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_number_conversions.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.h"
#include "ui/accessibility/ax_tree_serializer.h"
namespace ui {
class AXTreeSerializerTest : public testing::Test {
public:
AXTreeSerializerTest() {}
virtual ~AXTreeSerializerTest() {}
protected:
void CreateTreeSerializer();
AXTreeUpdate treedata0_;
AXTreeUpdate treedata1_;
scoped_ptr<AXSerializableTree> tree0_;
scoped_ptr<AXSerializableTree> tree1_;
scoped_ptr<AXTreeSource<const AXNode*> > tree0_source_;
scoped_ptr<AXTreeSource<const AXNode*> > tree1_source_;
scoped_ptr<AXTreeSerializer<const AXNode*> > serializer_;
private:
DISALLOW_COPY_AND_ASSIGN(AXTreeSerializerTest);
};
void AXTreeSerializerTest::CreateTreeSerializer() {
if (serializer_)
return;
tree0_.reset(new AXSerializableTree(treedata0_));
tree1_.reset(new AXSerializableTree(treedata1_));
tree0_source_.reset(tree0_->CreateTreeSource());
serializer_.reset(new AXTreeSerializer<const AXNode*>(tree0_source_.get()));
AXTreeUpdate unused_update;
serializer_->SerializeChanges(tree0_->GetRoot(), &unused_update);
tree1_source_.reset(tree1_->CreateTreeSource());
serializer_->ChangeTreeSourceForTesting(tree1_source_.get());
}
TEST_F(AXTreeSerializerTest, UpdateContainsOnlyChangedNodes) {
treedata0_.nodes.resize(3);
treedata0_.nodes[0].id = 1;
treedata0_.nodes[0].role = AX_ROLE_ROOT_WEB_AREA;
treedata0_.nodes[0].child_ids.push_back(2);
treedata0_.nodes[0].child_ids.push_back(3);
treedata0_.nodes[1].id = 2;
treedata0_.nodes[2].id = 3;
treedata1_.nodes.resize(4);
treedata1_.nodes[0].id = 1;
treedata1_.nodes[0].role = AX_ROLE_ROOT_WEB_AREA;
treedata1_.nodes[0].child_ids.push_back(4);
treedata1_.nodes[0].child_ids.push_back(2);
treedata1_.nodes[0].child_ids.push_back(3);
treedata1_.nodes[1].id = 2;
treedata1_.nodes[2].id = 3;
treedata1_.nodes[3].id = 4;
CreateTreeSerializer();
AXTreeUpdate update;
serializer_->SerializeChanges(tree1_->GetFromId(1), &update);
EXPECT_EQ(0, update.node_id_to_clear);
ASSERT_EQ(static_cast<size_t>(2), update.nodes.size());
EXPECT_EQ(1, update.nodes[0].id);
EXPECT_EQ(4, update.nodes[1].id);
}
TEST_F(AXTreeSerializerTest, NewRootUpdatesEntireTree) {
treedata0_.nodes.resize(4);
treedata0_.nodes[0].id = 1;
treedata0_.nodes[0].role = AX_ROLE_ROOT_WEB_AREA;
treedata0_.nodes[0].child_ids.push_back(2);
treedata0_.nodes[1].id = 2;
treedata0_.nodes[1].child_ids.push_back(3);
treedata0_.nodes[2].id = 3;
treedata0_.nodes[2].child_ids.push_back(4);
treedata0_.nodes[3].id = 4;
treedata1_.nodes.resize(4);
treedata1_.nodes[0].id = 5;
treedata1_.nodes[0].role = AX_ROLE_ROOT_WEB_AREA;
treedata1_.nodes[0].child_ids.push_back(2);
treedata1_.nodes[1].id = 2;
treedata1_.nodes[1].child_ids.push_back(3);
treedata1_.nodes[2].id = 3;
treedata1_.nodes[2].child_ids.push_back(4);
treedata1_.nodes[3].id = 4;
CreateTreeSerializer();
AXTreeUpdate update;
serializer_->SerializeChanges(tree1_->GetFromId(4), &update);
EXPECT_EQ(1, update.node_id_to_clear);
ASSERT_EQ(static_cast<size_t>(4), update.nodes.size());
EXPECT_EQ(5, update.nodes[0].id);
EXPECT_EQ(2, update.nodes[1].id);
EXPECT_EQ(3, update.nodes[2].id);
EXPECT_EQ(4, update.nodes[3].id);
}
TEST_F(AXTreeSerializerTest, ReparentingUpdatesSubtree) {
treedata0_.nodes.resize(5);
treedata0_.nodes[0].id = 1;
treedata0_.nodes[0].role = AX_ROLE_ROOT_WEB_AREA;
treedata0_.nodes[0].child_ids.push_back(2);
treedata0_.nodes[1].id = 2;
treedata0_.nodes[1].child_ids.push_back(3);
treedata0_.nodes[1].child_ids.push_back(5);
treedata0_.nodes[2].id = 3;
treedata0_.nodes[2].child_ids.push_back(4);
treedata0_.nodes[3].id = 4;
treedata0_.nodes[4].id = 5;
treedata1_.nodes.resize(5);
treedata1_.nodes[0].id = 1;
treedata1_.nodes[0].role = AX_ROLE_ROOT_WEB_AREA;
treedata1_.nodes[0].child_ids.push_back(2);
treedata1_.nodes[1].id = 2;
treedata1_.nodes[1].child_ids.push_back(3);
treedata1_.nodes[2].id = 3;
treedata1_.nodes[2].child_ids.push_back(4);
treedata1_.nodes[3].id = 4;
treedata1_.nodes[3].child_ids.push_back(5);
treedata1_.nodes[4].id = 5;
CreateTreeSerializer();
AXTreeUpdate update;
serializer_->SerializeChanges(tree1_->GetFromId(4), &update);
EXPECT_EQ(2, update.node_id_to_clear);
ASSERT_EQ(static_cast<size_t>(4), update.nodes.size());
EXPECT_EQ(2, update.nodes[0].id);
EXPECT_EQ(3, update.nodes[1].id);
EXPECT_EQ(4, update.nodes[2].id);
EXPECT_EQ(5, update.nodes[3].id);
}
}