browser/components/tabview/test/browser_tabview_bug629195.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_bug629195.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +let win;
     1.8 +let contentWindow;
     1.9 +let originalTab;
    1.10 +
    1.11 +function test() {
    1.12 +  waitForExplicitFinish();
    1.13 +
    1.14 +  newWindowWithTabView(
    1.15 +    function() {
    1.16 +      ok(win.TabView.isVisible(), "Tab View is visible");
    1.17 +
    1.18 +      contentWindow = win.document.getElementById("tab-view").contentWindow;
    1.19 +      is(contentWindow.GroupItems.groupItems.length, 1, "There is one group");
    1.20 +      is(contentWindow.GroupItems.groupItems[0].getChildren().length, 1,
    1.21 +         "The group has only one tab item");
    1.22 +
    1.23 +      // show the undo close group button
    1.24 +      let group = contentWindow.GroupItems.groupItems[0];
    1.25 +      hideGroupItem(group, function () restore(group.id));
    1.26 +    },
    1.27 +    function(newWin) {
    1.28 +      win = newWin;
    1.29 +      originalTab = win.gBrowser.visibleTabs[0];
    1.30 +      win.gBrowser.addTab();
    1.31 +      win.gBrowser.pinTab(originalTab);
    1.32 +    }
    1.33 +  );
    1.34 +}
    1.35 +
    1.36 +function restore(groupId) {
    1.37 +  // window state ready
    1.38 +  let handleSSWindowStateReady = function() {
    1.39 +    win.removeEventListener("SSWindowStateReady", handleSSWindowStateReady, false);
    1.40 +
    1.41 +    executeSoon(function() { 
    1.42 +      is(contentWindow.GroupItems.groupItems.length, 1, "There is one group");
    1.43 +
    1.44 +      let group = contentWindow.GroupItems.groupItems[0];
    1.45 +      ok(!group.hidden, "The group is visible");
    1.46 +      is(group.getChildren().length, 2, "This group has two tab items");
    1.47 +
    1.48 +      // check the position of the group item and the tab items.
    1.49 +      let tabItemOne = group.getChildren()[0];
    1.50 +      let tabItemTwo = group.getChildren()[1];
    1.51 +
    1.52 +      let groupBounds = group.getBounds();
    1.53 +      let tabItemOneBounds = tabItemOne.getBounds();
    1.54 +      let tabItemTwoBounds = tabItemTwo.getBounds();
    1.55 +
    1.56 +      ok(groupBounds.left < tabItemOneBounds.left && 
    1.57 +         (groupBounds.right) > (tabItemOneBounds.right) &&
    1.58 +         groupBounds.top < tabItemOneBounds.top && 
    1.59 +         (groupBounds.bottom) > (tabItemOneBounds.bottom), 
    1.60 +         "Tab item one is within the group");
    1.61 +
    1.62 +      ok(groupBounds.left < tabItemOneBounds.left && 
    1.63 +         (groupBounds.right) > (tabItemTwoBounds.right) &&
    1.64 +         groupBounds.top < tabItemOneBounds.top && 
    1.65 +         (groupBounds.bottom) > (tabItemTwoBounds.bottom), 
    1.66 +         "Tab item two is within the group");
    1.67 +
    1.68 +      win.close();
    1.69 +      finish();
    1.70 +    });
    1.71 +  }
    1.72 +  win.addEventListener("SSWindowStateReady", handleSSWindowStateReady, false);
    1.73 +
    1.74 +  // simulate restoring previous session (one group and two tab items)
    1.75 +  const DUMMY_PAGE_URL = "http://example.com/";
    1.76 +  let newState = {
    1.77 +    windows: [{
    1.78 +      tabs: [{
    1.79 +        entries: [{ url: DUMMY_PAGE_URL }],
    1.80 +        index: 2,
    1.81 +        hidden: false,
    1.82 +        attributes: {},
    1.83 +        extData: {
    1.84 +          "tabview-tab":
    1.85 +            '{"bounds":{"left":208,"top":54,"width":205,"height":169},' +
    1.86 +            '"userSize":null,"url":"' + DUMMY_PAGE_URL + '","groupID":' + 
    1.87 +            groupId + ',"imageData":null,"title":null}'
    1.88 +        }}, {
    1.89 +        entries: [{ url: DUMMY_PAGE_URL }],
    1.90 +        index: 1,
    1.91 +        hidden: false,
    1.92 +        attributes: {},
    1.93 +        extData: {
    1.94 +          "tabview-tab":
    1.95 +            '{"bounds":{"left":429,"top":54,"width":205,"height":169},' +
    1.96 +            '"userSize":null,"url":"' + DUMMY_PAGE_URL + '","groupID":' + 
    1.97 +            groupId + ',"imageData":null,"title":null}'
    1.98 +        }
    1.99 +      }],
   1.100 +      extData: {
   1.101 +        "tabview-groups": '{"nextID":' + (groupId + 1) + ',"activeGroupId":' + groupId + '}',
   1.102 +        "tabview-group": 
   1.103 +          '{"' + groupId + '":{"bounds":{"left":202,"top":30,"width":455,"height":249},' + 
   1.104 +          '"userSize":null,"locked":{},"title":"","id":' + groupId +'}}',
   1.105 +        "tabview-ui": '{"pageBounds":{"left":0,"top":0,"width":788,"height":548}}'
   1.106 +      }, sizemode:"normal"
   1.107 +    }]
   1.108 +  };
   1.109 +  let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
   1.110 +  ss.setWindowState(win, JSON.stringify(newState), true);
   1.111 +}
   1.112 +

mercurial