Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / automation / tests / tabs / events.js
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.
4
5 var allTests = [
6   function testEventListenerTarget() {
7     var cancelButton = tree.root.firstChild().children()[2];
8     assertEq('Cancel', cancelButton.attributes['ax_attr_name']);
9     cancelButton.addEventListener('focus', function onFocusTarget(event) {
10       window.setTimeout(function() {
11         cancelButton.removeEventListener('focus', onFocusTarget);
12         chrome.test.succeed();
13       }, 0);
14     });
15     cancelButton.focus();
16   },
17   function testEventListenerBubble() {
18     var cancelButton = tree.root.firstChild().children()[2];
19     assertEq('Cancel', cancelButton.attributes['ax_attr_name']);
20     var cancelButtonGotEvent = false;
21     cancelButton.addEventListener('focus', function onFocusBubble(event) {
22       cancelButtonGotEvent = true;
23       cancelButton.removeEventListener('focus', onFocusBubble);
24     });
25     tree.root.addEventListener('focus', function onFocusBubbleRoot(event) {
26       assertEq('focus', event.type);
27       assertEq(cancelButton, event.target);
28       assertTrue(cancelButtonGotEvent);
29       tree.root.removeEventListener('focus', onFocusBubbleRoot);
30       chrome.test.succeed();
31     });
32     cancelButton.focus();
33   },
34   function testStopPropagation() {
35     var cancelButton = tree.root.firstChild().children()[2];
36     assertEq('Cancel', cancelButton.attributes['ax_attr_name']);
37     function onFocusStopPropRoot(event) {
38       tree.root.removeEventListener('focus', onFocusStopPropRoot);
39       chrome.test.fail("Focus event was propagated to root");
40     };
41     cancelButton.addEventListener('focus', function onFocusStopProp(event) {
42       cancelButton.removeEventListener('focus', onFocusStopProp);
43       event.stopPropagation();
44       window.setTimeout((function() {
45         tree.root.removeEventListener('focus', onFocusStopPropRoot);
46         chrome.test.succeed();
47       }).bind(this), 0);
48     });
49     tree.root.addEventListener('focus', onFocusStopPropRoot);
50     cancelButton.focus();
51   },
52   function testEventListenerCapture() {
53     var cancelButton = tree.root.firstChild().children()[2];
54     assertEq('Cancel', cancelButton.attributes['ax_attr_name']);
55     var cancelButtonGotEvent = false;
56     function onFocusCapture(event) {
57       cancelButtonGotEvent = true;
58       cancelButton.removeEventListener('focus', onFocusCapture);
59       chrome.test.fail("Focus event was not captured by root");
60     };
61     cancelButton.addEventListener('focus', onFocusCapture);
62     tree.root.addEventListener('focus', function onFocusCaptureRoot(event) {
63       assertEq('focus', event.type);
64       assertEq(cancelButton, event.target);
65       assertFalse(cancelButtonGotEvent);
66       event.stopPropagation();
67       tree.root.removeEventListener('focus', onFocusCaptureRoot);
68       tree.root.removeEventListener('focus', onFocusCapture);
69       window.setTimeout(chrome.test.succeed.bind(this), 0);
70     }, true);
71     cancelButton.focus();
72   }
73 ];
74
75 setUpAndRunTests(allTests)