OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Include test fixture. | 5 // Include test fixture. |
6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']); | 6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']); |
7 | 7 |
8 /** | 8 /** |
9 * Test fixture for automation_util.js. | 9 * Test fixture for automation_util.js. |
10 * @constructor | 10 * @constructor |
11 * @extends {ChromeVoxE2ETestBase} | 11 * @extends {ChromeVoxE2ETestBase} |
12 */ | 12 */ |
13 function AutomationUtilE2ETest() { | 13 function AutomationUtilE2ETest() { |
14 ChromeVoxNextE2ETest.call(this); | 14 ChromeVoxNextE2ETest.call(this); |
15 } | 15 } |
16 | 16 |
17 AutomationUtilE2ETest.prototype = { | 17 AutomationUtilE2ETest.prototype = { |
18 __proto__: ChromeVoxNextE2ETest.prototype, | 18 __proto__: ChromeVoxNextE2ETest.prototype, |
19 | 19 |
20 /** @override */ | 20 /** @override */ |
21 setUp: function() { | 21 setUp: function() { |
22 window.Dir = AutomationUtil.Dir; | 22 window.Dir = AutomationUtil.Dir; |
23 }, | 23 }, |
24 | 24 |
25 basicDoc: function() {/*! | 25 basicDoc: function() {/*! |
26 <p><a href='#'></a>hello</p> | 26 <p><a href='#'></a>hello</p> |
27 <h1><ul><li>a</ul><button></h1> | 27 <h1><ul><li>a</ul><button></h1> |
28 */}, | |
29 | |
30 secondDoc: function() {/*! | |
31 <html> | |
32 <head><title>Second doc</title></head> | |
33 <body><div>Second</div></body> | |
34 </html> | |
35 */}, | |
36 | |
37 iframeDoc: function() {/*! | |
38 <html> | |
39 <head><title>Second doc</title></head> | |
40 <body> | |
41 <iframe src="data:text/html,<p>Inside</p>"></iframe> | |
42 </body> | |
43 </html> | |
28 */} | 44 */} |
29 }; | 45 }; |
30 | 46 |
31 TEST_F('AutomationUtilE2ETest', 'GetAncestors', function() { | 47 TEST_F('AutomationUtilE2ETest', 'GetAncestors', function() { |
32 this.runWithLoadedTree(this.basicDoc, function(root) { | 48 this.runWithLoadedTree(this.basicDoc, function(root) { |
33 var expectedLength = 1; | 49 var expectedLength = 1; |
34 while (root) { | 50 while (root) { |
35 var ancestors = AutomationUtil.getAncestors(root); | 51 var ancestors = AutomationUtil.getAncestors(root); |
36 assertEquals(expectedLength++, ancestors.length); | 52 assertEquals(expectedLength++, ancestors.length); |
37 root = root.firstChild; | 53 root = root.firstChild; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 | 106 |
91 // Ancestor. | 107 // Ancestor. |
92 left = left.firstChild; | 108 left = left.firstChild; |
93 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right)); | 109 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right)); |
94 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(right, left)); | 110 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(right, left)); |
95 | 111 |
96 // Ordered. | 112 // Ordered. |
97 right = right.lastChild; | 113 right = right.lastChild; |
98 assertEquals(Dir.BACKWARD, AutomationUtil.getDirection(right, left)); | 114 assertEquals(Dir.BACKWARD, AutomationUtil.getDirection(right, left)); |
99 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right)); | 115 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right)); |
100 | |
101 }); | 116 }); |
102 }); | 117 }); |
118 | |
119 TEST_F('AutomationUtilE2ETest', 'IsInSameWebpage', function() { | |
120 this.runWithLoadedTree(this.basicDoc, function(root) { | |
121 this.runWithLoadedTree(this.secondDoc, function(root2) { | |
122 chrome.automation.getDesktop(this.newCallback(function(desktop) { | |
123 assertTrue(AutomationUtil.isInSameWebpage(root, root)); | |
124 assertTrue(AutomationUtil.isInSameWebpage(root.firstChild, root)); | |
125 assertTrue(AutomationUtil.isInSameWebpage(root, root.firstChild)); | |
126 | |
127 assertTrue(AutomationUtil.isInSameWebpage(root2, root2)); | |
128 assertTrue(AutomationUtil.isInSameWebpage(root2.firstChild, root2)); | |
129 assertTrue(AutomationUtil.isInSameWebpage(root2, root2.firstChild)); | |
130 | |
131 assertFalse(AutomationUtil.isInSameWebpage(root, root2)); | |
132 assertFalse(AutomationUtil.isInSameWebpage(root.firstChild, root2)); | |
133 assertFalse(AutomationUtil.isInSameWebpage(root2.firstChild)); | |
134 assertFalse(AutomationUtil.isInSameWebpage( | |
135 root.firstChild, root2.firstChild)); | |
136 | |
137 assertFalse(AutomationUtil.isInSameWebpage(root, desktop)); | |
138 assertFalse(AutomationUtil.isInSameWebpage(root2, desktop)); | |
139 }.bind(this))); | |
140 }.bind(this)); | |
141 }.bind(this)); | |
142 }); | |
143 | |
144 TEST_F('AutomationUtilE2ETest', 'IsInSameWebpageIframe', function() { | |
145 // Wait for load complete on both outer frame and iframe. | |
146 var outerFrame; | |
147 var innerframe; | |
Peter Lundblad
2015/12/01 12:49:58
s/innerframe/innerFrame/
dmazzoni
2015/12/01 19:19:01
Done.
| |
148 var desktop; | |
149 var onSuccess = this.newCallback(function() { | |
150 assertTrue(AutomationUtil.isInSameWebpage(outerFrame, innerFrame)); | |
151 assertFalse(AutomationUtil.isInSameWebpage(outerFrame, desktop)); | |
152 assertFalse(AutomationUtil.isInSameWebpage(innerFrame, desktop)); | |
153 assertFalse(AutomationUtil.isInSameWebpage(outerFrame.parent, innerFrame)); | |
154 }.bind(this)); | |
155 | |
156 chrome.automation.getDesktop(function(r) { | |
157 desktop = r; | |
158 this.runWithTab(this.iframeDoc, function(newTabUrl) { | |
159 var listener = function(evt) { | |
160 if (evt.target.docUrl == newTabUrl) | |
161 outerFrame = evt.target; | |
162 if (evt.target.docUrl.indexOf('data:text/html') == 0) | |
163 innerFrame = evt.target; | |
164 | |
165 if (outerFrame && innerFrame) { | |
166 desktop.removeEventListener('loadComplete', listener, true); | |
167 onSuccess(); | |
168 } | |
169 }.bind(this); | |
170 desktop.addEventListener('loadComplete', listener, true); | |
171 }.bind(this)); | |
172 }.bind(this)); | |
173 }); | |
OLD | NEW |