michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function test() { michael@0: let cw; michael@0: michael@0: let createGroupItem = function () { michael@0: return createGroupItemWithBlankTabs(window, 400, 200, 0, 5); michael@0: } michael@0: michael@0: let assertCorrectItemOrder = function (items) { michael@0: for (let i=1; i items[i].tab._tPos) { michael@0: ok(false, 'tabs were correctly reordered'); michael@0: return; michael@0: } michael@0: } michael@0: ok(true, 'tabs were correctly reordered'); michael@0: } michael@0: michael@0: let testVariousTabOrders = function () { michael@0: let groupItem = createGroupItem(); michael@0: let [tab1, tab2, tab3, tab4, tab5] = groupItem.getChildren(); michael@0: michael@0: // prepare tests michael@0: let tests = []; michael@0: tests.push([tab1, tab2, tab3, tab4, tab5]); michael@0: tests.push([tab5, tab4, tab3, tab2, tab1]); michael@0: tests.push([tab1, tab2, tab3, tab4]); michael@0: tests.push([tab4, tab3, tab2, tab1]); michael@0: tests.push([tab1, tab2, tab3]); michael@0: tests.push([tab1, tab2, tab3]); michael@0: tests.push([tab1, tab3, tab2]); michael@0: tests.push([tab2, tab1, tab3]); michael@0: tests.push([tab2, tab3, tab1]); michael@0: tests.push([tab3, tab1, tab2]); michael@0: tests.push([tab3, tab2, tab1]); michael@0: tests.push([tab1, tab2]); michael@0: tests.push([tab2, tab1]); michael@0: tests.push([tab1]); michael@0: michael@0: // test reordering of empty groups - removes the last tab and causes michael@0: // the groupItem to close michael@0: tests.push([]); michael@0: michael@0: while (tests.length) { michael@0: let test = tests.shift(); michael@0: michael@0: // prepare michael@0: let items = groupItem.getChildren(); michael@0: while (test.length < items.length) michael@0: items[items.length-1].close(); michael@0: michael@0: let orig = cw.Utils.copy(items); michael@0: items.sort(function (a, b) test.indexOf(a) - test.indexOf(b)); michael@0: michael@0: // order and check michael@0: groupItem.reorderTabsBasedOnTabItemOrder(); michael@0: assertCorrectItemOrder(items); michael@0: michael@0: // revert to original item order michael@0: items.sort(function (a, b) orig.indexOf(a) - orig.indexOf(b)); michael@0: groupItem.reorderTabsBasedOnTabItemOrder(); michael@0: } michael@0: michael@0: testMoveBetweenGroups(); michael@0: } michael@0: michael@0: let testMoveBetweenGroups = function () { michael@0: let groupItem = createGroupItem(); michael@0: let groupItem2 = createGroupItem(); michael@0: michael@0: afterAllTabsLoaded(function () { michael@0: // move item from group1 to group2 michael@0: let child = groupItem.getChild(2); michael@0: groupItem.remove(child); michael@0: michael@0: groupItem2.add(child, {index: 3}); michael@0: groupItem2.reorderTabsBasedOnTabItemOrder(); michael@0: michael@0: assertCorrectItemOrder(groupItem.getChildren()); michael@0: assertCorrectItemOrder(groupItem2.getChildren()); michael@0: michael@0: // move item from group2 to group1 michael@0: child = groupItem2.getChild(1); michael@0: groupItem2.remove(child); michael@0: michael@0: groupItem.add(child, {index: 1}); michael@0: groupItem.reorderTabsBasedOnTabItemOrder(); michael@0: michael@0: assertCorrectItemOrder(groupItem.getChildren()); michael@0: assertCorrectItemOrder(groupItem2.getChildren()); michael@0: michael@0: // cleanup michael@0: closeGroupItem(groupItem, function () { michael@0: closeGroupItem(groupItem2, function () { michael@0: hideTabView(finish); michael@0: }); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: showTabView(function () { michael@0: cw = TabView.getContentWindow(); michael@0: afterAllTabsLoaded(testVariousTabOrders); michael@0: }); michael@0: }