Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 /** | 5 /** |
| 6 * Test fixture for switch_access.js. | 6 * Test fixture for tree_walker.js. |
| 7 * @constructor | 7 * @constructor |
| 8 * @extends {testing.Test} | 8 * @extends {testing.Test} |
| 9 */ | 9 */ |
| 10 function SwitchAccessUnitTest () { | 10 function TreeWalkerUnitTest () { |
|
David Tseng
2017/03/29 21:57:21
AutomationTreeWalkerUnitTest
elichtenberg
2017/03/30 21:46:56
Done.
| |
| 11 testing.Test.call(this); | 11 testing.Test.call(this); |
| 12 }; | 12 }; |
| 13 | 13 |
| 14 SwitchAccessUnitTest.prototype = { | 14 TreeWalkerUnitTest.prototype = { |
| 15 __proto__: testing.Test.prototype, | 15 __proto__: testing.Test.prototype, |
| 16 | 16 |
| 17 /** @override */ | 17 /** @override */ |
| 18 extraLibraries: [ | 18 extraLibraries: [ |
| 19 'test_support.js', | 19 'tree_walker.js', |
| 20 'prefs.js', | 20 'testable_tree_walker.js', |
| 21 'switch_access.js', | |
| 22 'testable_switch_access.js', | |
| 23 ], | 21 ], |
| 24 | 22 |
| 25 getSampleTree: function() { | 23 getSampleTree: function() { |
| 26 // root | 24 // root |
| 27 // middle1 | 25 // middle1 |
| 28 // leaf1 | 26 // leaf1 |
| 29 // leaf2 | 27 // leaf2 |
| 30 // leaf3 | 28 // leaf3 |
| 31 // middle2 | 29 // middle2 |
| 32 // leaf4 | 30 // leaf4 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 middle2: middle2, | 69 middle2: middle2, |
| 72 leaf1: leaf1, | 70 leaf1: leaf1, |
| 73 leaf2: leaf2, | 71 leaf2: leaf2, |
| 74 leaf3: leaf3, | 72 leaf3: leaf3, |
| 75 leaf4: leaf4, | 73 leaf4: leaf4, |
| 76 leaf5: leaf5 | 74 leaf5: leaf5 |
| 77 }; | 75 }; |
| 78 } | 76 } |
| 79 }; | 77 }; |
| 80 | 78 |
| 81 TEST_F('SwitchAccessUnitTest', 'GetNextNode', function() { | 79 TEST_F('TreeWalkerUnitTest', 'GetNextNode', function() { |
| 82 let tree = this.getSampleTree(); | 80 let tree = this.getSampleTree(); |
| 83 let tsa = new TestableSwitchAccess(); | 81 let treeWalker = new TestableTreeWalker(); |
| 84 | 82 |
| 85 let order = | 83 let order = |
| 86 [tree.root, tree.middle1, tree.leaf1, tree.leaf2, tree.leaf3, | 84 [tree.root, tree.middle1, tree.leaf1, tree.leaf2, tree.leaf3, |
| 87 tree.middle2, tree.leaf4, tree.leaf5]; | 85 tree.middle2, tree.leaf4, tree.leaf5]; |
| 88 let node = tree.root; | 86 let node = tree.root; |
| 89 for (let i = 0; i < order.length; i++) { | 87 for (let i = 0; i < order.length; i++) { |
| 90 assertEquals(order[i], node); | 88 assertEquals(order[i], node); |
| 91 node = tsa.getNextNode(node); | 89 node = treeWalker.getNextNode(node); |
| 92 } | 90 } |
| 93 assertEquals(null, node); | 91 assertEquals(null, node); |
| 94 }); | 92 }); |
| 95 | 93 |
| 96 TEST_F('SwitchAccessUnitTest', 'GetPreviousNode', function() { | 94 TEST_F('TreeWalkerUnitTest', 'GetPreviousNode', function() { |
| 97 let tree = this.getSampleTree(); | 95 let tree = this.getSampleTree(); |
| 98 let tsa = new TestableSwitchAccess(); | 96 let treeWalker = new TestableTreeWalker(); |
| 99 | 97 |
| 100 let order = | 98 let order = |
| 101 [tree.leaf5, tree.leaf4, tree.middle2, tree.leaf3, tree.leaf2, | 99 [tree.leaf5, tree.leaf4, tree.middle2, tree.leaf3, tree.leaf2, |
| 102 tree.leaf1, tree.middle1, tree.root]; | 100 tree.leaf1, tree.middle1, tree.root]; |
| 103 let node = tree.leaf5; | 101 let node = tree.leaf5; |
| 104 for (let i = 0; i < order.length; i++) { | 102 for (let i = 0; i < order.length; i++) { |
| 105 assertEquals(order[i], node); | 103 assertEquals(order[i], node); |
| 106 node = tsa.getPreviousNode(node); | 104 node = treeWalker.getPreviousNode(node); |
| 107 } | 105 } |
| 108 assertEquals(null, node); | 106 assertEquals(null, node); |
| 109 }); | 107 }); |
| 110 | 108 |
| 111 TEST_F('SwitchAccessUnitTest', 'GetYoungestDescendant', function() { | 109 TEST_F('TreeWalkerUnitTest', 'GetYoungestDescendant', function() { |
| 112 let tree = this.getSampleTree(); | 110 let tree = this.getSampleTree(); |
| 113 let tsa = new TestableSwitchAccess(); | 111 let treeWalker = new TestableTreeWalker(); |
| 114 | 112 |
| 115 assertEquals(tree.leaf5, tsa.getYoungestDescendant(tree.root)); | 113 assertEquals(tree.leaf5, treeWalker.getYoungestDescendant(tree.root)); |
| 116 assertEquals(tree.leaf3, tsa.getYoungestDescendant(tree.middle1)); | 114 assertEquals(tree.leaf3, treeWalker.getYoungestDescendant(tree.middle1)); |
| 117 assertEquals(tree.leaf5, tsa.getYoungestDescendant(tree.middle2)); | 115 assertEquals(tree.leaf5, treeWalker.getYoungestDescendant(tree.middle2)); |
| 118 assertEquals(null, tsa.getYoungestDescendant(tree.leaf1)); | 116 assertEquals(null, treeWalker.getYoungestDescendant(tree.leaf1)); |
| 119 assertEquals(null, tsa.getYoungestDescendant(tree.leaf2)); | 117 assertEquals(null, treeWalker.getYoungestDescendant(tree.leaf2)); |
| 120 assertEquals(null, tsa.getYoungestDescendant(tree.leaf3)); | 118 assertEquals(null, treeWalker.getYoungestDescendant(tree.leaf3)); |
| 121 assertEquals(null, tsa.getYoungestDescendant(tree.leaf4)); | 119 assertEquals(null, treeWalker.getYoungestDescendant(tree.leaf4)); |
| 122 assertEquals(null, tsa.getYoungestDescendant(tree.leaf5)); | 120 assertEquals(null, treeWalker.getYoungestDescendant(tree.leaf5)); |
| 123 }); | 121 }); |
| 124 | 122 |
| 125 TEST_F('SwitchAccessUnitTest', 'IsInteresting', function() { | 123 TEST_F('TreeWalkerUnitTest', 'IsInteresting', function() { |
| 126 let node1 = {}; | 124 let node1 = {}; |
| 127 let node2 = {state: {}}; | 125 let node2 = {state: {}}; |
| 128 let node3 = {state: {focusable: false}}; | 126 let node3 = {state: {focusable: false}}; |
| 129 let node4 = {state: {focusable: true}}; | 127 let node4 = {state: {focusable: true}}; |
| 130 let tsa = new TestableSwitchAccess(); | 128 let treeWalker = new TestableTreeWalker(); |
| 131 | 129 |
| 132 assertTrue(tsa.isInteresting(node1) === undefined); | 130 assertTrue(treeWalker.isInteresting(node1) === undefined); |
| 133 assertTrue(tsa.isInteresting(node2) === undefined); | 131 assertTrue(treeWalker.isInteresting(node2) === undefined); |
| 134 assertFalse(tsa.isInteresting(node3)); | 132 assertFalse(treeWalker.isInteresting(node3)); |
| 135 assertTrue(tsa.isInteresting(node4)); | 133 assertTrue(treeWalker.isInteresting(node4)); |
| 136 }); | 134 }); |
| OLD | NEW |