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

mercurial