Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / chromevox / cvox2 / background / automation_util_test.extjs
blob2c75b9fc26bea3c972fe4f6d44892d6770432128
1 // Copyright 2014 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.
5 // Include test fixture.
6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']);
8 /**
9  * Test fixture for automation_util.js.
10  * @constructor
11  * @extends {ChromeVoxE2ETestBase}
12  */
13 function AutomationUtilE2ETest() {
14   ChromeVoxNextE2ETest.call(this);
17 AutomationUtilE2ETest.prototype = {
18   __proto__: ChromeVoxNextE2ETest.prototype,
20   /** @override */
21   setUp: function() {
22     window.Dir = AutomationUtil.Dir;
23   },
25   basicDoc: function() {/*!
26     <p><a href='#'></a>hello</p>
27     <h1><ul><li>a</ul><button></h1>
28   */}
31 TEST_F('AutomationUtilE2ETest', 'GetAncestors', function() {
32   this.runWithLoadedTree(this.basicDoc, function(root) {
33     var expectedLength = 1;
34     while (root) {
35       var ancestors = AutomationUtil.getAncestors(root);
36       assertEquals(expectedLength++, ancestors.length);
37       root = root.firstChild;
38     }
39   });
40 });
41   
42 TEST_F('AutomationUtilE2ETest', 'GetUniqueAncestors', function() {
43   this.runWithLoadedTree(this.basicDoc, function(root) {
44     var leftmost = root, rightmost = root;
45     while (leftmost.firstChild)
46       leftmost = leftmost.firstChild;
47     while (rightmost.lastChild)
48       rightmost = rightmost.lastChild;
50     var leftAncestors = AutomationUtil.getAncestors(leftmost);
51     var rightAncestors = AutomationUtil.getAncestors(rightmost);
52     assertEquals(chrome.automation.RoleType.link, leftmost.role);
53     assertEquals(chrome.automation.RoleType.button, rightmost.role);
54     assertEquals(
55         1, AutomationUtil.getDivergence(leftAncestors, rightAncestors));
56     assertEquals(
57         -1, AutomationUtil.getDivergence(leftAncestors, leftAncestors));
59     var uniqueAncestorsLeft =
60         AutomationUtil.getUniqueAncestors(rightmost, leftmost);
61     var uniqueAncestorsRight =
62         AutomationUtil.getUniqueAncestors(leftmost, rightmost);
64     assertEquals(2, uniqueAncestorsLeft.length);
65     assertEquals(chrome.automation.RoleType.paragraph,
66         uniqueAncestorsLeft[0].role);
67     assertEquals(chrome.automation.RoleType.link,
68         uniqueAncestorsLeft[1].role);
70     assertEquals(3, uniqueAncestorsRight.length);
71     assertEquals(chrome.automation.RoleType.heading,
72         uniqueAncestorsRight[0].role);
73     assertEquals(chrome.automation.RoleType.group,
74         uniqueAncestorsRight[1].role);
75     assertEquals(chrome.automation.RoleType.button,
76         uniqueAncestorsRight[2].role);
78     assertEquals(
79         1, AutomationUtil.getUniqueAncestors(leftmost, leftmost).length);
81   });
82 });
83   
84 TEST_F('AutomationUtilE2ETest', 'GetDirection', function() {
85   this.runWithLoadedTree(this.basicDoc, function(root) {
86     var left = root, right = root;
88     // Same node.
89     assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right));
91     // Ancestor.
92     left = left.firstChild;
93     assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right));
94     assertEquals(Dir.FORWARD, AutomationUtil.getDirection(right, left));
96     // Ordered.
97     right = right.lastChild;
98     assertEquals(Dir.BACKWARD, AutomationUtil.getDirection(right, left));
99     assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right));
101   });