1 // Copyright (c) 2011 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 pass = chrome.test.callbackPass;
6 var fail = chrome.test.callbackFail;
7 var assertEq = chrome.test.assertEq;
8 var assertFalse = chrome.test.assertFalse;
9 var assertTrue = chrome.test.assertTrue;
11 function pageUrl(letter) {
12 return chrome.extension.getURL(letter + ".html");
15 // Creates one window with tabs set to the urls in the array |tabUrls|.
16 // At least one url must be specified.
17 // The |callback| should look like function(windowId, tabIds) {...}.
18 function createWindow(tabUrls, winOptions, callback) {
19 winOptions["url"] = tabUrls;
20 chrome.windows.create(winOptions, function(win) {
22 assertTrue(win.id > 0);
23 assertEq(tabUrls.length, win.tabs.length);
25 for (var i = 0; i < win.tabs.length; i++)
26 newTabIds.push(win.tabs[i].id);
28 callback(win.id, newTabIds);
32 // Waits until all tabs (yes, in every window) have status "complete".
33 // This is useful to prevent test overlap when testing tab events.
34 // |callback| should look like function() {...}. Note that |callback| expects
36 function waitForAllTabs(callback) {
37 // Wait for all tabs to load.
38 function waitForTabs(){
39 chrome.windows.getAll({"populate": true}, function(windows) {
41 for (var i in windows){
42 for (var j in windows[i].tabs) {
43 if (windows[i].tabs[j].status != "complete") {
54 window.setTimeout(waitForTabs, 30);