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 | newWindowWithTabView(onTabViewWindowLoaded, null, 1000, 800); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | function onTabViewWindowLoaded(win) { |
michael@0 | 11 | let contentWindow = win.document.getElementById("tab-view").contentWindow; |
michael@0 | 12 | let [originalTab] = win.gBrowser.visibleTabs; |
michael@0 | 13 | |
michael@0 | 14 | ok(win.TabView.isVisible(), "Tab View is visible"); |
michael@0 | 15 | is(contentWindow.GroupItems.groupItems.length, 1, "There is only one group"); |
michael@0 | 16 | let currentActiveGroup = contentWindow.GroupItems.getActiveGroupItem(); |
michael@0 | 17 | |
michael@0 | 18 | // Create a group |
michael@0 | 19 | // Note: 150 x 150 should be larger than the minimum size for a group item |
michael@0 | 20 | let firstBox = new contentWindow.Rect(80, 80, 160, 160); |
michael@0 | 21 | let firstGroup = new contentWindow.GroupItem([], { bounds: firstBox, |
michael@0 | 22 | immediately: true }); |
michael@0 | 23 | ok(firstGroup.getBounds().equals(firstBox), "This group got its bounds"); |
michael@0 | 24 | |
michael@0 | 25 | // Create a second group |
michael@0 | 26 | let secondBox = new contentWindow.Rect(80, 280, 160, 160); |
michael@0 | 27 | let secondGroup = new contentWindow.GroupItem([], { bounds: secondBox, |
michael@0 | 28 | immediately: true }); |
michael@0 | 29 | ok(secondGroup.getBounds().equals(secondBox), "This second group got its bounds"); |
michael@0 | 30 | |
michael@0 | 31 | // A third group is created later, but multiple functions need access to it. |
michael@0 | 32 | let thirdGroup = null; |
michael@0 | 33 | |
michael@0 | 34 | is(secondGroup.getBounds().top - firstGroup.getBounds().bottom, 40, |
michael@0 | 35 | "There's currently 40 px between the first group and second group"); |
michael@0 | 36 | |
michael@0 | 37 | let endGame = function() { |
michael@0 | 38 | firstGroup.container.parentNode.removeChild(firstGroup.container); |
michael@0 | 39 | firstGroup.close(); |
michael@0 | 40 | thirdGroup.container.parentNode.removeChild(thirdGroup.container); |
michael@0 | 41 | thirdGroup.close(); |
michael@0 | 42 | |
michael@0 | 43 | win.close(); |
michael@0 | 44 | ok(win.closed, "new window is closed"); |
michael@0 | 45 | finish(); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | let continueWithPart2 = function() { |
michael@0 | 49 | |
michael@0 | 50 | ok(firstGroup.getBounds().equals(firstBox), "The first group should still have its bounds"); |
michael@0 | 51 | |
michael@0 | 52 | // Create a third group |
michael@0 | 53 | let thirdBox = new contentWindow.Rect(80, 280, 200, 160); |
michael@0 | 54 | thirdGroup = new contentWindow.GroupItem([], { bounds: thirdBox, |
michael@0 | 55 | immediately: true }); |
michael@0 | 56 | ok(thirdGroup.getBounds().equals(thirdBox), "This third group got its bounds"); |
michael@0 | 57 | |
michael@0 | 58 | is(thirdGroup.getBounds().top - firstGroup.getBounds().bottom, 40, |
michael@0 | 59 | "There's currently 40 px between the first group and third group"); |
michael@0 | 60 | |
michael@0 | 61 | // Just move it to the left and drop it. |
michael@0 | 62 | checkSnap(thirdGroup, 0, 0, contentWindow, function(snapped){ |
michael@0 | 63 | ok(!snapped,"Offset: Just move it to the left and drop it"); |
michael@0 | 64 | |
michael@0 | 65 | // Move the second group up 10 px. It shouldn't snap yet. |
michael@0 | 66 | checkSnap(thirdGroup, 0, -10, contentWindow, function(snapped){ |
michael@0 | 67 | ok(!snapped,"Offset: Moving up 10 should not snap"); |
michael@0 | 68 | |
michael@0 | 69 | // Move the second group up 10 px. It now should snap. |
michael@0 | 70 | checkSnap(thirdGroup, 0, -10, contentWindow, function(snapped){ |
michael@0 | 71 | ok(snapped,"Offset: Moving up 10 again should snap!"); |
michael@0 | 72 | endGame(); |
michael@0 | 73 | }); |
michael@0 | 74 | }); |
michael@0 | 75 | }); |
michael@0 | 76 | }; |
michael@0 | 77 | |
michael@0 | 78 | let part1 = function() { |
michael@0 | 79 | // Just pick it up and drop it. |
michael@0 | 80 | checkSnap(secondGroup, 0, 0, contentWindow, function(snapped){ |
michael@0 | 81 | ok(!snapped,"Right under: Just pick it up and drop it"); |
michael@0 | 82 | |
michael@0 | 83 | // Move the second group up 10 px. It shouldn't snap yet. |
michael@0 | 84 | checkSnap(secondGroup, 0, -10, contentWindow, function(snapped){ |
michael@0 | 85 | ok(!snapped,"Right under: Moving up 10 should not snap"); |
michael@0 | 86 | |
michael@0 | 87 | // Move the second group up 10 px. It now should snap. |
michael@0 | 88 | checkSnap(secondGroup, 0, -10, contentWindow, function(snapped){ |
michael@0 | 89 | ok(snapped,"Right under: Moving up 10 again should snap!"); |
michael@0 | 90 | // cheat by removing the second group, so that we disappear immediately |
michael@0 | 91 | secondGroup.container.parentNode.removeChild(secondGroup.container); |
michael@0 | 92 | secondGroup.close(); |
michael@0 | 93 | continueWithPart2(); |
michael@0 | 94 | }); |
michael@0 | 95 | }); |
michael@0 | 96 | }); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | part1(); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function simulateDragDrop(tabItem, offsetX, offsetY, contentWindow) { |
michael@0 | 103 | // enter drag mode |
michael@0 | 104 | let dataTransfer; |
michael@0 | 105 | |
michael@0 | 106 | EventUtils.synthesizeMouse( |
michael@0 | 107 | tabItem.container, 1, 1, { type: "mousedown" }, contentWindow); |
michael@0 | 108 | let event = contentWindow.document.createEvent("DragEvents"); |
michael@0 | 109 | event.initDragEvent( |
michael@0 | 110 | "dragenter", true, true, contentWindow, 0, 0, 0, 0, 0, |
michael@0 | 111 | false, false, false, false, 1, null, dataTransfer); |
michael@0 | 112 | tabItem.container.dispatchEvent(event); |
michael@0 | 113 | |
michael@0 | 114 | // drag over |
michael@0 | 115 | if (offsetX || offsetY) { |
michael@0 | 116 | let Ci = Components.interfaces; |
michael@0 | 117 | let utils = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor). |
michael@0 | 118 | getInterface(Ci.nsIDOMWindowUtils); |
michael@0 | 119 | let rect = tabItem.getBounds(); |
michael@0 | 120 | for (let i = 1; i <= 5; i++) { |
michael@0 | 121 | let left = rect.left + 1 + Math.round(i * offsetX / 5); |
michael@0 | 122 | let top = rect.top + 1 + Math.round(i * offsetY / 5); |
michael@0 | 123 | utils.sendMouseEvent("mousemove", left, top, 0, 1, 0); |
michael@0 | 124 | } |
michael@0 | 125 | event = contentWindow.document.createEvent("DragEvents"); |
michael@0 | 126 | event.initDragEvent( |
michael@0 | 127 | "dragover", true, true, contentWindow, 0, 0, 0, 0, 0, |
michael@0 | 128 | false, false, false, false, 0, null, dataTransfer); |
michael@0 | 129 | tabItem.container.dispatchEvent(event); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | // drop |
michael@0 | 133 | EventUtils.synthesizeMouse( |
michael@0 | 134 | tabItem.container, 0, 0, { type: "mouseup" }, contentWindow); |
michael@0 | 135 | event = contentWindow.document.createEvent("DragEvents"); |
michael@0 | 136 | event.initDragEvent( |
michael@0 | 137 | "drop", true, true, contentWindow, 0, 0, 0, 0, 0, |
michael@0 | 138 | false, false, false, false, 0, null, dataTransfer); |
michael@0 | 139 | tabItem.container.dispatchEvent(event); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | function checkSnap(item, offsetX, offsetY, contentWindow, callback) { |
michael@0 | 143 | let firstTop = item.getBounds().top; |
michael@0 | 144 | let firstLeft = item.getBounds().left; |
michael@0 | 145 | let onDrop = function() { |
michael@0 | 146 | let snapped = false; |
michael@0 | 147 | item.container.removeEventListener('drop', onDrop, false); |
michael@0 | 148 | if (item.getBounds().top != firstTop + offsetY) |
michael@0 | 149 | snapped = true; |
michael@0 | 150 | if (item.getBounds().left != firstLeft + offsetX) |
michael@0 | 151 | snapped = true; |
michael@0 | 152 | callback(snapped); |
michael@0 | 153 | }; |
michael@0 | 154 | item.container.addEventListener('drop', onDrop, false); |
michael@0 | 155 | simulateDragDrop(item, offsetX, offsetY, contentWindow); |
michael@0 | 156 | } |
michael@0 | 157 |