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 // Utility functions to help with tabs/windows testing.
7 // Removes current windows and creates one window with tabs set to
8 // the urls in the array |tabUrls|. At least one url must be specified.
9 // The |callback| should look like function(windowId, tabIds) {...}.
10 function setupWindow(tabUrls
, callback
) {
11 createWindow(tabUrls
, {}, function(winId
, tabIds
) {
12 // Remove all other windows.
14 chrome
.windows
.getAll({}, function(windows
) {
15 for (var i
in windows
) {
16 if (windows
[i
].id
!= winId
) {
17 chrome
.windows
.remove(windows
[i
].id
, function() {
19 if (removedCount
== windows
.length
- 1)
20 callback(winId
, tabIds
);
24 if (windows
.length
== 1)
25 callback(winId
, tabIds
);
30 // Creates one window with tabs set to the urls in the array |tabUrls|.
31 // At least one url must be specified.
32 // The |callback| should look like function(windowId, tabIds) {...}.
33 function createWindow(tabUrls
, winOptions
, callback
) {
34 winOptions
["url"] = tabUrls
;
35 chrome
.windows
.create(winOptions
, function(win
) {
37 assertTrue(win
.id
> 0);
38 assertEq(tabUrls
.length
, win
.tabs
.length
);
40 for (var i
= 0; i
< win
.tabs
.length
; i
++)
41 newTabIds
.push(win
.tabs
[i
].id
);
43 callback(win
.id
, newTabIds
);
47 // Waits until all tabs (yes, in every window) have status "complete".
48 // This is useful to prevent test overlap when testing tab events.
49 // |callback| should look like function() {...}. Note that |callback| expects
51 function waitForAllTabs(callback
) {
52 // Wait for all tabs to load.
53 function waitForTabs(){
54 chrome
.windows
.getAll({"populate": true}, function(windows
) {
56 for (var i
in windows
){
57 for (var j
in windows
[i
].tabs
) {
58 if (windows
[i
].tabs
[j
].status
!= "complete") {
69 window
.setTimeout(waitForTabs
, 30);