Skip to content

Commit

Permalink
Bug 1458061 - Implement ability to reload a selection of tabs. r=Gijs
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: CyJLk7pxGRr

--HG--
extra : amend_source : 97c7d53733c2996e06aa2994f57949357cef35ad
  • Loading branch information
layely committed Jun 29, 2018
1 parent 5877ab7 commit 9bf6837
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
4 changes: 4 additions & 0 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7864,6 +7864,10 @@ var TabContextMenu = {
document.getElementById("context_undoCloseTab").disabled =
SessionStore.getClosedTabCount(window) == 0;

// Only one of Reload_Tab/Reload_Selected_Tabs should be visible.
document.getElementById("context_reloadTab").hidden = multiselectionContext;
document.getElementById("context_reloadSelectedTabs").hidden = !multiselectionContext;

// Only one of pin/unpin/multiselect-pin/multiselect-unpin should be visible
let contextPinTab = document.getElementById("context_pinTab");
contextPinTab.hidden = this.contextTab.pinned || multiselectionContext;
Expand Down
3 changes: 3 additions & 0 deletions browser/base/content/browser.xul
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
onpopuphidden="if (event.target == this) TabContextMenu.contextTab = null;">
<menuitem id="context_reloadTab" label="&reloadTab.label;" accesskey="&reloadTab.accesskey;"
oncommand="gBrowser.reloadTab(TabContextMenu.contextTab);"/>
<menuitem id="context_reloadSelectedTabs" label="&reloadSelectedTabs.label;" hidden="true"
accesskey="&reloadSelectedTabs.accesskey;"
oncommand="gBrowser.reloadMultiSelectedTabs();"/>
<menuitem id="context_toggleMuteTab" oncommand="TabContextMenu.contextTab.toggleMuteAudio();"/>
<menuitem id="context_toggleMuteSelectedTabs" hidden="true"
oncommand="gBrowser.toggleMuteAudioOnMultiSelectedTabs(TabContextMenu.contextTab);"/>
Expand Down
14 changes: 10 additions & 4 deletions browser/base/content/tabbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3259,11 +3259,17 @@ window._gBrowser = {
},

reloadAllTabs() {
let tabs = this.visibleTabs;
let l = tabs.length;
for (var i = 0; i < l; i++) {
this.reloadTabs(this.visibleTabs);
},

reloadMultiSelectedTabs() {
this.reloadTabs(this.selectedTabs);
},

reloadTabs(tabs) {
for (let tab of tabs) {
try {
this.getBrowserForTab(tabs[i]).reload();
this.getBrowserForTab(tab).reload();
} catch (e) {
// ignore failure to reload so others will be reloaded
}
Expand Down
1 change: 1 addition & 0 deletions browser/base/content/test/tabs/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ support-files =
[browser_multiselect_tabs_mute_unmute.js]
[browser_multiselect_tabs_pin_unpin.js]
[browser_multiselect_tabs_positional_attrs.js]
[browser_multiselect_tabs_reload.js]
[browser_multiselect_tabs_using_Ctrl.js]
[browser_multiselect_tabs_using_Shift.js]
[browser_navigatePinnedTab.js]
Expand Down
50 changes: 50 additions & 0 deletions browser/base/content/test/tabs/browser_multiselect_tabs_reload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const PREF_MULTISELECT_TABS = "browser.tabs.multiselect";

async function tabLoaded(tab) {
const browser = gBrowser.getBrowserForTab(tab);
await BrowserTestUtils.browserLoaded(browser);
return true;
}

add_task(async function setPref() {
await SpecialPowers.pushPrefEnv({
set: [[PREF_MULTISELECT_TABS, true]]
});
});

add_task(async function test() {
let tab1 = await addTab();
let tab2 = await addTab();
let tab3 = await addTab();

let menuItemReloadTab = document.getElementById("context_reloadTab");
let menuItemReloadSelectedTabs = document.getElementById("context_reloadSelectedTabs");

await BrowserTestUtils.switchTab(gBrowser, tab1);
await triggerClickOn(tab2, { ctrlKey: true });

ok(tab1.multiselected, "Tab1 is multi-selected");
ok(tab2.multiselected, "Tab2 is multi-selected");
ok(!tab3.multiselected, "Tab3 is not multi-selected");

updateTabContextMenu(tab3);
is(menuItemReloadTab.hidden, false, "Reload Tab is visible");
is(menuItemReloadSelectedTabs.hidden, true, "Reload Selected Tabs is hidden");

updateTabContextMenu(tab2);
is(menuItemReloadTab.hidden, true, "Reload Tab is hidden");
is(menuItemReloadSelectedTabs.hidden, false, "Reload Selected Tabs is visible");

let tab1Loaded = tabLoaded(tab1);
let tab2Loaded = tabLoaded(tab2);
menuItemReloadSelectedTabs.click();
await tab1Loaded;
await tab2Loaded;

// We got here because tab1 and tab2 are reloaded. Otherwise the test would have timed out and failed.
ok(true, "Tab1 and Tab2 are reloaded");

BrowserTestUtils.removeTab(tab1);
BrowserTestUtils.removeTab(tab2);
BrowserTestUtils.removeTab(tab3);
});
4 changes: 4 additions & 0 deletions browser/locales/en-US/chrome/browser/browser.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ but will never be visible at the same time. -->
<!-- Unpin Tab and Unpin Selected Tabs have the same accesskey
but will never be visible at the same time. -->
<!ENTITY unpinSelectedTabs.accesskey "b">
<!-- Reload Tab and Reload Selected Tabs have the same accesskey
but will never be visible at the same time. -->
<!ENTITY reloadSelectedTabs.label "Reload Selected Tabs">
<!ENTITY reloadSelectedTabs.accesskey "R">

<!-- LOCALIZATION NOTE (pinTab.label, unpinTab.label): "Pin" is being
used as a metaphor for expressing the fact that these tabs are "pinned" to the
Expand Down

0 comments on commit 9bf6837

Please sign in to comment.