2009-03-14 01:48:48 -07:00
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
|
*
|
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
|
*
|
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
|
* License.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
|
*
|
2009-12-21 13:50:30 -08:00
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
2009-03-14 01:48:48 -07:00
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s):
|
|
|
|
|
* Paul O’Shannessy <poshannessy@mozilla.com> (primary author)
|
|
|
|
|
*
|
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
|
*
|
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
|
/** Test for Bug 484108 **/
|
2010-10-09 20:23:36 -07:00
|
|
|
|
requestLongerTimeout(2);
|
2009-11-16 23:26:12 -08:00
|
|
|
|
|
|
|
|
|
waitForExplicitFinish();
|
2009-03-14 01:48:48 -07:00
|
|
|
|
|
|
|
|
|
// builds the tests state based on a few parameters
|
2010-08-27 08:12:02 -07:00
|
|
|
|
function buildTestState(num, selected, hidden) {
|
2009-03-14 01:48:48 -07:00
|
|
|
|
let state = { windows: [ { "tabs": [], "selected": selected } ] };
|
2010-08-27 08:12:02 -07:00
|
|
|
|
while (num--) {
|
2009-03-14 01:48:48 -07:00
|
|
|
|
state.windows[0].tabs.push({entries: [{url: "http://example.com/"}]});
|
2010-08-27 08:12:02 -07:00
|
|
|
|
let i = state.windows[0].tabs.length - 1;
|
|
|
|
|
if (hidden.length > 0 && i == hidden[0]) {
|
|
|
|
|
state.windows[0].tabs[i].hidden = true;
|
|
|
|
|
hidden.splice(0, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-14 01:48:48 -07:00
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// builds an array of the indexs we expect to see in the order they get loaded
|
|
|
|
|
function buildExpectedOrder(num, selected, shown) {
|
|
|
|
|
// assume selected is 1-based index
|
|
|
|
|
selected--;
|
|
|
|
|
let expected = [selected];
|
|
|
|
|
// fill left to selected if space
|
|
|
|
|
for (let i = selected - (shown - expected.length); i >= 0 && i < selected; i++)
|
|
|
|
|
expected.push(i);
|
|
|
|
|
// fill from left to right until right length or end
|
|
|
|
|
for (let i = selected + 1; expected.length < shown && i < num; i++)
|
|
|
|
|
expected.push(i);
|
|
|
|
|
// fill in the remaining
|
|
|
|
|
for (let i = 0; i < num; i++) {
|
|
|
|
|
if (expected.indexOf(i) == -1) {
|
|
|
|
|
expected.push(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return expected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the number of tests we're running
|
2011-02-12 14:12:44 -08:00
|
|
|
|
let numTests = 7;
|
2009-03-14 01:48:48 -07:00
|
|
|
|
let completedTests = 0;
|
|
|
|
|
|
2010-07-05 02:40:54 -07:00
|
|
|
|
let tabMinWidth = parseInt(getComputedStyle(gBrowser.selectedTab, null).minWidth);
|
2009-03-14 01:48:48 -07:00
|
|
|
|
|
2010-08-27 08:12:02 -07:00
|
|
|
|
function runTest(testNum, totalTabs, selectedTab, shownTabs, hiddenTabs, order) {
|
2009-03-14 01:48:48 -07:00
|
|
|
|
let test = {
|
2010-08-27 08:12:02 -07:00
|
|
|
|
state: buildTestState(totalTabs, selectedTab, hiddenTabs),
|
2009-03-14 01:48:48 -07:00
|
|
|
|
numTabsToShow: shownTabs,
|
|
|
|
|
expectedOrder: order,
|
|
|
|
|
actualOrder: [],
|
|
|
|
|
windowWidth: null,
|
|
|
|
|
callback: null,
|
|
|
|
|
window: null,
|
|
|
|
|
|
|
|
|
|
handleSSTabRestoring: function (aEvent) {
|
|
|
|
|
let tab = aEvent.originalTarget;
|
|
|
|
|
let tabbrowser = this.window.gBrowser;
|
2010-04-09 04:18:02 -07:00
|
|
|
|
let currentIndex = Array.indexOf(tabbrowser.tabs, tab);
|
2009-03-14 01:48:48 -07:00
|
|
|
|
this.actualOrder.push(currentIndex);
|
|
|
|
|
|
|
|
|
|
if (this.actualOrder.length < this.state.windows[0].tabs.length)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// all of the tabs should be restoring or restored by now
|
|
|
|
|
is(this.actualOrder.length, this.state.windows[0].tabs.length,
|
|
|
|
|
"Test #" + testNum + ": Number of restored tabs is as expected");
|
|
|
|
|
|
|
|
|
|
is(this.actualOrder.join(" "), this.expectedOrder.join(" "),
|
|
|
|
|
"Test #" + testNum + ": 'visible' tabs restored first");
|
|
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
this.window.close();
|
|
|
|
|
// if we're all done, explicitly finish
|
2009-10-13 06:31:53 -07:00
|
|
|
|
if (++completedTests == numTests) {
|
|
|
|
|
this.window.removeEventListener("load", this, false);
|
|
|
|
|
this.window.removeEventListener("SSTabRestoring", this, false);
|
2009-03-14 01:48:48 -07:00
|
|
|
|
finish();
|
2009-10-13 06:31:53 -07:00
|
|
|
|
}
|
2009-03-14 01:48:48 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
handleLoad: function (aEvent) {
|
|
|
|
|
let _this = this;
|
|
|
|
|
executeSoon(function () {
|
2010-11-24 01:50:53 -08:00
|
|
|
|
let extent = _this.window.outerWidth - _this.window.gBrowser.tabContainer.mTabstrip.scrollClientSize;
|
|
|
|
|
let windowWidth = _this.tabbarWidth + extent;
|
|
|
|
|
_this.window.resizeTo(windowWidth, _this.window.outerHeight);
|
2009-03-14 01:48:48 -07:00
|
|
|
|
ss.setWindowState(_this.window, JSON.stringify(_this.state), true);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Implement nsIDOMEventListener for handling various window and tab events
|
|
|
|
|
handleEvent: function (aEvent) {
|
|
|
|
|
switch (aEvent.type) {
|
|
|
|
|
case "load":
|
|
|
|
|
this.handleLoad(aEvent);
|
|
|
|
|
break;
|
|
|
|
|
case "SSTabRestoring":
|
|
|
|
|
this.handleSSTabRestoring(aEvent);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// setup and actually run the test
|
|
|
|
|
run: function () {
|
2010-11-24 01:50:53 -08:00
|
|
|
|
this.tabbarWidth = Math.floor((this.numTabsToShow - 0.5) * tabMinWidth);
|
2009-03-14 01:48:48 -07:00
|
|
|
|
this.window = openDialog(location, "_blank", "chrome,all,dialog=no");
|
|
|
|
|
this.window.addEventListener("SSTabRestoring", this, false);
|
|
|
|
|
this.window.addEventListener("load", this, false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
test.run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// actually create & run the tests
|
2010-08-27 08:12:02 -07:00
|
|
|
|
runTest(1, 13, 1, 6, [], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
|
|
|
|
|
runTest(2, 13, 13, 6, [], [12, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6]);
|
|
|
|
|
runTest(3, 13, 4, 6, [], [3, 4, 5, 6, 7, 8, 0, 1, 2, 9, 10, 11, 12]);
|
|
|
|
|
runTest(4, 13, 11, 6, [], [10, 7, 8, 9, 11, 12, 0, 1, 2, 3, 4, 5, 6]);
|
|
|
|
|
runTest(5, 13, 13, 6, [0, 4, 9], [12, 6, 7, 8, 10, 11, 1, 2, 3, 5, 0, 4, 9]);
|
|
|
|
|
runTest(6, 13, 4, 6, [1, 7, 12], [3, 4, 5, 6, 8, 9, 0, 2, 10, 11, 1, 7, 12]);
|
2011-02-12 14:12:44 -08:00
|
|
|
|
runTest(7, 13, 4, 6, [0, 1, 2], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2]);
|
2009-03-14 01:48:48 -07:00
|
|
|
|
|
|
|
|
|
// finish() is run by the last test to finish, so no cleanup down here
|
2009-11-16 23:26:12 -08:00
|
|
|
|
}
|