summaryrefslogtreecommitdiffstats
path: root/toolkit/components/windowwatcher/test/browser_non_popup_from_popup.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/windowwatcher/test/browser_non_popup_from_popup.js')
-rw-r--r--toolkit/components/windowwatcher/test/browser_non_popup_from_popup.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/toolkit/components/windowwatcher/test/browser_non_popup_from_popup.js b/toolkit/components/windowwatcher/test/browser_non_popup_from_popup.js
new file mode 100644
index 0000000000..9c905bacc1
--- /dev/null
+++ b/toolkit/components/windowwatcher/test/browser_non_popup_from_popup.js
@@ -0,0 +1,53 @@
+"use strict";
+
+// Opening non-popup from a popup should open a new tab in the most recent
+// non-popup window.
+add_task(async function test_non_popup_from_popup() {
+ const BLANK_PAGE = "data:text/html,";
+
+ // A page opened in a new tab.
+ const OPEN_PAGE = "data:text/plain,hello";
+
+ // A page opened in a new popup.
+ // This opens a new non-popup page with OPEN_PAGE,
+ // tha should be opened in a new tab in most recent window.
+ const NON_POPUP_OPENER = btoa(
+ `data:text/html,<script>window.open('${OPEN_PAGE}', '', '')</script>`
+ );
+
+ // A page opened in a new tab.
+ // This opens a popup with NON_POPUP_OPENER.
+ const POPUP_OPENER = `data:text/html,<script>window.open(atob("${NON_POPUP_OPENER}"), "", "width=500");</script>`;
+
+ await SpecialPowers.pushPrefEnv({
+ set: [["browser.link.open_newwindow", 3]],
+ });
+
+ await BrowserTestUtils.withNewTab(
+ {
+ gBrowser,
+ url: BLANK_PAGE,
+ },
+ async function (browser) {
+ // Wait for a popup opened by POPUP_OPENER.
+ const newPopupPromise = BrowserTestUtils.waitForNewWindow();
+
+ // Wait for a new tab opened by NON_POPUP_OPENER.
+ const newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, OPEN_PAGE);
+
+ // Open a new tab that opens a popup with NON_POPUP_OPENER.
+ BrowserTestUtils.startLoadingURIString(gBrowser, POPUP_OPENER);
+
+ let win = await newPopupPromise;
+ Assert.ok(true, "popup is opened");
+
+ let tab = await newTabPromise;
+ Assert.ok(true, "new tab is opened in the recent window");
+
+ BrowserTestUtils.removeTab(tab);
+ await BrowserTestUtils.closeWindow(win);
+ }
+ );
+
+ await SpecialPowers.popPrefEnv();
+});