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 |
| 41 var assertState = function(win) { |
| 42 if (win.id == 'normal') { |
| 43 chrome.test.assertFalse(win.isMinimized()); |
| 44 chrome.test.assertFalse(win.isMaximized()); |
| 45 } |
| 46 if (win.id == 'maximized') { |
| 47 chrome.test.assertFalse(win.isMinimized()); |
| 48 chrome.test.assertTrue(win.isMaximized()); |
| 49 } |
| 50 } |
| 51 |
| 52 var testRestoreState = function(state_type) { |
| 53 chrome.app.window.create( |
| 54 'empty.html', |
| 55 { id: state_type, state: state_type }, |
| 56 callbackPass(windowCreated) |
| 57 ); |
| 58 function windowCreated(win) { |
| 59 assertState(win); |
| 60 win.onClosed.addListener(callbackPass(windowClosed)); |
| 61 win.close(); |
| 62 function windowClosed() { |
| 63 chrome.app.window.create( |
| 64 'empty.html', |
| 65 { id: state_type }, |
| 66 function(win2) { assertState(win2); } |
| 67 ); |
| 68 } |
| 69 }; |
| 70 } |
| 71 |
38 chrome.app.runtime.onLaunched.addListener(function() { | 72 chrome.app.runtime.onLaunched.addListener(function() { |
39 chrome.test.runTests([ | 73 chrome.test.runTests([ |
40 function testFramelessRestoreSize() { | 74 function testFramelessRestoreSize() { |
41 testRestoreSize('frameless', 'none'); | 75 testRestoreSize('frameless', 'none'); |
42 }, | 76 }, |
43 function testFramedRestoreSize() { | 77 function testFramedRestoreSize() { |
44 testRestoreSize('framed', 'chrome'); | 78 testRestoreSize('framed', 'chrome'); |
45 }, | 79 }, |
| 80 function testRestoreNormal() { |
| 81 testRestoreState('normal'); |
| 82 }, |
| 83 function testRestoreMaximized() { |
| 84 testRestoreState('maximized'); |
| 85 }, |
| 86 // Minimize and fullscreen behavior are platform dependent. |
46 ]); | 87 ]); |
47 }); | 88 }); |
OLD | NEW |