browser/components/tabview/test/browser_tabview_bug626525.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:4394c655522e
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 let prefsBranch;
5 let currentActiveGroupItemId;
6
7 function test() {
8 waitForExplicitFinish();
9
10 // disable the first run pref
11 prefsBranch = Services.prefs.getBranch("browser.panorama.");
12 prefsBranch.setBoolPref("experienced_first_run", false);
13
14 let win =
15 window.openDialog(getBrowserURL(), "_blank", "all,dialog=no", "about:blank");
16
17 let onLoad = function() {
18 win.removeEventListener("load", onLoad, false);
19
20 let theObserver = function(subject, topic, data) {
21 Services.obs.removeObserver(
22 theObserver, "browser-delayed-startup-finished");
23 test1(win);
24 }
25 Services.obs.addObserver(
26 theObserver, "browser-delayed-startup-finished", false);
27 };
28
29 win.addEventListener("load", onLoad, false);
30 }
31
32 // check whether tha menu is hidden when the "experienced_first_run" pref is
33 // false
34 function test1(win) {
35 is(win.gBrowser.tabs.length - win.gBrowser.visibleTabs.length, 0,
36 "There are no hidden tabs")
37
38 let originalTab = win.gBrowser.visibleTabs[0];
39
40 openTabContextPopup(win, originalTab);
41
42 ok(win.document.getElementById("context_tabViewMenu").hidden,
43 "The menu should be hidden");
44
45 closeTabContextPopup(win);
46
47 executeSoon(function() {
48 ok(!win.TabView.getContentWindow(), "The tab view iframe is not loaded");
49 test2(win);
50 });
51 }
52
53 // press the next group key combination and check whether the iframe has loaded or not
54 function test2(win) {
55 goToNextGroup(win);
56
57 // give it a delay so we can ensure the iframe has not been loaded
58 executeSoon(function() {
59 ok(!win.TabView.getContentWindow(),
60 "The tab view iframe is not loaded after pressing the next group key combination");
61
62 test3(win);
63 });
64 }
65
66 // first run has happened, open the tab context menupopup and the tabview menu,
67 // move a tab to another group including iframe initialization. Then,
68 // use the key combination to change to the next group.
69 function test3(win) {
70 prefsBranch.setBoolPref("experienced_first_run", true);
71
72 let newTab = win.gBrowser.addTab("about:blank");
73
74 // open the tab context menupopup and the tabview menupopup
75 openTabContextPopup(win, newTab);
76 win.document.getElementById("context_tabViewMenuPopup").openPopup(
77 win.document.getElementById("context_tabViewMenu"), "end_after", 0, 0,
78 true, false);
79
80 ok(!win.document.getElementById("context_tabViewMenu").hidden,
81 "The menu should be visible now");
82 is(win.gBrowser.tabs.length - win.gBrowser.visibleTabs.length, 0,
83 "There are no hidden tabs")
84 ok(!win.TabView.getContentWindow(),
85 "The tab view iframe is not loaded after opening tab context menu");
86
87 let onTabViewFrameInitialized = function() {
88 win.removeEventListener(
89 "tabviewframeinitialized", onTabViewFrameInitialized, false);
90
91 let contentWindow = win.document.getElementById("tab-view").contentWindow;
92
93 // show the tab view to ensure groups are created before checking.
94 let onTabViewShown = function() {
95 win.removeEventListener("tabviewshown", onTabViewShown, false);
96
97 ok(win.TabView.isVisible(), "Tab View is visible");
98
99 is(contentWindow.GroupItems.groupItems.length, 2,
100 "There are two group items");
101 is(contentWindow.GroupItems.groupItems[0].getChildren().length, 1,
102 "There should be one tab item in the first group");
103 is(contentWindow.GroupItems.groupItems[1].getChildren().length, 1,
104 "There should be one tab item in the second group");
105
106 // simulate the next group key combination
107 currentActiveGroupItemId =
108 contentWindow.GroupItems.getActiveGroupItem().id;
109
110 win.addEventListener("tabviewhidden", onTabViewHidden, false);
111
112 win.TabView.toggle();
113 };
114 let onTabViewHidden = function() {
115 win.removeEventListener("tabviewhidden", onTabViewHidden, false);
116
117 goToNextGroup(win);
118
119 isnot(contentWindow.GroupItems.getActiveGroupItem().id,
120 currentActiveGroupItemId, "Just switched to another group");
121
122 // close the window and finish it
123 win.close();
124 finish();
125 };
126 win.addEventListener("tabviewshown", onTabViewShown, false);
127 // give it a delay to ensure everything is loaded.
128 executeSoon(function() { win.TabView.toggle(); });
129 };
130 win.addEventListener(
131 "tabviewframeinitialized", onTabViewFrameInitialized, false);
132 // move the tab to another group using the menu item
133 win.document.getElementById("context_tabViewNewGroup").doCommand();
134
135 // close popups
136 win.document.getElementById("context_tabViewMenuPopup").hidePopup();
137 closeTabContextPopup(win);
138 }
139
140 function openTabContextPopup(win, tab) {
141 var evt = new Event("");
142 tab.dispatchEvent(evt);
143 win.document.getElementById("tabContextMenu").openPopup(
144 tab, "end_after", 0, 0, true, false, evt);
145 }
146
147 function closeTabContextPopup(win) {
148 win.document.getElementById("tabContextMenu").hidePopup();
149 }
150

mercurial