- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / window_update / show_state / test.js
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
3 // found in the LICENSE file.
4
5 var pass = chrome.test.callbackPass;
6
7 var width = 0;
8 var height = 0;
9
10 var deltaWidth = 20;
11 var deltaHeight = 30;
12
13 function checkRestoreAfterFullscreen(theWindow) {
14   chrome.test.assertEq('normal', theWindow.state);
15   chrome.test.assertEq(width, theWindow.width);
16   chrome.test.assertEq(height, theWindow.height);
17   chrome.windows.remove(theWindow.id, pass());
18 }
19
20 function checkFullscreen(theWindow) {
21   if (theWindow.type == 'panel') {
22     // Panels do not support fullscreen.
23     chrome.test.assertEq('normal', theWindow.state);
24   } else {
25     chrome.test.assertEq('fullscreen', theWindow.state);
26   }
27
28   chrome.windows.update(theWindow.id, {'state': 'normal'},
29       pass(checkRestoreAfterFullscreen));
30 }
31
32 function checkRestoreWithBounds(theWindow) {
33   chrome.test.assertEq('normal', theWindow.state);
34   chrome.test.assertEq(width, theWindow.width);
35   chrome.test.assertEq(height, theWindow.height);
36
37   chrome.windows.update(theWindow.id, {'state': 'fullscreen'},
38     pass(checkFullscreen));
39 }
40
41 function checkMaximized(theWindow) {
42   if (theWindow.type == 'panel') {
43     // Maximize is the same as restore for panels.
44     chrome.test.assertEq('normal', theWindow.state);
45     chrome.test.assertEq(width, theWindow.width);
46     chrome.test.assertEq(height, theWindow.height);
47   } else {
48     chrome.test.assertEq('maximized', theWindow.state);
49     chrome.test.assertTrue(width < theWindow.width ||
50                            height < theWindow.height);
51   }
52
53   width += deltaWidth;
54   height += deltaHeight;
55   chrome.windows.update(theWindow.id,
56       {'state': 'normal', 'width': width, 'height': height},
57       pass(checkRestoreWithBounds));
58 }
59
60 function checkRestored(theWindow) {
61   chrome.test.assertEq('normal', theWindow.state);
62   chrome.test.assertEq(width, theWindow.width);
63   chrome.test.assertEq(height, theWindow.height);
64
65   chrome.windows.update(theWindow.id, {'state': 'maximized'}, pass(checkMaximized));
66 }
67
68 function checkMinimized(theWindow) {
69   chrome.test.assertEq('minimized', theWindow.state);
70   chrome.windows.update(theWindow.id, {'state': 'normal'}, pass(checkRestored));
71 }
72
73 function minimizeWindow(theWindow) {
74   chrome.test.assertEq('normal', theWindow.state);
75   width = theWindow.width;
76   height = theWindow.height;
77   chrome.windows.update(theWindow.id, {'state': 'minimized'}, pass(checkMinimized));
78 }
79
80 function testWindowState(windowType) {
81   // Specifying size prevents 'panel' windows from computing size
82   // asynchronously. It ensures panel sizes stay fixed through the test.
83   // Do not use the big size because the maximium panel sizes are based on a
84   // factor of the screen resolution and the try bot might be configured with
85   // 800x600 resolution.
86   chrome.windows.create({ 'url': 'hello.html', 'type': windowType, 'width': 200,
87                           'height': 200 },
88     pass(minimizeWindow));
89 }
90
91 chrome.test.runTests([
92   function changeWindowState() {
93     testWindowState('normal');
94   },
95   function changePopupWindowState() {
96     testWindowState('popup');
97   },
98   function changePanelWindowState() {
99     testWindowState('panel');
100   }
101 ]);