Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: ui/accessibility/ax_tree_serializer_unittest.cc

Issue 1144363004: When serializing accessibility tree, skip invalid children. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Windows link Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/accessibility/ax_tree_serializer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // The update should delete the subtree rooted at node id=2, and 172 // The update should delete the subtree rooted at node id=2, and
173 // then include nodes 2...5. 173 // then include nodes 2...5.
174 EXPECT_EQ(2, update.node_id_to_clear); 174 EXPECT_EQ(2, update.node_id_to_clear);
175 ASSERT_EQ(static_cast<size_t>(4), update.nodes.size()); 175 ASSERT_EQ(static_cast<size_t>(4), update.nodes.size());
176 EXPECT_EQ(2, update.nodes[0].id); 176 EXPECT_EQ(2, update.nodes[0].id);
177 EXPECT_EQ(3, update.nodes[1].id); 177 EXPECT_EQ(3, update.nodes[1].id);
178 EXPECT_EQ(4, update.nodes[2].id); 178 EXPECT_EQ(4, update.nodes[2].id);
179 EXPECT_EQ(5, update.nodes[3].id); 179 EXPECT_EQ(5, update.nodes[3].id);
180 } 180 }
181 181
182 // A variant of AXTreeSource that returns true for IsValid() for one
183 // particular id.
184 class AXTreeSourceWithInvalidId : public AXTreeSource<const AXNode*> {
185 public:
186 AXTreeSourceWithInvalidId(AXTree* tree, int invalid_id)
187 : tree_(tree),
188 invalid_id_(invalid_id) {}
189 ~AXTreeSourceWithInvalidId() override {}
190
191 // AXTreeSource implementation.
192 AXNode* GetRoot() const override { return tree_->root(); }
193 AXNode* GetFromId(int32 id) const override { return tree_->GetFromId(id); }
194 int32 GetId(const AXNode* node) const override { return node->id(); }
195 void GetChildren(const AXNode* node,
196 std::vector<const AXNode*>* out_children) const override {
197 for (int i = 0; i < node->child_count(); ++i)
198 out_children->push_back(node->ChildAtIndex(i));
199 }
200 AXNode* GetParent(const AXNode* node) const override {
201 return node->parent();
202 }
203 bool IsValid(const AXNode* node) const override {
204 return node != NULL && node->id() != invalid_id_;
205 }
206 bool IsEqual(const AXNode* node1, const AXNode* node2) const override {
207 return node1 == node2;
208 }
209 const AXNode* GetNull() const override { return NULL; }
210 void SerializeNode(const AXNode* node, AXNodeData* out_data) const override {
211 *out_data = node->data();
212 if (node->id() == invalid_id_)
213 out_data->id = -1;
214 }
215
216 private:
217 AXTree* tree_;
218 int invalid_id_;
219
220 DISALLOW_COPY_AND_ASSIGN(AXTreeSourceWithInvalidId);
221 };
222
223 // Test that the serializer skips invalid children.
224 TEST(AXTreeSerializerInvalidTest, InvalidChild) {
225 // (1 (2 3))
226 AXTreeUpdate treedata;
227 treedata.nodes.resize(3);
228 treedata.nodes[0].id = 1;
229 treedata.nodes[0].role = AX_ROLE_ROOT_WEB_AREA;
230 treedata.nodes[0].child_ids.push_back(2);
231 treedata.nodes[0].child_ids.push_back(3);
232 treedata.nodes[1].id = 2;
233 treedata.nodes[2].id = 3;
234
235 AXTree tree(treedata);
236 AXTreeSourceWithInvalidId source(&tree, 3);
237
238 AXTreeSerializer<const AXNode*> serializer(&source);
239 AXTreeUpdate update;
240 serializer.SerializeChanges(tree.root(), &update);
241
242 ASSERT_EQ(2U, update.nodes.size());
243 EXPECT_EQ(1, update.nodes[0].id);
244 EXPECT_EQ(2, update.nodes[1].id);
245 }
246
182 } // namespace ui 247 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/ax_tree_serializer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698