browser chrome test for the all-tabs panel

This commit is contained in:
Dão Gottwald 2010-02-08 21:10:38 +01:00
Родитель 01d5391e2b
Коммит 6eb84ef6e9
3 изменённых файлов: 156 добавлений и 1 удалений

Просмотреть файл

@ -576,7 +576,7 @@ var allTabs = {
if (this._initiated)
return;
this._initiated = true;
Array.forEach(gBrowser.mTabs, function (tab) {
this._addPreview(tab);
}, this);

Просмотреть файл

@ -82,6 +82,7 @@ _TEST_FILES = \
_BROWSER_FILES = \
browser_NetworkPrioritizer.js \
browser_allTabsPanel.js \
browser_alltabslistener.js \
browser_bug304198.js \
browser_bug321000.js \

Просмотреть файл

@ -0,0 +1,154 @@
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() {
var tab = pickOne(gBrowser.tabContainer.childNodes);
return [tab, Array.indexOf(gBrowser.tabContainer.childNodes, tab)];
}
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);
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);
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;
var currentIndex = rand(0, gBrowser.browsers.length - 1);
do {
var newIndex = rand(0, gBrowser.browsers.length - 1);
} while (newIndex == currentIndex);
gBrowser.moveTabTo(gBrowser.tabContainer.childNodes[currentIndex], newIndex);
next();
return currentIndex + "->" + newIndex;
}