Bug 1001521 - Fix tabview tests that remove the original tab r=smacleod
authorTim Taubert <ttaubert@mozilla.com>
Fri, 25 Apr 2014 18:01:04 +0200
changeset 181239 19681dccb432ddfe95692742cf4cfa659cfb6ac8
parent 181238 644472efabae7e5d18f00e35d8e0c15cdfd409b1
child 181240 95515135a1c425b0a0c9e0165c3812d89768cd1d
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewerssmacleod
bugs1001521
milestone32.0a1
Bug 1001521 - Fix tabview tests that remove the original tab r=smacleod
browser/components/tabview/test/browser_tabview_bug595601.js
browser/components/tabview/test/browser_tabview_bug608153.js
browser/components/tabview/test/browser_tabview_bug608158.js
browser/components/tabview/test/browser_tabview_bug608405.js
browser/components/tabview/test/browser_tabview_bug613541.js
browser/components/tabview/test/browser_tabview_bug624847.js
browser/components/tabview/test/browser_tabview_bug626455.js
browser/components/tabview/test/browser_tabview_bug633788.js
browser/components/tabview/test/browser_tabview_bug685692.js
--- a/browser/components/tabview/test/browser_tabview_bug595601.js
+++ b/browser/components/tabview/test/browser_tabview_bug595601.js
@@ -32,16 +32,17 @@ function test() {
 
   TabsProgressListener.init();
 
   registerCleanupFunction(function () {
     TabsProgressListener.uninit();
 
     Services.prefs.clearUserPref("browser.sessionstore.restore_hidden_tabs");
 
+    gBrowser.selectedTab = gBrowser.tabs[0];
     ss.setBrowserState(stateBackup);
   });
 
   TabView._initFrame(function () {
     executeSoon(testRestoreWithHiddenTabs);
   });
 }
 
