OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 var assertBoundsEqual = function(a, b) { | 7 var assertBoundsEqual = function(a, b) { |
8 chrome.test.assertEq(a.left, b.left, 'left'); | 8 chrome.test.assertEq(a.left, b.left, 'left'); |
9 chrome.test.assertEq(a.top, b.top, 'top'); | 9 chrome.test.assertEq(a.top, b.top, 'top'); |
10 chrome.test.assertEq(a.width, b.width, 'width'); | 10 chrome.test.assertEq(a.width, b.width, 'width'); |
11 chrome.test.assertEq(a.height, b.height, 'height'); | 11 chrome.test.assertEq(a.height, b.height, 'height'); |
12 }; | 12 }; |
13 | 13 |
14 var testRestoreSize = function(id, frameType) { | 14 var testRestoreSize = function(id, frameType) { |
15 chrome.app.window.create('empty.html', | 15 chrome.app.window.create('empty.html', |
16 { id: id, | 16 { id: id, |
17 left: 113, top: 117, width: 314, height: 271, | 17 left: 113, top: 117, width: 314, height: 271, |
18 frame: frameType }, callbackPass(function(win) { | 18 frame: frameType }, callbackPass(function(win) { |
19 var bounds = win.getBounds(); | 19 var bounds = win.getBounds(); |
20 | 20 |
21 assertBoundsEqual({ left:113, top:117, width:314, height:271 }, bounds); | 21 assertBoundsEqual({ left:113, top:117, width:314, height:271 }, bounds); |
22 var newBounds = { left:447, top:440, width:647, height:504 }; | 22 var newBounds = { left:447, top:440, width:647, height:504 }; |
23 win.onBoundsChanged.addListener(callbackPass(boundsChanged)); | 23 win.onBoundsChanged.addListener(callbackPass(boundsChanged)); |
24 win.setBounds(newBounds); | 24 win.setBounds(newBounds); |
25 function boundsChanged() { | 25 function boundsChanged() { |
26 assertBoundsEqual(newBounds, win.getBounds()); | 26 assertBoundsEqual(newBounds, win.getBounds()); |
| 27 win.onClosed.addListener(callbackPass(windowClosed)); |
27 win.close(); | 28 win.close(); |
| 29 } |
| 30 function windowClosed() { |
28 chrome.app.window.create('empty.html', | 31 chrome.app.window.create('empty.html', |
29 { id: id, | 32 { id: id, |
30 left: 113, top: 117, width: 314, height: 271, | 33 left: 113, top: 117, width: 314, height: 271, |
31 frame: frameType }, callbackPass(function(win2) { | 34 frame: frameType }, callbackPass(function(win2) { |
32 assertBoundsEqual(newBounds, win2.getBounds()); | 35 assertBoundsEqual(newBounds, win2.getBounds()); |
33 })); | 36 })); |
34 } | 37 } |
35 })); | 38 })); |
36 } | 39 } |
37 | 40 |
38 chrome.app.runtime.onLaunched.addListener(function() { | 41 chrome.app.runtime.onLaunched.addListener(function() { |
39 chrome.test.runTests([ | 42 chrome.test.runTests([ |
40 function testFramelessRestoreSize() { | 43 function testFramelessRestoreSize() { |
41 testRestoreSize('frameless', 'none'); | 44 testRestoreSize('frameless', 'none'); |
42 }, | 45 }, |
43 function testFramedRestoreSize() { | 46 function testFramedRestoreSize() { |
44 testRestoreSize('framed', 'chrome'); | 47 testRestoreSize('framed', 'chrome'); |
45 }, | 48 }, |
46 ]); | 49 ]); |
47 }); | 50 }); |
OLD | NEW |