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 // Test that the window's content size is the same as our inner bounds.
53 // This has to be an interactive test because contentWindow.innerWidth|Height is
54 // sometimes 0 in the browser test due to an unidentified race condition.
55 function testInnerBounds() {
65 function assertInnerBounds(win) {
66 chrome.test.assertEq(300, win.contentWindow.innerWidth);
67 chrome.test.assertEq(301, win.contentWindow.innerHeight);
69 chrome.test.assertEq(300, win.innerBounds.width);
70 chrome.test.assertEq(301, win.innerBounds.height);
71 chrome.test.assertEq(200, win.innerBounds.minWidth);
72 chrome.test.assertEq(201, win.innerBounds.minHeight);
73 chrome.test.assertEq(400, win.innerBounds.maxWidth);
74 chrome.test.assertEq(401, win.innerBounds.maxHeight);
77 chrome.test.runTests([
78 function createFrameChrome() {
79 chrome.app.window.create('test.html', {
80 innerBounds: innerBounds
81 }, callbackPass(function (win) {
82 assertInnerBounds(win);
85 function createFrameNone() {
86 chrome.app.window.create('test.html', {
88 innerBounds: innerBounds
89 }, callbackPass(function (win) {
90 assertInnerBounds(win);
93 function createFrameColor() {
94 chrome.app.window.create('test.html', {
95 frame: {color: '#ff0000'},
96 innerBounds: innerBounds
97 }, callbackPass(function (win) {
98 assertInnerBounds(win);
104 function testCreate() {
105 chrome.test.runTests([
106 function createUnfocusedWindow() {
107 chrome.app.window.create('test.html', {
108 innerBounds: { width: 200, height: 200 },
110 }, callbackPass(testWindowNeverGetsFocus));
112 function createTwiceUnfocused() {
113 chrome.app.window.create('test.html', {
114 id: 'createTwiceUnfocused', focused: false,
115 innerBounds: { width: 200, height: 200 }
116 }, callbackPass(function(win) {
117 win.contentWindow.onload = callbackPass(function() {
118 chrome.app.window.create('test.html', {
119 id: 'createTwiceUnfocused', focused: false,
120 innerBounds: { width: 200, height: 200 }
121 }, callbackPass(testWindowNeverGetsFocus));
125 function createFocusedWindow() {
126 chrome.app.window.create('test.html', {
127 innerBounds: { width: 200, height: 200 },
129 }, callbackPass(testWindowGetsFocus));
131 function createDefaultFocusStateWindow() {
132 chrome.app.window.create('test.html', {
133 innerBounds: { width: 200, height: 200 },
134 }, callbackPass(testWindowGetsFocus));
136 function createTwiceFocusUnfocus() {
137 chrome.app.window.create('test.html', {
138 id: 'createTwiceFocusUnfocus', focused: true,
139 innerBounds: { width: 200, height: 200 }
140 }, callbackPass(function(win) {
141 win.contentWindow.onload = callbackPass(function() {
142 chrome.app.window.create('test.html', {
143 id: 'createTwiceFocusUnfocus', focused: false,
144 innerBounds: { width: 200, height: 200 }
145 }, callbackPass(testWindowGetsFocus));
149 function createTwiceUnfocusFocus() {
150 chrome.app.window.create('test.html', {
151 id: 'createTwiceUnfocusFocus', focused: false,
152 innerBounds: { width: 200, height: 200 }
153 }, callbackPass(function(win) {
154 win.contentWindow.onload = callbackPass(function() {
155 chrome.app.window.create('test.html', {
156 id: 'createTwiceUnfocusFocus', focused: true,
157 innerBounds: { width: 200, height: 200 }
158 }, 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);
173 function testShow() {
174 chrome.test.runTests([
175 function createUnfocusThenShow() {
176 chrome.app.window.create('test.html', {
177 id: 'createUnfocusThenShow', focused: false,
178 innerBounds: { width: 200, height: 200 }
179 }, callbackPass(function(win) {
180 win.contentWindow.onload = callbackPass(function() {
182 // This test fails on Linux GTK, see http://crbug.com/325219
183 // And none of those tests run on Linux Aura, see
184 // http://crbug.com/325142
185 // We remove this and disable the entire test for Linux GTK when the
186 // test will run on other platforms, see http://crbug.com/328829
187 if (navigator.platform.indexOf('Linux') != 0)
188 testWindowGetsFocus(win);
192 function createUnfocusThenShowUnfocused() {
193 chrome.app.window.create('test.html', {
194 id: 'createUnfocusThenShowUnfocused', focused: false,
195 innerBounds: { width: 200, height: 200 }
196 }, callbackPass(function(win) {
197 win.contentWindow.onload = callbackPass(function() {
199 testWindowNeverGetsFocus(win);
203 function createUnfocusThenShowFocusedThenShowUnfocused() {
204 chrome.app.window.create('test.html', {
205 id: 'createUnfocusThenShowFocusedThenShowUnfocused', focused: false,
206 innerBounds: { width: 200, height: 200 }
207 }, callbackPass(function(win) {
208 win.contentWindow.onload = callbackPass(function() {
211 // This test fails on Linux GTK, see http://crbug.com/325219
212 // And none of those tests run on Linux Aura, see
213 // http://crbug.com/325142
214 // We remove this and disable the entire test for Linux GTK when the
215 // test will run on other platforms, see http://crbug.com/328829
216 if (navigator.platform.indexOf('Linux') != 0)
217 testWindowGetsFocus(win);
224 function testDrawAttention() {
225 chrome.test.runTests([
226 function drawThenClearAttention() {
227 chrome.app.window.create('test.html', {}, callbackPass(function(win) {
229 win.clearAttention();
235 chrome.app.runtime.onLaunched.addListener(function() {
236 chrome.test.sendMessage('Launched', function(reply) {