--- a/browser/components/tabview/test/browser_tabview_bug608153.js
+++ b/browser/components/tabview/test/browser_tabview_bug608153.js
@@ -4,16 +4,20 @@
 function test() {
   waitForExplicitFinish();
 
   let pinnedTab = gBrowser.addTab();
   gBrowser.pinTab(pinnedTab);
 
   registerCleanupFunction(function() {
     gBrowser.unpinTab(pinnedTab);
+
+    // Don't remove the initial tab.
+    gBrowser.moveTabTo(gBrowser.tabs[1], 0);
+
     while (gBrowser.tabs[1])
       gBrowser.removeTab(gBrowser.tabs[1]);
     hideTabView();
   });
 
   showTabView(function() {
     let cw = TabView.getContentWindow();
     let groupItemOne = cw.GroupItems.groupItems[0];
--- a/browser/components/tabview/test/browser_tabview_bug608158.js
+++ b/browser/components/tabview/test/browser_tabview_bug608158.js
@@ -1,36 +1,28 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 function test() {
   waitForExplicitFinish();
-
-  window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
-  TabView.toggle();
+  newWindowWithTabView(onTabViewWindowLoaded);
 }
 
-function onTabViewWindowLoaded() {
-  window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
-
-  let contentWindow = document.getElementById("tab-view").contentWindow;
+function onTabViewWindowLoaded(win) {
+  let contentWindow = win.TabView.getContentWindow();
 
   is(contentWindow.GroupItems.groupItems.length, 1, 
      "There is one group item on startup");
-  is(gBrowser.tabs.length, 1, "There is one tab on startup");
+  is(win.gBrowser.tabs.length, 1, "There is one tab on startup");
   let groupItem = contentWindow.GroupItems.groupItems[0];
 
   hideGroupItem(groupItem, function () {
-    let onTabViewHidden = function() {
-      window.removeEventListener("tabviewhidden", onTabViewHidden, false);
+    hideTabView(() => {
       is(contentWindow.GroupItems.groupItems.length, 1, 
          "There is still one group item");
       isnot(groupItem, contentWindow.GroupItems.groupItems[0], 
             "The initial group item is not the same as the final group item");
-      is(gBrowser.tabs.length, 1, "There is only one tab");
-      ok(!TabView.isVisible(), "Tab View is hidden");
-      finish();
-    };
-    window.addEventListener("tabviewhidden", onTabViewHidden, false);
-
-    TabView.hide();
+      is(win.gBrowser.tabs.length, 1, "There is only one tab");
+      ok(!win.TabView.isVisible(), "Tab View is hidden");
+      promiseWindowClosed(win).then(finish);
+    }, win);
   });
 }
--- a/browser/components/tabview/test/browser_tabview_bug608405.js
+++ b/browser/components/tabview/test/browser_tabview_bug608405.js
@@ -35,17 +35,17 @@ function test() {
       targetGroup.add(tabItem);
 
       // check state after adding tabItem to targetGroup
       is(tabItem.parent, targetGroup, 'tabItem changed groups');
       is(cw.GroupItems.groupItems.length, 1, 'source group was closed automatically');
       is(targetGroup.getChildren().length, 2, 'target group has now two children');
 
       // cleanup and finish
-      tabItem.close();
+      targetGroup.getChild(0).close();
       hideTabView(finishTest);
     });
   }
 
   waitForExplicitFinish();
 
   showTabView(function () {
     cw = TabView.getContentWindow();
--- a/browser/components/tabview/test/browser_tabview_bug613541.js
+++ b/browser/components/tabview/test/browser_tabview_bug613541.js
@@ -1,26 +1,27 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 function test() {
   let cw;
+  let win;
   let currentTest;
 
   let getGroupItem = function (index) {
     return cw.GroupItems.groupItems[index];
   }
 
   let createGroupItem = function (numTabs) {
     let bounds = new cw.Rect(20, 20, 200, 200);
     let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true});
     cw.UI.setActive(groupItem);
 
     for (let i=0; i<numTabs || 0; i++)
-      gBrowser.loadOneTab('about:blank', {inBackground: true});
+      win.gBrowser.loadOneTab('about:blank', {inBackground: true});
 
     return groupItem;
   }
 
   let tests = [];
 
   let next = function () {
     let test = tests.shift();
@@ -30,31 +31,31 @@ function test() {
       if (currentTest) {
         currentTest += ' (post-check)';
         assertTabViewIsHidden();
         assertNumberOfGroupItems(1);
         assertNumberOfTabs(1);
       }
 
       currentTest = test.name;
-      showTabView(test.func);
+      showTabView(test.func, win);
     } else
-      hideTabView(finish);
+      promiseWindowClosed(win).then(finish);
   }
 
   let assertTabViewIsHidden = function () {
-    ok(!TabView.isVisible(), currentTest + ': tabview is hidden');
+    ok(!win.TabView.isVisible(), currentTest + ': tabview is hidden');
   }
 
   let assertNumberOfGroupItems = function (num) {
     is(cw.GroupItems.groupItems.length, num, currentTest + ': number of groupItems is equal to ' + num);
   }
 
   let assertNumberOfTabs = function (num) {
-    is(gBrowser.tabs.length, num, currentTest + ': number of tabs is equal to ' + num);
+    is(win.gBrowser.tabs.length, num, currentTest + ': number of tabs is equal to ' + num);
   }
 
   let assertGroupItemRemoved = function (groupItem) {
     is(cw.GroupItems.groupItems.indexOf(groupItem), -1, currentTest + ': groupItem was removed');
   }
 
   let assertGroupItemExists = function (groupItem) {
     isnot(cw.GroupItems.groupItems.indexOf(groupItem), -1, currentTest + ': groupItem still exists');
@@ -63,46 +64,46 @@ function test() {
   // setup: 1 non-empty group
   // action: close the group
   // expected: new group with blank tab is created and zoomed into
   let testSingleGroup1 = function () {
     let groupItem = getGroupItem(0);
     closeGroupItem(groupItem, function () {
       assertNumberOfGroupItems(1);
       assertGroupItemRemoved(groupItem);
-      whenTabViewIsHidden(next);
+      whenTabViewIsHidden(next, win);
     });
   }
 
   // setup: 1 non-empty group
   // action: hide the group, exit panorama
   // expected: new group with blank tab is created and zoomed into
   let testSingleGroup2 = function () {
     let groupItem = getGroupItem(0);
     hideGroupItem(groupItem, function () {
       hideTabView(function () {
         assertNumberOfGroupItems(1);
         assertGroupItemRemoved(groupItem);
         next();
-      });
+      }, win);
     });
   }
 
   // setup: 2 non-empty groups
   // action: close one group
   // expected: nothing should happen
   let testNonEmptyGroup1 = function () {
     let groupItem = getGroupItem(0);
     let newGroupItem = createGroupItem(1);
     assertNumberOfGroupItems(2);
 
     closeGroupItem(groupItem, function () {
       assertNumberOfGroupItems(1);
       assertGroupItemExists(newGroupItem);
-      hideTabView(next);
+      hideTabView(next, win);
     });
   }
 
   // setup: 2 non-empty groups
   // action: hide one group, exit panorama
   // expected: nothing should happen
   let testNonEmptyGroup2 = function () {
     let groupItem = getGroupItem(0);
@@ -110,102 +111,102 @@ function test() {
     assertNumberOfGroupItems(2);
 
     hideGroupItem(groupItem, function () {
       hideTabView(function () {
         assertNumberOfGroupItems(1);
         assertGroupItemRemoved(groupItem);
         assertGroupItemExists(newGroupItem);
         next();
-      });
+      }, win);
     });
   }
 
   // setup: 1 pinned tab, 1 empty group
   // action: exit panorama
   // expected: nothing should happen
   let testPinnedTab1 = function () {
-    gBrowser.pinTab(gBrowser.selectedTab);
+    win.gBrowser.pinTab(win.gBrowser.selectedTab);
 
     let groupItem = getGroupItem(0);
     hideTabView(function () {
       assertNumberOfGroupItems(1);
       assertGroupItemExists(groupItem);
-      gBrowser.unpinTab(gBrowser.selectedTab);
+      win.gBrowser.unpinTab(win.gBrowser.selectedTab);
       next();
-    });
+    }, win);
   }
 
   // setup: 1 pinned tab
   // action: exit panorama
   // expected: new blank group is created
   let testPinnedTab2 = function () {
-    gBrowser.pinTab(gBrowser.selectedTab);
+    win.gBrowser.pinTab(win.gBrowser.selectedTab);
     getGroupItem(0).close();
 
     hideTabView(function () {
       assertNumberOfTabs(1);
       assertNumberOfGroupItems(1);
-      gBrowser.unpinTab(gBrowser.selectedTab);
+      win.gBrowser.unpinTab(win.gBrowser.selectedTab);
       next();
-    });
+    }, win);
   }
 
   // setup: 1 pinned tab, 1 empty group, 1 non-empty group
   // action: close non-empty group
   // expected: nothing should happen
   let testPinnedTab3 = function () {
-    gBrowser.pinTab(gBrowser.selectedTab);
+    win.gBrowser.pinTab(win.gBrowser.selectedTab);
 
     let groupItem = getGroupItem(0);
     let newGroupItem = createGroupItem(1);
     assertNumberOfGroupItems(2);
 
     closeGroupItem(newGroupItem, function () {
       assertNumberOfGroupItems(1);
       assertGroupItemExists(groupItem);
 
-      gBrowser.unpinTab(gBrowser.selectedTab);
-      hideTabView(next);
+      win.gBrowser.unpinTab(win.gBrowser.selectedTab);
+      hideTabView(next, win);
     });
   }
 
   // setup: 1 pinned tab, 1 empty group, 1 non-empty group
   // action: hide non-empty group, exit panorama
   // expected: nothing should happen
   let testPinnedTab4 = function () {
-    gBrowser.pinTab(gBrowser.selectedTab);
+    win.gBrowser.pinTab(win.gBrowser.selectedTab);
 
     let groupItem = getGroupItem(0);
     let newGroupItem = createGroupItem(1);
     assertNumberOfGroupItems(2);
 
     hideGroupItem(newGroupItem, function () {
       hideTabView(function () {
         assertNumberOfGroupItems(1);
         assertGroupItemExists(groupItem);
         assertGroupItemRemoved(newGroupItem);
-        gBrowser.unpinTab(gBrowser.selectedTab);
+        win.gBrowser.unpinTab(win.gBrowser.selectedTab);
         next();
-      });
+      }, win);
     });
   }
 
   // setup: 1 non-empty group, 1 empty group
   // action: close non-empty group
   // expected: empty group is re-used, new tab is created and zoomed into
   let testEmptyGroup1 = function () {
     let groupItem = getGroupItem(0);
     let newGroupItem = createGroupItem(0);
     assertNumberOfGroupItems(2);
 
     closeGroupItem(groupItem, function () {
       assertNumberOfGroupItems(1);
       assertGroupItemExists(newGroupItem);
-      whenTabViewIsHidden(next);
+      whenTabViewIsHidden(next, win);
     });
   }
 
   // setup: 1 non-empty group, 1 empty group
   // action: hide non-empty group, exit panorama
   // expected: empty group is re-used, new tab is created and zoomed into
   let testEmptyGroup2 = function () {
     let groupItem = getGroupItem(0);
@@ -213,34 +214,34 @@ function test() {
     assertNumberOfGroupItems(2);
 
     hideGroupItem(groupItem, function () {
       hideTabView(function () {
         assertNumberOfGroupItems(1);
         assertGroupItemRemoved(groupItem);
         assertGroupItemExists(newGroupItem);
         next();
-      });
+      }, win);
     });
   }
 
   // setup: 1 hidden group, 1 non-empty group
   // action: close non-empty group
   // expected: nothing should happen
   let testHiddenGroup1 = function () {
     let groupItem = getGroupItem(0);
     let hiddenGroupItem = createGroupItem(1);
     assertNumberOfGroupItems(2);
 
     hideGroupItem(hiddenGroupItem, function () {
       closeGroupItem(groupItem, function () {
         assertNumberOfGroupItems(1);
         assertGroupItemRemoved(groupItem);
         assertGroupItemExists(hiddenGroupItem);
-        hideTabView(next);
+        hideTabView(next, win);
       });
     });
   }
 
   // setup: 1 hidden group, 1 non-empty group
   // action: hide non-empty group, exit panorama
   // expected: new group with blank tab is created and zoomed into
   let testHiddenGroup2 = function () {
@@ -250,17 +251,17 @@ function test() {
 
     hideGroupItem(hiddenGroupItem, function () {
       hideGroupItem(groupItem, function () {
         hideTabView(function () {
           assertNumberOfGroupItems(1);
           assertGroupItemRemoved(groupItem);
           assertGroupItemRemoved(hiddenGroupItem);
           next();
-        });
+        }, win);
       });
     });
   }
 
   tests.push({name: 'testSingleGroup1', func: testSingleGroup1});
   tests.push({name: 'testSingleGroup2', func: testSingleGroup2});
 
   tests.push({name: 'testNonEmptyGroup1', func: testNonEmptyGroup1});
