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.
5 var current = chrome.app.window.current();
7 var nextTestNumber = 1;
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;
19 bg.eventCallback = null;
21 chrome.test.succeed();
24 waitForBackgroundPageToSeeEvent();
26 current[eventName].addListener(listener);
29 // For anonymous functions, setting 'generatedName' controls what shows up in
30 // the apitest framework's logging output.
31 test.generatedName = "Test" + nextTestNumber++ + "_" + eventName;
38 makeEventTest('onMinimized', function() { current.minimize(); }),
39 makeEventTest('onMaximized', function() { current.maximize(); }),
40 makeEventTest('onRestored', function() {
44 makeEventTest('onRestored', function() {
48 makeEventTest('onBoundsChanged', function() {
49 current.outerBounds.setPosition(5, 5);
51 makeEventTest('onBoundsChanged', function() {
52 current.outerBounds.setSize(150, 150);
54 makeEventTest('onBoundsChanged', function() {
55 current.innerBounds.setPosition(40, 40);
57 makeEventTest('onBoundsChanged', function() {
58 current.innerBounds.setSize(100, 100);
63 chrome.runtime.getBackgroundPage(function(page) {
65 chrome.test.runTests(tests);