| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/accessibility/ax_tree_serializer.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 #include <stdint.h> | 8 #include <stdint.h> |
| 7 | 9 |
| 10 #include <memory> |
| 11 |
| 8 #include "base/macros.h" | 12 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/accessibility/ax_node.h" | 15 #include "ui/accessibility/ax_node.h" |
| 13 #include "ui/accessibility/ax_serializable_tree.h" | 16 #include "ui/accessibility/ax_serializable_tree.h" |
| 14 #include "ui/accessibility/ax_tree.h" | 17 #include "ui/accessibility/ax_tree.h" |
| 15 #include "ui/accessibility/ax_tree_serializer.h" | |
| 16 | 18 |
| 17 namespace ui { | 19 namespace ui { |
| 18 | 20 |
| 19 using BasicAXTreeSerializer = | 21 using BasicAXTreeSerializer = |
| 20 AXTreeSerializer<const AXNode*, AXNodeData, AXTreeData>; | 22 AXTreeSerializer<const AXNode*, AXNodeData, AXTreeData>; |
| 21 | 23 |
| 22 // The framework for these tests is that each test sets up |treedata0_| | 24 // The framework for these tests is that each test sets up |treedata0_| |
| 23 // and |treedata1_| and then calls GetTreeSerializer, which creates a | 25 // and |treedata1_| and then calls GetTreeSerializer, which creates a |
| 24 // serializer for a tree that's initially in state |treedata0_|, but then | 26 // serializer for a tree that's initially in state |treedata0_|, but then |
| 25 // changes to state |treedata1_|. This allows each test to check the | 27 // changes to state |treedata1_|. This allows each test to check the |
| 26 // updates created by AXTreeSerializer or unit-test its private | 28 // updates created by AXTreeSerializer or unit-test its private |
| 27 // member functions. | 29 // member functions. |
| 28 class AXTreeSerializerTest : public testing::Test { | 30 class AXTreeSerializerTest : public testing::Test { |
| 29 public: | 31 public: |
| 30 AXTreeSerializerTest() {} | 32 AXTreeSerializerTest() {} |
| 31 ~AXTreeSerializerTest() override {} | 33 ~AXTreeSerializerTest() override {} |
| 32 | 34 |
| 33 protected: | 35 protected: |
| 34 void CreateTreeSerializer(); | 36 void CreateTreeSerializer(); |
| 35 | 37 |
| 36 AXTreeUpdate treedata0_; | 38 AXTreeUpdate treedata0_; |
| 37 AXTreeUpdate treedata1_; | 39 AXTreeUpdate treedata1_; |
| 38 scoped_ptr<AXSerializableTree> tree0_; | 40 std::unique_ptr<AXSerializableTree> tree0_; |
| 39 scoped_ptr<AXSerializableTree> tree1_; | 41 std::unique_ptr<AXSerializableTree> tree1_; |
| 40 scoped_ptr<AXTreeSource<const AXNode*, AXNodeData, AXTreeData> > | 42 std::unique_ptr<AXTreeSource<const AXNode*, AXNodeData, AXTreeData>> |
| 41 tree0_source_; | 43 tree0_source_; |
| 42 scoped_ptr<AXTreeSource<const AXNode*, AXNodeData, AXTreeData> > | 44 std::unique_ptr<AXTreeSource<const AXNode*, AXNodeData, AXTreeData>> |
| 43 tree1_source_; | 45 tree1_source_; |
| 44 scoped_ptr<BasicAXTreeSerializer> serializer_; | 46 std::unique_ptr<BasicAXTreeSerializer> serializer_; |
| 45 | 47 |
| 46 private: | 48 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(AXTreeSerializerTest); | 49 DISALLOW_COPY_AND_ASSIGN(AXTreeSerializerTest); |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 void AXTreeSerializerTest::CreateTreeSerializer() { | 52 void AXTreeSerializerTest::CreateTreeSerializer() { |
| 51 if (serializer_) | 53 if (serializer_) |
| 52 return; | 54 return; |
| 53 | 55 |
| 54 tree0_.reset(new AXSerializableTree(treedata0_)); | 56 tree0_.reset(new AXSerializableTree(treedata0_)); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 tree1_->GetFromId(2)->SwapChildren(node2_children); | 334 tree1_->GetFromId(2)->SwapChildren(node2_children); |
| 333 | 335 |
| 334 // Now try to serialize again. We should get the whole tree because the | 336 // Now try to serialize again. We should get the whole tree because the |
| 335 // previous failed call to SerializeChanges reset it. | 337 // previous failed call to SerializeChanges reset it. |
| 336 update = AXTreeUpdate(); | 338 update = AXTreeUpdate(); |
| 337 serializer_->SerializeChanges(tree1_->GetFromId(7), &update); | 339 serializer_->SerializeChanges(tree1_->GetFromId(7), &update); |
| 338 ASSERT_EQ(static_cast<size_t>(5), update.nodes.size()); | 340 ASSERT_EQ(static_cast<size_t>(5), update.nodes.size()); |
| 339 } | 341 } |
| 340 | 342 |
| 341 } // namespace ui | 343 } // namespace ui |
| OLD | NEW |