browser/components/tabview/test/browser_tabview_bug626525.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 let prefsBranch;
     5 let currentActiveGroupItemId;
     7 function test() {
     8   waitForExplicitFinish();
    10   // disable the first run pref
    11   prefsBranch = Services.prefs.getBranch("browser.panorama.");
    12   prefsBranch.setBoolPref("experienced_first_run", false);
    14   let win =
    15     window.openDialog(getBrowserURL(), "_blank", "all,dialog=no", "about:blank");
    17   let onLoad = function() {
    18     win.removeEventListener("load", onLoad, false);
    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   };
    29   win.addEventListener("load", onLoad, false);
    30 }
    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")
    38   let originalTab = win.gBrowser.visibleTabs[0];
    40   openTabContextPopup(win, originalTab);
    42   ok(win.document.getElementById("context_tabViewMenu").hidden,
    43      "The menu should be hidden");
    45   closeTabContextPopup(win);
    47   executeSoon(function() { 
    48     ok(!win.TabView.getContentWindow(), "The tab view iframe is not loaded");
    49     test2(win);
    50   });
    51 }
    53 // press the next group key combination and check whether the iframe has loaded or not
    54 function test2(win) {
    55   goToNextGroup(win);
    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");
    62     test3(win);
    63   });
    64 }
    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);
    72   let newTab = win.gBrowser.addTab("about:blank");
    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);
    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");
    87   let onTabViewFrameInitialized = function() {
    88      win.removeEventListener(
    89        "tabviewframeinitialized", onTabViewFrameInitialized, false);
    91      let contentWindow = win.document.getElementById("tab-view").contentWindow;
    93      // show the tab view to ensure groups are created before checking.
    94      let onTabViewShown = function() {
    95        win.removeEventListener("tabviewshown", onTabViewShown, false);
    97        ok(win.TabView.isVisible(), "Tab View is visible");
    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");
   106        // simulate the next group key combination
   107        currentActiveGroupItemId =
   108          contentWindow.GroupItems.getActiveGroupItem().id;
   110        win.addEventListener("tabviewhidden", onTabViewHidden, false);
   112        win.TabView.toggle();
   113      };
   114      let onTabViewHidden = function() {
   115        win.removeEventListener("tabviewhidden", onTabViewHidden, false);
   117        goToNextGroup(win);
   119        isnot(contentWindow.GroupItems.getActiveGroupItem().id,
   120              currentActiveGroupItemId, "Just switched to another group");
   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();
   135   // close popups
   136   win.document.getElementById("context_tabViewMenuPopup").hidePopup();
   137   closeTabContextPopup(win);
   138 }
   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 }
   147 function closeTabContextPopup(win) {
   148   win.document.getElementById("tabContextMenu").hidePopup();
   149 }

mercurial