browser/components/tabview/test/browser_tabview_bug716880.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_bug716880.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +let contentWindow;
     1.8 +let pinnedTab;
     1.9 +
    1.10 +function test() {
    1.11 +  waitForExplicitFinish();
    1.12 +
    1.13 +  registerCleanupFunction(function() {
    1.14 +    while (gBrowser.tabs[1])
    1.15 +      gBrowser.removeTab(gBrowser.tabs[1]);
    1.16 +    hideTabView();
    1.17 +  });
    1.18 +
    1.19 +  pinnedTab = gBrowser.addTab("about:blank");
    1.20 +  gBrowser.pinTab(pinnedTab);
    1.21 +  ok(pinnedTab.pinned, "Tab 1 is pinned");
    1.22 +
    1.23 +  gBrowser.addTab("about:mozilla");
    1.24 +  showTabView(setup);
    1.25 +}
    1.26 +
    1.27 +function setup() {
    1.28 +  let prefix = "setup: ";
    1.29 +  
    1.30 +  registerCleanupFunction(function() {
    1.31 +    let groupItem = contentWindow.GroupItems.groupItem(groupItemTwoId);
    1.32 +    if (groupItem)
    1.33 +      closeGroupItem(groupItem);
    1.34 +  });
    1.35 +
    1.36 +  contentWindow = TabView.getContentWindow();
    1.37 +  let groupItemOne = contentWindow.GroupItems.groupItems[0];
    1.38 +
    1.39 +  is(contentWindow.GroupItems.groupItems.length, 1,
    1.40 +    prefix + "There is only one group");
    1.41 +
    1.42 +  is(groupItemOne.getChildren().length, 2,
    1.43 +    prefix + "The number of tabs in group one is 2");
    1.44 +
    1.45 +  // Create a second group with a dummy page.
    1.46 +  let groupItemTwo =
    1.47 +    createGroupItemWithTabs(window, 300, 300, 310, ["about:blank"]);
    1.48 +  let groupItemTwoId = groupItemTwo.id;
    1.49 +
    1.50 +  // Add a new tab to the second group, from where we will execute the switch
    1.51 +  // to tab.
    1.52 +  groupItemTwo.newTab("about:blank");
    1.53 +
    1.54 +  is(contentWindow.GroupItems.getActiveGroupItem(), groupItemTwo, 
    1.55 +     prefix + "The group two is the active group");
    1.56 +  
    1.57 +  is(contentWindow.UI.getActiveTab(), groupItemTwo.getChild(1), 
    1.58 +     prefix + "The second tab item in group two is active");
    1.59 +
    1.60 +  hideTabView(function () { switchToURL(groupItemOne, groupItemTwo) } );
    1.61 +}
    1.62 +
    1.63 +
    1.64 +function switchToURL(groupItemOne, groupItemTwo) {
    1.65 +  let prefix = "after switching: ";
    1.66 +
    1.67 +  /**
    1.68 +   * At this point, focus is on group two. Let's switch to a tab with an URL
    1.69 +   * contained in group one and then go to the pinned tab after the
    1.70 +   * switch. The selected group should be group one.
    1.71 +   */
    1.72 +  // Set the urlbar to include the moz-action.
    1.73 +  gURLBar.value = "moz-action:switchtab,about:mozilla";
    1.74 +  // Focus the urlbar so we can press enter.
    1.75 +  gURLBar.focus();
    1.76 +  // Press enter.
    1.77 +  EventUtils.synthesizeKey("VK_RETURN", {});
    1.78 +
    1.79 +  // Focus on the app tab.
    1.80 +  EventUtils.synthesizeKey("1", { accelKey: true });
    1.81 +
    1.82 +  // Check group one is active after a "switch to tab" action was executed and 
    1.83 +  // the app tab receives focus.
    1.84 +  is(contentWindow.GroupItems.getActiveGroupItem(), groupItemOne, 
    1.85 +    prefix + "The group one is the active group");
    1.86 +
    1.87 +  is(groupItemOne.getChildren().length, 2,
    1.88 +    prefix + "The number of tabs in group one is 2");
    1.89 +
    1.90 +  is(groupItemTwo.getChildren().length, 1,
    1.91 +    prefix + "The number of tabs in group two is 1");
    1.92 +
    1.93 +  gBrowser.removeTab(pinnedTab);
    1.94 +  finish();
    1.95 +}
    1.96 \ No newline at end of file

mercurial