From 5bc21c09ff90509081a094566fae33b1ed33620c Mon Sep 17 00:00:00 2001
From: Sean Doyle
diff --git a/src/tests/functional/navigation_tests.js b/src/tests/functional/navigation_tests.js index e1aa7e757..eebef546c 100644 --- a/src/tests/functional/navigation_tests.js +++ b/src/tests/functional/navigation_tests.js @@ -1,4 +1,4 @@ -import { test } from "@playwright/test" +import { expect, test } from "@playwright/test" import { assert } from "chai" import { clickWithoutScrolling, @@ -473,6 +473,12 @@ test("ignores links with a [target] attribute that targets an iframe with [name= assert.equal(pathname(page.url()), "/src/tests/fixtures/one.html") }) +test("ignores forms with a [target=_blank] attribute", async ({ page }) => { + const [popup] = await Promise.all([page.waitForEvent("popup"), page.click("#form-target-blank button")]) + + expect(pathname(popup.url())).toContain("/src/tests/fixtures/one.html") +}) + test("ignores forms with a [target] attribute that targets an iframe with a matching [name]", async ({ page }) => { await page.click("#form-target-iframe button") await nextBeat() @@ -482,6 +488,12 @@ test("ignores forms with a [target] attribute that targets an iframe with a matc assert.equal(await pathnameForIFrame(page, "iframe"), "/src/tests/fixtures/one.html") }) +test("ignores forms with a button[formtarget=_blank] attribute", async ({ page }) => { + const [popup] = await Promise.all([page.waitForEvent("popup"), page.click("#button-formtarget-blank")]) + + expect(pathname(popup.url())).toContain("/src/tests/fixtures/one.html") +}) + test("ignores forms with a button[formtarget] attribute that targets an iframe with [name='']", async ({ page }) => { diff --git a/src/util.js b/src/util.js index dcb15c31b..57c48ea6a 100644 --- a/src/util.js +++ b/src/util.js @@ -218,14 +218,18 @@ export async function around(callback, reader) { return [before, after] } -export function doesNotTargetIFrame(anchor) { - if (anchor.hasAttribute("target")) { - for (const element of document.getElementsByName(anchor.target)) { +export function doesNotTargetIFrame(name) { + if (name === "_blank") { + return false + } else if (name) { + for (const element of document.getElementsByName(name)) { if (element instanceof HTMLIFrameElement) return false } - } - return true + return true + } else { + return true + } } export function findLinkFromClickTarget(target) {