1 // Utility functions to help with tabs/windows testing.
3 // Removes current windows and creates one window with tabs set to
4 // the urls in the array |tabUrls|. At least one url must be specified.
5 // The |callback| should look like function(windowId, tabIds) {...}.
6 function setupWindow(tabUrls
, callback
) {
7 createWindow(tabUrls
, {}, function(winId
, tabIds
) {
8 // Remove all other windows.
10 chrome
.windows
.getAll({}, function(windows
) {
11 for (var i
in windows
) {
12 if (windows
[i
].id
!= winId
) {
13 chrome
.windows
.remove(windows
[i
].id
, function() {
15 if (removedCount
== windows
.length
- 1)
16 callback(winId
, tabIds
);
20 if (windows
.length
== 1)
21 callback(winId
, tabIds
);
26 // Creates one window with tabs set to the urls in the array |tabUrls|.
27 // At least one url must be specified.
28 // The |callback| should look like function(windowId, tabIds) {...}.
29 function createWindow(tabUrls
, winOptions
, callback
) {
30 winOptions
["url"] = tabUrls
;
31 chrome
.windows
.create(winOptions
, function(win
) {
33 assertTrue(win
.id
> 0);
34 assertEq(tabUrls
.length
, win
.tabs
.length
);
36 for (var i
= 0; i
< win
.tabs
.length
; i
++)
37 newTabIds
.push(win
.tabs
[i
].id
);
39 callback(win
.id
, newTabIds
);
43 // Waits until all tabs (yes, in every window) have status "complete".
44 // This is useful to prevent test overlap when testing tab events.
45 // |callback| should look like function() {...}. Note that |callback| expects
47 function waitForAllTabs(callback
) {
48 // Wait for all tabs to load.
49 function waitForTabs(){
50 chrome
.windows
.getAll({"populate": true}, function(windows
) {
52 for (var i
in windows
){
53 for (var j
in windows
[i
].tabs
) {
54 if (windows
[i
].tabs
[j
].status
!= "complete") {
65 window
.setTimeout(waitForTabs
, 30);