| OLD | NEW |
| 1 <!-- |
| 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
| 3 * source code is governed by a BSD-style license that can be found in the |
| 4 * LICENSE file. |
| 5 --> |
| 1 <script src="tabs_util.js"></script> | 6 <script src="tabs_util.js"></script> |
| 2 | 7 <script src="events.js"></script> |
| 3 <script> | |
| 4 var testTabId; | |
| 5 var otherTabId; | |
| 6 var firstWindowId; | |
| 7 var secondWindowId; | |
| 8 | |
| 9 chrome.test.runTests([ | |
| 10 function init() { | |
| 11 chrome.tabs.getSelected(null, pass(function(tab) { | |
| 12 testTabId = tab.id; | |
| 13 firstWindowId = tab.windowId; | |
| 14 })); | |
| 15 }, | |
| 16 | |
| 17 function tabsOnCreated() { | |
| 18 chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) { | |
| 19 assertEq(pageUrl("f"), tab.url); | |
| 20 otherTabId = tab.id; | |
| 21 assertEq(true, tab.selected); | |
| 22 }); | |
| 23 | |
| 24 chrome.tabs.create({"windowId": firstWindowId, "url": pageUrl("f"), | |
| 25 "selected": true}, pass(function(tab) {})); | |
| 26 }, | |
| 27 | |
| 28 function tabsOnUpdatedIgnoreTabArg() { | |
| 29 // A third argument was added to the onUpdated event callback. | |
| 30 // Test that an event handler which ignores this argument works. | |
| 31 var onUpdatedCompleted = chrome.test.listenForever(chrome.tabs.onUpdated, | |
| 32 function(tabid, changeInfo) { | |
| 33 if (tabid == otherTabId && changeInfo.status == "complete") { | |
| 34 onUpdatedCompleted(); | |
| 35 } | |
| 36 } | |
| 37 ); | |
| 38 | |
| 39 chrome.tabs.update(otherTabId, {"url": pageUrl("f")}, pass()); | |
| 40 }, | |
| 41 | |
| 42 function tabsOnUpdated() { | |
| 43 var onUpdatedCompleted = chrome.test.listenForever( | |
| 44 chrome.tabs.onUpdated, | |
| 45 function(tabid, changeInfo, tab) { | |
| 46 // |tab| contains the id of the tab it describes. | |
| 47 // Test that |tabid| matches this id. | |
| 48 assertEq(tabid, tab.id); | |
| 49 | |
| 50 // If |changeInfo| has a status property, than | |
| 51 // it should match the status of the tab in |tab|. | |
| 52 if (changeInfo.status) { | |
| 53 assertEq(changeInfo.status, tab.status); | |
| 54 } | |
| 55 | |
| 56 if (tabid == otherTabId && changeInfo.status == "complete") { | |
| 57 onUpdatedCompleted(); | |
| 58 } | |
| 59 } | |
| 60 ); | |
| 61 | |
| 62 chrome.tabs.update(otherTabId, {"url": pageUrl("f")}, pass()); | |
| 63 }, | |
| 64 | |
| 65 function tabsOnMoved() { | |
| 66 chrome.test.listenOnce(chrome.tabs.onMoved, function(tabid, info) { | |
| 67 assertEq(otherTabId, tabid); | |
| 68 }); | |
| 69 | |
| 70 chrome.tabs.move(otherTabId, {"index": 0}, pass()); | |
| 71 }, | |
| 72 | |
| 73 function tabsOnSelectionChanged() { | |
| 74 chrome.test.listenOnce(chrome.tabs.onSelectionChanged, | |
| 75 function(tabid, info) { | |
| 76 assertEq(testTabId, tabid); | |
| 77 } | |
| 78 ); | |
| 79 | |
| 80 chrome.tabs.update(testTabId, {"selected": true}, pass()); | |
| 81 }, | |
| 82 | |
| 83 function setupTabsOnAttachDetach() { | |
| 84 createWindow([""], {}, pass(function(winId, tabIds) { | |
| 85 secondWindowId = winId; | |
| 86 })); | |
| 87 }, | |
| 88 | |
| 89 function tabsOnAttached() { | |
| 90 function moveAndListen(tabId, properties, callback) { | |
| 91 chrome.test.listenOnce(chrome.tabs.onAttached, | |
| 92 function(testTabId, info) { | |
| 93 // Ensure notification is correct. | |
| 94 assertEq(testTabId, tabId); | |
| 95 assertEq(properties.windowId, info.newWindowId); | |
| 96 assertEq(properties.index, info.newPosition); | |
| 97 if (callback) | |
| 98 callback(); | |
| 99 }); | |
| 100 chrome.tabs.move(tabId, properties); | |
| 101 }; | |
| 102 | |
| 103 // Move tab to second window, then back to first. | |
| 104 // The original tab/window configuration should be restored. | |
| 105 // tabsOnDetached() depends on it. | |
| 106 moveAndListen(testTabId, {"windowId": secondWindowId, "index": 0}, | |
| 107 pass(function() { | |
| 108 moveAndListen(testTabId, {"windowId": firstWindowId, "index": 1}); | |
| 109 })); | |
| 110 }, | |
| 111 | |
| 112 function tabsOnDetached() { | |
| 113 function moveAndListen(tabId, oldWindowId, oldIndex, properties, | |
| 114 callback) { | |
| 115 chrome.test.listenOnce(chrome.tabs.onDetached, | |
| 116 function(detachedTabId, info) { | |
| 117 // Ensure notification is correct. | |
| 118 assertEq(detachedTabId, tabId); | |
| 119 assertEq(oldWindowId, info.oldWindowId); | |
| 120 assertEq(oldIndex, info.oldPosition); | |
| 121 if (callback) | |
| 122 callback(); | |
| 123 }); | |
| 124 chrome.tabs.move(tabId, properties); | |
| 125 }; | |
| 126 | |
| 127 // Move tab to second window, then back to first. | |
| 128 moveAndListen(testTabId, firstWindowId, 1, | |
| 129 {"windowId": secondWindowId, "index": 0}, pass(function() { | |
| 130 moveAndListen(testTabId, secondWindowId, 0, | |
| 131 {"windowId": firstWindowId, "index": 1}); | |
| 132 })); | |
| 133 }, | |
| 134 | |
| 135 function windowsOnCreated() { | |
| 136 chrome.test.listenOnce(chrome.windows.onCreated, function(window) { | |
| 137 assertTrue(window.width > 0); | |
| 138 assertTrue(window.height > 0); | |
| 139 assertEq("normal", window.type); | |
| 140 assertTrue(!window.incognito); | |
| 141 windowEventsWindow = window; | |
| 142 chrome.tabs.getAllInWindow(window.id, pass(function(tabs) { | |
| 143 assertEq(pageUrl("a"), tabs[0].url); | |
| 144 })); | |
| 145 }); | |
| 146 | |
| 147 chrome.windows.create({"url": pageUrl("a")}, pass(function(tab) {})); | |
| 148 }, | |
| 149 | |
| 150 /* | |
| 151 This test doesn't work on mac because the Chromium app never gets | |
| 152 brought to the front. See: crbug.com/60963. | |
| 153 It also doesn't work on Chrome OS for unknown reasons. | |
| 154 It also times out on the full XP builder for unknown reasons. | |
| 155 See: crbug.com/61035. | |
| 156 | |
| 157 function windowsOnFocusChanged() { | |
| 158 chrome.windows.getCurrent(pass(function(windowA) { | |
| 159 chrome.windows.create({}, pass(function(windowB) { | |
| 160 chrome.windows.update(windowA.id, {focused: true}, pass(function() { | |
| 161 chrome.windows.update(windowB.id, {focused: true}, pass(function() { | |
| 162 chrome.test.listenOnce(chrome.windows.onFocusChanged, | |
| 163 function(changedWindowId) { | |
| 164 assertEq(windowEventsWindow.id, changedWindowId); | |
| 165 }); | |
| 166 chrome.windows.remove(windowB.id); | |
| 167 })); | |
| 168 })); | |
| 169 })); | |
| 170 })); | |
| 171 } | |
| 172 */ | |
| 173 ]); | |
| 174 </script> | |
| OLD | NEW |