browser/components/tabview/test/browser_tabview_bug597980.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_bug597980.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,82 @@
     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 +  newWindowWithTabView(part1);
    1.11 +}
    1.12 +
    1.13 +function part1(win) {
    1.14 +  registerCleanupFunction(function() win.close());
    1.15 +
    1.16 +  let contentWindow = win.TabView.getContentWindow();
    1.17 +  is(contentWindow.GroupItems.groupItems.length, 1, "Has only one group");
    1.18 +
    1.19 +  let originalTab = win.gBrowser.selectedTab;
    1.20 +  let originalGroup = contentWindow.GroupItems.groupItems[0];
    1.21 +  let newTab = win.gBrowser.loadOneTab("about:blank", {inBackground: true});
    1.22 +  
    1.23 +  is(originalGroup.getChildren().length, 2, "The original group now has two tabs");
    1.24 +  
    1.25 +  // create group two with the new tab
    1.26 +  let box = new contentWindow.Rect(300,300,150,150);
    1.27 +  let newGroup = new contentWindow.GroupItem([], {bounds: box, immediately: true});
    1.28 +  newGroup.add(newTab._tabViewTabItem, {immediately: true});
    1.29 +
    1.30 +  // ensure active group item and tab
    1.31 +  contentWindow.UI.setActive(originalGroup);
    1.32 +  is(contentWindow.GroupItems.getActiveGroupItem(), originalGroup,
    1.33 +     "The original group is active");
    1.34 +  is(contentWindow.UI.getActiveTab(), originalTab._tabViewTabItem,
    1.35 +     "The original tab is active");
    1.36 +  
    1.37 +  function checkActive(callback, time) {
    1.38 +    is(contentWindow.GroupItems.getActiveGroupItem(), newGroup,
    1.39 +       "The new group is active");
    1.40 +    is(contentWindow.UI.getActiveTab(), newTab._tabViewTabItem,
    1.41 +       "The new tab is active");
    1.42 +    if (time)
    1.43 +      setTimeout(callback, time);
    1.44 +    else
    1.45 +      callback();
    1.46 +  }
    1.47 +
    1.48 +  // click on the new tab, and check that the new tab and group are active
    1.49 +  // at two times: 10 ms after (still during the animation) and
    1.50 +  // 500 ms after (after the animation, hopefully). Either way, the new
    1.51 +  // tab and group should be active.
    1.52 +  EventUtils.sendMouseEvent({ type: "mousedown" },
    1.53 +                            newTab._tabViewTabItem.container, contentWindow);
    1.54 +  EventUtils.sendMouseEvent({ type: "mouseup" },
    1.55 +                            newTab._tabViewTabItem.container, contentWindow);
    1.56 +  setTimeout(function() {
    1.57 +    checkActive(function() {
    1.58 +      checkActive(function() {
    1.59 +        win.close();
    1.60 +        newWindowWithTabView(part2);
    1.61 +      });
    1.62 +    }, 490);
    1.63 +  }, 10)
    1.64 +}
    1.65 +
    1.66 +function part2(win) {
    1.67 +  registerCleanupFunction(function() win.close());
    1.68 +
    1.69 +  let newTab = win.gBrowser.loadOneTab("about:blank", {inBackground: true});
    1.70 +  hideTabView(function() {
    1.71 +    let selectedTab = win.gBrowser.selectedTab;
    1.72 +    isnot(selectedTab, newTab, "They are different tabs");
    1.73 +
    1.74 +    // switch the selected tab to new tab
    1.75 +    win.gBrowser.selectedTab = newTab;
    1.76 +
    1.77 +    showTabView(function () {
    1.78 +      hideTabView(function () {
    1.79 +        is(win.gBrowser.selectedTab, newTab,
    1.80 +           "The selected tab should be the same as before (new tab)");
    1.81 +        waitForFocus(finish);
    1.82 +      }, win);
    1.83 +    }, win);
    1.84 +  }, win);
    1.85 +}

mercurial