diff --git a/mobile/android/components/extensions/ext-utils.js b/mobile/android/components/extensions/ext-utils.js index 991f6ac00504..2ad04bb87e71 100644 --- a/mobile/android/components/extensions/ext-utils.js +++ b/mobile/android/components/extensions/ext-utils.js @@ -254,6 +254,8 @@ class TabTracker extends TabTrackerBase { // Keep track of the extension popup tab. this._extensionPopupTabWeak = null; + // Keep track of the selected tabId + this._selectedTabId = null; } init() { @@ -371,6 +373,8 @@ class TabTracker extends TabTrackerBase { switch (event) { case "Tab:Selected": { + this._selectedTabId = data.id; + // If a new tab has been selected while an extension popup tab is still open, // close it immediately. const nativeTab = BrowserApp.getTabForId(data.id); @@ -413,6 +417,12 @@ class TabTracker extends TabTrackerBase { if (this.extensionPopupTab && this.extensionPopupTab === nativeTab) { this._extensionPopupTabWeak = null; + // Do not switch to the parent tab of the extension popup tab + // if the popup tab is not the selected tab. + if (this._selectedTabId !== tabId) { + return; + } + // Select the parent tab when the closed tab was an extension popup tab. const {BrowserApp} = windowTracker.topWindow; const popupParentTab = BrowserApp.getTabForId(nativeTab.parentId); diff --git a/mobile/android/components/extensions/test/mochitest/chrome.ini b/mobile/android/components/extensions/test/mochitest/chrome.ini index e606a6d4f5f5..002e4d05b413 100644 --- a/mobile/android/components/extensions/test/mochitest/chrome.ini +++ b/mobile/android/components/extensions/test/mochitest/chrome.ini @@ -16,3 +16,4 @@ tags = webextensions [test_ext_pageAction_show_hide.html] [test_ext_pageAction_getPopup_setPopup.html] skip-if = os == 'android' # bug 1373170 +[test_ext_popup_behavior.html] diff --git a/mobile/android/components/extensions/test/mochitest/test_ext_popup_behavior.html b/mobile/android/components/extensions/test/mochitest/test_ext_popup_behavior.html new file mode 100644 index 000000000000..235faabea344 --- /dev/null +++ b/mobile/android/components/extensions/test/mochitest/test_ext_popup_behavior.html @@ -0,0 +1,180 @@ + + + + PageAction Test + + + + + + + + + + + +