@@ -274,13 +275,14 @@ function test() {
   tests.push({name: 'testEmptyGroup1', func: testEmptyGroup1});
   tests.push({name: 'testEmptyGroup2', func: testEmptyGroup2});
 
   tests.push({name: 'testHiddenGroup1', func: testHiddenGroup1});
   tests.push({name: 'testHiddenGroup2', func: testHiddenGroup2}),
 
   waitForExplicitFinish();
 
-  showTabView(function () {
-    cw = TabView.getContentWindow();
+  newWindowWithTabView(window => {
+    win = window;
+    cw = win.TabView.getContentWindow();
     next();
   });
 }
--- a/browser/components/tabview/test/browser_tabview_bug624847.js
+++ b/browser/components/tabview/test/browser_tabview_bug624847.js
@@ -1,113 +1,109 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 function test() {
   let cw;
+  let win;
   let groupItemId;
   let prefix = 'start';
 
   let assertTabViewIsHidden = function () {
-    ok(!TabView.isVisible(), prefix + ': tabview is hidden');
+    ok(!win.TabView.isVisible(), prefix + ': tabview is hidden');
   }
 
   let assertNumberOfGroups = function (num) {
     is(cw.GroupItems.groupItems.length, num, prefix + ': there should be ' + num + ' groups');
   }
 
   let assertNumberOfTabs = function (num) {
-    is(gBrowser.visibleTabs.length, num, prefix + ': there should be ' + num + ' tabs');
+    is(win.gBrowser.visibleTabs.length, num, prefix + ': there should be ' + num + ' tabs');
   }
 
   let assertNumberOfPinnedTabs = function (num) {
-    is(gBrowser._numPinnedTabs, num, prefix + ': there should be ' + num + ' pinned tabs');
+    is(win.gBrowser._numPinnedTabs, num, prefix + ': there should be ' + num + ' pinned tabs');
   }
 
   let assertGroupItemPreserved = function () {
     is(cw.GroupItems.groupItems[0].id, groupItemId, prefix + ': groupItem was preserved');
   }
 
   let assertValidPrerequisites = function () {
     assertNumberOfTabs(1);
     assertNumberOfGroups(1);
     assertNumberOfPinnedTabs(0);
     assertTabViewIsHidden();
   }
 
   let createTab = function (url) {
-    return gBrowser.loadOneTab(url || 'http://mochi.test:8888/', {inBackground: true});
+    return win.gBrowser.loadOneTab(url || 'http://mochi.test:8888/', {inBackground: true});
   }
 
   let createBlankTab = function () {
     return createTab('about:blank');
   }
 
   let finishTest = function () {
     prefix = 'finish';
     assertValidPrerequisites();
-    finish();
+    promiseWindowClosed(win).then(finish);
   }
 
   let testUndoCloseWithSelectedBlankTab = function () {
     prefix = 'unpinned';
     let tab = createTab();
     assertNumberOfTabs(2);
 
     afterAllTabsLoaded(function () {
-      gBrowser.removeTab(tab);
+      win.gBrowser.removeTab(tab);
       assertNumberOfTabs(1);
       assertNumberOfPinnedTabs(0);
 
       restoreTab(function () {
         prefix = 'unpinned-restored';
         assertValidPrerequisites();
         assertGroupItemPreserved();
 
         createBlankTab();
-        afterAllTabsLoaded(testUndoCloseWithSelectedBlankPinnedTab);
-      });
-    });
+        afterAllTabsLoaded(testUndoCloseWithSelectedBlankPinnedTab, win);
+      }, 0, win);
+    }, win);
   }
 
   let testUndoCloseWithSelectedBlankPinnedTab = function () {
     prefix = 'pinned';
     assertNumberOfTabs(2);
 
     afterAllTabsLoaded(function () {
-      gBrowser.removeTab(gBrowser.tabs[0]);
-      gBrowser.pinTab(gBrowser.tabs[0]);
-
-      registerCleanupFunction(function () {
-        let tab = gBrowser.tabs[0];
-        if (tab.pinned)
-          gBrowser.unpinTab(tab);
-      });
+      win.gBrowser.removeTab(win.gBrowser.tabs[0]);
+      win.gBrowser.pinTab(win.gBrowser.tabs[0]);
 
       assertNumberOfTabs(1);
       assertNumberOfPinnedTabs(1);
 
       restoreTab(function () {
         prefix = 'pinned-restored';
         assertValidPrerequisites();
         assertGroupItemPreserved();
 
         createBlankTab();
-        gBrowser.removeTab(gBrowser.tabs[0]);
+        win.gBrowser.removeTab(win.gBrowser.tabs[0]);
 
-        afterAllTabsLoaded(finishTest);
-      });
-    });
+        afterAllTabsLoaded(finishTest, win);
+      }, 0, win);
+    }, win);
   }
 
   waitForExplicitFinish();
