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 | requestLongerTimeout(2); |
michael@0 | 7 | newWindowWithTabView(onTabViewWindowLoaded); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | function onTabViewWindowLoaded(win) { |
michael@0 | 11 | ok(win.TabView.isVisible(), "Tab View is visible"); |
michael@0 | 12 | |
michael@0 | 13 | let contentWindow = win.document.getElementById("tab-view").contentWindow; |
michael@0 | 14 | let [originalTab] = win.gBrowser.visibleTabs; |
michael@0 | 15 | let currentGroup = contentWindow.GroupItems.getActiveGroupItem(); |
michael@0 | 16 | |
michael@0 | 17 | // let's create a group small enough to get stacked |
michael@0 | 18 | let group = new contentWindow.GroupItem([], { |
michael@0 | 19 | immediately: true, |
michael@0 | 20 | bounds: {left: 20, top: 300, width: 400, height: 400} |
michael@0 | 21 | }); |
michael@0 | 22 | |
michael@0 | 23 | let expander = contentWindow.iQ(group.container).find(".stackExpander"); |
michael@0 | 24 | ok("length" in expander && expander.length == 1, "The group has an expander."); |
michael@0 | 25 | |
michael@0 | 26 | // procreate! |
michael@0 | 27 | contentWindow.UI.setActive(group); |
michael@0 | 28 | for (var i=0; i<7; i++) { |
michael@0 | 29 | win.gBrowser.loadOneTab('http://example.com#' + i, {inBackground: true}); |
michael@0 | 30 | } |
michael@0 | 31 | let children = group.getChildren(); |
michael@0 | 32 | |
michael@0 | 33 | // Wait until they all update because, once updated, they will notice that they |
michael@0 | 34 | // don't have favicons and this will change their styling at some unknown time. |
michael@0 | 35 | afterAllTabItemsUpdated(function() { |
michael@0 | 36 | ok(!group.shouldStack(group._children.length), "The group should not stack."); |
michael@0 | 37 | is(expander[0].style.display, "none", "The expander is hidden."); |
michael@0 | 38 | |
michael@0 | 39 | // now resize the group down. |
michael@0 | 40 | group.setSize(100, 100, true); |
michael@0 | 41 | |
michael@0 | 42 | ok(group.shouldStack(group._children.length), "The group should stack."); |
michael@0 | 43 | isnot(expander[0].style.display, "none", "The expander is now visible!"); |
michael@0 | 44 | let expanderBounds = expander.bounds(); |
michael@0 | 45 | ok(group.getBounds().contains(expanderBounds), "The expander lies in the group."); |
michael@0 | 46 | let stackCenter = children[0].getBounds().center(); |
michael@0 | 47 | ok(stackCenter.y < expanderBounds.center().y, "The expander is below the stack."); |
michael@0 | 48 | |
michael@0 | 49 | // STAGE 1: |
michael@0 | 50 | // Here, we just expand the group, click elsewhere, and make sure |
michael@0 | 51 | // it collapsed. |
michael@0 | 52 | let stage1expanded = function() { |
michael@0 | 53 | group.removeSubscriber("expanded", stage1expanded); |
michael@0 | 54 | |
michael@0 | 55 | ok(group.expanded, "The group is now expanded."); |
michael@0 | 56 | is(expander[0].style.display, "none", "The expander is hidden!"); |
michael@0 | 57 | |
michael@0 | 58 | let overlay = contentWindow.document.getElementById("expandedTray"); |
michael@0 | 59 | ok(overlay, "The expanded tray exists."); |
michael@0 | 60 | let $overlay = contentWindow.iQ(overlay); |
michael@0 | 61 | |
michael@0 | 62 | group.addSubscriber("collapsed", stage1collapsed); |
michael@0 | 63 | // null type means "click", for some reason... |
michael@0 | 64 | EventUtils.synthesizeMouse(contentWindow.document.body, 10, $overlay.bounds().bottom + 5, |
michael@0 | 65 | {type: null}, contentWindow); |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | let stage1collapsed = function() { |
michael@0 | 69 | group.removeSubscriber("collapsed", stage1collapsed); |
michael@0 | 70 | ok(!group.expanded, "The group is no longer expanded."); |
michael@0 | 71 | isnot(expander[0].style.display, "none", "The expander is visible!"); |
michael@0 | 72 | let expanderBounds = expander.bounds(); |
michael@0 | 73 | ok(group.getBounds().contains(expanderBounds), "The expander still lies in the group."); |
michael@0 | 74 | let stackCenter = children[0].getBounds().center(); |
michael@0 | 75 | ok(stackCenter.y < expanderBounds.center().y, "The expander is below the stack."); |
michael@0 | 76 | |
michael@0 | 77 | // now, try opening it up again. |
michael@0 | 78 | group.addSubscriber("expanded", stage2expanded); |
michael@0 | 79 | EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow); |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | // STAGE 2: |
michael@0 | 83 | // Now make sure every child of the group shows up within this "tray", and |
michael@0 | 84 | // click on one of them and make sure we go into the tab and the tray collapses. |
michael@0 | 85 | let stage2expanded = function() { |
michael@0 | 86 | group.removeSubscriber("expanded", stage2expanded); |
michael@0 | 87 | |
michael@0 | 88 | ok(group.expanded, "The group is now expanded."); |
michael@0 | 89 | is(expander[0].style.display, "none", "The expander is hidden!"); |
michael@0 | 90 | |
michael@0 | 91 | let overlay = contentWindow.document.getElementById("expandedTray"); |
michael@0 | 92 | ok(overlay, "The expanded tray exists."); |
michael@0 | 93 | let $overlay = contentWindow.iQ(overlay); |
michael@0 | 94 | let overlayBounds = $overlay.bounds(); |
michael@0 | 95 | |
michael@0 | 96 | children.forEach(function(child, i) { |
michael@0 | 97 | ok(overlayBounds.contains(child.getBounds()), "Child " + i + " is in the overlay"); |
michael@0 | 98 | }); |
michael@0 | 99 | |
michael@0 | 100 | win.addEventListener("tabviewhidden", stage2hidden, false); |
michael@0 | 101 | // again, null type means "click", for some reason... |
michael@0 | 102 | EventUtils.synthesizeMouse(children[1].container, 2, 2, {type: null}, contentWindow); |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | let stage2hidden = function() { |
michael@0 | 106 | win.removeEventListener("tabviewhidden", stage2hidden, false); |
michael@0 | 107 | |
michael@0 | 108 | is(win.gBrowser.selectedTab, children[1].tab, "We clicked on the second child."); |
michael@0 | 109 | |
michael@0 | 110 | win.addEventListener("tabviewshown", stage2shown, false); |
michael@0 | 111 | win.TabView.toggle(); |
michael@0 | 112 | }; |
michael@0 | 113 | |
michael@0 | 114 | let stage2shown = function() { |
michael@0 | 115 | win.removeEventListener("tabviewshown", stage2shown, false); |
michael@0 | 116 | ok(!group.expanded, "The group is not expanded."); |
michael@0 | 117 | isnot(expander[0].style.display, "none", "The expander is visible!"); |
michael@0 | 118 | let expanderBounds = expander.bounds(); |
michael@0 | 119 | ok(group.getBounds().contains(expanderBounds), "The expander still lies in the group."); |
michael@0 | 120 | let stackCenter = children[0].getBounds().center(); |
michael@0 | 121 | ok(stackCenter.y < expanderBounds.center().y, "The expander is below the stack."); |
michael@0 | 122 | |
michael@0 | 123 | is(group.getTopChild(), children[1], "The top child in the stack is the second tab item"); |
michael@0 | 124 | let topChildzIndex = children[1].zIndex; |
michael@0 | 125 | // the second tab item should have the largest z-index. |
michael@0 | 126 | // only check the first 6 tabs as the stack only contains 6 tab items. |
michael@0 | 127 | for (let i = 0; i < 6; i++) { |
michael@0 | 128 | if (i != 1) |
michael@0 | 129 | ok(children[i].zIndex < topChildzIndex, |
michael@0 | 130 | "The child[" + i + "] has smaller zIndex than second child"); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | // okay, expand this group one last time |
michael@0 | 134 | group.addSubscriber("expanded", stage3expanded); |
michael@0 | 135 | EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | // STAGE 3: |
michael@0 | 139 | // Ensure that stack still shows the same top item after a expand and a collapse. |
michael@0 | 140 | let stage3expanded = function() { |
michael@0 | 141 | group.removeSubscriber("expanded", stage3expanded); |
michael@0 | 142 | |
michael@0 | 143 | ok(group.expanded, "The group is now expanded."); |
michael@0 | 144 | let overlay = contentWindow.document.getElementById("expandedTray"); |
michael@0 | 145 | let $overlay = contentWindow.iQ(overlay); |
michael@0 | 146 | |
michael@0 | 147 | group.addSubscriber("collapsed", stage3collapsed); |
michael@0 | 148 | // null type means "click", for some reason... |
michael@0 | 149 | EventUtils.synthesizeMouse(contentWindow.document.body, 10, $overlay.bounds().bottom + 5, |
michael@0 | 150 | {type: null}, contentWindow); |
michael@0 | 151 | }; |
michael@0 | 152 | |
michael@0 | 153 | let stage3collapsed = function() { |
michael@0 | 154 | group.removeSubscriber("collapsed", stage3collapsed); |
michael@0 | 155 | |
michael@0 | 156 | ok(!group.expanded, "The group is no longer expanded."); |
michael@0 | 157 | isnot(expander[0].style.display, "none", "The expander is visible!"); |
michael@0 | 158 | |
michael@0 | 159 | let stackCenter = children[0].getBounds().center(); |
michael@0 | 160 | ok(stackCenter.y < expanderBounds.center().y, "The expander is below the stack."); |
michael@0 | 161 | |
michael@0 | 162 | is(group.getTopChild(), children[1], |
michael@0 | 163 | "The top child in the stack is still the second tab item"); |
michael@0 | 164 | let topChildzIndex = children[1].zIndex; |
michael@0 | 165 | // the second tab item should have the largest z-index. |
michael@0 | 166 | // only check the first 6 tabs as the stack only contains 6 tab items. |
michael@0 | 167 | for (let i = 0; i < 6; i++) { |
michael@0 | 168 | if (i != 1) |
michael@0 | 169 | ok(children[i].zIndex < topChildzIndex, |
michael@0 | 170 | "The child[" + i + "] has smaller zIndex than second dhild after a collapse."); |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | // In preparation for Stage 4, find that original tab and make it the active tab. |
michael@0 | 174 | let originalTabItem = originalTab._tabViewTabItem; |
michael@0 | 175 | contentWindow.UI.setActive(originalTabItem); |
michael@0 | 176 | |
michael@0 | 177 | // now, try opening it up again. |
michael@0 | 178 | group.addSubscriber("expanded", stage4expanded); |
michael@0 | 179 | EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow); |
michael@0 | 180 | }; |
michael@0 | 181 | |
michael@0 | 182 | // STAGE 4: |
michael@0 | 183 | // Activate another tab not in this group, expand our stacked group, but then |
michael@0 | 184 | // enter Panorama (i.e., zoom into this other group), and make sure we can go to |
michael@0 | 185 | // it and that the tray gets collapsed. |
michael@0 | 186 | let stage4expanded = function() { |
michael@0 | 187 | group.removeSubscriber("expanded", stage4expanded); |
michael@0 | 188 | |
michael@0 | 189 | ok(group.expanded, "The group is now expanded."); |
michael@0 | 190 | is(expander[0].style.display, "none", "The expander is hidden!"); |
michael@0 | 191 | let overlay = contentWindow.document.getElementById("expandedTray"); |
michael@0 | 192 | ok(overlay, "The expanded tray exists."); |
michael@0 | 193 | |
michael@0 | 194 | let activeTab = contentWindow.UI.getActiveTab(); |
michael@0 | 195 | ok(activeTab, "There is an active tab."); |
michael@0 | 196 | let originalTabItem = originalTab._tabViewTabItem; |
michael@0 | 197 | |
michael@0 | 198 | isnot(activeTab, originalTabItem, "But it's not what it was a moment ago."); |
michael@0 | 199 | let someChildIsActive = group.getChildren().some(function(child) |
michael@0 | 200 | child == activeTab); |
michael@0 | 201 | ok(someChildIsActive, "Now one of the children in the group is active."); |
michael@0 | 202 | |
michael@0 | 203 | // now activate Panorama... |
michael@0 | 204 | win.addEventListener("tabviewhidden", stage4hidden, false); |
michael@0 | 205 | win.TabView.toggle(); |
michael@0 | 206 | }; |
michael@0 | 207 | |
michael@0 | 208 | let stage4hidden = function() { |
michael@0 | 209 | win.removeEventListener("tabviewhidden", stage4hidden, false); |
michael@0 | 210 | |
michael@0 | 211 | isnot(win.gBrowser.selectedTab, originalTab, "We did not enter the original tab."); |
michael@0 | 212 | |
michael@0 | 213 | let someChildIsSelected = group.getChildren().some(function(child) |
michael@0 | 214 | child.tab == win.gBrowser.selectedTab); |
michael@0 | 215 | ok(someChildIsSelected, "Instead we're in one of the stack's children."); |
michael@0 | 216 | |
michael@0 | 217 | win.addEventListener("tabviewshown", stage4shown, false); |
michael@0 | 218 | win.TabView.toggle(); |
michael@0 | 219 | }; |
michael@0 | 220 | |
michael@0 | 221 | let stage4shown = function() { |
michael@0 | 222 | win.removeEventListener("tabviewshown", stage4shown, false); |
michael@0 | 223 | |
michael@0 | 224 | let overlay = contentWindow.document.getElementById("expandedTray"); |
michael@0 | 225 | ok(!group.expanded, "The group is no longer expanded."); |
michael@0 | 226 | isnot(expander[0].style.display, "none", "The expander is visible!"); |
michael@0 | 227 | |
michael@0 | 228 | win.close(); |
michael@0 | 229 | finish(); |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | // get the ball rolling |
michael@0 | 233 | group.addSubscriber("expanded", stage1expanded); |
michael@0 | 234 | EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow); |
michael@0 | 235 | }, win); |
michael@0 | 236 | } |