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