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 | waitForExplicitFinish(); |
michael@0 | 6 | |
michael@0 | 7 | function moveTabOutOfGroup(aTab, aGroup, aCW, aCallback) { |
michael@0 | 8 | let tabPos = aTab.getBounds().center(); |
michael@0 | 9 | let groupPos = aGroup.getBounds(); |
michael@0 | 10 | let groupPosX = (groupPos.left + groupPos.right) / 2; |
michael@0 | 11 | let groupPosY = groupPos.bottom + 200; |
michael@0 | 12 | let offsetX = Math.round(groupPosX - tabPos.x); |
michael@0 | 13 | let offsetY = Math.round(groupPosY - tabPos.y); |
michael@0 | 14 | |
michael@0 | 15 | simulateDragDrop(aTab, offsetX, offsetY, aCW); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | function moveTabInGroup(aTab, aIndexTo, aGroup, aCW) { |
michael@0 | 19 | let tabTo = aGroup.getChild(aIndexTo); |
michael@0 | 20 | let tabPos = aTab.getBounds().center(); |
michael@0 | 21 | let tabToPos = tabTo.getBounds().center(); |
michael@0 | 22 | let offsetX = Math.round(tabToPos.x - tabPos.x); |
michael@0 | 23 | let offsetY = Math.round(tabToPos.y - tabPos.y); |
michael@0 | 24 | |
michael@0 | 25 | simulateDragDrop(aTab, offsetX, offsetY, aCW); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function getTabNumbers(aGroup) { |
michael@0 | 29 | return aGroup.getChildren().map(function (child) { |
michael@0 | 30 | let url = child.tab.linkedBrowser.currentURI.spec; |
michael@0 | 31 | return url.replace("about:blank#", ""); |
michael@0 | 32 | }).join(","); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | function moveTabs(aGroup, aCW) { |
michael@0 | 36 | // Test 1: Move the last tab to the third position. |
michael@0 | 37 | let tab = aGroup.getChild(6); |
michael@0 | 38 | moveTabInGroup(tab, 2, aGroup, aCW); |
michael@0 | 39 | is(getTabNumbers(aGroup), "0,1,6,2,3,4,5", "Validate tab positions in test 1."); |
michael@0 | 40 | |
michael@0 | 41 | // Test 2: Move the second tab to the end of the list. |
michael@0 | 42 | tab = aGroup.getChild(1); |
michael@0 | 43 | moveTabInGroup(tab, 6, aGroup, aCW); |
michael@0 | 44 | is(getTabNumbers(aGroup), "0,6,2,3,4,5,1", "Validate tab positions in test 2."); |
michael@0 | 45 | |
michael@0 | 46 | // Test 3: Move the fifth tab outside the group. |
michael@0 | 47 | tab = aGroup.getChild(4); |
michael@0 | 48 | moveTabOutOfGroup(tab, aGroup, aCW); |
michael@0 | 49 | is(getTabNumbers(aGroup), "0,6,2,3,5,1", "Validate tab positions in test 3."); |
michael@0 | 50 | is(aCW.GroupItems.groupItems.length, 3, "Validate group count in test 3."); |
michael@0 | 51 | |
michael@0 | 52 | // This test is disabled because it is fragile -- see bug 797975 |
michael@0 | 53 | if (false) { |
michael@0 | 54 | // Test 4: Move the fifth tab back into the group, on the second row. |
michael@0 | 55 | waitForTransition(tab, function() { |
michael@0 | 56 | moveTabInGroup(tab, 4, aGroup, aCW); |
michael@0 | 57 | is(getTabNumbers(aGroup), "0,6,2,3,4,5,1", "Validate tab positions in test 4."); |
michael@0 | 58 | is(aCW.GroupItems.groupItems.length, 2, "Validate group count in test 4."); |
michael@0 | 59 | closeGroupItem(aGroup, function() { hideTabView(finish) }); |
michael@0 | 60 | }); |
michael@0 | 61 | } else { |
michael@0 | 62 | closeGroupItem(aGroup, function() { hideTabView(finish) }); |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function createGroup(win) { |
michael@0 | 67 | registerCleanupFunction(function() win.close()); |
michael@0 | 68 | let cw = win.TabView.getContentWindow(); |
michael@0 | 69 | let group = createGroupItemWithTabs(win, 400, 430, 100, [ |
michael@0 | 70 | "about:blank#0", "about:blank#1", "about:blank#2", "about:blank#3", |
michael@0 | 71 | "about:blank#4", "about:blank#5", "about:blank#6" |
michael@0 | 72 | ]); |
michael@0 | 73 | let groupSize = group.getChildren().length; |
michael@0 | 74 | |
michael@0 | 75 | is(cw.GroupItems.groupItems.length, 2, "Validate group count in tab view."); |
michael@0 | 76 | ok(!group.shouldStack(groupSize), "Check that group should not stack."); |
michael@0 | 77 | is(group._columns, 3, "Check the there should be three columns."); |
michael@0 | 78 | |
michael@0 | 79 | moveTabs(group, cw); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | newWindowWithTabView(createGroup); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function simulateDragDrop(aTab, aOffsetX, aOffsetY, aCW) { |
michael@0 | 86 | let target = aTab.container; |
michael@0 | 87 | let rect = target.getBoundingClientRect(); |
michael@0 | 88 | let startX = (rect.right - rect.left) / 2; |
michael@0 | 89 | let startY = (rect.bottom - rect.top) / 2; |
michael@0 | 90 | let steps = 2; |
michael@0 | 91 | let incrementX = aOffsetX / steps; |
michael@0 | 92 | let incrementY = aOffsetY / steps; |
michael@0 | 93 | |
michael@0 | 94 | EventUtils.synthesizeMouse( |
michael@0 | 95 | target, startX, startY, { type: "mousedown" }, aCW); |
michael@0 | 96 | for (let i = 1; i <= steps; i++) { |
michael@0 | 97 | EventUtils.synthesizeMouse( |
michael@0 | 98 | target, incrementX + startX, incrementY + startY, |
michael@0 | 99 | { type: "mousemove" }, aCW); |
michael@0 | 100 | }; |
michael@0 | 101 | EventUtils.synthesizeMouseAtCenter(target, { type: "mouseup" }, aCW); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | function waitForTransition(aTab, aCallback) { |
michael@0 | 105 | let groupContainer = aTab.parent.container; |
michael@0 | 106 | groupContainer.addEventListener("transitionend", function onTransitionEnd(aEvent) { |
michael@0 | 107 | if (aEvent.target == groupContainer) { |
michael@0 | 108 | groupContainer.removeEventListener("transitionend", onTransitionEnd); |
michael@0 | 109 | executeSoon(aCallback); |
michael@0 | 110 | } |
michael@0 | 111 | }); |
michael@0 | 112 | } |