OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 var callbackPass = chrome.test.callbackPass; | 5 var callbackPass = chrome.test.callbackPass; |
6 | 6 |
7 function testWindowGetsFocus(win) { | 7 function testWindowGetsFocus(win) { |
8 // If the window is already focused, we are done. | 8 // If the window is already focused, we are done. |
9 if (win.contentWindow.document.hasFocus()) { | 9 if (win.contentWindow.document.hasFocus()) { |
10 chrome.test.assertTrue(win.contentWindow.document.hasFocus(), | 10 chrome.test.assertTrue(win.contentWindow.document.hasFocus(), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 return; | 42 return; |
43 } | 43 } |
44 | 44 |
45 win.contentWindow.onload = callbackPass(function() { | 45 win.contentWindow.onload = callbackPass(function() { |
46 chrome.test.assertFalse(win.contentWindow.document.hasFocus(), | 46 chrome.test.assertFalse(win.contentWindow.document.hasFocus(), |
47 "window should not be focused"); | 47 "window should not be focused"); |
48 win.close(); | 48 win.close(); |
49 }); | 49 }); |
50 } | 50 } |
51 | 51 |
| 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 }; |
| 64 |
| 65 function assertInnerBounds(win) { |
| 66 chrome.test.assertEq(300, win.contentWindow.innerWidth); |
| 67 chrome.test.assertEq(301, win.contentWindow.innerHeight); |
| 68 |
| 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 } |
| 76 |
| 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 ]); |
| 102 } |
| 103 |
52 function testCreate() { | 104 function testCreate() { |
53 chrome.test.runTests([ | 105 chrome.test.runTests([ |
54 function createUnfocusedWindow() { | 106 function createUnfocusedWindow() { |
55 chrome.app.window.create('test.html', { | 107 chrome.app.window.create('test.html', { |
56 innerBounds: { width: 200, height: 200 }, | 108 innerBounds: { width: 200, height: 200 }, |
57 focused: false | 109 focused: false |
58 }, callbackPass(testWindowNeverGetsFocus)); | 110 }, callbackPass(testWindowNeverGetsFocus)); |
59 }, | 111 }, |
60 function createTwiceUnfocused() { | 112 function createTwiceUnfocused() { |
61 chrome.app.window.create('test.html', { | 113 chrome.app.window.create('test.html', { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 })); | 219 })); |
168 }, | 220 }, |
169 ]); | 221 ]); |
170 } | 222 } |
171 | 223 |
172 chrome.app.runtime.onLaunched.addListener(function() { | 224 chrome.app.runtime.onLaunched.addListener(function() { |
173 chrome.test.sendMessage('Launched', function(reply) { | 225 chrome.test.sendMessage('Launched', function(reply) { |
174 window[reply](); | 226 window[reply](); |
175 }); | 227 }); |
176 }); | 228 }); |
OLD | NEW |