1 // Copyright 2013 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 var callbackPass = chrome.test.callbackPass;
7 function testWindowGetsFocus(win) {
8 // If the window is already focused, we are done.
9 if (win.contentWindow.document.hasFocus()) {
10 chrome.test.assertTrue(win.contentWindow.document.hasFocus(),
11 "window has been focused");
16 // Otherwise, we wait for the focus event.
17 win.contentWindow.onfocus = callbackPass(function() {
18 chrome.test.assertTrue(win.contentWindow.document.hasFocus(),
19 "window has been focused");
24 function testWindowNeverGetsFocus(win) {
25 win.contentWindow.onfocus = function() {
26 chrome.test.assertFalse(win.contentWindow.document.hasFocus(),
27 "window should not be focused");
31 if (win.contentWindow.document.hasFocus()) {
32 chrome.test.assertFalse(win.contentWindow.document.hasFocus(),
33 "window should not be focused");
38 if (win.contentWindow.document.readyState == 'complete') {
39 chrome.test.assertFalse(win.contentWindow.document.hasFocus(),
40 "window should not be focused");
45 win.contentWindow.onload = callbackPass(function() {
46 chrome.test.assertFalse(win.contentWindow.document.hasFocus(),
47 "window should not be focused");
52 function testCreate() {
53 chrome.test.runTests([
54 function createUnfocusedWindow() {
55 chrome.app.window.create('test.html', {
56 innerBounds: { width: 200, height: 200 },
58 }, callbackPass(testWindowNeverGetsFocus));
60 function createTwiceUnfocused() {
61 chrome.app.window.create('test.html', {
62 id: 'createTwiceUnfocused', focused: false,
63 innerBounds: { width: 200, height: 200 }
64 }, callbackPass(function(win) {
65 win.contentWindow.onload = callbackPass(function() {
66 chrome.app.window.create('test.html', {
67 id: 'createTwiceUnfocused', focused: false,
68 innerBounds: { width: 200, height: 200 }
69 }, callbackPass(testWindowNeverGetsFocus));
73 function createFocusedWindow() {
74 chrome.app.window.create('test.html', {
75 innerBounds: { width: 200, height: 200 },
77 }, callbackPass(testWindowGetsFocus));
79 function createDefaultFocusStateWindow() {
80 chrome.app.window.create('test.html', {
81 innerBounds: { width: 200, height: 200 },
82 }, callbackPass(testWindowGetsFocus));
84 function createTwiceFocusUnfocus() {
85 chrome.app.window.create('test.html', {
86 id: 'createTwiceFocusUnfocus', focused: true,
87 innerBounds: { width: 200, height: 200 }
88 }, callbackPass(function(win) {
89 win.contentWindow.onload = callbackPass(function() {
90 chrome.app.window.create('test.html', {
91 id: 'createTwiceFocusUnfocus', focused: false,
92 innerBounds: { width: 200, height: 200 }
93 }, callbackPass(testWindowGetsFocus));
97 function createTwiceUnfocusFocus() {
98 chrome.app.window.create('test.html', {
99 id: 'createTwiceUnfocusFocus', focused: false,
100 innerBounds: { width: 200, height: 200 }
101 }, callbackPass(function(win) {
102 win.contentWindow.onload = callbackPass(function() {
103 chrome.app.window.create('test.html', {
104 id: 'createTwiceUnfocusFocus', focused: true,
105 innerBounds: { width: 200, height: 200 }
106 }, callbackPass(function() {
107 // This test fails on Linux GTK, see http://crbug.com/325219
108 // And none of those tests run on Linux Aura, see
109 // http://crbug.com/325142
110 // We remove this and disable the entire test for Linux GTK when the
111 // test will run on other platforms, see http://crbug.com/328829
112 if (navigator.platform.indexOf('Linux') != 0)
113 testWindowGetsFocus(win);
121 function testShow() {
122 chrome.test.runTests([
123 function createUnfocusThenShow() {
124 chrome.app.window.create('test.html', {
125 id: 'createUnfocusThenShow', focused: false,
126 innerBounds: { width: 200, height: 200 }
127 }, callbackPass(function(win) {
128 win.contentWindow.onload = callbackPass(function() {
130 // This test fails on Linux GTK, see http://crbug.com/325219
131 // And none of those tests run on Linux Aura, see
132 // http://crbug.com/325142
133 // We remove this and disable the entire test for Linux GTK when the
134 // test will run on other platforms, see http://crbug.com/328829
135 if (navigator.platform.indexOf('Linux') != 0)
136 testWindowGetsFocus(win);
140 function createUnfocusThenShowUnfocused() {
141 chrome.app.window.create('test.html', {
142 id: 'createUnfocusThenShowUnfocused', focused: false,
143 innerBounds: { width: 200, height: 200 }
144 }, callbackPass(function(win) {
145 win.contentWindow.onload = callbackPass(function() {
147 testWindowNeverGetsFocus(win);
151 function createUnfocusThenShowFocusedThenShowUnfocused() {
152 chrome.app.window.create('test.html', {
153 id: 'createUnfocusThenShowFocusedThenShowUnfocused', focused: false,
154 innerBounds: { width: 200, height: 200 }
155 }, callbackPass(function(win) {
156 win.contentWindow.onload = callbackPass(function() {
159 // This test fails on Linux GTK, see http://crbug.com/325219
160 // And none of those tests run on Linux Aura, see
161 // http://crbug.com/325142
162 // We remove this and disable the entire test for Linux GTK when the
163 // test will run on other platforms, see http://crbug.com/328829
164 if (navigator.platform.indexOf('Linux') != 0)
165 testWindowGetsFocus(win);
172 chrome.app.runtime.onLaunched.addListener(function() {
173 chrome.test.sendMessage('Launched', function(reply) {