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

Side by Side Diff: chrome/browser/resources/chromeos/switch_access/switch_access_unittest.gtestjs

Issue 2777203006: Added auto-scan, made some small changes to how prefs are stored, refactored. (Closed)
Patch Set: Responding to comments. Refactored tree_walker. Removed testable_tree_walker. Created 3 years, 8 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * Test fixture for switch_access.js.
7 * @constructor
8 * @extends {testing.Test}
9 */
10 function SwitchAccessUnitTest () {
11 testing.Test.call(this);
12 };
13
14 SwitchAccessUnitTest.prototype = {
15 __proto__: testing.Test.prototype,
16
17 /** @override */
18 extraLibraries: [
19 'test_support.js',
20 'prefs.js',
21 'switch_access.js',
22 'testable_switch_access.js',
23 ],
24
25 getSampleTree: function() {
26 // root
27 // middle1
28 // leaf1
29 // leaf2
30 // leaf3
31 // middle2
32 // leaf4
33 // leaf5
34 let root = {};
35 let middle1 = {};
36 let middle2 = {};
37 let leaf1 = {};
38 let leaf2 = {};
39 let leaf3 = {};
40 let leaf4 = {};
41 let leaf5 = {};
42
43 root.firstChild = middle1;
44 root.lastChild = middle2;
45
46 middle1.parent = root;
47 middle2.parent = root;
48 middle1.nextSibling = middle2;
49 middle2.previousSibling = middle1;
50 middle1.firstChild = leaf1;
51 middle1.lastChild = leaf3;
52 middle2.firstChild = leaf4;
53 middle2.lastChild = leaf5;
54
55 leaf1.parent = middle1;
56 leaf2.parent = middle1;
57 leaf3.parent = middle1;
58 leaf1.nextSibling = leaf2;
59 leaf2.previousSibling = leaf1;
60 leaf2.nextSibling = leaf3;
61 leaf3.previousSibling = leaf2;
62
63 leaf4.parent = middle2;
64 leaf5.parent = middle2;
65 leaf4.nextSibling = leaf5;
66 leaf5.previousSibling = leaf4;
67
68 return {
69 root: root,
70 middle1: middle1,
71 middle2: middle2,
72 leaf1: leaf1,
73 leaf2: leaf2,
74 leaf3: leaf3,
75 leaf4: leaf4,
76 leaf5: leaf5
77 };
78 }
79 };
80
81 TEST_F('SwitchAccessUnitTest', 'GetNextNode', function() {
82 let tree = this.getSampleTree();
83 let tsa = new TestableSwitchAccess();
84
85 let order =
86 [tree.root, tree.middle1, tree.leaf1, tree.leaf2, tree.leaf3,
87 tree.middle2, tree.leaf4, tree.leaf5];
88 let node = tree.root;
89 for (let i = 0; i < order.length; i++) {
90 assertEquals(order[i], node);
91 node = tsa.getNextNode(node);
92 }
93 assertEquals(null, node);
94 });
95
96 TEST_F('SwitchAccessUnitTest', 'GetPreviousNode', function() {
97 let tree = this.getSampleTree();
98 let tsa = new TestableSwitchAccess();
99
100 let order =
101 [tree.leaf5, tree.leaf4, tree.middle2, tree.leaf3, tree.leaf2,
102 tree.leaf1, tree.middle1, tree.root];
103 let node = tree.leaf5;
104 for (let i = 0; i < order.length; i++) {
105 assertEquals(order[i], node);
106 node = tsa.getPreviousNode(node);
107 }
108 assertEquals(null, node);
109 });
110
111 TEST_F('SwitchAccessUnitTest', 'GetYoungestDescendant', function() {
112 let tree = this.getSampleTree();
113 let tsa = new TestableSwitchAccess();
114
115 assertEquals(tree.leaf5, tsa.getYoungestDescendant(tree.root));
116 assertEquals(tree.leaf3, tsa.getYoungestDescendant(tree.middle1));
117 assertEquals(tree.leaf5, tsa.getYoungestDescendant(tree.middle2));
118 assertEquals(null, tsa.getYoungestDescendant(tree.leaf1));
119 assertEquals(null, tsa.getYoungestDescendant(tree.leaf2));
120 assertEquals(null, tsa.getYoungestDescendant(tree.leaf3));
121 assertEquals(null, tsa.getYoungestDescendant(tree.leaf4));
122 assertEquals(null, tsa.getYoungestDescendant(tree.leaf5));
123 });
124
125 TEST_F('SwitchAccessUnitTest', 'IsInteresting', function() {
126 let node1 = {};
127 let node2 = {state: {}};
128 let node3 = {state: {focusable: false}};
129 let node4 = {state: {focusable: true}};
130 let tsa = new TestableSwitchAccess();
131
132 assertTrue(tsa.isInteresting(node1) === undefined);
133 assertTrue(tsa.isInteresting(node2) === undefined);
134 assertFalse(tsa.isInteresting(node3));
135 assertTrue(tsa.isInteresting(node4));
136 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698