1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_dragdrop.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 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 + showTabView(onTabViewShown); 1.10 +} 1.11 + 1.12 +function onTabViewShown() { 1.13 + ok(TabView.isVisible(), "Tab View is visible"); 1.14 + 1.15 + let contentWindow = TabView.getContentWindow(); 1.16 + let [originalTab] = gBrowser.visibleTabs; 1.17 + 1.18 + let createGroupItem = function (left, top, width, height) { 1.19 + let box = new contentWindow.Rect(left, top, width, height); 1.20 + let groupItem = new contentWindow.GroupItem([], {bounds: box, immediately: true}); 1.21 + 1.22 + contentWindow.UI.setActive(groupItem); 1.23 + gBrowser.loadOneTab("about:blank", {inBackground: true}); 1.24 + 1.25 + return groupItem; 1.26 + }; 1.27 + 1.28 + // create group one and two 1.29 + let groupOne = createGroupItem(20, 20, 300, 300); 1.30 + let groupTwo = createGroupItem(20, 400, 300, 300); 1.31 + 1.32 + waitForFocus(function () { 1.33 + addTest(contentWindow, groupOne.id, groupTwo.id, originalTab); 1.34 + }); 1.35 +} 1.36 + 1.37 +function addTest(contentWindow, groupOneId, groupTwoId, originalTab) { 1.38 + let groupOne = contentWindow.GroupItems.groupItem(groupOneId); 1.39 + let groupTwo = contentWindow.GroupItems.groupItem(groupTwoId); 1.40 + let groupOneTabItemCount = groupOne.getChildren().length; 1.41 + let groupTwoTabItemCount = groupTwo.getChildren().length; 1.42 + is(groupOneTabItemCount, 1, "GroupItem one has one tab"); 1.43 + is(groupTwoTabItemCount, 1, "GroupItem two has one tab as well"); 1.44 + 1.45 + let tabItem = groupOne.getChild(0); 1.46 + ok(tabItem, "The tab item exists"); 1.47 + 1.48 + // calculate the offsets 1.49 + let groupTwoRectCenter = groupTwo.getBounds().center(); 1.50 + let tabItemRectCenter = tabItem.getBounds().center(); 1.51 + let offsetX = 1.52 + Math.round(groupTwoRectCenter.x - tabItemRectCenter.x); 1.53 + let offsetY = 1.54 + Math.round(groupTwoRectCenter.y - tabItemRectCenter.y); 1.55 + 1.56 + function endGame() { 1.57 + groupTwo.removeSubscriber("childAdded", endGame); 1.58 + 1.59 + is(groupOne.getChildren().length, --groupOneTabItemCount, 1.60 + "The number of children in group one is decreased by 1"); 1.61 + is(groupTwo.getChildren().length, ++groupTwoTabItemCount, 1.62 + "The number of children in group two is increased by 1"); 1.63 + 1.64 + closeGroupItem(groupOne, function () { 1.65 + closeGroupItem(groupTwo, function () hideTabView(finish)); 1.66 + }); 1.67 + } 1.68 + 1.69 + groupTwo.addSubscriber("childAdded", endGame); 1.70 + simulateDragDrop(tabItem.container, offsetX, offsetY, contentWindow); 1.71 +} 1.72 + 1.73 +function simulateDragDrop(element, offsetX, offsetY, contentWindow) { 1.74 + let rect = element.getBoundingClientRect(); 1.75 + let startX = (rect.right - rect.left)/2; 1.76 + let startY = (rect.bottom - rect.top)/2; 1.77 + let incrementX = offsetX / 2; 1.78 + let incrementY = offsetY / 2; 1.79 + 1.80 + EventUtils.synthesizeMouse( 1.81 + element, startX, startY, { type: "mousedown" }); 1.82 + 1.83 + for (let i = 1; i <= 2; i++) { 1.84 + EventUtils.synthesizeMouse( 1.85 + element, (startX + incrementX * i), (startY + incrementY * i), 1.86 + { type: "mousemove" }); 1.87 + } 1.88 + 1.89 + EventUtils.synthesizeMouse( 1.90 + element, (startX + incrementX * 2), (startY + incrementY * 2), 1.91 + { type: "mouseup" }); 1.92 +}