michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource:///modules/CustomizableUI.jsm"); michael@0: michael@0: michael@0: function test() { michael@0: let cw; michael@0: let win; michael@0: let prefix; michael@0: michael@0: let getToolbar = function () { michael@0: return win.document.getElementById("TabsToolbar"); michael@0: } michael@0: michael@0: let assertToolbarButtonExists = function () { michael@0: isnot(getToolbar().currentSet.indexOf("tabview-button"), -1, michael@0: prefix + ": panorama button should be in the toolbar"); michael@0: } michael@0: michael@0: let assertToolbarButtonNotExists = function () { michael@0: is(getToolbar().currentSet.indexOf("tabview-button"), -1, michael@0: prefix + ": panorama button should not be in the toolbar"); michael@0: } michael@0: michael@0: let assertNumberOfTabs = function (num) { michael@0: is(win.gBrowser.tabs.length, num, prefix + ': there are ' + num + ' tabs'); michael@0: } michael@0: michael@0: let removeToolbarButton = function () { michael@0: let toolbar = getToolbar(); michael@0: let currentSet = toolbar.currentSet.split(","); michael@0: let buttonId = "tabview-button"; michael@0: let pos = currentSet.indexOf(buttonId); michael@0: michael@0: if (-1 < pos) { michael@0: CustomizableUI.removeWidgetFromArea("tabview-button"); michael@0: } michael@0: } michael@0: michael@0: let testNameGroup = function () { michael@0: prefix = 'name-group'; michael@0: assertToolbarButtonNotExists(); michael@0: let groupItem = cw.GroupItems.groupItems[0]; michael@0: michael@0: groupItem.setTitle('title'); michael@0: assertToolbarButtonNotExists(); michael@0: groupItem.setTitle(''); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(groupItem.$titleShield[0], {}, cw); michael@0: EventUtils.synthesizeKey('t', {}, cw); michael@0: groupItem.$title[0].blur(); michael@0: michael@0: assertToolbarButtonExists(); michael@0: next(); michael@0: } michael@0: michael@0: let testDragToCreateGroup = function () { michael@0: prefix = 'drag-to-create-group'; michael@0: assertToolbarButtonNotExists(); michael@0: let width = cw.innerWidth; michael@0: let height = cw.innerHeight; michael@0: michael@0: let body = cw.document.body; michael@0: EventUtils.synthesizeMouse(body, width - 10, height - 10, {type: 'mousedown'}, cw); michael@0: EventUtils.synthesizeMouse(body, width - 200, height - 200, {type: 'mousemove'}, cw); michael@0: EventUtils.synthesizeMouse(body, width - 200, height - 200, {type: 'mouseup'}, cw); michael@0: michael@0: assertToolbarButtonExists(); michael@0: next(); michael@0: } michael@0: michael@0: let testCreateOrphan = function (tab) { michael@0: prefix = 'create-orphan'; michael@0: assertNumberOfTabs(1); michael@0: assertToolbarButtonNotExists(); michael@0: michael@0: let width = cw.innerWidth; michael@0: let height = cw.innerHeight; michael@0: michael@0: let body = cw.document.body; michael@0: EventUtils.synthesizeMouse(body, width - 10, height - 10, { clickCount: 2 }, cw); michael@0: michael@0: whenTabViewIsHidden(function () { michael@0: assertNumberOfTabs(2); michael@0: assertToolbarButtonExists(); michael@0: michael@0: next(); michael@0: }, win); michael@0: } michael@0: michael@0: let testDragToCreateOrphan = function (tab) { michael@0: if (!tab) { michael@0: let tab = win.gBrowser.loadOneTab('about:blank', {inBackground: true}); michael@0: afterAllTabsLoaded(function () testDragToCreateOrphan(tab), win); michael@0: return; michael@0: } michael@0: michael@0: prefix = 'drag-to-create-orphan'; michael@0: assertNumberOfTabs(2); michael@0: assertToolbarButtonNotExists(); michael@0: michael@0: let width = cw.innerWidth; michael@0: let height = cw.innerHeight; michael@0: michael@0: let target = tab._tabViewTabItem.container; michael@0: let rect = target.getBoundingClientRect(); michael@0: EventUtils.synthesizeMouseAtCenter(target, {type: 'mousedown'}, cw); michael@0: EventUtils.synthesizeMouse(target, rect.width - 10, rect.height - 10, {type: 'mousemove'}, cw); michael@0: EventUtils.synthesizeMouse(target, width - 300, height - 300, {type: 'mousemove'}, cw); michael@0: EventUtils.synthesizeMouse(target, width - 200, height - 200, {type: 'mousemove'}, cw); michael@0: EventUtils.synthesizeMouseAtCenter(target, {type: 'mouseup'}, cw); michael@0: michael@0: assertToolbarButtonExists(); michael@0: next(); michael@0: } michael@0: michael@0: let testReAddingAfterRemoval = function () { michael@0: prefix = 're-adding-after-removal'; michael@0: assertToolbarButtonNotExists(); michael@0: michael@0: win.TabView.firstUseExperienced = true; michael@0: assertToolbarButtonExists(); michael@0: removeToolbarButton(); michael@0: assertToolbarButtonNotExists(); michael@0: michael@0: win.close(); michael@0: michael@0: newWindowWithTabView(function (newWin) { michael@0: win = newWin; michael@0: win.TabView.firstUseExperienced = true; michael@0: assertToolbarButtonNotExists(); michael@0: next(); michael@0: }); michael@0: } michael@0: michael@0: let tests = [testNameGroup, testDragToCreateGroup, testCreateOrphan, michael@0: testDragToCreateOrphan, testReAddingAfterRemoval]; michael@0: michael@0: let next = function () { michael@0: if (win) michael@0: win.close(); michael@0: michael@0: let test = tests.shift(); michael@0: michael@0: if (!test) { michael@0: finish(); michael@0: return; michael@0: } michael@0: michael@0: TabView.firstUseExperienced = false; michael@0: michael@0: let onLoad = function (newWin) { michael@0: win = newWin; michael@0: removeToolbarButton(); michael@0: }; michael@0: michael@0: let onShow = function () { michael@0: cw = win.TabView.getContentWindow(); michael@0: michael@0: let groupItem = cw.GroupItems.groupItems[0]; michael@0: groupItem.setSize(200, 200, true); michael@0: groupItem.setUserSize(); michael@0: michael@0: SimpleTest.waitForFocus(function () { michael@0: assertToolbarButtonNotExists(); michael@0: test(); michael@0: }, cw); michael@0: }; michael@0: michael@0: newWindowWithTabView(onShow, onLoad); michael@0: } michael@0: michael@0: waitForExplicitFinish(); michael@0: requestLongerTimeout(2); michael@0: michael@0: next(); michael@0: }