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

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: 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() {
dmazzoni 2017/03/14 16:08:49 To make it easier to understand, I recommend a bit
elichtenberg 2017/03/14 17:36:49 Done. Do I need an extra line above the comment, o
25 let root = {};
26 let middle1 = {};
27 let middle2 = {};
28 let leaf1 = {};
29 let leaf2 = {};
30 let leaf3 = {};
31 let leaf4 = {};
32 let leaf5 = {};
33
34 root.firstChild = middle1;
35 root.lastChild = middle2;
36
37 middle1.parent = root;
38 middle2.parent = root;
39 middle1.nextSibling = middle2;
40 middle2.previousSibling = middle1;
41 middle1.firstChild = leaf1;
42 middle1.lastChild = leaf3;
43 middle2.firstChild = leaf4;
44 middle2.lastChild = leaf5;
45
46 leaf1.parent = middle1;
47 leaf2.parent = middle1;
48 leaf3.parent = middle1;
49 leaf1.nextSibling = leaf2;
50 leaf2.previousSibling = leaf1;
51 leaf2.nextSibling = leaf3;
52 leaf3.previousSibling = leaf2;
53
54 leaf4.parent = middle2;
55 leaf5.parent = middle2;
56 leaf4.nextSibling = leaf5;
57 leaf5.previousSibling = leaf4;
58
59 return {
60 root: root,
61 middle1: middle1,
62 middle2: middle2,
63 leaf1: leaf1,
64 leaf2: leaf2,
65 leaf3: leaf3,
66 leaf4: leaf4,
67 leaf5: leaf5
68 };
69 }
70 };
71
72 TEST_F('SwitchAccessUnitTest', 'GetNextNode', function() {
73 let tree = this.getSampleTree();
74 let tsa = new TestableSwitchAccess();
75
76 assertTrue(tsa.getNextNode(tree.root) === tree.middle1);
dmazzoni 2017/03/14 16:08:49 An alternative idea for readability: var inOrder
elichtenberg 2017/03/14 17:36:49 Done. Did it slightly differently but with the sam
77 assertTrue(tsa.getNextNode(tree.middle1) === tree.leaf1);
78 assertTrue(tsa.getNextNode(tree.leaf1) === tree.leaf2);
79 assertTrue(tsa.getNextNode(tree.leaf2) === tree.leaf3);
80 assertTrue(tsa.getNextNode(tree.leaf3) === tree.middle2);
81 assertTrue(tsa.getNextNode(tree.middle2) === tree.leaf4);
82 assertTrue(tsa.getNextNode(tree.leaf4) === tree.leaf5);
83 assertTrue(tsa.getNextNode(tree.leaf5) === null);
84 });
85
86 TEST_F('SwitchAccessUnitTest', 'GetPreviousNode', function() {
87 let tree = this.getSampleTree();
88 let tsa = new TestableSwitchAccess();
89
90 assertTrue(tsa.getPreviousNode(tree.leaf5) === tree.leaf4);
91 assertTrue(tsa.getPreviousNode(tree.leaf4) === tree.middle2);
92 assertTrue(tsa.getPreviousNode(tree.middle2) === tree.leaf3);
93 assertTrue(tsa.getPreviousNode(tree.leaf3) === tree.leaf2);
94 assertTrue(tsa.getPreviousNode(tree.leaf2) === tree.leaf1);
95 assertTrue(tsa.getPreviousNode(tree.leaf1) === tree.middle1);
96 assertTrue(tsa.getPreviousNode(tree.middle1) === tree.root);
97 assertTrue(tsa.getPreviousNode(tree.root) === null);
98 });
99
100 TEST_F('SwitchAccessUnitTest', 'GetYoungestDescendant', function() {
101 let tree = this.getSampleTree();
102 let tsa = new TestableSwitchAccess();
103
104 assertTrue(tsa.getYoungestDescendant(tree.root) === tree.leaf5);
105 assertTrue(tsa.getYoungestDescendant(tree.middle1) === tree.leaf3);
106 assertTrue(tsa.getYoungestDescendant(tree.middle2) === tree.leaf5);
107 assertTrue(tsa.getYoungestDescendant(tree.leaf1) === null);
108 assertTrue(tsa.getYoungestDescendant(tree.leaf2) === null);
109 assertTrue(tsa.getYoungestDescendant(tree.leaf3) === null);
110 assertTrue(tsa.getYoungestDescendant(tree.leaf4) === null);
111 assertTrue(tsa.getYoungestDescendant(tree.leaf5) === null);
112 });
113
114 TEST_F('SwitchAccessUnitTest', 'IsInteresting', function() {
115 let node1 = {};
116 let node2 = {state: {}};
117 let node3 = {state: {focusable: false}};
118 let node4 = {state: {focusable: true}};
119 let tsa = new TestableSwitchAccess();
120
121 assertTrue(tsa.isInteresting(node1) === undefined);
122 assertTrue(tsa.isInteresting(node2) === undefined);
123 assertFalse(tsa.isInteresting(node3));
124 assertTrue(tsa.isInteresting(node4));
125 });
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