browser/components/tabview/test/browser_tabview_bug595943.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:771a5ea56688
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 function test() {
5 waitForExplicitFinish();
6
7 // Show TabView
8 window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
9 TabView.toggle();
10 }
11
12 function onTabViewWindowLoaded() {
13 window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
14 ok(TabView.isVisible(), "Tab View is visible");
15
16 let contentWindow = document.getElementById("tab-view").contentWindow;
17
18 // establish initial state
19 is(contentWindow.GroupItems.groupItems.length, 1, "we start with one group (the default)");
20 is(gBrowser.tabs.length, 1, "we start with one tab");
21
22 let originalTab = gBrowser.tabs[0];
23 ok(contentWindow.GroupItems.groupItems[0]._children[0].tab == originalTab,
24 "the original tab is in the original group");
25
26 // create a second group
27 let box = new contentWindow.Rect(20, 20, 180, 180);
28 let groupItem = new contentWindow.GroupItem([], { bounds: box });
29 is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups");
30 contentWindow.UI.setActive(groupItem);
31
32 // create a second tab
33 let normalXulTab = gBrowser.loadOneTab("about:blank");
34 is(gBrowser.tabs.length, 2, "we now have two tabs");
35 is(groupItem._children.length, 1, "the new tab was added to the group");
36
37 // create a third tab
38 let appXulTab = gBrowser.loadOneTab("about:blank");
39 is(gBrowser.tabs.length, 3, "we now have three tabs");
40 gBrowser.pinTab(appXulTab);
41 is(groupItem._children.length, 1, "the app tab is not in the group");
42
43 // We now have two groups with one tab each, plus an app tab.
44 // Click into one of the tabs, close it and make sure we don't go back to Tab View.
45 function onTabViewHidden() {
46 window.removeEventListener("tabviewhidden", onTabViewHidden, false);
47 ok(!TabView.isVisible(), "Tab View is hidden because we clicked on the app tab");
48
49 // Remove the tab we're looking at.
50 gBrowser.removeTab(normalXulTab);
51
52 // Make sure we haven't returned to TabView; this is the crux of this test
53 ok(!TabView.isVisible(), "Tab View remains hidden");
54
55 // clean up
56 gBrowser.selectedTab = originalTab;
57
58 gBrowser.unpinTab(appXulTab);
59 gBrowser.removeTab(appXulTab);
60
61 ok(groupItem.closeIfEmpty(), "the second group was empty");
62
63 // Verify ending state
64 is(gBrowser.tabs.length, 1, "we finish with one tab");
65 is(contentWindow.GroupItems.groupItems.length, 1,
66 "we finish with one group");
67 ok(!TabView.isVisible(), "we finish with Tab View hidden");
68
69 finish();
70 }
71
72 window.addEventListener("tabviewhidden", onTabViewHidden, false);
73 EventUtils.sendMouseEvent({ type: "mousedown" }, normalXulTab._tabViewTabItem.container, contentWindow);
74 EventUtils.sendMouseEvent({ type: "mouseup" }, normalXulTab._tabViewTabItem.container, contentWindow);
75 }

mercurial