OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/accessibility/ax_node.h" | 8 #include "ui/accessibility/ax_node.h" |
9 #include "ui/accessibility/ax_serializable_tree.h" | 9 #include "ui/accessibility/ax_serializable_tree.h" |
10 #include "ui/accessibility/ax_tree.h" | 10 #include "ui/accessibility/ax_tree.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 int tree_size = tree1.size(); | 145 int tree_size = tree1.size(); |
146 | 146 |
147 // Now iterate over which node to update first, |k|. | 147 // Now iterate over which node to update first, |k|. |
148 for (int k = 0; k < tree_size; k++) { | 148 for (int k = 0; k < tree_size; k++) { |
149 SCOPED_TRACE("i=" + base::IntToString(i) + | 149 SCOPED_TRACE("i=" + base::IntToString(i) + |
150 " j=" + base::IntToString(j) + | 150 " j=" + base::IntToString(j) + |
151 " k=" + base::IntToString(k)); | 151 " k=" + base::IntToString(k)); |
152 | 152 |
153 // Start by serializing tree0 and unserializing it into a new | 153 // Start by serializing tree0 and unserializing it into a new |
154 // empty tree |dst_tree|. | 154 // empty tree |dst_tree|. |
155 scoped_ptr<AXTreeSource<const AXNode*, AXNodeData> > tree0_source( | 155 scoped_ptr<AXTreeSource<const AXNode*, AXNodeData, AXTreeData> > |
156 tree0.CreateTreeSource()); | 156 tree0_source(tree0.CreateTreeSource()); |
157 AXTreeSerializer<const AXNode*, AXNodeData> serializer( | 157 AXTreeSerializer<const AXNode*, AXNodeData, AXTreeData> serializer( |
158 tree0_source.get()); | 158 tree0_source.get()); |
159 AXTreeUpdate<AXNodeData> update0; | 159 AXTreeUpdate update0; |
160 serializer.SerializeChanges(tree0.root(), &update0); | 160 serializer.SerializeChanges(tree0.root(), &update0); |
161 | 161 |
162 AXTree dst_tree; | 162 AXTree dst_tree; |
163 ASSERT_TRUE(dst_tree.Unserialize(update0)); | 163 ASSERT_TRUE(dst_tree.Unserialize(update0)); |
164 | 164 |
165 // At this point, |dst_tree| should now be identical to |tree0|. | 165 // At this point, |dst_tree| should now be identical to |tree0|. |
166 EXPECT_EQ(TreeToString(tree0), TreeToString(dst_tree)); | 166 EXPECT_EQ(TreeToString(tree0), TreeToString(dst_tree)); |
167 | 167 |
168 // Next, pretend that tree0 turned into tree1, and serialize | 168 // Next, pretend that tree0 turned into tree1, and serialize |
169 // a sequence of updates to |dst_tree| to match. | 169 // a sequence of updates to |dst_tree| to match. |
170 scoped_ptr<AXTreeSource<const AXNode*, AXNodeData> > tree1_source( | 170 scoped_ptr<AXTreeSource<const AXNode*, AXNodeData, AXTreeData> > |
171 tree1.CreateTreeSource()); | 171 tree1_source(tree1.CreateTreeSource()); |
172 serializer.ChangeTreeSourceForTesting(tree1_source.get()); | 172 serializer.ChangeTreeSourceForTesting(tree1_source.get()); |
173 | 173 |
174 for (int k_index = 0; k_index < tree_size; ++k_index) { | 174 for (int k_index = 0; k_index < tree_size; ++k_index) { |
175 int id = 1 + (k + k_index) % tree_size; | 175 int id = 1 + (k + k_index) % tree_size; |
176 AXTreeUpdate<AXNodeData> update; | 176 AXTreeUpdate update; |
177 serializer.SerializeChanges(tree1.GetFromId(id), &update); | 177 serializer.SerializeChanges(tree1.GetFromId(id), &update); |
178 ASSERT_TRUE(dst_tree.Unserialize(update)); | 178 ASSERT_TRUE(dst_tree.Unserialize(update)); |
179 } | 179 } |
180 | 180 |
181 // After the sequence of updates, |dst_tree| should now be | 181 // After the sequence of updates, |dst_tree| should now be |
182 // identical to |tree1|. | 182 // identical to |tree1|. |
183 EXPECT_EQ(TreeToString(tree1), TreeToString(dst_tree)); | 183 EXPECT_EQ(TreeToString(tree1), TreeToString(dst_tree)); |
184 } | 184 } |
185 } | 185 } |
186 } | 186 } |
187 } | 187 } |
188 | 188 |
189 } // namespace ui | 189 } // namespace ui |
OLD | NEW |