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 // tabs api test: removing windows.
6 // browser_tests.exe --gtest_filter=ExtensionApiTest.TabOnRemoved
8 // We have a bunch of places where we need to remember some state from one
9 // test (or setup code) to subsequent tests.
10 var firstWindowId = null;
11 var secondWindowId = null;
13 var windowEventsWindow = null;
16 var pass = chrome.test.callbackPass;
17 var assertEq = chrome.test.assertEq;
18 var assertTrue = chrome.test.assertTrue;
20 function pageUrl(letter) {
21 return chrome.extension.getURL(letter + ".html");
24 chrome.test.runTests([
25 // Open some pages, so that we can try to close them.
26 function setupLetterPages() {
27 var pages = ["chrome://newtab/", pageUrl('a'), pageUrl('b'),
28 pageUrl('c'), pageUrl('d'), pageUrl('e')];
29 setupWindow(pages, pass(function(winId, tabIds) {
30 firstWindowId = winId;
31 moveTabIds['a'] = tabIds[1];
32 moveTabIds['b'] = tabIds[2];
33 moveTabIds['c'] = tabIds[3];
34 moveTabIds['d'] = tabIds[4];
35 moveTabIds['e'] = tabIds[5];
36 createWindow(["chrome://newtab/"], {}, pass(function(winId, tabIds) {
37 secondWindowId = winId;
39 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
40 assertEq(pages.length, tabs.length);
42 assertEq(pages[i], tabs[i].url);
48 function tabsOnRemoved() {
49 chrome.test.listenOnce(chrome.tabs.onRemoved,
50 function(tabid, removeInfo) {
51 assertEq(moveTabIds['c'], tabid);
52 assertEq(firstWindowId, removeInfo.windowId);
53 assertEq(false, removeInfo.isWindowClosing);
56 chrome.tabs.remove(moveTabIds['c'], pass());
59 function windowsOnCreated() {
60 chrome.test.listenOnce(chrome.windows.onCreated, function(window) {
61 windowEventsWindow = window;
62 chrome.tabs.getAllInWindow(window.id, pass(function(tabs) {
63 assertEq(pageUrl("a"), tabs[0].url);
67 chrome.windows.create({"url": pageUrl("a")}, pass(function(tab) {}));
70 function windowsOnRemoved() {
71 chrome.test.listenOnce(chrome.windows.onRemoved, function(windowId) {
72 assertEq(windowEventsWindow.id, windowId);
75 chrome.test.listenOnce(chrome.tabs.onRemoved,
76 function(tabId, removeInfo) {
77 assertEq(windowEventsWindow.id, removeInfo.windowId);
78 assertEq(true, removeInfo.isWindowClosing);
81 chrome.windows.remove(windowEventsWindow.id, pass());