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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/chromeos/switch_access/switch_access_unittest.gtestjs
diff --git a/chrome/browser/resources/chromeos/switch_access/switch_access_unittest.gtestjs b/chrome/browser/resources/chromeos/switch_access/switch_access_unittest.gtestjs
new file mode 100644
index 0000000000000000000000000000000000000000..c181fcb0468401f673f7421564bc428d6059af84
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/switch_access_unittest.gtestjs
@@ -0,0 +1,125 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * Test fixture for switch_access.js.
+ * @constructor
+ * @extends {testing.Test}
+ */
+function SwitchAccessUnitTest () {
+ testing.Test.call(this);
+};
+
+SwitchAccessUnitTest.prototype = {
+ __proto__: testing.Test.prototype,
+
+ /** @override */
+ extraLibraries: [
+ 'test_support.js',
+ 'switch_access.js',
+ 'testable_switch_access.js',
+ ],
+
+ 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
+ let root = {};
+ let middle1 = {};
+ let middle2 = {};
+ let leaf1 = {};
+ let leaf2 = {};
+ let leaf3 = {};
+ let leaf4 = {};
+ let leaf5 = {};
+
+ root.firstChild = middle1;
+ root.lastChild = middle2;
+
+ middle1.parent = root;
+ middle2.parent = root;
+ middle1.nextSibling = middle2;
+ middle2.previousSibling = middle1;
+ middle1.firstChild = leaf1;
+ middle1.lastChild = leaf3;
+ middle2.firstChild = leaf4;
+ middle2.lastChild = leaf5;
+
+ leaf1.parent = middle1;
+ leaf2.parent = middle1;
+ leaf3.parent = middle1;
+ leaf1.nextSibling = leaf2;
+ leaf2.previousSibling = leaf1;
+ leaf2.nextSibling = leaf3;
+ leaf3.previousSibling = leaf2;
+
+ leaf4.parent = middle2;
+ leaf5.parent = middle2;
+ leaf4.nextSibling = leaf5;
+ leaf5.previousSibling = leaf4;
+
+ return {
+ root: root,
+ middle1: middle1,
+ middle2: middle2,
+ leaf1: leaf1,
+ leaf2: leaf2,
+ leaf3: leaf3,
+ leaf4: leaf4,
+ leaf5: leaf5
+ };
+ }
+};
+
+TEST_F('SwitchAccessUnitTest', 'GetNextNode', function() {
+ let tree = this.getSampleTree();
+ let tsa = new TestableSwitchAccess();
+
+ 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
+ assertTrue(tsa.getNextNode(tree.middle1) === tree.leaf1);
+ assertTrue(tsa.getNextNode(tree.leaf1) === tree.leaf2);
+ assertTrue(tsa.getNextNode(tree.leaf2) === tree.leaf3);
+ assertTrue(tsa.getNextNode(tree.leaf3) === tree.middle2);
+ assertTrue(tsa.getNextNode(tree.middle2) === tree.leaf4);
+ assertTrue(tsa.getNextNode(tree.leaf4) === tree.leaf5);
+ assertTrue(tsa.getNextNode(tree.leaf5) === null);
+});
+
+TEST_F('SwitchAccessUnitTest', 'GetPreviousNode', function() {
+ let tree = this.getSampleTree();
+ let tsa = new TestableSwitchAccess();
+
+ assertTrue(tsa.getPreviousNode(tree.leaf5) === tree.leaf4);
+ assertTrue(tsa.getPreviousNode(tree.leaf4) === tree.middle2);
+ assertTrue(tsa.getPreviousNode(tree.middle2) === tree.leaf3);
+ assertTrue(tsa.getPreviousNode(tree.leaf3) === tree.leaf2);
+ assertTrue(tsa.getPreviousNode(tree.leaf2) === tree.leaf1);
+ assertTrue(tsa.getPreviousNode(tree.leaf1) === tree.middle1);
+ assertTrue(tsa.getPreviousNode(tree.middle1) === tree.root);
+ assertTrue(tsa.getPreviousNode(tree.root) === null);
+});
+
+TEST_F('SwitchAccessUnitTest', 'GetYoungestDescendant', function() {
+ let tree = this.getSampleTree();
+ let tsa = new TestableSwitchAccess();
+
+ assertTrue(tsa.getYoungestDescendant(tree.root) === tree.leaf5);
+ assertTrue(tsa.getYoungestDescendant(tree.middle1) === tree.leaf3);
+ assertTrue(tsa.getYoungestDescendant(tree.middle2) === tree.leaf5);
+ assertTrue(tsa.getYoungestDescendant(tree.leaf1) === null);
+ assertTrue(tsa.getYoungestDescendant(tree.leaf2) === null);
+ assertTrue(tsa.getYoungestDescendant(tree.leaf3) === null);
+ assertTrue(tsa.getYoungestDescendant(tree.leaf4) === null);
+ assertTrue(tsa.getYoungestDescendant(tree.leaf5) === null);
+});
+
+TEST_F('SwitchAccessUnitTest', 'IsInteresting', function() {
+ let node1 = {};
+ let node2 = {state: {}};
+ let node3 = {state: {focusable: false}};
+ let node4 = {state: {focusable: true}};
+ let tsa = new TestableSwitchAccess();
+
+ assertTrue(tsa.isInteresting(node1) === undefined);
+ assertTrue(tsa.isInteresting(node2) === undefined);
+ assertFalse(tsa.isInteresting(node3));
+ assertTrue(tsa.isInteresting(node4));
+});
« 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