browser/components/tabview/test/browser_tabview_bug595943.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_bug595943.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +function test() {
     1.8 +  waitForExplicitFinish();
     1.9 +
    1.10 +  // Show TabView
    1.11 +  window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
    1.12 +  TabView.toggle();
    1.13 +}
    1.14 +
    1.15 +function onTabViewWindowLoaded() {
    1.16 +  window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
    1.17 +  ok(TabView.isVisible(), "Tab View is visible");
    1.18 +
    1.19 +  let contentWindow = document.getElementById("tab-view").contentWindow;
    1.20 +
    1.21 +  // establish initial state
    1.22 +  is(contentWindow.GroupItems.groupItems.length, 1, "we start with one group (the default)"); 
    1.23 +  is(gBrowser.tabs.length, 1, "we start with one tab");
    1.24 +
    1.25 +  let originalTab = gBrowser.tabs[0];
    1.26 +  ok(contentWindow.GroupItems.groupItems[0]._children[0].tab == originalTab, 
    1.27 +    "the original tab is in the original group");
    1.28 +      
    1.29 +  // create a second group 
    1.30 +  let box = new contentWindow.Rect(20, 20, 180, 180);
    1.31 +  let groupItem = new contentWindow.GroupItem([], { bounds: box });
    1.32 +  is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups");
    1.33 +  contentWindow.UI.setActive(groupItem);
    1.34 +  
    1.35 +  // create a second tab
    1.36 +  let normalXulTab = gBrowser.loadOneTab("about:blank");
    1.37 +  is(gBrowser.tabs.length, 2, "we now have two tabs");
    1.38 +  is(groupItem._children.length, 1, "the new tab was added to the group");
    1.39 +  
    1.40 +  // create a third tab
    1.41 +  let appXulTab = gBrowser.loadOneTab("about:blank");
    1.42 +  is(gBrowser.tabs.length, 3, "we now have three tabs");
    1.43 +  gBrowser.pinTab(appXulTab);
    1.44 +  is(groupItem._children.length, 1, "the app tab is not in the group");
    1.45 +  
    1.46 +  // We now have two groups with one tab each, plus an app tab.
    1.47 +  // Click into one of the tabs, close it and make sure we don't go back to Tab View.
    1.48 +  function onTabViewHidden() {
    1.49 +    window.removeEventListener("tabviewhidden", onTabViewHidden, false);
    1.50 +    ok(!TabView.isVisible(), "Tab View is hidden because we clicked on the app tab");
    1.51 +  
    1.52 +    // Remove the tab we're looking at.
    1.53 +    gBrowser.removeTab(normalXulTab);  
    1.54 +  
    1.55 +    // Make sure we haven't returned to TabView; this is the crux of this test
    1.56 +    ok(!TabView.isVisible(), "Tab View remains hidden");
    1.57 +  
    1.58 +    // clean up
    1.59 +    gBrowser.selectedTab = originalTab;
    1.60 +    
    1.61 +    gBrowser.unpinTab(appXulTab);
    1.62 +    gBrowser.removeTab(appXulTab);
    1.63 +
    1.64 +    ok(groupItem.closeIfEmpty(), "the second group was empty");
    1.65 +
    1.66 +    // Verify ending state
    1.67 +    is(gBrowser.tabs.length, 1, "we finish with one tab");
    1.68 +    is(contentWindow.GroupItems.groupItems.length, 1,
    1.69 +       "we finish with one group");
    1.70 +    ok(!TabView.isVisible(), "we finish with Tab View hidden");
    1.71 +      
    1.72 +    finish();
    1.73 +  }
    1.74 +
    1.75 +  window.addEventListener("tabviewhidden", onTabViewHidden, false);
    1.76 +  EventUtils.sendMouseEvent({ type: "mousedown" }, normalXulTab._tabViewTabItem.container, contentWindow);
    1.77 +  EventUtils.sendMouseEvent({ type: "mouseup" }, normalXulTab._tabViewTabItem.container, contentWindow);
    1.78 +}

mercurial