1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
<script src="tabs_util.js"></script>
<script>
var firstWindowId;
var secondWindowId;
var moveTabIds = {};
chrome.test.runTests([
// Do a series of moves so that we get the following
//
// Before:
// Window1: (newtab),a,b,c,d,e
// Window2: (newtab)
//
// After:
// Window1: (newtab),a,e,c
// Window2: b,(newtab),d
function setupLetterPages() {
var pages = ["chrome://newtab/", pageUrl('a'), pageUrl('b'),
pageUrl('c'), pageUrl('d'), pageUrl('e')];
createWindow(pages, {}, pass(function(winId, tabIds) {
firstWindowId = winId;
moveTabIds['a'] = tabIds[1];
moveTabIds['b'] = tabIds[2];
moveTabIds['c'] = tabIds[3];
moveTabIds['d'] = tabIds[4];
moveTabIds['e'] = tabIds[5];
createWindow(["chrome://newtab/"], {}, pass(function(winId, tabIds) {
secondWindowId = winId;
}));
chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
assertEq(pages.length, tabs.length);
for (var i in tabs) {
assertEq(pages[i], tabs[i].url);
}
}));
}));
},
function move() {
// Check that the tab/window state is what we expect after doing moves.
function checkMoveResults() {
chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
assertEq(4, tabs.length);
assertEq("chrome://newtab/", tabs[0].url);
assertEq(pageUrl("a"), tabs[1].url);
assertEq(pageUrl("e"), tabs[2].url);
assertEq(pageUrl("c"), tabs[3].url);
chrome.tabs.getAllInWindow(secondWindowId, pass(function(tabs) {
assertEq(3, tabs.length);
assertEq(pageUrl("b"), tabs[0].url);
assertEq("chrome://newtab/", tabs[1].url);
assertEq(pageUrl("d"), tabs[2].url);
}));
}));
}
chrome.tabs.move(moveTabIds['b'], {"windowId": secondWindowId, "index": 0},
pass(function(tabB) {
chrome.test.assertEq(0, tabB.index);
chrome.tabs.move(moveTabIds['e'], {"index": 2},
pass(function(tabE) {
chrome.test.assertEq(2, tabE.index);
chrome.tabs.move(moveTabIds['d'], {"windowId": secondWindowId,
"index": 2}, pass(function(tabD) {
chrome.test.assertEq(2, tabD.index);
checkMoveResults();
}));
}));
}));
},
function remove() {
chrome.tabs.remove(moveTabIds["d"], pass(function() {
chrome.tabs.getAllInWindow(secondWindowId,
pass(function(tabs) {
assertEq(2, tabs.length);
assertEq(pageUrl("b"), tabs[0].url);
assertEq("chrome://newtab/", tabs[1].url);
}));
}));
}
]);
</script>
|