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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 SCOPED_TRACE("tree1 is " + TreeToString(tree0)); | 200 SCOPED_TRACE("tree1 is " + TreeToString(tree0)); |
201 | 201 |
202 // Now iterate over which node to update first, |k|. | 202 // Now iterate over which node to update first, |k|. |
203 for (int k = 0; k < tree_size; k++) { | 203 for (int k = 0; k < tree_size; k++) { |
204 SCOPED_TRACE("i=" + base::IntToString(i) + | 204 SCOPED_TRACE("i=" + base::IntToString(i) + |
205 " j=" + base::IntToString(j) + | 205 " j=" + base::IntToString(j) + |
206 " k=" + base::IntToString(k)); | 206 " k=" + base::IntToString(k)); |
207 | 207 |
208 // Start by serializing tree0 and unserializing it into a new | 208 // Start by serializing tree0 and unserializing it into a new |
209 // empty tree |dst_tree|. | 209 // empty tree |dst_tree|. |
210 scoped_ptr<AXTreeSource<AXNode> > tree0_source( | 210 scoped_ptr<AXTreeSource<const AXNode*> > tree0_source( |
211 tree0.CreateTreeSource()); | 211 tree0.CreateTreeSource()); |
212 AXTreeSerializer<AXNode> serializer(tree0_source.get()); | 212 AXTreeSerializer<const AXNode*> serializer(tree0_source.get()); |
213 AXTreeUpdate update0; | 213 AXTreeUpdate update0; |
214 serializer.SerializeChanges(tree0.GetRoot(), &update0); | 214 serializer.SerializeChanges(tree0.GetRoot(), &update0); |
215 | 215 |
216 AXTree dst_tree; | 216 AXTree dst_tree; |
217 ASSERT_TRUE(dst_tree.Unserialize(update0)); | 217 ASSERT_TRUE(dst_tree.Unserialize(update0)); |
218 | 218 |
219 // At this point, |dst_tree| should now be identical to |tree0|. | 219 // At this point, |dst_tree| should now be identical to |tree0|. |
220 EXPECT_EQ(TreeToString(tree0), TreeToString(dst_tree)); | 220 EXPECT_EQ(TreeToString(tree0), TreeToString(dst_tree)); |
221 | 221 |
222 // Next, pretend that tree0 turned into tree1, and serialize | 222 // Next, pretend that tree0 turned into tree1, and serialize |
223 // a sequence of updates to |dst_tree| to match. | 223 // a sequence of updates to |dst_tree| to match. |
224 scoped_ptr<AXTreeSource<AXNode> > tree1_source( | 224 scoped_ptr<AXTreeSource<const AXNode*> > tree1_source( |
225 tree1.CreateTreeSource()); | 225 tree1.CreateTreeSource()); |
226 serializer.ChangeTreeSourceForTesting(tree1_source.get()); | 226 serializer.ChangeTreeSourceForTesting(tree1_source.get()); |
227 | 227 |
228 for (int k_index = 0; k_index < tree_size; ++k_index) { | 228 for (int k_index = 0; k_index < tree_size; ++k_index) { |
229 int id = 1 + (k + k_index) % tree_size; | 229 int id = 1 + (k + k_index) % tree_size; |
230 AXTreeUpdate update; | 230 AXTreeUpdate update; |
231 serializer.SerializeChanges(tree1.GetFromId(id), &update); | 231 serializer.SerializeChanges(tree1.GetFromId(id), &update); |
232 ASSERT_TRUE(dst_tree.Unserialize(update)); | 232 ASSERT_TRUE(dst_tree.Unserialize(update)); |
233 } | 233 } |
234 | 234 |
235 // After the sequence of updates, |dst_tree| should now be | 235 // After the sequence of updates, |dst_tree| should now be |
236 // identical to |tree1|. | 236 // identical to |tree1|. |
237 EXPECT_EQ(TreeToString(tree1), TreeToString(dst_tree)); | 237 EXPECT_EQ(TreeToString(tree1), TreeToString(dst_tree)); |
238 } | 238 } |
239 } | 239 } |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 } // namespace ui | 243 } // namespace ui |
OLD | NEW |