2010-02-08 12:10:38 -08:00
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
allTabs.init();
|
|
|
|
nextSequence();
|
|
|
|
}
|
|
|
|
|
|
|
|
var sequences = 3;
|
|
|
|
var chars = "ABCDEFGHI";
|
|
|
|
var closedTabs;
|
|
|
|
var history;
|
|
|
|
var steps;
|
|
|
|
var whenOpen = [
|
|
|
|
startSearch,
|
|
|
|
clearSearch, clearSearch,
|
|
|
|
closeTab,
|
|
|
|
moveTab,
|
|
|
|
closePanel,
|
|
|
|
];
|
|
|
|
var whenClosed = [
|
|
|
|
openPanel, openPanel, openPanel, openPanel, openPanel, openPanel,
|
|
|
|
closeTab, closeTab, closeTab,
|
|
|
|
moveTab, moveTab, moveTab,
|
|
|
|
selectTab, selectTab,
|
|
|
|
undoCloseTab,
|
|
|
|
openTab,
|
|
|
|
];
|
|
|
|
|
|
|
|
function rand(min, max) {
|
|
|
|
return min + Math.floor(Math.random() * (max - min + 1));
|
|
|
|
}
|
|
|
|
function pickOne(array) {
|
|
|
|
return array[rand(0, array.length - 1)];
|
|
|
|
}
|
|
|
|
function pickOneTab() {
|
2010-03-22 09:04:18 -07:00
|
|
|
var tab = pickOne(gBrowser.tabs);
|
|
|
|
return [tab, Array.indexOf(gBrowser.tabs, tab)];
|
2010-02-08 12:10:38 -08:00
|
|
|
}
|
|
|
|
function nextSequence() {
|
|
|
|
while (gBrowser.browsers.length > 1)
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
if (sequences-- <= 0) {
|
|
|
|
allTabs.close();
|
|
|
|
gBrowser.addTab();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
closedTabs = 0;
|
|
|
|
steps = rand(10, 20);
|
|
|
|
var initialTabs = "";
|
|
|
|
while (gBrowser.browsers.length < rand(3, 20)) {
|
|
|
|
let tabChar = pickOne(chars);
|
|
|
|
initialTabs += tabChar;
|
|
|
|
gBrowser.addTab("data:text/plain," + tabChar);
|
|
|
|
}
|
|
|
|
history = [initialTabs];
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
function next() {
|
|
|
|
executeSoon(function () {
|
|
|
|
is(allTabs.previews.length, gBrowser.browsers.length,
|
|
|
|
history.join(", "));
|
|
|
|
if (steps-- <= 0) {
|
|
|
|
nextSequence();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var step;
|
|
|
|
var rv;
|
|
|
|
do {
|
|
|
|
step = pickOne(allTabs.isOpen ? whenOpen : whenClosed);
|
2010-02-11 01:23:31 -08:00
|
|
|
info(step.name);
|
2010-02-08 12:10:38 -08:00
|
|
|
rv = step();
|
|
|
|
} while (rv === false);
|
|
|
|
history.push(step.name + (rv !== true && rv !== undefined ? " " + rv : ""));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function openPanel() {
|
|
|
|
if (allTabs.isOpen)
|
|
|
|
return false;
|
|
|
|
allTabs.panel.addEventListener("popupshown", function () {
|
|
|
|
allTabs.panel.removeEventListener("popupshown", arguments.callee, false);
|
|
|
|
next();
|
|
|
|
}, false);
|
|
|
|
allTabs.open();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function closePanel() {
|
|
|
|
allTabs.panel.addEventListener("popuphidden", function () {
|
|
|
|
allTabs.panel.removeEventListener("popuphidden", arguments.callee, false);
|
|
|
|
next();
|
|
|
|
}, false);
|
|
|
|
allTabs.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeTab() {
|
|
|
|
if (gBrowser.browsers.length == 1)
|
|
|
|
return false;
|
|
|
|
var [tab, index] = pickOneTab();
|
|
|
|
gBrowser.removeTab(tab);
|
|
|
|
closedTabs++;
|
|
|
|
next();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
function startSearch() {
|
|
|
|
allTabs.filterField.value = pickOne(chars);
|
2010-03-05 05:40:48 -08:00
|
|
|
info(allTabs.filterField.value);
|
2010-02-08 12:10:38 -08:00
|
|
|
allTabs.filter();
|
|
|
|
next();
|
|
|
|
return allTabs.filterField.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearSearch() {
|
|
|
|
if (!allTabs.filterField.value)
|
|
|
|
return false;
|
|
|
|
allTabs.filterField.value = "";
|
|
|
|
allTabs.filter();
|
|
|
|
next();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function undoCloseTab() {
|
|
|
|
if (!closedTabs)
|
|
|
|
return false;
|
|
|
|
window.undoCloseTab(0);
|
|
|
|
closedTabs--;
|
|
|
|
next();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectTab() {
|
|
|
|
var [tab, index] = pickOneTab();
|
|
|
|
gBrowser.selectedTab = tab;
|
|
|
|
next();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
function openTab() {
|
|
|
|
BrowserOpenTab();
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveTab() {
|
|
|
|
if (gBrowser.browsers.length == 1)
|
|
|
|
return false;
|
2010-02-09 01:32:10 -08:00
|
|
|
var [tab, currentIndex] = pickOneTab();
|
2010-02-08 12:10:38 -08:00
|
|
|
do {
|
2010-02-09 01:32:10 -08:00
|
|
|
var [, newIndex] = pickOneTab();
|
2010-02-08 12:10:38 -08:00
|
|
|
} while (newIndex == currentIndex);
|
2010-02-09 01:32:10 -08:00
|
|
|
gBrowser.moveTabTo(tab, newIndex);
|
2010-02-08 12:10:38 -08:00
|
|
|
next();
|
|
|
|
return currentIndex + "->" + newIndex;
|
|
|
|
}
|