1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug587503.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 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 + waitForExplicitFinish(); 1.9 + 1.10 + function moveTabOutOfGroup(aTab, aGroup, aCW, aCallback) { 1.11 + let tabPos = aTab.getBounds().center(); 1.12 + let groupPos = aGroup.getBounds(); 1.13 + let groupPosX = (groupPos.left + groupPos.right) / 2; 1.14 + let groupPosY = groupPos.bottom + 200; 1.15 + let offsetX = Math.round(groupPosX - tabPos.x); 1.16 + let offsetY = Math.round(groupPosY - tabPos.y); 1.17 + 1.18 + simulateDragDrop(aTab, offsetX, offsetY, aCW); 1.19 + } 1.20 + 1.21 + function moveTabInGroup(aTab, aIndexTo, aGroup, aCW) { 1.22 + let tabTo = aGroup.getChild(aIndexTo); 1.23 + let tabPos = aTab.getBounds().center(); 1.24 + let tabToPos = tabTo.getBounds().center(); 1.25 + let offsetX = Math.round(tabToPos.x - tabPos.x); 1.26 + let offsetY = Math.round(tabToPos.y - tabPos.y); 1.27 + 1.28 + simulateDragDrop(aTab, offsetX, offsetY, aCW); 1.29 + } 1.30 + 1.31 + function getTabNumbers(aGroup) { 1.32 + return aGroup.getChildren().map(function (child) { 1.33 + let url = child.tab.linkedBrowser.currentURI.spec; 1.34 + return url.replace("about:blank#", ""); 1.35 + }).join(","); 1.36 + } 1.37 + 1.38 + function moveTabs(aGroup, aCW) { 1.39 + // Test 1: Move the last tab to the third position. 1.40 + let tab = aGroup.getChild(6); 1.41 + moveTabInGroup(tab, 2, aGroup, aCW); 1.42 + is(getTabNumbers(aGroup), "0,1,6,2,3,4,5", "Validate tab positions in test 1."); 1.43 + 1.44 + // Test 2: Move the second tab to the end of the list. 1.45 + tab = aGroup.getChild(1); 1.46 + moveTabInGroup(tab, 6, aGroup, aCW); 1.47 + is(getTabNumbers(aGroup), "0,6,2,3,4,5,1", "Validate tab positions in test 2."); 1.48 + 1.49 + // Test 3: Move the fifth tab outside the group. 1.50 + tab = aGroup.getChild(4); 1.51 + moveTabOutOfGroup(tab, aGroup, aCW); 1.52 + is(getTabNumbers(aGroup), "0,6,2,3,5,1", "Validate tab positions in test 3."); 1.53 + is(aCW.GroupItems.groupItems.length, 3, "Validate group count in test 3."); 1.54 + 1.55 + // This test is disabled because it is fragile -- see bug 797975 1.56 + if (false) { 1.57 + // Test 4: Move the fifth tab back into the group, on the second row. 1.58 + waitForTransition(tab, function() { 1.59 + moveTabInGroup(tab, 4, aGroup, aCW); 1.60 + is(getTabNumbers(aGroup), "0,6,2,3,4,5,1", "Validate tab positions in test 4."); 1.61 + is(aCW.GroupItems.groupItems.length, 2, "Validate group count in test 4."); 1.62 + closeGroupItem(aGroup, function() { hideTabView(finish) }); 1.63 + }); 1.64 + } else { 1.65 + closeGroupItem(aGroup, function() { hideTabView(finish) }); 1.66 + } 1.67 + } 1.68 + 1.69 + function createGroup(win) { 1.70 + registerCleanupFunction(function() win.close()); 1.71 + let cw = win.TabView.getContentWindow(); 1.72 + let group = createGroupItemWithTabs(win, 400, 430, 100, [ 1.73 + "about:blank#0", "about:blank#1", "about:blank#2", "about:blank#3", 1.74 + "about:blank#4", "about:blank#5", "about:blank#6" 1.75 + ]); 1.76 + let groupSize = group.getChildren().length; 1.77 + 1.78 + is(cw.GroupItems.groupItems.length, 2, "Validate group count in tab view."); 1.79 + ok(!group.shouldStack(groupSize), "Check that group should not stack."); 1.80 + is(group._columns, 3, "Check the there should be three columns."); 1.81 + 1.82 + moveTabs(group, cw); 1.83 + } 1.84 + 1.85 + newWindowWithTabView(createGroup); 1.86 +} 1.87 + 1.88 +function simulateDragDrop(aTab, aOffsetX, aOffsetY, aCW) { 1.89 + let target = aTab.container; 1.90 + let rect = target.getBoundingClientRect(); 1.91 + let startX = (rect.right - rect.left) / 2; 1.92 + let startY = (rect.bottom - rect.top) / 2; 1.93 + let steps = 2; 1.94 + let incrementX = aOffsetX / steps; 1.95 + let incrementY = aOffsetY / steps; 1.96 + 1.97 + EventUtils.synthesizeMouse( 1.98 + target, startX, startY, { type: "mousedown" }, aCW); 1.99 + for (let i = 1; i <= steps; i++) { 1.100 + EventUtils.synthesizeMouse( 1.101 + target, incrementX + startX, incrementY + startY, 1.102 + { type: "mousemove" }, aCW); 1.103 + }; 1.104 + EventUtils.synthesizeMouseAtCenter(target, { type: "mouseup" }, aCW); 1.105 +} 1.106 + 1.107 +function waitForTransition(aTab, aCallback) { 1.108 + let groupContainer = aTab.parent.container; 1.109 + groupContainer.addEventListener("transitionend", function onTransitionEnd(aEvent) { 1.110 + if (aEvent.target == groupContainer) { 1.111 + groupContainer.removeEventListener("transitionend", onTransitionEnd); 1.112 + executeSoon(aCallback); 1.113 + } 1.114 + }); 1.115 +}