1 // Copyright (c) 2012 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.
10 chrome.test.runTests([
12 chrome.tabs.getSelected(null, pass(function(tab) {
14 firstWindowId = tab.windowId;
18 function tabsOnCreated() {
19 chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) {
20 assertEq(pageUrl("f"), tab.url);
22 assertEq(true, tab.selected);
25 chrome.tabs.create({"windowId": firstWindowId, "url": pageUrl("f"),
26 "selected": true}, pass(function(tab) {}));
29 function tabsOnUpdatedIgnoreTabArg() {
30 // A third argument was added to the onUpdated event callback.
31 // Test that an event handler which ignores this argument works.
32 var onUpdatedCompleted = chrome.test.listenForever(chrome.tabs.onUpdated,
33 function(tabid, changeInfo) {
34 if (tabid == otherTabId && changeInfo.status == "complete") {
40 chrome.tabs.update(otherTabId, {"url": pageUrl("f")}, pass());
43 function tabsOnUpdated() {
44 var onUpdatedCompleted = chrome.test.listenForever(
45 chrome.tabs.onUpdated,
46 function(tabid, changeInfo, tab) {
47 // |tab| contains the id of the tab it describes.
48 // Test that |tabid| matches this id.
49 assertEq(tabid, tab.id);
51 // If |changeInfo| has a status property, than
52 // it should match the status of the tab in |tab|.
53 if (changeInfo.status) {
54 assertEq(changeInfo.status, tab.status);
57 if (tabid == otherTabId && changeInfo.status == "complete") {
63 chrome.tabs.update(otherTabId, {"url": pageUrl("f")}, pass());
66 function tabsOnMoved() {
67 chrome.test.listenOnce(chrome.tabs.onMoved, function(tabid, info) {
68 assertEq(otherTabId, tabid);
71 chrome.tabs.move(otherTabId, {"index": 0}, pass());
74 function tabsOnSelectionChanged() {
75 // Note: tabs.onSelectionChanged is deprecated.
76 chrome.test.listenOnce(chrome.tabs.onSelectionChanged,
77 function(tabid, info) {
78 assertEq(testTabId, tabid);
79 assertEq(firstWindowId, info.windowId);
83 chrome.tabs.update(testTabId, {"selected": true}, pass());
86 function tabsOnActiveChanged() {
87 // Note: tabs.onActiveChanged is deprecated.
88 chrome.test.listenOnce(chrome.tabs.onActiveChanged,
89 function(tabid, info) {
90 assertEq(otherTabId, tabid);
91 assertEq(firstWindowId, info.windowId);
95 chrome.tabs.update(otherTabId, {"active": true}, pass());
98 function tabsOnActivated() {
99 chrome.test.listenOnce(chrome.tabs.onActivated,
101 assertEq(testTabId, info.tabId);
102 assertEq(firstWindowId, info.windowId);
106 chrome.tabs.update(testTabId, {"active": true}, pass());
109 function setupTabsOnAttachDetach() {
110 createWindow([""], {}, pass(function(winId, tabIds) {
111 secondWindowId = winId;
115 function tabsOnAttached() {
116 function moveAndListen(tabId, properties, callback) {
117 chrome.test.listenOnce(chrome.tabs.onAttached,
118 function(testTabId, info) {
119 // Ensure notification is correct.
120 assertEq(testTabId, tabId);
121 assertEq(properties.windowId, info.newWindowId);
122 assertEq(properties.index, info.newPosition);
126 chrome.tabs.move(tabId, properties);
129 // Move tab to second window, then back to first.
130 // The original tab/window configuration should be restored.
131 // tabsOnDetached() depends on it.
132 moveAndListen(testTabId, {"windowId": secondWindowId, "index": 0},
134 moveAndListen(testTabId, {"windowId": firstWindowId, "index": 1});
138 function tabsOnDetached() {
139 function moveAndListen(tabId, oldWindowId, oldIndex, properties,
141 chrome.test.listenOnce(chrome.tabs.onDetached,
142 function(detachedTabId, info) {
143 // Ensure notification is correct.
144 assertEq(detachedTabId, tabId);
145 assertEq(oldWindowId, info.oldWindowId);
146 assertEq(oldIndex, info.oldPosition);
150 chrome.tabs.move(tabId, properties);
153 // Move tab to second window, then back to first.
154 moveAndListen(testTabId, firstWindowId, 1,
155 {"windowId": secondWindowId, "index": 0}, pass(function() {
156 moveAndListen(testTabId, secondWindowId, 0,
157 {"windowId": firstWindowId, "index": 1});
161 function tabsOnZoomChange() {
162 chrome.tabs.setZoom(testTabId, 1, function() {
163 chrome.test.listenOnce(
164 chrome.tabs.onZoomChange,
165 function(zoomChangeInfo) {
166 assertEq(testTabId, zoomChangeInfo.tabId);
167 assertEq(1, zoomChangeInfo.oldZoomFactor);
168 assertEq(3.14159, +zoomChangeInfo.newZoomFactor.toFixed(5));
169 assertEq("automatic", zoomChangeInfo.zoomSettings.mode);
170 assertEq("per-origin", zoomChangeInfo.zoomSettings.scope);
173 chrome.tabs.setZoom(testTabId, 3.14159);
177 function windowsOnCreated() {
178 chrome.test.listenOnce(chrome.windows.onCreated, function(window) {
179 assertTrue(window.width > 0);
180 assertTrue(window.height > 0);
181 assertEq("normal", window.type);
182 assertTrue(!window.incognito);
183 windowEventsWindow = window;
184 chrome.tabs.getAllInWindow(window.id, pass(function(tabs) {
185 assertEq(pageUrl("a"), tabs[0].url);
189 chrome.windows.create({"url": pageUrl("a")}, pass(function(tab) {}));
193 This test doesn't work on mac because the Chromium app never gets
194 brought to the front. See: crbug.com/60963.
195 It also doesn't work on Chrome OS for unknown reasons.
196 It also times out on the full XP builder for unknown reasons.
197 See: crbug.com/61035.
199 function windowsOnFocusChanged() {
200 chrome.windows.getCurrent(pass(function(windowA) {
201 chrome.windows.create({}, pass(function(windowB) {
202 chrome.windows.update(windowA.id, {focused: true}, pass(function() {
203 chrome.windows.update(windowB.id, {focused: true}, pass(function() {
204 chrome.test.listenOnce(chrome.windows.onFocusChanged,
205 function(changedWindowId) {
206 assertEq(windowEventsWindow.id, changedWindowId);
208 chrome.windows.remove(windowB.id);