OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 var firstWindowId; |
| 6 var secondWindowId; |
| 7 var moveTabIds = {}; |
| 8 |
| 9 chrome.test.runTests([ |
| 10 // Do a series of moves and removes so that we get the following |
| 11 // |
| 12 // Before: |
| 13 // Window1: (newtab),a,b,c,d,e |
| 14 // Window2: (newtab) |
| 15 // |
| 16 // After: |
| 17 // Window1: (newtab),a |
| 18 // Window2: b,(newtab) |
| 19 function setupLetterPages() { |
| 20 var pages = ["chrome://newtab/", pageUrl('a'), pageUrl('b'), |
| 21 pageUrl('c'), pageUrl('d'), pageUrl('e')]; |
| 22 createWindow(pages, {}, pass(function(winId, tabIds) { |
| 23 firstWindowId = winId; |
| 24 moveTabIds['a'] = tabIds[1]; |
| 25 moveTabIds['b'] = tabIds[2]; |
| 26 moveTabIds['c'] = tabIds[3]; |
| 27 moveTabIds['d'] = tabIds[4]; |
| 28 moveTabIds['e'] = tabIds[5]; |
| 29 createWindow(["chrome://newtab/"], {}, pass(function(winId, tabIds) { |
| 30 secondWindowId = winId; |
| 31 })); |
| 32 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { |
| 33 assertEq(pages.length, tabs.length); |
| 34 for (var i in tabs) { |
| 35 assertEq(pages[i], tabs[i].url); |
| 36 } |
| 37 })); |
| 38 })); |
| 39 }, |
| 40 |
| 41 function move() { |
| 42 // Check that the tab/window state is what we expect after doing moves. |
| 43 function checkMoveResults() { |
| 44 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { |
| 45 assertEq(4, tabs.length); |
| 46 assertEq("chrome://newtab/", tabs[0].url); |
| 47 assertEq(pageUrl("a"), tabs[1].url); |
| 48 assertEq(pageUrl("e"), tabs[2].url); |
| 49 assertEq(pageUrl("c"), tabs[3].url); |
| 50 |
| 51 chrome.tabs.getAllInWindow(secondWindowId, pass(function(tabs) { |
| 52 assertEq(3, tabs.length); |
| 53 assertEq(pageUrl("b"), tabs[0].url); |
| 54 assertEq("chrome://newtab/", tabs[1].url); |
| 55 assertEq(pageUrl("d"), tabs[2].url); |
| 56 })); |
| 57 })); |
| 58 } |
| 59 |
| 60 chrome.tabs.move(moveTabIds['b'], {"windowId": secondWindowId, "index": 0}, |
| 61 pass(function(tabB) { |
| 62 chrome.test.assertEq(0, tabB.index); |
| 63 chrome.tabs.move(moveTabIds['e'], {"index": 2}, |
| 64 pass(function(tabE) { |
| 65 chrome.test.assertEq(2, tabE.index); |
| 66 chrome.tabs.move(moveTabIds['d'], {"windowId": secondWindowId, |
| 67 "index": 2}, pass(function(tabD) { |
| 68 chrome.test.assertEq(2, tabD.index); |
| 69 checkMoveResults(); |
| 70 })); |
| 71 })); |
| 72 })); |
| 73 }, |
| 74 |
| 75 function remove() { |
| 76 chrome.tabs.remove(moveTabIds["d"], pass(function() { |
| 77 chrome.tabs.getAllInWindow(secondWindowId, |
| 78 pass(function(tabs) { |
| 79 assertEq(2, tabs.length); |
| 80 assertEq(pageUrl("b"), tabs[0].url); |
| 81 assertEq("chrome://newtab/", tabs[1].url); |
| 82 })); |
| 83 })); |
| 84 }, |
| 85 |
| 86 function moveMultipleTabs() { |
| 87 chrome.tabs.move([moveTabIds['e'], moveTabIds['c']], |
| 88 {windowId: secondWindowId, index: 1}, |
| 89 pass(function(tabsA) { |
| 90 assertEq(2, tabsA.length); |
| 91 assertEq(secondWindowId, tabsA[0].windowId); |
| 92 assertEq(pageUrl('e'), tabsA[0].url); |
| 93 assertEq(1, tabsA[0].index); |
| 94 assertEq(secondWindowId, tabsA[1].windowId); |
| 95 assertEq(pageUrl('c'), tabsA[1].url); |
| 96 assertEq(2, tabsA[1].index); |
| 97 chrome.tabs.query({windowId: secondWindowId}, pass(function(tabsB) { |
| 98 assertEq(4, tabsB.length); |
| 99 })); |
| 100 })); |
| 101 }, |
| 102 |
| 103 function removeMultipleTabs() { |
| 104 chrome.tabs.remove([moveTabIds['e'], moveTabIds['c']], pass(function() { |
| 105 chrome.tabs.query({windowId: secondWindowId}, pass(function(tabs) { |
| 106 assertEq(2, tabs.length); |
| 107 assertEq(pageUrl("b"), tabs[0].url); |
| 108 assertEq("chrome://newtab/", tabs[1].url); |
| 109 })); |
| 110 })); |
| 111 }, |
| 112 |
| 113 // Make sure we don't crash when the index is out of range. |
| 114 function moveToInvalidTab() { |
| 115 var error_msg = "Invalid value for argument 2. Property 'index': " + |
| 116 "Value must not be less than 0."; |
| 117 try { |
| 118 chrome.tabs.move(moveTabIds['b'], {index: -1}, function(tab) { |
| 119 chrome.test.fail("Moved a tab to an invalid index"); |
| 120 }); |
| 121 } catch (e) { |
| 122 assertEq(error_msg, e.message); |
| 123 } |
| 124 chrome.tabs.move(moveTabIds['b'], {index: 10000}, pass(function(tabB) { |
| 125 assertEq(1, tabB.index); |
| 126 })); |
| 127 } |
| 128 ]); |
OLD | NEW |