1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug616729.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +function test() { 1.8 + let cw; 1.9 + 1.10 + let createGroupItem = function () { 1.11 + return createGroupItemWithBlankTabs(window, 400, 200, 0, 5); 1.12 + } 1.13 + 1.14 + let assertCorrectItemOrder = function (items) { 1.15 + for (let i=1; i<items.length; i++) { 1.16 + if (items[i-1].tab._tPos > items[i].tab._tPos) { 1.17 + ok(false, 'tabs were correctly reordered'); 1.18 + return; 1.19 + } 1.20 + } 1.21 + ok(true, 'tabs were correctly reordered'); 1.22 + } 1.23 + 1.24 + let testVariousTabOrders = function () { 1.25 + let groupItem = createGroupItem(); 1.26 + let [tab1, tab2, tab3, tab4, tab5] = groupItem.getChildren(); 1.27 + 1.28 + // prepare tests 1.29 + let tests = []; 1.30 + tests.push([tab1, tab2, tab3, tab4, tab5]); 1.31 + tests.push([tab5, tab4, tab3, tab2, tab1]); 1.32 + tests.push([tab1, tab2, tab3, tab4]); 1.33 + tests.push([tab4, tab3, tab2, tab1]); 1.34 + tests.push([tab1, tab2, tab3]); 1.35 + tests.push([tab1, tab2, tab3]); 1.36 + tests.push([tab1, tab3, tab2]); 1.37 + tests.push([tab2, tab1, tab3]); 1.38 + tests.push([tab2, tab3, tab1]); 1.39 + tests.push([tab3, tab1, tab2]); 1.40 + tests.push([tab3, tab2, tab1]); 1.41 + tests.push([tab1, tab2]); 1.42 + tests.push([tab2, tab1]); 1.43 + tests.push([tab1]); 1.44 + 1.45 + // test reordering of empty groups - removes the last tab and causes 1.46 + // the groupItem to close 1.47 + tests.push([]); 1.48 + 1.49 + while (tests.length) { 1.50 + let test = tests.shift(); 1.51 + 1.52 + // prepare 1.53 + let items = groupItem.getChildren(); 1.54 + while (test.length < items.length) 1.55 + items[items.length-1].close(); 1.56 + 1.57 + let orig = cw.Utils.copy(items); 1.58 + items.sort(function (a, b) test.indexOf(a) - test.indexOf(b)); 1.59 + 1.60 + // order and check 1.61 + groupItem.reorderTabsBasedOnTabItemOrder(); 1.62 + assertCorrectItemOrder(items); 1.63 + 1.64 + // revert to original item order 1.65 + items.sort(function (a, b) orig.indexOf(a) - orig.indexOf(b)); 1.66 + groupItem.reorderTabsBasedOnTabItemOrder(); 1.67 + } 1.68 + 1.69 + testMoveBetweenGroups(); 1.70 + } 1.71 + 1.72 + let testMoveBetweenGroups = function () { 1.73 + let groupItem = createGroupItem(); 1.74 + let groupItem2 = createGroupItem(); 1.75 + 1.76 + afterAllTabsLoaded(function () { 1.77 + // move item from group1 to group2 1.78 + let child = groupItem.getChild(2); 1.79 + groupItem.remove(child); 1.80 + 1.81 + groupItem2.add(child, {index: 3}); 1.82 + groupItem2.reorderTabsBasedOnTabItemOrder(); 1.83 + 1.84 + assertCorrectItemOrder(groupItem.getChildren()); 1.85 + assertCorrectItemOrder(groupItem2.getChildren()); 1.86 + 1.87 + // move item from group2 to group1 1.88 + child = groupItem2.getChild(1); 1.89 + groupItem2.remove(child); 1.90 + 1.91 + groupItem.add(child, {index: 1}); 1.92 + groupItem.reorderTabsBasedOnTabItemOrder(); 1.93 + 1.94 + assertCorrectItemOrder(groupItem.getChildren()); 1.95 + assertCorrectItemOrder(groupItem2.getChildren()); 1.96 + 1.97 + // cleanup 1.98 + closeGroupItem(groupItem, function () { 1.99 + closeGroupItem(groupItem2, function () { 1.100 + hideTabView(finish); 1.101 + }); 1.102 + }); 1.103 + }); 1.104 + } 1.105 + 1.106 + waitForExplicitFinish(); 1.107 + 1.108 + showTabView(function () { 1.109 + cw = TabView.getContentWindow(); 1.110 + afterAllTabsLoaded(testVariousTabOrders); 1.111 + }); 1.112 +}