browser/components/tabview/test/browser_tabview_bug626525.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/tabview/test/browser_tabview_bug626525.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,150 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +let prefsBranch;
     1.8 +let currentActiveGroupItemId;
     1.9 +
    1.10 +function test() {
    1.11 +  waitForExplicitFinish();
    1.12 +
    1.13 +  // disable the first run pref
    1.14 +  prefsBranch = Services.prefs.getBranch("browser.panorama.");
    1.15 +  prefsBranch.setBoolPref("experienced_first_run", false);
    1.16 +
    1.17 +  let win =
    1.18 +    window.openDialog(getBrowserURL(), "_blank", "all,dialog=no", "about:blank");
    1.19 +
    1.20 +  let onLoad = function() {
    1.21 +    win.removeEventListener("load", onLoad, false);
    1.22 +
    1.23 +    let theObserver = function(subject, topic, data) {
    1.24 +      Services.obs.removeObserver(
    1.25 +        theObserver, "browser-delayed-startup-finished");
    1.26 +      test1(win);
    1.27 +    }
    1.28 +    Services.obs.addObserver(
    1.29 +      theObserver, "browser-delayed-startup-finished", false);
    1.30 +  };
    1.31 +
    1.32 +  win.addEventListener("load", onLoad, false);
    1.33 +}
    1.34 +
    1.35 +// check whether tha menu is hidden when the "experienced_first_run" pref is
    1.36 +// false
    1.37 +function test1(win) {
    1.38 +  is(win.gBrowser.tabs.length - win.gBrowser.visibleTabs.length, 0,
    1.39 +     "There are no hidden tabs")
    1.40 +
    1.41 +  let originalTab = win.gBrowser.visibleTabs[0];
    1.42 +
    1.43 +  openTabContextPopup(win, originalTab);
    1.44 +
    1.45 +  ok(win.document.getElementById("context_tabViewMenu").hidden,
    1.46 +     "The menu should be hidden");
    1.47 +
    1.48 +  closeTabContextPopup(win);
    1.49 +
    1.50 +  executeSoon(function() { 
    1.51 +    ok(!win.TabView.getContentWindow(), "The tab view iframe is not loaded");
    1.52 +    test2(win);
    1.53 +  });
    1.54 +}
    1.55 +
    1.56 +// press the next group key combination and check whether the iframe has loaded or not
    1.57 +function test2(win) {
    1.58 +  goToNextGroup(win);
    1.59 +
    1.60 +  // give it a delay so we can ensure the iframe has not been loaded
    1.61 +  executeSoon(function() {
    1.62 +    ok(!win.TabView.getContentWindow(),
    1.63 +       "The tab view iframe is not loaded after pressing the next group key combination");
    1.64 +
    1.65 +    test3(win);
    1.66 +  });
    1.67 +}
    1.68 +
    1.69 +// first run has happened, open the tab context menupopup and the tabview menu,
    1.70 +// move a tab to another group including iframe initialization.  Then,
    1.71 +// use the key combination to change to the next group.
    1.72 +function test3(win) {
    1.73 +  prefsBranch.setBoolPref("experienced_first_run", true);
    1.74 +
    1.75 +  let newTab = win.gBrowser.addTab("about:blank");
    1.76 +
    1.77 +  // open the tab context menupopup and the tabview menupopup
    1.78 +  openTabContextPopup(win, newTab);
    1.79 +  win.document.getElementById("context_tabViewMenuPopup").openPopup(
    1.80 +    win.document.getElementById("context_tabViewMenu"), "end_after", 0, 0,
    1.81 +    true, false);
    1.82 +
    1.83 +  ok(!win.document.getElementById("context_tabViewMenu").hidden,
    1.84 +     "The menu should be visible now");
    1.85 +  is(win.gBrowser.tabs.length - win.gBrowser.visibleTabs.length, 0,
    1.86 +     "There are no hidden tabs")
    1.87 +  ok(!win.TabView.getContentWindow(),
    1.88 +     "The tab view iframe is not loaded after opening tab context menu");
    1.89 +
    1.90 +  let onTabViewFrameInitialized = function() {
    1.91 +     win.removeEventListener(
    1.92 +       "tabviewframeinitialized", onTabViewFrameInitialized, false);
    1.93 +
    1.94 +     let contentWindow = win.document.getElementById("tab-view").contentWindow;
    1.95 +
    1.96 +     // show the tab view to ensure groups are created before checking.
    1.97 +     let onTabViewShown = function() {
    1.98 +       win.removeEventListener("tabviewshown", onTabViewShown, false);
    1.99 +
   1.100 +       ok(win.TabView.isVisible(), "Tab View is visible");
   1.101 +
   1.102 +       is(contentWindow.GroupItems.groupItems.length, 2,
   1.103 +          "There are two group items");
   1.104 +       is(contentWindow.GroupItems.groupItems[0].getChildren().length, 1,
   1.105 +          "There should be one tab item in the first group");
   1.106 +       is(contentWindow.GroupItems.groupItems[1].getChildren().length, 1,
   1.107 +          "There should be one tab item in the second group");
   1.108 +
   1.109 +       // simulate the next group key combination
   1.110 +       currentActiveGroupItemId =
   1.111 +         contentWindow.GroupItems.getActiveGroupItem().id;
   1.112 +
   1.113 +       win.addEventListener("tabviewhidden", onTabViewHidden, false);
   1.114 +
   1.115 +       win.TabView.toggle();
   1.116 +     };
   1.117 +     let onTabViewHidden = function() {
   1.118 +       win.removeEventListener("tabviewhidden", onTabViewHidden, false);
   1.119 +
   1.120 +       goToNextGroup(win);
   1.121 +
   1.122 +       isnot(contentWindow.GroupItems.getActiveGroupItem().id,
   1.123 +             currentActiveGroupItemId, "Just switched to another group");
   1.124 +
   1.125 +       // close the window and finish it
   1.126 +       win.close();
   1.127 +       finish();
   1.128 +     };
   1.129 +     win.addEventListener("tabviewshown", onTabViewShown, false);
   1.130 +     // give it a delay to ensure everything is loaded.
   1.131 +     executeSoon(function() { win.TabView.toggle(); });
   1.132 +  };
   1.133 +  win.addEventListener(
   1.134 +    "tabviewframeinitialized", onTabViewFrameInitialized, false);
   1.135 +  // move the tab to another group using the menu item
   1.136 +  win.document.getElementById("context_tabViewNewGroup").doCommand();
   1.137 +
   1.138 +  // close popups
   1.139 +  win.document.getElementById("context_tabViewMenuPopup").hidePopup();
   1.140 +  closeTabContextPopup(win);
   1.141 +}
   1.142 +
   1.143 +function openTabContextPopup(win, tab) {
   1.144 +  var evt = new Event("");
   1.145 +  tab.dispatchEvent(evt);
   1.146 +  win.document.getElementById("tabContextMenu").openPopup(
   1.147 +    tab, "end_after", 0, 0, true, false, evt);
   1.148 +}
   1.149 +
   1.150 +function closeTabContextPopup(win) {
   1.151 +  win.document.getElementById("tabContextMenu").hidePopup();
   1.152 +}
   1.153 +

mercurial