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 | showTabView(onTabViewShown); |
michael@0 | 7 | } |
michael@0 | 8 | |
michael@0 | 9 | function onTabViewShown() { |
michael@0 | 10 | ok(TabView.isVisible(), "Tab View is visible"); |
michael@0 | 11 | |
michael@0 | 12 | let contentWindow = TabView.getContentWindow(); |
michael@0 | 13 | let [originalTab] = gBrowser.visibleTabs; |
michael@0 | 14 | |
michael@0 | 15 | let createGroupItem = function (left, top, width, height) { |
michael@0 | 16 | let box = new contentWindow.Rect(left, top, width, height); |
michael@0 | 17 | let groupItem = new contentWindow.GroupItem([], {bounds: box, immediately: true}); |
michael@0 | 18 | |
michael@0 | 19 | contentWindow.UI.setActive(groupItem); |
michael@0 | 20 | gBrowser.loadOneTab("about:blank", {inBackground: true}); |
michael@0 | 21 | |
michael@0 | 22 | return groupItem; |
michael@0 | 23 | }; |
michael@0 | 24 | |
michael@0 | 25 | // create group one and two |
michael@0 | 26 | let groupOne = createGroupItem(20, 20, 300, 300); |
michael@0 | 27 | let groupTwo = createGroupItem(20, 400, 300, 300); |
michael@0 | 28 | |
michael@0 | 29 | waitForFocus(function () { |
michael@0 | 30 | addTest(contentWindow, groupOne.id, groupTwo.id, originalTab); |
michael@0 | 31 | }); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function addTest(contentWindow, groupOneId, groupTwoId, originalTab) { |
michael@0 | 35 | let groupOne = contentWindow.GroupItems.groupItem(groupOneId); |
michael@0 | 36 | let groupTwo = contentWindow.GroupItems.groupItem(groupTwoId); |
michael@0 | 37 | let groupOneTabItemCount = groupOne.getChildren().length; |
michael@0 | 38 | let groupTwoTabItemCount = groupTwo.getChildren().length; |
michael@0 | 39 | is(groupOneTabItemCount, 1, "GroupItem one has one tab"); |
michael@0 | 40 | is(groupTwoTabItemCount, 1, "GroupItem two has one tab as well"); |
michael@0 | 41 | |
michael@0 | 42 | let tabItem = groupOne.getChild(0); |
michael@0 | 43 | ok(tabItem, "The tab item exists"); |
michael@0 | 44 | |
michael@0 | 45 | // calculate the offsets |
michael@0 | 46 | let groupTwoRectCenter = groupTwo.getBounds().center(); |
michael@0 | 47 | let tabItemRectCenter = tabItem.getBounds().center(); |
michael@0 | 48 | let offsetX = |
michael@0 | 49 | Math.round(groupTwoRectCenter.x - tabItemRectCenter.x); |
michael@0 | 50 | let offsetY = |
michael@0 | 51 | Math.round(groupTwoRectCenter.y - tabItemRectCenter.y); |
michael@0 | 52 | |
michael@0 | 53 | function endGame() { |
michael@0 | 54 | groupTwo.removeSubscriber("childAdded", endGame); |
michael@0 | 55 | |
michael@0 | 56 | is(groupOne.getChildren().length, --groupOneTabItemCount, |
michael@0 | 57 | "The number of children in group one is decreased by 1"); |
michael@0 | 58 | is(groupTwo.getChildren().length, ++groupTwoTabItemCount, |
michael@0 | 59 | "The number of children in group two is increased by 1"); |
michael@0 | 60 | |
michael@0 | 61 | closeGroupItem(groupOne, function () { |
michael@0 | 62 | closeGroupItem(groupTwo, function () hideTabView(finish)); |
michael@0 | 63 | }); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | groupTwo.addSubscriber("childAdded", endGame); |
michael@0 | 67 | simulateDragDrop(tabItem.container, offsetX, offsetY, contentWindow); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function simulateDragDrop(element, offsetX, offsetY, contentWindow) { |
michael@0 | 71 | let rect = element.getBoundingClientRect(); |
michael@0 | 72 | let startX = (rect.right - rect.left)/2; |
michael@0 | 73 | let startY = (rect.bottom - rect.top)/2; |
michael@0 | 74 | let incrementX = offsetX / 2; |
michael@0 | 75 | let incrementY = offsetY / 2; |
michael@0 | 76 | |
michael@0 | 77 | EventUtils.synthesizeMouse( |
michael@0 | 78 | element, startX, startY, { type: "mousedown" }); |
michael@0 | 79 | |
michael@0 | 80 | for (let i = 1; i <= 2; i++) { |
michael@0 | 81 | EventUtils.synthesizeMouse( |
michael@0 | 82 | element, (startX + incrementX * i), (startY + incrementY * i), |
michael@0 | 83 | { type: "mousemove" }); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | EventUtils.synthesizeMouse( |
michael@0 | 87 | element, (startX + incrementX * 2), (startY + incrementY * 2), |
michael@0 | 88 | { type: "mouseup" }); |
michael@0 | 89 | } |