1 // Copyright 2013 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 function compareId(a, b) {
9 chrome.app.runtime.onLaunched.addListener(function() {
10 chrome.test.runTests([
12 function testGetAllNoWindows() {
13 chrome.test.assertEq({}, chrome.app.window.getAll());
14 chrome.test.succeed();
17 function testGetAllOneWindow() {
18 chrome.app.window.create('index.html', {id: 'win1'}, function(win) {
19 win.contentWindow.addEventListener('load', function() {
20 chrome.test.assertEq([win], chrome.app.window.getAll());
21 win.onClosed.addListener(function() {
22 chrome.test.succeed();
29 function testGetAllMultipleWindows() {
30 chrome.app.window.create('index.html', {id: 'win1'}, function(win1) {
31 win1.contentWindow.addEventListener('load', function() {
32 chrome.app.window.create('index.html', {id: 'win2'}, function(win2) {
33 win2.contentWindow.addEventListener('load', function() {
34 var windows = chrome.app.window.getAll().sort(compareId);
35 chrome.test.assertEq([win1, win2], windows);
36 win2.onClosed.addListener(function() {
37 chrome.test.succeed();
39 win1.onClosed.addListener(function() {
49 function testGetNoWindows() {
50 chrome.test.assertEq(null, chrome.app.window.get(''));
51 chrome.test.succeed();
55 chrome.app.window.create('index.html', {id: 'win1'}, function(win1) {
56 win1.contentWindow.addEventListener('load', function() {
57 chrome.app.window.create('index.html', {id: 'win2'}, function(win2) {
58 win2.contentWindow.addEventListener('load', function() {
59 chrome.test.assertEq(win1, chrome.app.window.get('win1'));
60 chrome.test.assertEq(win2, chrome.app.window.get('win2'));
61 chrome.test.assertEq(null, chrome.app.window.get('win3'));
62 win2.onClosed.addListener(function() {
63 chrome.test.succeed();
65 win1.onClosed.addListener(function() {