michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() { michael@0: is(gBrowser.tabs.length, 1, "one tab is open initially"); michael@0: michael@0: // Add several new tabs in sequence, interrupted by selecting a michael@0: // different tab, moving a tab around and closing a tab, michael@0: // returning a list of opened tabs for verifying the expected order. michael@0: // The new tab behaviour is documented in bug 465673 michael@0: let tabs = []; michael@0: function addTab(aURL, aReferrer) { michael@0: tabs.push(gBrowser.addTab(aURL, {referrerURI: aReferrer})); michael@0: } michael@0: michael@0: addTab("http://mochi.test:8888/#0"); michael@0: gBrowser.selectedTab = tabs[0]; michael@0: addTab("http://mochi.test:8888/#1"); michael@0: addTab("http://mochi.test:8888/#2", gBrowser.currentURI); michael@0: addTab("http://mochi.test:8888/#3", gBrowser.currentURI); michael@0: gBrowser.selectedTab = tabs[tabs.length - 1]; michael@0: gBrowser.selectedTab = tabs[0]; michael@0: addTab("http://mochi.test:8888/#4", gBrowser.currentURI); michael@0: gBrowser.selectedTab = tabs[3]; michael@0: addTab("http://mochi.test:8888/#5", gBrowser.currentURI); michael@0: gBrowser.removeTab(tabs.pop()); michael@0: addTab("about:blank", gBrowser.currentURI); michael@0: gBrowser.moveTabTo(gBrowser.selectedTab, 1); michael@0: addTab("http://mochi.test:8888/#6", gBrowser.currentURI); michael@0: addTab(); michael@0: addTab("http://mochi.test:8888/#7"); michael@0: michael@0: function testPosition(tabNum, expectedPosition, msg) { michael@0: is(Array.indexOf(gBrowser.tabs, tabs[tabNum]), expectedPosition, msg); michael@0: } michael@0: michael@0: testPosition(0, 3, "tab without referrer was opened to the far right"); michael@0: testPosition(1, 7, "tab without referrer was opened to the far right"); michael@0: testPosition(2, 5, "tab with referrer opened immediately to the right"); michael@0: testPosition(3, 1, "next tab with referrer opened further to the right"); michael@0: testPosition(4, 4, "tab selection changed, tab opens immediately to the right"); michael@0: testPosition(5, 6, "blank tab with referrer opens to the right of 3rd original tab where removed tab was"); michael@0: testPosition(6, 2, "tab has moved, new tab opens immediately to the right"); michael@0: testPosition(7, 8, "blank tab without referrer opens at the end"); michael@0: testPosition(8, 9, "tab without referrer opens at the end"); michael@0: michael@0: tabs.forEach(gBrowser.removeTab, gBrowser); michael@0: }