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

Unified Diff: ui/accessibility/ax_generated_tree_unittest.cc

Issue 967583002: Improve AXTree unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update automation_apitest.cc Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/automation/automation_apitest.cc ('k') | ui/accessibility/ax_tree.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/accessibility/ax_generated_tree_unittest.cc
diff --git a/ui/accessibility/ax_generated_tree_unittest.cc b/ui/accessibility/ax_generated_tree_unittest.cc
index b0bd21c81ff5bad3a00fc28e7ae04aacf36f4911..cb1038c018ce17beb5ff8203b93ac89182cff150 100644
--- a/ui/accessibility/ax_generated_tree_unittest.cc
+++ b/ui/accessibility/ax_generated_tree_unittest.cc
@@ -48,11 +48,37 @@ std::string TreeToString(const AXTree& tree) {
} // anonymous namespace
// Test the TreeGenerator class by building all possible trees with
-// 3 nodes and the ids [1...3].
-TEST(AXGeneratedTreeTest, TestTreeGenerator) {
+// 3 nodes and the ids [1...3], with no permutations of ids.
+TEST(AXGeneratedTreeTest, TestTreeGeneratorNoPermutations) {
int tree_size = 3;
- TreeGenerator generator(tree_size);
+ TreeGenerator generator(tree_size, false);
const char* EXPECTED_TREES[] = {
+ "(1)",
+ "(1 (2))",
+ "(1 (2 3))",
+ "(1 (2 (3)))",
+ };
+
+ int n = generator.UniqueTreeCount();
+ ASSERT_EQ(static_cast<int>(arraysize(EXPECTED_TREES)), n);
+
+ for (int i = 0; i < n; ++i) {
+ AXTree tree;
+ generator.BuildUniqueTree(i, &tree);
+ std::string str = TreeToString(tree);
+ EXPECT_EQ(EXPECTED_TREES[i], str);
+ }
+}
+
+// Test the TreeGenerator class by building all possible trees with
+// 3 nodes and the ids [1...3] permuted in any order.
+TEST(AXGeneratedTreeTest, TestTreeGeneratorWithPermutations) {
+ int tree_size = 3;
+ TreeGenerator generator(tree_size, true);
+ const char* EXPECTED_TREES[] = {
+ "(1)",
+ "(1 (2))",
+ "(2 (1))",
"(1 (2 3))",
"(2 (1 3))",
"(3 (1 2))",
@@ -92,26 +118,31 @@ TEST(AXGeneratedTreeTest, SerializeGeneratedTrees) {
// the algorithm you may want to try even larger tree sizes if you
// can afford the time.
#ifdef NDEBUG
- int tree_size = 4;
+ int max_tree_size = 4;
#else
LOG(WARNING) << "Debug build, only testing trees with 3 nodes and not 4.";
- int tree_size = 3;
+ int max_tree_size = 3;
#endif
- TreeGenerator generator(tree_size);
- int n = generator.UniqueTreeCount();
+ TreeGenerator generator0(max_tree_size, false);
+ int n0 = generator0.UniqueTreeCount();
- for (int i = 0; i < n; i++) {
+ TreeGenerator generator1(max_tree_size, true);
+ int n1 = generator1.UniqueTreeCount();
+
+ for (int i = 0; i < n0; i++) {
// Build the first tree, tree0.
AXSerializableTree tree0;
- generator.BuildUniqueTree(i, &tree0);
+ generator0.BuildUniqueTree(i, &tree0);
SCOPED_TRACE("tree0 is " + TreeToString(tree0));
- for (int j = 0; j < n; j++) {
+ for (int j = 0; j < n1; j++) {
// Build the second tree, tree1.
AXSerializableTree tree1;
- generator.BuildUniqueTree(j, &tree1);
- SCOPED_TRACE("tree1 is " + TreeToString(tree0));
+ generator1.BuildUniqueTree(j, &tree1);
+ SCOPED_TRACE("tree1 is " + TreeToString(tree1));
+
+ int tree_size = tree1.size();
// Now iterate over which node to update first, |k|.
for (int k = 0; k < tree_size; k++) {
« no previous file with comments | « chrome/browser/extensions/api/automation/automation_apitest.cc ('k') | ui/accessibility/ax_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698