browser/components/tabview/test/browser_tabview_bug624727_perwindowpb.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_bug624727_perwindowpb.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,143 @@
     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 +  let createGroupItem = function (aWindow) {
     1.9 +    let cw = aWindow.TabView.getContentWindow();
    1.10 +    let bounds = new cw.Rect(20, 20, 400, 200);
    1.11 +    let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true});
    1.12 +    cw.UI.setActive(groupItem);
    1.13 +
    1.14 +    let groupItemId = groupItem.id;
    1.15 +    registerCleanupFunction(function() {
    1.16 +      let groupItem = cw.GroupItems.groupItem(groupItemId);
    1.17 +      if (groupItem)
    1.18 +        groupItem.close();
    1.19 +    });
    1.20 +
    1.21 +    for (let i=0; i<3; i++)
    1.22 +      aWindow.gBrowser.addTab('about:blank');
    1.23 +  }
    1.24 +
    1.25 +  let assertTabViewIsHidden = function (aWindow, prefix) {
    1.26 +    ok(!aWindow.TabView.isVisible(), prefix + ': tabview is hidden');
    1.27 +  }
    1.28 +
    1.29 +  let assertNumberOfTabs = function (aWindow, prefix, num) {
    1.30 +    is(aWindow.gBrowser.tabs.length, num, prefix + ': there are ' + num + ' tabs');
    1.31 +  }
    1.32 +
    1.33 +  let assertNumberOfPinnedTabs = function (aWindow, prefix, num) {
    1.34 +    is(aWindow.gBrowser._numPinnedTabs, num, prefix + ': there are ' + num + ' pinned tabs');
    1.35 +  }
    1.36 +
    1.37 +  let assertNumberOfGroups = function (aCW, prefix, num) {
    1.38 +    is(aCW.GroupItems.groupItems.length, num, prefix + ': there are ' + num + ' groups');
    1.39 +  }
    1.40 +
    1.41 +  let assertOneTabInGroup = function (prefix, groupItem) {
    1.42 +    is(groupItem.getChildren().length, 1, prefix + ': group contains one tab');
    1.43 +  }
    1.44 +
    1.45 +  let assertValidPrerequisites = function (aWindow, prefix) {
    1.46 +    assertNumberOfTabs(aWindow, prefix, 1);
    1.47 +    assertNumberOfPinnedTabs(aWindow, prefix, 0);
    1.48 +    assertTabViewIsHidden(aWindow, prefix);
    1.49 +  }
    1.50 +
    1.51 +  let assertValidSetup = function (aWindow, prefix) {
    1.52 +    let cw = aWindow.TabView.getContentWindow();
    1.53 +    assertNumberOfGroups(cw, prefix, 2);
    1.54 +    assertNumberOfTabs(aWindow, prefix, 4);
    1.55 +    assertNumberOfPinnedTabs(aWindow, prefix, 2);
    1.56 +
    1.57 +    let [group1, group2] = cw.GroupItems.groupItems;
    1.58 +    assertOneTabInGroup(prefix, group1);
    1.59 +    assertOneTabInGroup(prefix, group2);
    1.60 +  }
    1.61 +
    1.62 +  let testStateAfterEnteringPB = function (aWindow, aCallback) {
    1.63 +    let prefix = 'window is private';
    1.64 +    ok(PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix);
    1.65 +
    1.66 +    assertTabViewIsHidden(aWindow, prefix);
    1.67 +
    1.68 +    showTabView(function () {
    1.69 +      let cw = aWindow.TabView.getContentWindow();
    1.70 +
    1.71 +      assertNumberOfGroups(cw, prefix, 1);
    1.72 +      assertNumberOfTabs(aWindow, prefix, 1);
    1.73 +      assertOneTabInGroup(prefix, cw.GroupItems.groupItems[0]);
    1.74 +      aCallback();
    1.75 +    }, aWindow);
    1.76 +  }
    1.77 +
    1.78 +  let testStateAfterLeavingPB = function (aWindow) {
    1.79 +    let prefix = 'window is not private';
    1.80 +    ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix);
    1.81 +
    1.82 +    assertTabViewIsHidden(aWindow, prefix);
    1.83 +
    1.84 +    showTabView(function () {
    1.85 +      assertValidSetup(aWindow, prefix);
    1.86 +      finishTest(aWindow);
    1.87 +    }, aWindow);
    1.88 +  }
    1.89 +
    1.90 +  let finishTest = function (aWindow) {
    1.91 +    let cw = aWindow.TabView.getContentWindow();
    1.92 +
    1.93 +    // Remove pinned tabs
    1.94 +    aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[0]);
    1.95 +    aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[0]);
    1.96 +
    1.97 +    cw.GroupItems.groupItems[1].closeAll();
    1.98 +
    1.99 +    hideTabView(function () {
   1.100 +      assertValidPrerequisites(aWindow, 'exit');
   1.101 +      assertNumberOfGroups(cw, 'exit', 1);
   1.102 +      aWindow.close();
   1.103 +      finish();
   1.104 +    }, aWindow);
   1.105 +  }
   1.106 +
   1.107 +  let testOnWindow = function(aIsPrivate, aCallback) {
   1.108 +    let win = OpenBrowserWindow({private: aIsPrivate});
   1.109 +    win.addEventListener("load", function onLoad() {
   1.110 +      win.removeEventListener("load", onLoad, false);
   1.111 +      executeSoon(function() { aCallback(win) });
   1.112 +    }, false);
   1.113 +  }
   1.114 +
   1.115 +  waitForExplicitFinish();
   1.116 +  testOnWindow(false, function(publicWindow) {
   1.117 +    registerCleanupFunction(function () publicWindow.TabView.hide());
   1.118 +    assertValidPrerequisites(publicWindow, 'start');
   1.119 +
   1.120 +    showTabView(function () {
   1.121 +      let cw = publicWindow.TabView.getContentWindow();
   1.122 +      assertNumberOfGroups(cw, 'start', 1);
   1.123 +      createGroupItem(publicWindow);
   1.124 +
   1.125 +      afterAllTabsLoaded(function () {
   1.126 +        // Setup
   1.127 +        let groupItems = cw.GroupItems.groupItems;
   1.128 +        let [tabItem1, tabItem2, ] = groupItems[1].getChildren();
   1.129 +        publicWindow.gBrowser.pinTab(tabItem1.tab);
   1.130 +        publicWindow.gBrowser.pinTab(tabItem2.tab);
   1.131 +
   1.132 +        assertValidSetup(publicWindow, 'setup');
   1.133 +        hideTabView(function() {
   1.134 +          testOnWindow(true, function(privateWindow) {
   1.135 +            testStateAfterEnteringPB(privateWindow, function() {
   1.136 +              privateWindow.close();
   1.137 +              hideTabView(function() {
   1.138 +                testStateAfterLeavingPB(publicWindow);
   1.139 +              }, publicWindow);
   1.140 +            });
   1.141 +          });
   1.142 +        }, publicWindow);
   1.143 +      });
   1.144 +    }, publicWindow);
   1.145 +  });
   1.146 +}

mercurial