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

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

Issue 2748853002: Added unit tests for switch_access.js. (Closed)
Patch Set: Responded to comments Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/switch_access/test_support.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'switch_access.js',
21 'testable_switch_access.js',
22 ],
23
24 getSampleTree: function() {
25 // root
26 // middle1
27 // leaf1
28 // leaf2
29 // leaf3
30 // middle2
31 // leaf4
32 // leaf5
33 let root = {};
34 let middle1 = {};
35 let middle2 = {};
36 let leaf1 = {};
37 let leaf2 = {};
38 let leaf3 = {};
39 let leaf4 = {};
40 let leaf5 = {};
41
42 root.firstChild = middle1;
43 root.lastChild = middle2;
44
45 middle1.parent = root;
46 middle2.parent = root;
47 middle1.nextSibling = middle2;
48 middle2.previousSibling = middle1;
49 middle1.firstChild = leaf1;
50 middle1.lastChild = leaf3;
51 middle2.firstChild = leaf4;
52 middle2.lastChild = leaf5;
53
54 leaf1.parent = middle1;
55 leaf2.parent = middle1;
56 leaf3.parent = middle1;
57 leaf1.nextSibling = leaf2;
58 leaf2.previousSibling = leaf1;
59 leaf2.nextSibling = leaf3;
60 leaf3.previousSibling = leaf2;
61
62 leaf4.parent = middle2;
63 leaf5.parent = middle2;
64 leaf4.nextSibling = leaf5;
65 leaf5.previousSibling = leaf4;
66
67 return {
68 root: root,
69 middle1: middle1,
70 middle2: middle2,
71 leaf1: leaf1,
72 leaf2: leaf2,
73 leaf3: leaf3,
74 leaf4: leaf4,
75 leaf5: leaf5
76 };
77 }
78 };
79
80 TEST_F('SwitchAccessUnitTest', 'GetNextNode', function() {
81 let tree = this.getSampleTree();
82 let tsa = new TestableSwitchAccess();
83
84 let order =
85 [tree.root, tree.middle1, tree.leaf1, tree.leaf2, tree.leaf3,
86 tree.middle2, tree.leaf4, tree.leaf5];
87 let node = tree.root;
88 for (let i = 0; i < order.length; i++) {
89 assertEquals(order[i], node);
90 node = tsa.getNextNode(node);
91 }
92 assertEquals(null, node);
93 });
94
95 TEST_F('SwitchAccessUnitTest', 'GetPreviousNode', function() {
96 let tree = this.getSampleTree();
97 let tsa = new TestableSwitchAccess();
98
99 let order =
100 [tree.leaf5, tree.leaf4, tree.middle2, tree.leaf3, tree.leaf2,
101 tree.leaf1, tree.middle1, tree.root];
102 let node = tree.leaf5;
103 for (let i = 0; i < order.length; i++) {
104 assertEquals(order[i], node);
105 node = tsa.getPreviousNode(node);
106 }
107 assertEquals(null, node);
108 });
109
110 TEST_F('SwitchAccessUnitTest', 'GetYoungestDescendant', function() {
111 let tree = this.getSampleTree();
112 let tsa = new TestableSwitchAccess();
113
114 assertEquals(tree.leaf5, tsa.getYoungestDescendant(tree.root));
115 assertEquals(tree.leaf3, tsa.getYoungestDescendant(tree.middle1));
116 assertEquals(tree.leaf5, tsa.getYoungestDescendant(tree.middle2));
117 assertEquals(null, tsa.getYoungestDescendant(tree.leaf1));
118 assertEquals(null, tsa.getYoungestDescendant(tree.leaf2));
119 assertEquals(null, tsa.getYoungestDescendant(tree.leaf3));
120 assertEquals(null, tsa.getYoungestDescendant(tree.leaf4));
121 assertEquals(null, tsa.getYoungestDescendant(tree.leaf5));
122 });
123
124 TEST_F('SwitchAccessUnitTest', 'IsInteresting', function() {
125 let node1 = {};
126 let node2 = {state: {}};
127 let node3 = {state: {focusable: false}};
128 let node4 = {state: {focusable: true}};
129 let tsa = new TestableSwitchAccess();
130
131 assertTrue(tsa.isInteresting(node1) === undefined);
132 assertTrue(tsa.isInteresting(node2) === undefined);
133 assertFalse(tsa.isInteresting(node3));
134 assertTrue(tsa.isInteresting(node4));
135 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/switch_access/test_support.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698