Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / tabs / connect / tabs_util.js
blob9f13dd9df47a68fbd9f4462d2d49a65819b5e946
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.
9 var removedCount = 0;
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() {
14 removedCount++;
15 if (removedCount == windows.length - 1)
16 callback(winId, tabIds);
17 });
20 if (windows.length == 1)
21 callback(winId, tabIds);
22 });
23 });
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) {
32 var newTabIds = [];
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);
40 });
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
46 // zero arguments.
47 function waitForAllTabs(callback) {
48 // Wait for all tabs to load.
49 function waitForTabs(){
50 chrome.windows.getAll({"populate": true}, function(windows) {
51 var ready = true;
52 for (var i in windows){
53 for (var j in windows[i].tabs) {
54 if (windows[i].tabs[j].status != "complete") {
55 ready = false;
56 break;
59 if (!ready)
60 break;
62 if (ready)
63 callback();
64 else
65 window.setTimeout(waitForTabs, 30);
66 });
68 waitForTabs();