michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let prefsBranch; michael@0: let currentActiveGroupItemId; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: // disable the first run pref michael@0: prefsBranch = Services.prefs.getBranch("browser.panorama."); michael@0: prefsBranch.setBoolPref("experienced_first_run", false); michael@0: michael@0: let win = michael@0: window.openDialog(getBrowserURL(), "_blank", "all,dialog=no", "about:blank"); michael@0: michael@0: let onLoad = function() { michael@0: win.removeEventListener("load", onLoad, false); michael@0: michael@0: let theObserver = function(subject, topic, data) { michael@0: Services.obs.removeObserver( michael@0: theObserver, "browser-delayed-startup-finished"); michael@0: test1(win); michael@0: } michael@0: Services.obs.addObserver( michael@0: theObserver, "browser-delayed-startup-finished", false); michael@0: }; michael@0: michael@0: win.addEventListener("load", onLoad, false); michael@0: } michael@0: michael@0: // check whether tha menu is hidden when the "experienced_first_run" pref is michael@0: // false michael@0: function test1(win) { michael@0: is(win.gBrowser.tabs.length - win.gBrowser.visibleTabs.length, 0, michael@0: "There are no hidden tabs") michael@0: michael@0: let originalTab = win.gBrowser.visibleTabs[0]; michael@0: michael@0: openTabContextPopup(win, originalTab); michael@0: michael@0: ok(win.document.getElementById("context_tabViewMenu").hidden, michael@0: "The menu should be hidden"); michael@0: michael@0: closeTabContextPopup(win); michael@0: michael@0: executeSoon(function() { michael@0: ok(!win.TabView.getContentWindow(), "The tab view iframe is not loaded"); michael@0: test2(win); michael@0: }); michael@0: } michael@0: michael@0: // press the next group key combination and check whether the iframe has loaded or not michael@0: function test2(win) { michael@0: goToNextGroup(win); michael@0: michael@0: // give it a delay so we can ensure the iframe has not been loaded michael@0: executeSoon(function() { michael@0: ok(!win.TabView.getContentWindow(), michael@0: "The tab view iframe is not loaded after pressing the next group key combination"); michael@0: michael@0: test3(win); michael@0: }); michael@0: } michael@0: michael@0: // first run has happened, open the tab context menupopup and the tabview menu, michael@0: // move a tab to another group including iframe initialization. Then, michael@0: // use the key combination to change to the next group. michael@0: function test3(win) { michael@0: prefsBranch.setBoolPref("experienced_first_run", true); michael@0: michael@0: let newTab = win.gBrowser.addTab("about:blank"); michael@0: michael@0: // open the tab context menupopup and the tabview menupopup michael@0: openTabContextPopup(win, newTab); michael@0: win.document.getElementById("context_tabViewMenuPopup").openPopup( michael@0: win.document.getElementById("context_tabViewMenu"), "end_after", 0, 0, michael@0: true, false); michael@0: michael@0: ok(!win.document.getElementById("context_tabViewMenu").hidden, michael@0: "The menu should be visible now"); michael@0: is(win.gBrowser.tabs.length - win.gBrowser.visibleTabs.length, 0, michael@0: "There are no hidden tabs") michael@0: ok(!win.TabView.getContentWindow(), michael@0: "The tab view iframe is not loaded after opening tab context menu"); michael@0: michael@0: let onTabViewFrameInitialized = function() { michael@0: win.removeEventListener( michael@0: "tabviewframeinitialized", onTabViewFrameInitialized, false); michael@0: michael@0: let contentWindow = win.document.getElementById("tab-view").contentWindow; michael@0: michael@0: // show the tab view to ensure groups are created before checking. michael@0: let onTabViewShown = function() { michael@0: win.removeEventListener("tabviewshown", onTabViewShown, false); michael@0: michael@0: ok(win.TabView.isVisible(), "Tab View is visible"); michael@0: michael@0: is(contentWindow.GroupItems.groupItems.length, 2, michael@0: "There are two group items"); michael@0: is(contentWindow.GroupItems.groupItems[0].getChildren().length, 1, michael@0: "There should be one tab item in the first group"); michael@0: is(contentWindow.GroupItems.groupItems[1].getChildren().length, 1, michael@0: "There should be one tab item in the second group"); michael@0: michael@0: // simulate the next group key combination michael@0: currentActiveGroupItemId = michael@0: contentWindow.GroupItems.getActiveGroupItem().id; michael@0: michael@0: win.addEventListener("tabviewhidden", onTabViewHidden, false); michael@0: michael@0: win.TabView.toggle(); michael@0: }; michael@0: let onTabViewHidden = function() { michael@0: win.removeEventListener("tabviewhidden", onTabViewHidden, false); michael@0: michael@0: goToNextGroup(win); michael@0: michael@0: isnot(contentWindow.GroupItems.getActiveGroupItem().id, michael@0: currentActiveGroupItemId, "Just switched to another group"); michael@0: michael@0: // close the window and finish it michael@0: win.close(); michael@0: finish(); michael@0: }; michael@0: win.addEventListener("tabviewshown", onTabViewShown, false); michael@0: // give it a delay to ensure everything is loaded. michael@0: executeSoon(function() { win.TabView.toggle(); }); michael@0: }; michael@0: win.addEventListener( michael@0: "tabviewframeinitialized", onTabViewFrameInitialized, false); michael@0: // move the tab to another group using the menu item michael@0: win.document.getElementById("context_tabViewNewGroup").doCommand(); michael@0: michael@0: // close popups michael@0: win.document.getElementById("context_tabViewMenuPopup").hidePopup(); michael@0: closeTabContextPopup(win); michael@0: } michael@0: michael@0: function openTabContextPopup(win, tab) { michael@0: var evt = new Event(""); michael@0: tab.dispatchEvent(evt); michael@0: win.document.getElementById("tabContextMenu").openPopup( michael@0: tab, "end_after", 0, 0, true, false, evt); michael@0: } michael@0: michael@0: function closeTabContextPopup(win) { michael@0: win.document.getElementById("tabContextMenu").hidePopup(); michael@0: } michael@0: