Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / window_update / resize / 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 widthDelta = 10;
8 var heightDelta = 20;
9
10 var expectedWidth;
11 var expectedHeight;
12
13 function finishTest(currentWindow) {
14   chrome.test.assertEq(expectedWidth, currentWindow.width);
15   chrome.test.assertEq(expectedHeight, currentWindow.height);
16
17   chrome.windows.remove(currentWindow.id, pass());
18 }
19
20 function changeWidthAndHeight(currentWindow) {
21   chrome.test.assertEq(expectedWidth, currentWindow.width);
22   chrome.test.assertEq(expectedHeight, currentWindow.height);
23
24   expectedWidth = currentWindow.width + widthDelta;
25   expectedHeight = currentWindow.height + heightDelta;
26   chrome.windows.update(
27     currentWindow.id, { 'width': expectedWidth , 'height': expectedHeight},
28     pass(finishTest)
29   );
30 }
31
32 function changeHeight(currentWindow) {
33   chrome.test.assertEq(expectedWidth, currentWindow.width);
34   chrome.test.assertEq(expectedHeight, currentWindow.height);
35
36   expectedWidth = currentWindow.width;
37   expectedHeight = currentWindow.height + heightDelta;
38   chrome.windows.update(
39     currentWindow.id, { 'height': expectedHeight },
40     pass(changeWidthAndHeight)
41   );
42 }
43
44 function changeWidth(currentWindow) {
45   expectedWidth = currentWindow.width + widthDelta;
46   expectedHeight = currentWindow.height;
47   chrome.windows.update(
48     currentWindow.id, { 'width': expectedWidth },
49     pass(changeHeight)
50   );
51 }
52
53 chrome.test.runTests([
54   // Tests windows.update use of the chrome.windows.WINDOW_ID_CURRENT constant.
55   function testCurrentWindowResize() {
56     var newWidth = 400;
57     chrome.windows.create(
58         { 'url': 'blank.html', 'top': 0, 'left': 0, 'width': 500, 'height': 400,
59           'type': 'normal' },
60         pass(function(win1) {
61       chrome.windows.getCurrent(pass(function(win2) {
62         chrome.test.assertEq(win1.id, win2.id);
63         chrome.windows.update(
64             chrome.windows.WINDOW_ID_CURRENT, { 'width': newWidth },
65             pass(function(win3) {
66           chrome.test.assertEq(win2.id, win3.id);
67           chrome.test.assertEq(newWidth, win3.width);
68           chrome.test.assertEq(win2.height, win3.height);
69         }));
70       }));
71     }));
72   },
73
74   function testResizeNormal() {
75     chrome.windows.create(
76         { 'url': 'blank.html', 'top': 0, 'left': 0, 'width': 500, 'height': 500,
77           'type': 'normal' },
78         pass(changeWidth));
79   },
80   function testResizePopup() {
81     chrome.windows.create(
82         { 'url': 'blank.html', 'top': 0, 'left': 0, 'width': 300, 'height': 400,
83           'type': 'popup' },
84         pass(changeWidth));
85   },
86   function testResizePanel() {
87     chrome.windows.create(
88         { 'url': 'blank.html', 'top': 0, 'left': 0, 'width': 150, 'height': 200,
89           'type': 'panel' },
90         pass(changeWidth));
91   },
92 ]);