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: /** Test for Bug 484108 **/ michael@0: waitForExplicitFinish(); michael@0: requestLongerTimeout(5); michael@0: michael@0: // builds the tests state based on a few parameters michael@0: function buildTestState(num, selected, hidden, pinned) { michael@0: let state = { windows: [ { "tabs": [], "selected": selected + 1 } ] }; michael@0: while (num--) { michael@0: state.windows[0].tabs.push({ michael@0: entries: [ michael@0: { url: "http://example.com/?t=" + state.windows[0].tabs.length } michael@0: ] michael@0: }); michael@0: let i = state.windows[0].tabs.length - 1; michael@0: if (hidden.length > 0 && i == hidden[0]) { michael@0: state.windows[0].tabs[i].hidden = true; michael@0: hidden.splice(0, 1); michael@0: } michael@0: if (pinned.length > 0 && i == pinned[0]) { michael@0: state.windows[0].tabs[i].pinned = true; michael@0: pinned.splice(0, 1); michael@0: } michael@0: } michael@0: return state; michael@0: } michael@0: michael@0: let tests = [ michael@0: { testNum: 1, michael@0: totalTabs: 13, michael@0: selectedTab: 0, michael@0: shownTabs: 6, michael@0: hiddenTabs: [], michael@0: pinnedTabs: [], michael@0: order: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] michael@0: }, michael@0: { testNum: 2, michael@0: totalTabs: 13, michael@0: selectedTab: 12, michael@0: shownTabs: 6, michael@0: hiddenTabs: [], michael@0: pinnedTabs: [], michael@0: order: [12, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6] michael@0: }, michael@0: { testNum: 3, michael@0: totalTabs: 13, michael@0: selectedTab: 3, michael@0: shownTabs: 6, michael@0: hiddenTabs: [], michael@0: pinnedTabs: [], michael@0: order: [3, 4, 5, 6, 7, 8, 0, 1, 2, 9, 10, 11, 12] michael@0: }, michael@0: { testNum: 4, michael@0: totalTabs: 13, michael@0: selectedTab: 10, michael@0: shownTabs: 6, michael@0: hiddenTabs: [], michael@0: pinnedTabs: [], michael@0: order: [10, 7, 8, 9, 11, 12, 0, 1, 2, 3, 4, 5, 6] michael@0: }, michael@0: { testNum: 5, michael@0: totalTabs: 13, michael@0: selectedTab: 12, michael@0: shownTabs: 6, michael@0: hiddenTabs: [0, 4, 9], michael@0: pinnedTabs: [], michael@0: order: [12, 6, 7, 8, 10, 11, 1, 2, 3, 5, 0, 4, 9] michael@0: }, michael@0: { testNum: 6, michael@0: totalTabs: 13, michael@0: selectedTab: 3, michael@0: shownTabs: 6, michael@0: hiddenTabs: [1, 7, 12], michael@0: pinnedTabs: [], michael@0: order: [3, 4, 5, 6, 8, 9, 0, 2, 10, 11, 1, 7, 12] michael@0: }, michael@0: { testNum: 7, michael@0: totalTabs: 13, michael@0: selectedTab: 3, michael@0: shownTabs: 6, michael@0: hiddenTabs: [0, 1, 2], michael@0: pinnedTabs: [], michael@0: order: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2] michael@0: }, michael@0: { testNum: 8, michael@0: totalTabs: 13, michael@0: selectedTab: 0, michael@0: shownTabs: 6, michael@0: hiddenTabs: [], michael@0: pinnedTabs: [0], michael@0: order: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] michael@0: }, michael@0: { testNum: 9, michael@0: totalTabs: 13, michael@0: selectedTab: 1, michael@0: shownTabs: 6, michael@0: hiddenTabs: [], michael@0: pinnedTabs: [0], michael@0: order: [1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] michael@0: }, michael@0: { testNum: 10, michael@0: totalTabs: 13, michael@0: selectedTab: 3, michael@0: shownTabs: 6, michael@0: hiddenTabs: [2], michael@0: pinnedTabs: [0,1], michael@0: order: [3, 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 2] michael@0: }, michael@0: { testNum: 11, michael@0: totalTabs: 13, michael@0: selectedTab: 12, michael@0: shownTabs: 6, michael@0: hiddenTabs: [], michael@0: pinnedTabs: [0,1,2], michael@0: order: [12, 0, 1, 2, 7, 8, 9, 10, 11, 3, 4, 5, 6] michael@0: }, michael@0: { testNum: 12, michael@0: totalTabs: 13, michael@0: selectedTab: 6, michael@0: shownTabs: 6, michael@0: hiddenTabs: [3,4,5], michael@0: pinnedTabs: [0,1,2], michael@0: order: [6, 0, 1, 2, 7, 8, 9, 10, 11, 12, 3, 4, 5] michael@0: }, michael@0: { testNum: 13, michael@0: totalTabs: 13, michael@0: selectedTab: 1, michael@0: shownTabs: 6, michael@0: hiddenTabs: [3,4,5], michael@0: pinnedTabs: [0,1,2], michael@0: order: [1, 0, 2, 6, 7, 8, 9, 10, 11, 12, 3, 4, 5] michael@0: }, michael@0: { testNum: 14, michael@0: totalTabs: 13, michael@0: selectedTab: 2, michael@0: shownTabs: 6, michael@0: hiddenTabs: [], michael@0: pinnedTabs: [0,1,2], michael@0: order: [2, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] michael@0: }, michael@0: { testNum: 15, michael@0: totalTabs: 13, michael@0: selectedTab: 3, michael@0: shownTabs: 6, michael@0: hiddenTabs: [1,4], michael@0: pinnedTabs: [0,1,2], michael@0: order: [3, 0, 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 4] michael@0: } michael@0: ]; michael@0: michael@0: let tabMinWidth = michael@0: parseInt(getComputedStyle(gBrowser.selectedTab, null).minWidth); michael@0: let testIndex = 0; michael@0: michael@0: function runNextTest() { michael@0: if (tests.length == 0) { michael@0: finish(); michael@0: return; michael@0: } michael@0: michael@0: let wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) michael@0: .getInterface(Components.interfaces.nsIDOMWindowUtils); michael@0: wu.garbageCollect(); michael@0: michael@0: setTimeout(function() { michael@0: info ("Starting test " + (++testIndex)); michael@0: let test = tests.shift(); michael@0: let state = buildTestState(test.totalTabs, test.selectedTab, michael@0: test.hiddenTabs, test.pinnedTabs); michael@0: let tabbarWidth = Math.floor((test.shownTabs - 0.5) * tabMinWidth); michael@0: let win = openDialog(location, "_blank", "chrome,all,dialog=no"); michael@0: let tabsRestored = []; michael@0: michael@0: win.addEventListener("SSTabRestoring", function onSSTabRestoring(aEvent) { michael@0: let tab = aEvent.originalTarget; michael@0: let tabLink = tab.linkedBrowser.currentURI.spec; michael@0: let tabIndex = michael@0: tabLink.substring(tabLink.indexOf("?t=") + 3, tabLink.length); michael@0: michael@0: // we need to compare with the tab's restoring index, no with the michael@0: // position index, since the pinned tabs change the positions in the michael@0: // tabbar. michael@0: tabsRestored.push(tabIndex); michael@0: michael@0: if (tabsRestored.length < state.windows[0].tabs.length) michael@0: return; michael@0: michael@0: // all of the tabs should be restoring or restored by now michael@0: is(tabsRestored.length, state.windows[0].tabs.length, michael@0: "Test #" + testIndex + ": Number of restored tabs is as expected"); michael@0: michael@0: is(tabsRestored.join(" "), test.order.join(" "), michael@0: "Test #" + testIndex + ": 'visible' tabs restored first"); michael@0: michael@0: // cleanup michael@0: win.removeEventListener("SSTabRestoring", onSSTabRestoring, false); michael@0: win.close(); michael@0: executeSoon(runNextTest); michael@0: }, false); michael@0: michael@0: whenWindowLoaded(win, function(aEvent) { michael@0: let extent = michael@0: win.outerWidth - win.gBrowser.tabContainer.mTabstrip.scrollClientSize; michael@0: let windowWidth = tabbarWidth + extent; michael@0: win.resizeTo(windowWidth, win.outerHeight); michael@0: ss.setWindowState(win, JSON.stringify(state), true); michael@0: }); michael@0: }, 1000); michael@0: }; michael@0: michael@0: runNextTest(); michael@0: }