browser/components/tabview/test/browser_tabview_bug591706.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
michael@0 8 if (TabView.isVisible())
michael@0 9 onTabViewWindowLoaded();
michael@0 10 else
michael@0 11 TabView.show();
michael@0 12 }
michael@0 13
michael@0 14 function onTabViewWindowLoaded() {
michael@0 15 window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
michael@0 16
michael@0 17 ok(TabView.isVisible(), "Tab View is visible");
michael@0 18
michael@0 19 let contentWindow = document.getElementById("tab-view").contentWindow;
michael@0 20 let [originalTab] = gBrowser.visibleTabs;
michael@0 21
michael@0 22 // Create a first tab and orphan it
michael@0 23 let firstTab = gBrowser.loadOneTab("about:blank#1", {inBackground: true});
michael@0 24 let firstTabItem = firstTab._tabViewTabItem;
michael@0 25 let currentGroup = contentWindow.GroupItems.getActiveGroupItem();
michael@0 26 ok(currentGroup.getChildren().some(function(child) child == firstTabItem),"The first tab was made in the current group");
michael@0 27 contentWindow.GroupItems.getActiveGroupItem().remove(firstTabItem);
michael@0 28 ok(!currentGroup.getChildren().some(function(child) child == firstTabItem),"The first tab was orphaned");
michael@0 29
michael@0 30 // Create a group and make it active
michael@0 31 let box = new contentWindow.Rect(10, 10, 300, 300);
michael@0 32 let group = new contentWindow.GroupItem([], { bounds: box });
michael@0 33 ok(group.isEmpty(), "This group is empty");
michael@0 34 contentWindow.UI.setActive(group);
michael@0 35
michael@0 36 // Create a second tab in this new group
michael@0 37 let secondTab = gBrowser.loadOneTab("about:blank#2", {inBackground: true});
michael@0 38 let secondTabItem = secondTab._tabViewTabItem;
michael@0 39 ok(group.getChildren().some(function(child) child == secondTabItem),"The second tab was made in our new group");
michael@0 40 is(group.getChildren().length, 1, "Only one tab in the first group");
michael@0 41 isnot(firstTab.linkedBrowser.currentURI.spec, secondTab.linkedBrowser.currentURI.spec, "The two tabs must have different locations");
michael@0 42
michael@0 43 // Add the first tab to the group *programmatically*, without specifying a dropPos
michael@0 44 group.add(firstTabItem);
michael@0 45 is(group.getChildren().length, 2, "Two tabs in the group");
michael@0 46
michael@0 47 is(group.getChildren()[0].tab.linkedBrowser.currentURI.spec, secondTab.linkedBrowser.currentURI.spec, "The second tab was there first");
michael@0 48 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 49
michael@0 50 group.addSubscriber("close", function onClose() {
michael@0 51 group.removeSubscriber("close", onClose);
michael@0 52
michael@0 53 ok(group.isEmpty(), "The group is empty again");
michael@0 54
michael@0 55 is(contentWindow.GroupItems.getActiveGroupItem(), currentGroup, "There is an active group");
michael@0 56 is(gBrowser.tabs.length, 1, "There is only one tab left");
michael@0 57 is(gBrowser.visibleTabs.length, 1, "There is also only one visible tab");
michael@0 58
michael@0 59 let onTabViewHidden = function() {
michael@0 60 window.removeEventListener("tabviewhidden", onTabViewHidden, false);
michael@0 61 finish();
michael@0 62 };
michael@0 63 window.addEventListener("tabviewhidden", onTabViewHidden, false);
michael@0 64 gBrowser.selectedTab = originalTab;
michael@0 65
michael@0 66 TabView.hide();
michael@0 67 });
michael@0 68
michael@0 69 // Get rid of the group and its children
michael@0 70 group.closeAll();
michael@0 71 // close undo group
michael@0 72 let closeButton = group.$undoContainer.find(".close");
michael@0 73 EventUtils.sendMouseEvent(
michael@0 74 { type: "click" }, closeButton[0], contentWindow);
michael@0 75 }
michael@0 76
michael@0 77 function simulateDragDrop(srcElement, offsetX, offsetY, contentWindow) {
michael@0 78 // enter drag mode
michael@0 79 let dataTransfer;
michael@0 80
michael@0 81 EventUtils.synthesizeMouse(
michael@0 82 srcElement, 1, 1, { type: "mousedown" }, contentWindow);
michael@0 83 event = contentWindow.document.createEvent("DragEvents");
michael@0 84 event.initDragEvent(
michael@0 85 "dragenter", true, true, contentWindow, 0, 0, 0, 0, 0,
michael@0 86 false, false, false, false, 1, null, dataTransfer);
michael@0 87 srcElement.dispatchEvent(event);
michael@0 88
michael@0 89 // drag over
michael@0 90 for (let i = 4; i >= 0; i--)
michael@0 91 EventUtils.synthesizeMouse(
michael@0 92 srcElement, Math.round(offsetX/5), Math.round(offsetY/4),
michael@0 93 { type: "mousemove" }, contentWindow);
michael@0 94 event = contentWindow.document.createEvent("DragEvents");
michael@0 95 event.initDragEvent(
michael@0 96 "dragover", true, true, contentWindow, 0, 0, 0, 0, 0,
michael@0 97 false, false, false, false, 0, null, dataTransfer);
michael@0 98 srcElement.dispatchEvent(event);
michael@0 99
michael@0 100 // drop
michael@0 101 EventUtils.synthesizeMouse(srcElement, 0, 0, { type: "mouseup" }, contentWindow);
michael@0 102 event = contentWindow.document.createEvent("DragEvents");
michael@0 103 event.initDragEvent(
michael@0 104 "drop", true, true, contentWindow, 0, 0, 0, 0, 0,
michael@0 105 false, false, false, false, 0, null, dataTransfer);
michael@0 106 srcElement.dispatchEvent(event);
michael@0 107 }

mercurial