2008-08-11 13:40:45 -07:00
|
|
|
function test() {
|
2009-07-20 21:25:59 -07:00
|
|
|
gPrefService.setBoolPref("browser.ctrlTab.previews", true);
|
2008-11-06 09:33:22 -08:00
|
|
|
|
2008-08-11 13:40:45 -07:00
|
|
|
gBrowser.addTab();
|
|
|
|
gBrowser.addTab();
|
|
|
|
gBrowser.addTab();
|
|
|
|
|
2008-08-12 05:51:02 -07:00
|
|
|
assertTabs(4);
|
|
|
|
|
2008-08-11 13:40:45 -07:00
|
|
|
ctrlTabTest([2] , 1, 0);
|
|
|
|
ctrlTabTest([2, 3, 1], 2, 2);
|
2009-07-20 21:25:59 -07:00
|
|
|
ctrlTabTest([] , 5, 2);
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2008-08-12 05:51:02 -07:00
|
|
|
{
|
|
|
|
let selectedIndex = gBrowser.tabContainer.selectedIndex;
|
|
|
|
pressCtrlTab();
|
|
|
|
pressCtrlTab(true);
|
|
|
|
releaseCtrl();
|
|
|
|
is(gBrowser.tabContainer.selectedIndex, selectedIndex,
|
|
|
|
"Ctrl+Tab -> Ctrl+Shift+Tab keeps the selected tab");
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // test for bug 445369
|
|
|
|
let tabs = gBrowser.mTabs.length;
|
|
|
|
pressCtrlTab();
|
|
|
|
EventUtils.synthesizeKey("w", { ctrlKey: true });
|
|
|
|
is(gBrowser.mTabs.length, tabs - 1, "Ctrl+Tab -> Ctrl+W removes one tab");
|
|
|
|
releaseCtrl();
|
|
|
|
}
|
2009-07-20 21:25:59 -07:00
|
|
|
|
2008-08-12 05:51:02 -07:00
|
|
|
assertTabs(3);
|
2009-07-20 21:25:59 -07:00
|
|
|
ctrlTabTest([2, 1, 0], 9, 1);
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
gBrowser.addTab();
|
|
|
|
assertTabs(4);
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2008-08-12 05:51:02 -07:00
|
|
|
{ // test for bug 445369
|
|
|
|
selectTabs([1, 2, 0]);
|
|
|
|
|
|
|
|
let selectedTab = gBrowser.selectedTab;
|
|
|
|
let tabToRemove = gBrowser.mTabs[1];
|
|
|
|
|
|
|
|
pressCtrlTab();
|
|
|
|
pressCtrlTab();
|
|
|
|
EventUtils.synthesizeKey("w", { ctrlKey: true });
|
|
|
|
ok(!tabToRemove.parentNode,
|
|
|
|
"Ctrl+Tab*2 -> Ctrl+W removes the second most recently selected tab");
|
|
|
|
|
|
|
|
pressCtrlTab(true);
|
|
|
|
pressCtrlTab(true);
|
|
|
|
releaseCtrl();
|
|
|
|
ok(gBrowser.selectedTab == selectedTab,
|
|
|
|
"Ctrl+Tab*2 -> Ctrl+W -> Ctrl+Shift+Tab*2 keeps the selected tab");
|
|
|
|
}
|
2009-07-20 21:25:59 -07:00
|
|
|
gBrowser.removeTab(gBrowser.tabContainer.lastChild);
|
2008-08-12 05:51:02 -07:00
|
|
|
assertTabs(2);
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2008-11-04 00:19:55 -08:00
|
|
|
ctrlTabTest([1], 1, 0);
|
2008-08-11 13:40:45 -07:00
|
|
|
|
|
|
|
gBrowser.removeTab(gBrowser.tabContainer.lastChild);
|
2008-08-12 05:51:02 -07:00
|
|
|
assertTabs(1);
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2008-08-12 05:51:02 -07:00
|
|
|
{ // test for bug 445768
|
|
|
|
let focusedWindow = document.commandDispatcher.focusedWindow;
|
|
|
|
let eventConsumed = true;
|
|
|
|
let detectKeyEvent = function (event) {
|
|
|
|
eventConsumed = event.getPreventDefault();
|
|
|
|
};
|
|
|
|
document.addEventListener("keypress", detectKeyEvent, false);
|
|
|
|
pressCtrlTab();
|
|
|
|
document.removeEventListener("keypress", detectKeyEvent, false);
|
|
|
|
ok(eventConsumed, "Ctrl+Tab consumed by the tabbed browser if one tab is open");
|
2009-06-06 15:34:49 -07:00
|
|
|
is(focusedWindow, document.commandDispatcher.focusedWindow,
|
2008-08-12 05:51:02 -07:00
|
|
|
"Ctrl+Tab doesn't change focus if one tab is open");
|
|
|
|
}
|
2008-08-12 00:08:03 -07:00
|
|
|
|
2009-07-20 21:25:59 -07:00
|
|
|
// cleanup
|
|
|
|
gPrefService.clearUserPref("browser.ctrlTab.previews");
|
2008-11-06 09:33:22 -08:00
|
|
|
|
2008-08-12 06:03:45 -07:00
|
|
|
/* private utility functions */
|
2008-08-12 05:51:02 -07:00
|
|
|
|
|
|
|
function pressCtrlTab(aShiftKey)
|
|
|
|
EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true, shiftKey: !!aShiftKey });
|
2008-08-12 00:08:03 -07:00
|
|
|
|
2008-08-12 05:48:32 -07:00
|
|
|
function releaseCtrl()
|
|
|
|
EventUtils.synthesizeKey("VK_CONTROL", { type: "keyup" });
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2008-11-04 11:47:46 -08:00
|
|
|
function isOpen()
|
2009-07-20 21:25:59 -07:00
|
|
|
ctrlTab.isOpen;
|
2008-11-04 11:47:46 -08:00
|
|
|
|
2008-08-12 05:51:02 -07:00
|
|
|
function assertTabs(aTabs) {
|
|
|
|
var tabs = gBrowser.mTabs.length;
|
|
|
|
if (tabs != aTabs) {
|
|
|
|
while (gBrowser.mTabs.length > 1)
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
throw "expected " + aTabs + " open tabs, got " + tabs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectTabs(tabs) {
|
|
|
|
tabs.forEach(function (index) {
|
2008-08-12 05:48:32 -07:00
|
|
|
gBrowser.selectedTab = gBrowser.mTabs[index];
|
|
|
|
});
|
2008-08-12 05:51:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function ctrlTabTest(tabsToSelect, tabTimes, expectedIndex) {
|
|
|
|
selectTabs(tabsToSelect);
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2008-08-12 05:48:32 -07:00
|
|
|
var indexStart = gBrowser.tabContainer.selectedIndex;
|
|
|
|
var tabCount = gBrowser.mTabs.length;
|
|
|
|
var normalized = tabTimes % tabCount;
|
|
|
|
var where = normalized == 1 ? "back to the previously selected tab" :
|
|
|
|
normalized + " tabs back in most-recently-selected order";
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2008-08-12 05:48:32 -07:00
|
|
|
for (let i = 0; i < tabTimes; i++) {
|
|
|
|
pressCtrlTab();
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2008-08-12 05:48:32 -07:00
|
|
|
if (tabCount > 2)
|
|
|
|
is(gBrowser.tabContainer.selectedIndex, indexStart,
|
|
|
|
"Selected tab doesn't change while tabbing");
|
|
|
|
}
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2008-08-12 05:48:32 -07:00
|
|
|
if (tabCount > 2) {
|
2008-11-04 11:47:46 -08:00
|
|
|
ok(isOpen(),
|
2008-08-12 05:48:32 -07:00
|
|
|
"With " + tabCount + " tabs open, Ctrl+Tab opens the preview panel");
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2008-08-12 05:48:32 -07:00
|
|
|
releaseCtrl();
|
2008-08-11 13:40:45 -07:00
|
|
|
|
2008-11-04 11:47:46 -08:00
|
|
|
ok(!isOpen(),
|
2008-08-12 05:48:32 -07:00
|
|
|
"Releasing Ctrl closes the preview panel");
|
|
|
|
} else {
|
2008-11-04 11:47:46 -08:00
|
|
|
ok(!isOpen(),
|
2008-08-12 05:48:32 -07:00
|
|
|
"With " + tabCount + " tabs open, Ctrl+Tab doesn't open the preview panel");
|
|
|
|
}
|
|
|
|
|
|
|
|
is(gBrowser.tabContainer.selectedIndex, expectedIndex,
|
|
|
|
"With "+ tabCount +" tabs open and tab " + indexStart
|
|
|
|
+ " selected, Ctrl+Tab*" + tabTimes + " goes " + where);
|
|
|
|
}
|
2008-08-11 13:40:45 -07:00
|
|
|
}
|