-  registerCleanupFunction(function () TabView.hide());
 
-  showTabView(function () {
+  newWindowWithTabView(window => {
+    win = window;
+
     hideTabView(function () {
-      cw = TabView.getContentWindow();
+      cw = win.TabView.getContentWindow();
       groupItemId = cw.GroupItems.groupItems[0].id;
 
       assertValidPrerequisites();
       testUndoCloseWithSelectedBlankTab();
-    });
+    }, win);
   });
 }
--- a/browser/components/tabview/test/browser_tabview_bug626455.js
+++ b/browser/components/tabview/test/browser_tabview_bug626455.js
@@ -13,87 +13,87 @@ const TEST_URL = 'data:text/html,<script
                  'function(e){e.returnValue="?"}</script>';
 
 let contentWindow;
 let activeGroup;
 
 function test() {
   waitForExplicitFinish();
 
-  showTabView(function () {
-    contentWindow = TabView.getContentWindow();
+  newWindowWithTabView(win => {
+    contentWindow = win.TabView.getContentWindow();
     activeGroup = contentWindow.GroupItems.getActiveGroupItem();
 
-    gBrowser.browsers[0].loadURI("data:text/html,<p>test for bug 626455, tab1");
+    win.gBrowser.browsers[0].loadURI("data:text/html,<p>test for bug 626455, tab1");
 
-    let tab = gBrowser.addTab(TEST_URL);
-    afterAllTabsLoaded(() => testStayOnPage(tab));
+    let tab = win.gBrowser.addTab(TEST_URL);
+    afterAllTabsLoaded(() => testStayOnPage(win, tab));
   });
 }
 
-function testStayOnPage(blockingTab) {
+function testStayOnPage(win, blockingTab) {
   let browser = blockingTab.linkedBrowser;
   waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) {
     // stay on page
     btnStay.click();
 
     executeSoon(function () {
       showTabView(function () {
-        is(gBrowser.tabs.length, 1,
+        is(win.gBrowser.tabs.length, 1,
            "The total number of tab is 1 when staying on the page");
 
         // The other initial tab has been closed when trying to close the tab
         // group. The only tab left is the one with the onbeforeunload dialog.
-        let url = gBrowser.browsers[0].currentURI.spec;
+        let url = win.gBrowser.browsers[0].currentURI.spec;
         ok(url.contains("onbeforeunload"), "The open tab is the expected one");
 
         is(contentWindow.GroupItems.getActiveGroupItem(), activeGroup,
            "Active group is still the same");
 
         is(contentWindow.GroupItems.groupItems.length, 1,
            "Only one group is open");
 
         // start the next test
-        testLeavePage(gBrowser.tabs[0]);
-      });
+        testLeavePage(win, win.gBrowser.tabs[0]);
+      }, win);
     });
   });
 
   closeGroupItem(activeGroup);
 }
 
