From 6eb84ef6e99c500e593c53f63f3caad8d89dbf5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A3o=20Gottwald?= Date: Mon, 8 Feb 2010 21:10:38 +0100 Subject: [PATCH] browser chrome test for the all-tabs panel --- browser/base/content/browser-tabPreviews.js | 2 +- browser/base/content/test/Makefile.in | 1 + .../base/content/test/browser_allTabsPanel.js | 154 ++++++++++++++++++ 3 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 browser/base/content/test/browser_allTabsPanel.js diff --git a/browser/base/content/browser-tabPreviews.js b/browser/base/content/browser-tabPreviews.js index 9a15495d485..997fb5ba5b7 100644 --- a/browser/base/content/browser-tabPreviews.js +++ b/browser/base/content/browser-tabPreviews.js @@ -576,7 +576,7 @@ var allTabs = { if (this._initiated) return; this._initiated = true; - + Array.forEach(gBrowser.mTabs, function (tab) { this._addPreview(tab); }, this); diff --git a/browser/base/content/test/Makefile.in b/browser/base/content/test/Makefile.in index 8511bf5b3e6..55be8408ed7 100644 --- a/browser/base/content/test/Makefile.in +++ b/browser/base/content/test/Makefile.in @@ -82,6 +82,7 @@ _TEST_FILES = \ _BROWSER_FILES = \ browser_NetworkPrioritizer.js \ + browser_allTabsPanel.js \ browser_alltabslistener.js \ browser_bug304198.js \ browser_bug321000.js \ diff --git a/browser/base/content/test/browser_allTabsPanel.js b/browser/base/content/test/browser_allTabsPanel.js new file mode 100644 index 00000000000..a574056d62a --- /dev/null +++ b/browser/base/content/test/browser_allTabsPanel.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; +}