| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var firstWindowId; | 5 var firstWindowId; |
| 6 var secondWindowId; | 6 var secondWindowId; |
| 7 var moveTabIds = {}; | 7 var moveTabIds = {}; |
| 8 var kChromeUINewTabURL = "chrome://newtab/"; | 8 var kChromeUINewTabURL = "chrome://newtab/"; |
| 9 | 9 |
| 10 chrome.test.runTests([ | 10 chrome.test.runTests([ |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 assertEq(3, tabs.length); | 135 assertEq(3, tabs.length); |
| 136 assertEq(pageUrl("b"), tabs[0].url); | 136 assertEq(pageUrl("b"), tabs[0].url); |
| 137 assertEq(pageUrl("a"), tabs[1].url); | 137 assertEq(pageUrl("a"), tabs[1].url); |
| 138 assertEq(kChromeUINewTabURL, tabs[2].url); | 138 assertEq(kChromeUINewTabURL, tabs[2].url); |
| 139 })); | 139 })); |
| 140 })); | 140 })); |
| 141 }, | 141 }, |
| 142 | 142 |
| 143 // Make sure we don't crash when the index is out of range. | 143 // Make sure we don't crash when the index is out of range. |
| 144 function moveToInvalidTab() { | 144 function moveToInvalidTab() { |
| 145 var error_msg = "Invalid value for argument 2. Property 'index': " + | 145 var jsBindingsError = |
| 146 "Value must not be less than -1."; | 146 'Invalid value for argument 2. Property \'index\': ' + |
| 147 'Value must not be less than -1.'; |
| 148 var nativeBindingsError = |
| 149 'Error in invocation of tabs.move(' + |
| 150 '[integer|array] tabIds, object moveProperties, ' + |
| 151 'optional function callback): Error at parameter \'moveProperties\': ' + |
| 152 'Error at property \'index\': Value must be at least -1.'; |
| 153 var caught = false; |
| 147 try { | 154 try { |
| 148 chrome.tabs.move(moveTabIds['b'], {"index": -2}, function(tab) { | 155 chrome.tabs.move(moveTabIds['b'], {"index": -2}, function(tab) { |
| 149 chrome.test.fail("Moved a tab to an invalid index"); | 156 chrome.test.fail("Moved a tab to an invalid index"); |
| 150 }); | 157 }); |
| 151 } catch (e) { | 158 } catch (e) { |
| 152 assertEq(error_msg, e.message); | 159 assertTrue(e.message == jsBindingsError || |
| 160 e.message == nativeBindingsError, e.message); |
| 161 caught = true; |
| 153 } | 162 } |
| 163 assertTrue(caught); |
| 154 chrome.tabs.move(moveTabIds['b'], {"index": 10000}, pass(function(tabB) { | 164 chrome.tabs.move(moveTabIds['b'], {"index": 10000}, pass(function(tabB) { |
| 155 assertEq(2, tabB.index); | 165 assertEq(2, tabB.index); |
| 156 })); | 166 })); |
| 157 }, | 167 }, |
| 158 | 168 |
| 159 // Check that attempting to move an empty list of tabs doesn't crash browser | 169 // Check that attempting to move an empty list of tabs doesn't crash browser |
| 160 function moveEmptyTabList() { | 170 function moveEmptyTabList() { |
| 161 chrome.tabs.move([], {"index": 0}, fail("No tabs given.")); | 171 chrome.tabs.move([], {"index": 0}, fail("No tabs given.")); |
| 162 }, | 172 }, |
| 163 | 173 |
| 164 // Move a tab to the current window. | 174 // Move a tab to the current window. |
| 165 function moveToCurrentWindow() { | 175 function moveToCurrentWindow() { |
| 166 chrome.windows.getCurrent(pass(function(win) { | 176 chrome.windows.getCurrent(pass(function(win) { |
| 167 var targetWin = win.id == firstWindowId ? secondWindowId : firstWindowId; | 177 var targetWin = win.id == firstWindowId ? secondWindowId : firstWindowId; |
| 168 chrome.tabs.query({"windowId": targetWin}, pass(function(tabs) { | 178 chrome.tabs.query({"windowId": targetWin}, pass(function(tabs) { |
| 169 chrome.tabs.move(tabs[0].id, | 179 chrome.tabs.move(tabs[0].id, |
| 170 {"windowId": chrome.windows.WINDOW_ID_CURRENT, | 180 {"windowId": chrome.windows.WINDOW_ID_CURRENT, |
| 171 "index": 0}, | 181 "index": 0}, |
| 172 pass(function(tab) { | 182 pass(function(tab) { |
| 173 assertEq(win.id, tab.windowId); | 183 assertEq(win.id, tab.windowId); |
| 174 })); | 184 })); |
| 175 })); | 185 })); |
| 176 })); | 186 })); |
| 177 } | 187 } |
| 178 ]); | 188 ]); |
| OLD | NEW |