|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 let cw; |
|
6 |
|
7 let createGroupItem = function () { |
|
8 return createGroupItemWithBlankTabs(window, 400, 200, 0, 5); |
|
9 } |
|
10 |
|
11 let assertCorrectItemOrder = function (items) { |
|
12 for (let i=1; i<items.length; i++) { |
|
13 if (items[i-1].tab._tPos > items[i].tab._tPos) { |
|
14 ok(false, 'tabs were correctly reordered'); |
|
15 return; |
|
16 } |
|
17 } |
|
18 ok(true, 'tabs were correctly reordered'); |
|
19 } |
|
20 |
|
21 let testVariousTabOrders = function () { |
|
22 let groupItem = createGroupItem(); |
|
23 let [tab1, tab2, tab3, tab4, tab5] = groupItem.getChildren(); |
|
24 |
|
25 // prepare tests |
|
26 let tests = []; |
|
27 tests.push([tab1, tab2, tab3, tab4, tab5]); |
|
28 tests.push([tab5, tab4, tab3, tab2, tab1]); |
|
29 tests.push([tab1, tab2, tab3, tab4]); |
|
30 tests.push([tab4, tab3, tab2, tab1]); |
|
31 tests.push([tab1, tab2, tab3]); |
|
32 tests.push([tab1, tab2, tab3]); |
|
33 tests.push([tab1, tab3, tab2]); |
|
34 tests.push([tab2, tab1, tab3]); |
|
35 tests.push([tab2, tab3, tab1]); |
|
36 tests.push([tab3, tab1, tab2]); |
|
37 tests.push([tab3, tab2, tab1]); |
|
38 tests.push([tab1, tab2]); |
|
39 tests.push([tab2, tab1]); |
|
40 tests.push([tab1]); |
|
41 |
|
42 // test reordering of empty groups - removes the last tab and causes |
|
43 // the groupItem to close |
|
44 tests.push([]); |
|
45 |
|
46 while (tests.length) { |
|
47 let test = tests.shift(); |
|
48 |
|
49 // prepare |
|
50 let items = groupItem.getChildren(); |
|
51 while (test.length < items.length) |
|
52 items[items.length-1].close(); |
|
53 |
|
54 let orig = cw.Utils.copy(items); |
|
55 items.sort(function (a, b) test.indexOf(a) - test.indexOf(b)); |
|
56 |
|
57 // order and check |
|
58 groupItem.reorderTabsBasedOnTabItemOrder(); |
|
59 assertCorrectItemOrder(items); |
|
60 |
|
61 // revert to original item order |
|
62 items.sort(function (a, b) orig.indexOf(a) - orig.indexOf(b)); |
|
63 groupItem.reorderTabsBasedOnTabItemOrder(); |
|
64 } |
|
65 |
|
66 testMoveBetweenGroups(); |
|
67 } |
|
68 |
|
69 let testMoveBetweenGroups = function () { |
|
70 let groupItem = createGroupItem(); |
|
71 let groupItem2 = createGroupItem(); |
|
72 |
|
73 afterAllTabsLoaded(function () { |
|
74 // move item from group1 to group2 |
|
75 let child = groupItem.getChild(2); |
|
76 groupItem.remove(child); |
|
77 |
|
78 groupItem2.add(child, {index: 3}); |
|
79 groupItem2.reorderTabsBasedOnTabItemOrder(); |
|
80 |
|
81 assertCorrectItemOrder(groupItem.getChildren()); |
|
82 assertCorrectItemOrder(groupItem2.getChildren()); |
|
83 |
|
84 // move item from group2 to group1 |
|
85 child = groupItem2.getChild(1); |
|
86 groupItem2.remove(child); |
|
87 |
|
88 groupItem.add(child, {index: 1}); |
|
89 groupItem.reorderTabsBasedOnTabItemOrder(); |
|
90 |
|
91 assertCorrectItemOrder(groupItem.getChildren()); |
|
92 assertCorrectItemOrder(groupItem2.getChildren()); |
|
93 |
|
94 // cleanup |
|
95 closeGroupItem(groupItem, function () { |
|
96 closeGroupItem(groupItem2, function () { |
|
97 hideTabView(finish); |
|
98 }); |
|
99 }); |
|
100 }); |
|
101 } |
|
102 |
|
103 waitForExplicitFinish(); |
|
104 |
|
105 showTabView(function () { |
|
106 cw = TabView.getContentWindow(); |
|
107 afterAllTabsLoaded(testVariousTabOrders); |
|
108 }); |
|
109 } |