Do not announce robot account token before account ID is available
[chromium-blink-merge.git] / chrome / test / data / extensions / platform_apps / window_api_interactive / test.js
blobab02b4d5928e202fdd076bd94c83f66ae6231bc0
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");
12     win.close();
13     return;
14   }
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");
20     win.close();
21   });
24 function testWindowNeverGetsFocus(win) {
25   win.contentWindow.onfocus = function() {
26     chrome.test.assertFalse(win.contentWindow.document.hasFocus(),
27                             "window should not be focused");
28     win.close();
29   };
31   if (win.contentWindow.document.hasFocus()) {
32     chrome.test.assertFalse(win.contentWindow.document.hasFocus(),
33                             "window should not be focused");
34     win.close();
35     return;
36   };
38   if (win.contentWindow.document.readyState == 'complete') {
39     chrome.test.assertFalse(win.contentWindow.document.hasFocus(),
40                             "window should not be focused");
41     win.close();
42     return;
43   }
45   win.contentWindow.onload = callbackPass(function() {
46     chrome.test.assertFalse(win.contentWindow.document.hasFocus(),
47                             "window should not be focused");
48     win.close();
49   });
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() {
56   var innerBounds = {
57     width: 300,
58     height: 301,
59     minWidth: 200,
60     minHeight: 201,
61     maxWidth: 400,
62     maxHeight: 401
63   };
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);
75   }
77   chrome.test.runTests([
78     function createFrameChrome() {
79       chrome.app.window.create('test.html', {
80         innerBounds: innerBounds
81       }, callbackPass(function (win) {
82         assertInnerBounds(win);
83       }));
84     },
85     function createFrameNone() {
86       chrome.app.window.create('test.html', {
87         frame: 'none',
88         innerBounds: innerBounds
89       }, callbackPass(function (win) {
90         assertInnerBounds(win);
91       }));
92     },
93     function createFrameColor() {
94       chrome.app.window.create('test.html', {
95         frame: {color: '#ff0000'},
96         innerBounds: innerBounds
97       }, callbackPass(function (win) {
98         assertInnerBounds(win);
99       }));
100     }
101   ]);
104 function testCreate() {
105   chrome.test.runTests([
106     function createUnfocusedWindow() {
107       chrome.app.window.create('test.html', {
108         innerBounds: { width: 200, height: 200 },
109         focused: false
110       }, callbackPass(testWindowNeverGetsFocus));
111     },
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));
122         });
123       }));
124     },
125     function createFocusedWindow() {
126       chrome.app.window.create('test.html', {
127         innerBounds: { width: 200, height: 200 },
128         focused: true
129       }, callbackPass(testWindowGetsFocus));
130     },
131     function createDefaultFocusStateWindow() {
132       chrome.app.window.create('test.html', {
133         innerBounds: { width: 200, height: 200 },
134       }, callbackPass(testWindowGetsFocus));
135     },
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));
146         });
147       }));
148     },
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);
166           }));
167         });
168       }));
169     },
170   ]);
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() {
181           win.show();
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);
189         });
190       }));
191     },
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() {
198           win.show(false);
199           testWindowNeverGetsFocus(win);
200         });
201       }));
202     },
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() {
209           win.show(true);
210           win.show(false);
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);
218         });
219       }));
220     },
221   ]);
224 function testDrawAttention() {
225   chrome.test.runTests([
226     function drawThenClearAttention() {
227       chrome.app.window.create('test.html', {}, callbackPass(function(win) {
228         win.drawAttention();
229         win.clearAttention();
230       }));
231     }
232   ]);
235 chrome.app.runtime.onLaunched.addListener(function() {
236   chrome.test.sendMessage('Launched', function(reply) {
237     window[reply]();
238   });