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