michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function test() { michael@0: let cw; michael@0: let groupItem; michael@0: michael@0: let getTabItemAspect = function (tabItem) { michael@0: let bounds = cw.iQ('.thumb', tabItem.container).bounds(); michael@0: let padding = cw.TabItems.tabItemPadding; michael@0: return (bounds.height + padding.y) / (bounds.width + padding.x); michael@0: } michael@0: michael@0: let getAspectRange = function () { michael@0: let aspect = cw.TabItems.tabAspect; michael@0: let variance = aspect / 100 * 1.5; michael@0: return new cw.Range(aspect - variance, aspect + variance); michael@0: } michael@0: michael@0: let dragTabItem = function (tabItem) { michael@0: let doc = cw.document.documentElement; michael@0: let tabItem = groupItem.getChild(0); michael@0: let container = tabItem.container; michael@0: let aspectRange = getAspectRange(); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(container, {type: "mousedown"}, cw); michael@0: for (let x = 200; x <= 400; x += 100) michael@0: EventUtils.synthesizeMouse(doc, x, 100, {type: "mousemove"}, cw); michael@0: ok(aspectRange.contains(getTabItemAspect(tabItem)), "tabItem's aspect is correct"); michael@0: michael@0: ok(!groupItem.getBounds().intersects(tabItem.getBounds()), "tabItem was moved out of group bounds"); michael@0: ok(!tabItem.parent, "tabItem is orphaned"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(container, {type: "mouseup"}, cw); michael@0: ok(aspectRange.contains(getTabItemAspect(tabItem)), "tabItem's aspect is correct"); michael@0: } michael@0: michael@0: let testDragOutOfStackedGroup = function () { michael@0: dragTabItem(); michael@0: michael@0: let secondGroup = cw.GroupItems.groupItems[1]; michael@0: closeGroupItem(secondGroup, testDragOutOfExpandedStackedGroup); michael@0: } michael@0: michael@0: let testDragOutOfExpandedStackedGroup = function () { michael@0: groupItem.addSubscriber("expanded", function onExpanded() { michael@0: groupItem.removeSubscriber("expanded", onExpanded); michael@0: dragTabItem(); michael@0: }); michael@0: michael@0: groupItem.addSubscriber("collapsed", function onCollapsed() { michael@0: groupItem.removeSubscriber("collapsed", onCollapsed); michael@0: michael@0: let secondGroup = cw.GroupItems.groupItems[1]; michael@0: closeGroupItem(secondGroup, function () hideTabView(finishTest)); michael@0: }); michael@0: michael@0: groupItem.expand(); michael@0: } michael@0: michael@0: let finishTest = function () { michael@0: is(cw.GroupItems.groupItems.length, 1, "there is one groupItem"); michael@0: is(gBrowser.tabs.length, 1, "there is one tab"); michael@0: ok(!TabView.isVisible(), "tabview is hidden"); michael@0: michael@0: finish(); michael@0: } michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: newWindowWithTabView(function (win) { michael@0: registerCleanupFunction(function () win.close()); michael@0: michael@0: cw = win.TabView.getContentWindow(); michael@0: michael@0: groupItem = cw.GroupItems.groupItems[0]; michael@0: groupItem.setSize(200, 200, true); michael@0: michael@0: for (let i = 0; i < 9; i++) michael@0: win.gBrowser.addTab(); michael@0: michael@0: ok(groupItem.isStacked(), "groupItem is stacked"); michael@0: testDragOutOfStackedGroup(); michael@0: }); michael@0: }