41 function buildTestState(
num, selected) {
42 let state = {
windows: [ {
"tabs": [],
"selected": selected } ] };
44 state.windows[0].tabs.push({entries: [{
url:
"http://example.com/"}]});
49 function buildExpectedOrder(
num, selected, shown) {
54 for (let
i = selected - (shown - expected.length);
i >= 0 &&
i < selected;
i++)
57 for (let
i = selected + 1; expected.length < shown &&
i <
num;
i++)
60 for (let
i = 0;
i <
num;
i++) {
61 if (expected.indexOf(
i) == -1) {
69 let ss =
Cc[
"@mozilla.org/browser/sessionstore;1"].getService(
Ci.nsISessionStore);
74 let completedTests = 0;
77 let tabMinWidth =
gPrefService.getIntPref(
"browser.tabs.tabMinWidth");
79 function runTest(testNum, totalTabs, selectedTab, shownTabs, order) {
82 Ci.nsISupportsWeakReference]),
84 state: buildTestState(totalTabs, selectedTab),
85 numTabsToShow: shownTabs,
92 handleSSTabRestoring:
function (aEvent) {
93 let
tab = aEvent.originalTarget;
95 let currentIndex =
Array.indexOf(tabbrowser.mTabs, tab);
96 this.actualOrder.push(currentIndex);
98 if (this.actualOrder.length <
this.state.windows[0].tabs.length)
102 is(this.actualOrder.length,
this.state.windows[0].tabs.length,
103 "Test #" + testNum +
": Number of restored tabs is as expected");
105 is(this.actualOrder.join(
" "), this.expectedOrder.join(
" "),
106 "Test #" + testNum +
": 'visible' tabs restored first");
111 if (++completedTests == numTests)
115 handleLoad:
function (aEvent) {
117 executeSoon(
function () {
118 _this.window.resizeTo(_this.windowWidth, _this.window.outerHeight);
119 ss.setWindowState(_this.window,
JSON.stringify(_this.state),
true);
124 handleEvent:
function (aEvent) {
125 switch (aEvent.type) {
127 this.handleLoad(aEvent);
129 case "SSTabRestoring":
130 this.handleSSTabRestoring(aEvent);
137 this.windowWidth = Math.floor((this.numTabsToShow - 0.5) * tabMinWidth);
138 this.
window = openDialog(location,
"_blank",
"chrome,all,dialog=no");
139 this.
window.addEventListener(
"SSTabRestoring",
this,
false);
140 this.
window.addEventListener(
"load",
this,
false);
147 runTest(1, 13, 1, 6, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
148 runTest(2, 13, 13, 6, [12, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6]);
149 runTest(3, 13, 4, 6, [3, 4, 5, 6, 7, 8, 0, 1, 2, 9, 10, 11, 12]);
150 runTest(4, 13, 11, 6, [10, 7, 8, 9, 11, 12, 0, 1, 2, 3, 4, 5, 6]);
sbOSDControlService prototype QueryInterface
_getSelectedPageStyle s i