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 // verify initial state
8 ok(!TabView.isVisible(), "Tab View starts hidden");
10 window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
11 TabView.toggle();
12 }
14 let originalGroupItem = null;
15 let originalTab = null;
16 let contentWindow = null;
18 function onTabViewWindowLoaded() {
19 window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
20 ok(TabView.isVisible(), "Tab View is visible");
22 contentWindow = document.getElementById("tab-view").contentWindow;
24 is(contentWindow.GroupItems.groupItems.length, 1, "There is one group item on startup");
25 originalGroupItem = contentWindow.GroupItems.groupItems[0];
26 is(originalGroupItem.getChildren().length, 1, "There should be one Tab Item in that group.");
27 contentWindow.UI.setActive(originalGroupItem);
29 [originalTab] = gBrowser.visibleTabs;
31 testEmptyGroupItem(contentWindow);
32 }
34 function testEmptyGroupItem(contentWindow) {
35 let groupItemCount = contentWindow.GroupItems.groupItems.length;
37 // Preparation
38 //
40 // create empty group item
41 let emptyGroupItem = createEmptyGroupItem(contentWindow, 253, 335, 100);
42 ok(emptyGroupItem.isEmpty(), "This group is empty");
44 is(contentWindow.GroupItems.groupItems.length, ++groupItemCount,
45 "The number of groups is increased by 1");
47 // add four blank items
48 contentWindow.UI.setActive(emptyGroupItem);
50 let numNewTabs = 4;
51 let items = [];
52 for(let t=0; t<numNewTabs; t++) {
53 let newItem = contentWindow.gBrowser.loadOneTab("about:blank")._tabViewTabItem;
54 ok(newItem.container, "Created element "+t+":"+newItem.container);
55 items.push(newItem);
56 }
58 // Define main test function
59 //
61 let mainTestFunc = function() {
62 for(let j=0; j<numNewTabs; j++) {
63 for(let i=0; i<numNewTabs; i++) {
64 if (j!=i) {
65 // make sure there is no overlap between j's title and i's box.
66 let jitem = items[j];
67 let iitem = items[i];
68 let $jtitle = contentWindow.iQ(jitem.container).find(".tab-title");
69 let jbounds = $jtitle.bounds();
70 let ibounds = contentWindow.iQ(iitem.container).bounds();
72 ok(
73 (jbounds.top+jbounds.height < ibounds.top) ||
74 (jbounds.top > ibounds.top + ibounds.height) ||
75 (jbounds.left+jbounds.width < ibounds.left) ||
76 (jbounds.left > ibounds.left + ibounds.width),
77 "Items do not overlap: "
78 +jbounds.left+","+jbounds.top+","+jbounds.width+","+jbounds.height+" ; "
79 +ibounds.left+","+ibounds.top+","+ibounds.width+","+ibounds.height);
80 }
81 }
82 }
84 // Shut down
85 emptyGroupItem.addSubscriber("close", function onClose() {
86 emptyGroupItem.removeSubscriber("close", onClose);
88 // check the number of groups.
89 is(contentWindow.GroupItems.groupItems.length, --groupItemCount,
90 "The number of groups is decreased by 1");
92 let onTabViewHidden = function() {
93 window.removeEventListener("tabviewhidden", onTabViewHidden, false);
94 // assert that we're no longer in tab view
95 ok(!TabView.isVisible(), "Tab View is hidden");
96 finish();
97 };
98 window.addEventListener("tabviewhidden", onTabViewHidden, false);
100 TabView.toggle();
101 });
103 let closeButton = emptyGroupItem.container.getElementsByClassName("close");
104 ok(closeButton[0], "Group close button exists");
106 // click the close button
107 EventUtils.synthesizeMouse(closeButton[0], 1, 1, {}, contentWindow);
108 };
110 mainTestFunc();
111 }