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: waitForExplicitFinish(); michael@0: michael@0: window.addEventListener("tabviewshown", onTabViewWindowLoaded, false); michael@0: if (TabView.isVisible()) michael@0: onTabViewWindowLoaded(); michael@0: else michael@0: TabView.show(); michael@0: } michael@0: michael@0: function onTabViewWindowLoaded() { michael@0: window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false); michael@0: michael@0: ok(TabView.isVisible(), "Tab View is visible"); michael@0: michael@0: let contentWindow = document.getElementById("tab-view").contentWindow; michael@0: let [originalTab] = gBrowser.visibleTabs; michael@0: michael@0: // Create a first tab and orphan it michael@0: let firstTab = gBrowser.loadOneTab("about:blank#1", {inBackground: true}); michael@0: let firstTabItem = firstTab._tabViewTabItem; michael@0: let currentGroup = contentWindow.GroupItems.getActiveGroupItem(); michael@0: ok(currentGroup.getChildren().some(function(child) child == firstTabItem),"The first tab was made in the current group"); michael@0: contentWindow.GroupItems.getActiveGroupItem().remove(firstTabItem); michael@0: ok(!currentGroup.getChildren().some(function(child) child == firstTabItem),"The first tab was orphaned"); michael@0: michael@0: // Create a group and make it active michael@0: let box = new contentWindow.Rect(10, 10, 300, 300); michael@0: let group = new contentWindow.GroupItem([], { bounds: box }); michael@0: ok(group.isEmpty(), "This group is empty"); michael@0: contentWindow.UI.setActive(group); michael@0: michael@0: // Create a second tab in this new group michael@0: let secondTab = gBrowser.loadOneTab("about:blank#2", {inBackground: true}); michael@0: let secondTabItem = secondTab._tabViewTabItem; michael@0: ok(group.getChildren().some(function(child) child == secondTabItem),"The second tab was made in our new group"); michael@0: is(group.getChildren().length, 1, "Only one tab in the first group"); michael@0: isnot(firstTab.linkedBrowser.currentURI.spec, secondTab.linkedBrowser.currentURI.spec, "The two tabs must have different locations"); michael@0: michael@0: // Add the first tab to the group *programmatically*, without specifying a dropPos michael@0: group.add(firstTabItem); michael@0: is(group.getChildren().length, 2, "Two tabs in the group"); michael@0: michael@0: is(group.getChildren()[0].tab.linkedBrowser.currentURI.spec, secondTab.linkedBrowser.currentURI.spec, "The second tab was there first"); michael@0: is(group.getChildren()[1].tab.linkedBrowser.currentURI.spec, firstTab.linkedBrowser.currentURI.spec, "The first tab was just added and went to the end of the line"); michael@0: michael@0: group.addSubscriber("close", function onClose() { michael@0: group.removeSubscriber("close", onClose); michael@0: michael@0: ok(group.isEmpty(), "The group is empty again"); michael@0: michael@0: is(contentWindow.GroupItems.getActiveGroupItem(), currentGroup, "There is an active group"); michael@0: is(gBrowser.tabs.length, 1, "There is only one tab left"); michael@0: is(gBrowser.visibleTabs.length, 1, "There is also only one visible tab"); michael@0: michael@0: let onTabViewHidden = function() { michael@0: window.removeEventListener("tabviewhidden", onTabViewHidden, false); michael@0: finish(); michael@0: }; michael@0: window.addEventListener("tabviewhidden", onTabViewHidden, false); michael@0: gBrowser.selectedTab = originalTab; michael@0: michael@0: TabView.hide(); michael@0: }); michael@0: michael@0: // Get rid of the group and its children michael@0: group.closeAll(); michael@0: // close undo group michael@0: let closeButton = group.$undoContainer.find(".close"); michael@0: EventUtils.sendMouseEvent( michael@0: { type: "click" }, closeButton[0], contentWindow); michael@0: } michael@0: michael@0: function simulateDragDrop(srcElement, offsetX, offsetY, contentWindow) { michael@0: // enter drag mode michael@0: let dataTransfer; michael@0: michael@0: EventUtils.synthesizeMouse( michael@0: srcElement, 1, 1, { type: "mousedown" }, contentWindow); michael@0: event = contentWindow.document.createEvent("DragEvents"); michael@0: event.initDragEvent( michael@0: "dragenter", true, true, contentWindow, 0, 0, 0, 0, 0, michael@0: false, false, false, false, 1, null, dataTransfer); michael@0: srcElement.dispatchEvent(event); michael@0: michael@0: // drag over michael@0: for (let i = 4; i >= 0; i--) michael@0: EventUtils.synthesizeMouse( michael@0: srcElement, Math.round(offsetX/5), Math.round(offsetY/4), michael@0: { type: "mousemove" }, contentWindow); michael@0: event = contentWindow.document.createEvent("DragEvents"); michael@0: event.initDragEvent( michael@0: "dragover", true, true, contentWindow, 0, 0, 0, 0, 0, michael@0: false, false, false, false, 0, null, dataTransfer); michael@0: srcElement.dispatchEvent(event); michael@0: michael@0: // drop michael@0: EventUtils.synthesizeMouse(srcElement, 0, 0, { type: "mouseup" }, contentWindow); michael@0: event = contentWindow.document.createEvent("DragEvents"); michael@0: event.initDragEvent( michael@0: "drop", true, true, contentWindow, 0, 0, 0, 0, 0, michael@0: false, false, false, false, 0, null, dataTransfer); michael@0: srcElement.dispatchEvent(event); michael@0: }