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