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 var html = '<button>alpha</button><input type="text">hello</input>'; |
| 6 |
5 function getAllWebViews() { | 7 function getAllWebViews() { |
6 function findAllWebViews(node, nodes) { | 8 function findAllWebViews(node, nodes) { |
7 if (node.role == chrome.automation.RoleType.webView) | 9 if (node.role == chrome.automation.RoleType.webView) |
8 nodes.push(node); | 10 nodes.push(node); |
9 | 11 |
10 var children = node.children; | 12 var children = node.children; |
11 for (var i = 0; i < children.length; i++) { | 13 for (var i = 0; i < children.length; i++) { |
12 var child = findAllWebViews(children[i], nodes); | 14 var child = findAllWebViews(children[i], nodes); |
13 } | 15 } |
14 } | 16 } |
15 | 17 |
16 var webViews = []; | 18 var webViews = []; |
17 findAllWebViews(rootNode, webViews); | 19 findAllWebViews(rootNode, webViews); |
18 return webViews; | 20 return webViews; |
19 }; | 21 } |
20 | 22 |
21 var allTests = [ | 23 var allTests = [ |
22 function testLoadTabs() { | 24 function testLoadTabs() { |
23 var webViews = getAllWebViews(); | 25 runWithDocument(html, function() { |
24 assertEq(2, webViews.length); | 26 var webViews = getAllWebViews(); |
25 var subroot = webViews[1].firstChild; | 27 assertEq(2, webViews.length); |
26 assertEq(webViews[1], subroot.parent); | 28 var subroot = webViews[1].firstChild; |
27 assertEq(subroot, subroot.parent.children[0]); | 29 assertEq(webViews[1], subroot.parent); |
28 var button = subroot.firstChild.firstChild; | 30 assertEq(subroot, subroot.parent.children[0]); |
29 assertEq(chrome.automation.RoleType.button, button.role); | 31 var button = subroot.firstChild.firstChild; |
30 var input = subroot.firstChild.lastChild.previousSibling; | 32 assertEq(chrome.automation.RoleType.button, button.role); |
31 assertEq(chrome.automation.RoleType.textField, input.role); | 33 var input = subroot.firstChild.lastChild.previousSibling; |
32 chrome.test.succeed(); | 34 assertEq(chrome.automation.RoleType.textField, input.role); |
| 35 chrome.test.succeed(); |
| 36 }); |
33 }, | 37 }, |
34 | 38 |
35 function testSubevents() { | 39 function testSubevents() { |
36 var button = null; | 40 runWithDocument(html, function(subroot) { |
37 var webViews = getAllWebViews(); | 41 var button = null; |
38 var subroot = webViews[1].firstChild; | |
39 | 42 |
40 rootNode.addEventListener(chrome.automation.EventType.focus, | 43 rootNode.addEventListener(chrome.automation.EventType.focus, |
41 function(evt) { | 44 function(evt) { |
42 assertEq(button, evt.target); | 45 assertEq(button, evt.target); |
43 chrome.test.succeed(); | 46 chrome.test.succeed(); |
44 }, | 47 }, |
45 false); | 48 false); |
46 | 49 |
47 button = subroot.firstChild.firstChild; | 50 button = subroot.firstChild.firstChild; |
48 button.focus(); | 51 button.focus(); |
| 52 }); |
49 } | 53 } |
50 ]; | 54 ]; |
51 | 55 |
52 setupAndRunTests(allTests, | 56 setUpAndRunTests(allTests); |
53 '<button>alpha</button><input type="text">hello</input>'); | |
OLD | NEW |