- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / platform_apps / windows_api_properties / main.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 current = chrome.app.window.current();
6 var bg = null;
7 var nextTestNumber = 1;
8
9 function makeEventTest(eventName, startFunction) {
10   var test = function() {
11     bg.clearEventCounts();
12     var listener = function() {
13       current[eventName].removeListener(listener);
14       function waitForBackgroundPageToSeeEvent() {
15         if (!bg.eventCounts[eventName] > 0) {
16           bg.eventCallback = waitForBackgroundPageToSeeEvent;
17         }
18         else {
19           bg.eventCallback = null;
20           current.restore();
21           chrome.test.succeed();
22         }
23       }
24       waitForBackgroundPageToSeeEvent();
25     };
26     current[eventName].addListener(listener);
27     startFunction();
28   };
29   // For anonymous functions, setting 'generatedName' controls what shows up in
30   // the apitest framework's logging output.
31   test.generatedName = "Test" + nextTestNumber++  + "_" + eventName;
32   return test;
33 }
34
35
36 var tests = [
37
38   makeEventTest('onMinimized', function() { current.minimize(); }),
39   makeEventTest('onMaximized', function() { current.maximize(); }),
40   makeEventTest('onRestored', function() {
41     current.minimize();
42     current.restore();
43   }),
44   makeEventTest('onRestored', function() {
45     current.maximize();
46     current.restore();
47   }),
48   makeEventTest('onBoundsChanged', function() {
49     current.setBounds({left:5, top:5, width:100, height:100});
50   })
51
52 ];
53
54 chrome.runtime.getBackgroundPage(function(page) {
55   bg = page;
56   chrome.test.runTests(tests);
57 });