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