browser_bug462289.js (3856B)
1 var tab1, tab2; 2 3 function focus_in_navbar() { 4 var parent = document.activeElement.parentNode; 5 while (parent && parent.id != "nav-bar") { 6 parent = parent.parentNode; 7 } 8 9 return parent != null; 10 } 11 12 const SCOTCH_BONNET_PREF = "browser.urlbar.scotchBonnet.enableOverride"; 13 14 function test() { 15 Services.prefs.setBoolPref(SCOTCH_BONNET_PREF, false); 16 // Put the home button in the pre-proton placement to test focus states. 17 CustomizableUI.addWidgetToArea( 18 "home-button", 19 "nav-bar", 20 CustomizableUI.getPlacementOfWidget("stop-reload-button").position + 1 21 ); 22 registerCleanupFunction(async function resetToolbar() { 23 Services.prefs.clearUserPref(SCOTCH_BONNET_PREF); 24 await CustomizableUI.reset(); 25 }); 26 27 waitForExplicitFinish(); 28 29 tab1 = BrowserTestUtils.addTab(gBrowser, "about:blank", { 30 skipAnimation: true, 31 }); 32 tab2 = BrowserTestUtils.addTab(gBrowser, "about:blank", { 33 skipAnimation: true, 34 }); 35 36 EventUtils.synthesizeMouseAtCenter(tab1, {}); 37 setTimeout(step2, 0); 38 } 39 40 function step2() { 41 is(gBrowser.selectedTab, tab1, "1st click on tab1 selects tab"); 42 isnot( 43 document.activeElement, 44 tab1, 45 "1st click on tab1 does not activate tab" 46 ); 47 48 EventUtils.synthesizeMouseAtCenter(tab1, {}); 49 setTimeout(step3, 0); 50 } 51 52 async function step3() { 53 is( 54 gBrowser.selectedTab, 55 tab1, 56 "2nd click on selected tab1 keeps tab selected" 57 ); 58 isnot( 59 document.activeElement, 60 tab1, 61 "2nd click on selected tab1 does not activate tab" 62 ); 63 64 info("focusing URLBar then sending 3 Shift+Tab."); 65 gURLBar.focus(); 66 67 const previousButtonId = Services.prefs.getBoolPref("sidebar.revamp") 68 ? "sidebar-button" 69 : "home-button"; 70 71 let focused = BrowserTestUtils.waitForEvent( 72 document.getElementById(previousButtonId), 73 "focus" 74 ); 75 EventUtils.synthesizeKey("VK_TAB", { shiftKey: true }); 76 await focused; 77 info(`Focus is now on ${previousButtonId} button`); 78 79 focused = BrowserTestUtils.waitForEvent( 80 document.getElementById("tabs-newtab-button"), 81 "focus" 82 ); 83 EventUtils.synthesizeKey("VK_TAB", { shiftKey: true }); 84 await focused; 85 info("Focus is now on the new tab button"); 86 87 focused = BrowserTestUtils.waitForEvent(tab1, "focus"); 88 EventUtils.synthesizeKey("VK_TAB", { shiftKey: true }); 89 await focused; 90 is(gBrowser.selectedTab, tab1, "tab key to selected tab1 keeps tab selected"); 91 is(document.activeElement, tab1, "tab key to selected tab1 activates tab"); 92 93 EventUtils.synthesizeMouseAtCenter(tab1, {}); 94 setTimeout(step4, 0); 95 } 96 97 function step4() { 98 is( 99 gBrowser.selectedTab, 100 tab1, 101 "3rd click on activated tab1 keeps tab selected" 102 ); 103 is( 104 document.activeElement, 105 tab1, 106 "3rd click on activated tab1 keeps tab activated" 107 ); 108 109 gBrowser.addEventListener("TabSwitchDone", step5); 110 EventUtils.synthesizeMouseAtCenter(tab2, {}); 111 } 112 113 function step5() { 114 gBrowser.removeEventListener("TabSwitchDone", step5); 115 116 // The tabbox selects a tab within a setTimeout in a bubbling mousedown event 117 // listener, and focuses the current tab if another tab previously had focus. 118 is( 119 gBrowser.selectedTab, 120 tab2, 121 "click on tab2 while tab1 is activated selects tab" 122 ); 123 is( 124 document.activeElement, 125 tab2, 126 "click on tab2 while tab1 is activated activates tab" 127 ); 128 129 info("focusing content then sending middle-button mousedown to tab2."); 130 gBrowser.selectedBrowser.focus(); 131 132 EventUtils.synthesizeMouseAtCenter(tab2, { button: 1, type: "mousedown" }); 133 setTimeout(step6, 0); 134 } 135 136 function step6() { 137 is( 138 gBrowser.selectedTab, 139 tab2, 140 "middle-button mousedown on selected tab2 keeps tab selected" 141 ); 142 isnot( 143 document.activeElement, 144 tab2, 145 "middle-button mousedown on selected tab2 does not activate tab" 146 ); 147 148 gBrowser.removeTab(tab2); 149 gBrowser.removeTab(tab1); 150 151 finish(); 152 }