-function testLeavePage(blockingTab) {
+function testLeavePage(win, blockingTab) {
   let browser = blockingTab.linkedBrowser;
   waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) {
     // Leave page
     btnLeave.click();
   });
 
-  whenGroupClosed(activeGroup, finishTest);
+  whenGroupClosed(activeGroup, () => finishTest(win));
   closeGroupItem(activeGroup);
 }
 
-function finishTest() {
-  is(gBrowser.tabs.length, 1,
+function finishTest(win) {
+  is(win.gBrowser.tabs.length, 1,
      "The total number of tab is 1 after leaving the page");
   is(contentWindow.TabItems.getItems().length, 1,
      "The total number of tab items is 1 after leaving the page");
 
-  let location = gBrowser.browsers[0].currentURI.spec;
+  let location = win.gBrowser.browsers[0].currentURI.spec;
   is(location, BROWSER_NEW_TAB_URL, "The open tab is the expected one");
 
   isnot(contentWindow.GroupItems.getActiveGroupItem(), activeGroup,
      "Active group is no longer the same");
 
   is(contentWindow.GroupItems.groupItems.length, 1,
      "Only one group is open");
 
   contentWindow = null;
   activeGroup = null;
-  finish();
+  promiseWindowClosed(win).then(finish);
 }
 
 // ----------
 function whenGroupClosed(group, callback) {
   group.addSubscriber("close", function onClose() {
     group.removeSubscriber("close", onClose);
     callback();
   });
--- a/browser/components/tabview/test/browser_tabview_bug633788.js
+++ b/browser/components/tabview/test/browser_tabview_bug633788.js
@@ -1,31 +1,31 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 function test() {
   waitForExplicitFinish();
 
-  showTabView(function () {
-    is(gBrowser.tabs.length, 1, "There is only one tab");
+  newWindowWithTabView(win => {
+    is(win.gBrowser.tabs.length, 1, "There is only one tab");
 
-    let tab = gBrowser.tabs[0];
+    let tab = win.gBrowser.tabs[0];
     let tabItem = tab._tabViewTabItem;
     ok(tabItem.parent, "The tab item belongs to a group");
     let groupId = tabItem.parent.id;
 
     tab._tabViewTabItem.close();
 
     whenTabViewIsHidden(function() {
       // a new tab with group should be opened
-      is(gBrowser.tabs.length, 1, "There is still one tab");
-      isnot(gBrowser.selectedTab, tab, "The tab is different");
+      is(win.gBrowser.tabs.length, 1, "There is still one tab");
+      isnot(win.gBrowser.selectedTab, tab, "The tab is different");
 
-      tab = gBrowser.tabs[0];
+      tab = win.gBrowser.tabs[0];
       tabItem = tab._tabViewTabItem;
       ok(tabItem.parent, "This new tab item belongs to a group");
 
       is(tabItem.parent.id, groupId, "The group is different");
 
-      finish();
-    });
+      promiseWindowClosed(win).then(finish);
+    }, win);
   });
 }
--- a/browser/components/tabview/test/browser_tabview_bug685692.js
+++ b/browser/components/tabview/test/browser_tabview_bug685692.js
@@ -1,54 +1,48 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 function test() {
   waitForExplicitFinish();
 
-  gBrowser.addTab("http://example.com/");
-  gBrowser.addTab("http://example.com/");
+  newWindowWithTabView(win => {
+    win.gBrowser.addTab("http://example.com/");
+    win.gBrowser.addTab("http://example.com/");
 
-  registerCleanupFunction(function () {
-    while (gBrowser.tabs.length > 1)
-      gBrowser.removeTab(gBrowser.tabs[1]);
-    hideTabView();
-  })
-
-  afterAllTabsLoaded(function() {
-    showTabView(function() {
-      let cw = TabView.getContentWindow();
+    afterAllTabsLoaded(function() {
+      let cw = win.TabView.getContentWindow();
 
       let groupItemOne = cw.GroupItems.groupItems[0];
       is(groupItemOne.getChildren().length, 3, "The number of tabs in group one is 3");
- 
+
       // create a group with a blank tab
-      let groupItemTwo = createGroupItemWithBlankTabs(window, 400, 400, 40, 1);
+      let groupItemTwo = createGroupItemWithBlankTabs(win, 400, 400, 40, 1);
       is(groupItemTwo.getChildren().length, 1, "The number of tabs in group two is 1");
 
       cw.UI.setActive(groupItemOne);
 
-      moveTabToAnotherGroup(groupItemOne.getChild(2).tab, groupItemOne, groupItemTwo, function() {
-        moveTabToAnotherGroup(groupItemOne.getChild(1).tab, groupItemOne, groupItemTwo, function() {
+      moveTabToAnotherGroup(win, groupItemOne.getChild(2).tab, groupItemOne, groupItemTwo, function() {
+        moveTabToAnotherGroup(win, groupItemOne.getChild(1).tab, groupItemOne, groupItemTwo, function() {
           groupItemOne.close();
-          hideTabView(finish);
+          promiseWindowClosed(win).then(finish);
         });
       });
     });
   });
 }
 
-function moveTabToAnotherGroup(targetTab, groupItemOne, groupItemTwo, callback) {
+function moveTabToAnotherGroup(win, targetTab, groupItemOne, groupItemTwo, callback) {
   hideTabView(function() {
     let tabCountInGroupItemOne = groupItemOne.getChildren().length;
     let tabCountInGroupItemTwo = groupItemTwo.getChildren().length;
 
-    TabView.moveTabTo(targetTab, groupItemTwo.id);
+    win.TabView.moveTabTo(targetTab, groupItemTwo.id);
 
     showTabView(function() {
       is(groupItemOne.getChildren().length, --tabCountInGroupItemOne, "The number of tab items in group one is decreased");
       is(groupItemTwo.getChildren().length, ++tabCountInGroupItemTwo, "The number of tab items in group two is increased");
       is(groupItemTwo.getChild(tabCountInGroupItemTwo-1).tab, targetTab, "The last tab is the moved tab");
 
       callback();
-    });
-  });
+    }, win);
+  }, win);
 }