Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | function test() { |
michael@0 | 2 | gPrefService.setBoolPref("browser.ctrlTab.previews", true); |
michael@0 | 3 | |
michael@0 | 4 | gBrowser.addTab(); |
michael@0 | 5 | gBrowser.addTab(); |
michael@0 | 6 | gBrowser.addTab(); |
michael@0 | 7 | |
michael@0 | 8 | checkTabs(4); |
michael@0 | 9 | |
michael@0 | 10 | ctrlTabTest([2] , 1, 0); |
michael@0 | 11 | ctrlTabTest([2, 3, 1], 2, 2); |
michael@0 | 12 | ctrlTabTest([] , 4, 2); |
michael@0 | 13 | |
michael@0 | 14 | { |
michael@0 | 15 | let selectedIndex = gBrowser.tabContainer.selectedIndex; |
michael@0 | 16 | pressCtrlTab(); |
michael@0 | 17 | pressCtrlTab(true); |
michael@0 | 18 | releaseCtrl(); |
michael@0 | 19 | is(gBrowser.tabContainer.selectedIndex, selectedIndex, |
michael@0 | 20 | "Ctrl+Tab -> Ctrl+Shift+Tab keeps the selected tab"); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | { // test for bug 445369 |
michael@0 | 24 | let tabs = gBrowser.tabs.length; |
michael@0 | 25 | pressCtrlTab(); |
michael@0 | 26 | EventUtils.synthesizeKey("w", { ctrlKey: true }); |
michael@0 | 27 | is(gBrowser.tabs.length, tabs - 1, "Ctrl+Tab -> Ctrl+W removes one tab"); |
michael@0 | 28 | releaseCtrl(); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | { // test for bug 667314 |
michael@0 | 32 | let tabs = gBrowser.tabs.length; |
michael@0 | 33 | pressCtrlTab(); |
michael@0 | 34 | pressCtrlTab(true); |
michael@0 | 35 | EventUtils.synthesizeKey("w", { ctrlKey: true }); |
michael@0 | 36 | is(gBrowser.tabs.length, tabs - 1, "Ctrl+Tab -> Ctrl+W removes the selected tab"); |
michael@0 | 37 | releaseCtrl(); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | gBrowser.addTab(); |
michael@0 | 41 | checkTabs(3); |
michael@0 | 42 | ctrlTabTest([2, 1, 0], 7, 1); |
michael@0 | 43 | |
michael@0 | 44 | gBrowser.addTab(); |
michael@0 | 45 | checkTabs(4); |
michael@0 | 46 | |
michael@0 | 47 | { // test for bug 445369 |
michael@0 | 48 | selectTabs([1, 2, 0]); |
michael@0 | 49 | |
michael@0 | 50 | let selectedTab = gBrowser.selectedTab; |
michael@0 | 51 | let tabToRemove = gBrowser.tabs[1]; |
michael@0 | 52 | |
michael@0 | 53 | pressCtrlTab(); |
michael@0 | 54 | pressCtrlTab(); |
michael@0 | 55 | EventUtils.synthesizeKey("w", { ctrlKey: true }); |
michael@0 | 56 | ok(!tabToRemove.parentNode, |
michael@0 | 57 | "Ctrl+Tab*2 -> Ctrl+W removes the second most recently selected tab"); |
michael@0 | 58 | |
michael@0 | 59 | pressCtrlTab(true); |
michael@0 | 60 | pressCtrlTab(true); |
michael@0 | 61 | releaseCtrl(); |
michael@0 | 62 | ok(selectedTab.selected, |
michael@0 | 63 | "Ctrl+Tab*2 -> Ctrl+W -> Ctrl+Shift+Tab*2 keeps the selected tab"); |
michael@0 | 64 | } |
michael@0 | 65 | gBrowser.removeTab(gBrowser.tabContainer.lastChild); |
michael@0 | 66 | checkTabs(2); |
michael@0 | 67 | |
michael@0 | 68 | ctrlTabTest([1], 1, 0); |
michael@0 | 69 | |
michael@0 | 70 | gBrowser.removeTab(gBrowser.tabContainer.lastChild); |
michael@0 | 71 | checkTabs(1); |
michael@0 | 72 | |
michael@0 | 73 | { // test for bug 445768 |
michael@0 | 74 | let focusedWindow = document.commandDispatcher.focusedWindow; |
michael@0 | 75 | let eventConsumed = true; |
michael@0 | 76 | let detectKeyEvent = function (event) { |
michael@0 | 77 | eventConsumed = event.defaultPrevented; |
michael@0 | 78 | }; |
michael@0 | 79 | document.addEventListener("keypress", detectKeyEvent, false); |
michael@0 | 80 | pressCtrlTab(); |
michael@0 | 81 | document.removeEventListener("keypress", detectKeyEvent, false); |
michael@0 | 82 | ok(eventConsumed, "Ctrl+Tab consumed by the tabbed browser if one tab is open"); |
michael@0 | 83 | is(focusedWindow, document.commandDispatcher.focusedWindow, |
michael@0 | 84 | "Ctrl+Tab doesn't change focus if one tab is open"); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | // cleanup |
michael@0 | 88 | if (gPrefService.prefHasUserValue("browser.ctrlTab.previews")) |
michael@0 | 89 | gPrefService.clearUserPref("browser.ctrlTab.previews"); |
michael@0 | 90 | |
michael@0 | 91 | /* private utility functions */ |
michael@0 | 92 | |
michael@0 | 93 | function pressCtrlTab(aShiftKey) |
michael@0 | 94 | EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true, shiftKey: !!aShiftKey }); |
michael@0 | 95 | |
michael@0 | 96 | function releaseCtrl() |
michael@0 | 97 | EventUtils.synthesizeKey("VK_CONTROL", { type: "keyup" }); |
michael@0 | 98 | |
michael@0 | 99 | function isOpen() |
michael@0 | 100 | ctrlTab.isOpen; |
michael@0 | 101 | |
michael@0 | 102 | function checkTabs(aTabs) { |
michael@0 | 103 | var tabs = gBrowser.tabs.length; |
michael@0 | 104 | if (tabs != aTabs) { |
michael@0 | 105 | while (gBrowser.tabs.length > 1) |
michael@0 | 106 | gBrowser.removeCurrentTab(); |
michael@0 | 107 | throw "expected " + aTabs + " open tabs, got " + tabs; |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | function selectTabs(tabs) { |
michael@0 | 112 | tabs.forEach(function (index) { |
michael@0 | 113 | gBrowser.selectedTab = gBrowser.tabs[index]; |
michael@0 | 114 | }); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | function ctrlTabTest(tabsToSelect, tabTimes, expectedIndex) { |
michael@0 | 118 | selectTabs(tabsToSelect); |
michael@0 | 119 | |
michael@0 | 120 | var indexStart = gBrowser.tabContainer.selectedIndex; |
michael@0 | 121 | var tabCount = gBrowser.tabs.length; |
michael@0 | 122 | var normalized = tabTimes % tabCount; |
michael@0 | 123 | var where = normalized == 1 ? "back to the previously selected tab" : |
michael@0 | 124 | normalized + " tabs back in most-recently-selected order"; |
michael@0 | 125 | |
michael@0 | 126 | for (let i = 0; i < tabTimes; i++) { |
michael@0 | 127 | pressCtrlTab(); |
michael@0 | 128 | |
michael@0 | 129 | if (tabCount > 2) |
michael@0 | 130 | is(gBrowser.tabContainer.selectedIndex, indexStart, |
michael@0 | 131 | "Selected tab doesn't change while tabbing"); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | if (tabCount > 2) { |
michael@0 | 135 | ok(isOpen(), |
michael@0 | 136 | "With " + tabCount + " tabs open, Ctrl+Tab opens the preview panel"); |
michael@0 | 137 | |
michael@0 | 138 | releaseCtrl(); |
michael@0 | 139 | |
michael@0 | 140 | ok(!isOpen(), |
michael@0 | 141 | "Releasing Ctrl closes the preview panel"); |
michael@0 | 142 | } else { |
michael@0 | 143 | ok(!isOpen(), |
michael@0 | 144 | "With " + tabCount + " tabs open, Ctrl+Tab doesn't open the preview panel"); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | is(gBrowser.tabContainer.selectedIndex, expectedIndex, |
michael@0 | 148 | "With "+ tabCount +" tabs open and tab " + indexStart |
michael@0 | 149 | + " selected, Ctrl+Tab*" + tabTimes + " goes " + where); |
michael@0 | 150 | } |
michael@0 | 151 | } |