Skip to content

Commit cf415bb

Browse files
authored
test: add failing popup tests (#1849)
1 parent 39c9a45 commit cf415bb

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

test/browsercontext.spec.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
const utils = require('./utils');
19-
const {FFOX, CHROMIUM, WEBKIT} = utils.testOptions(browserType);
19+
const {FFOX, CHROMIUM, WEBKIT, MAC} = utils.testOptions(browserType);
2020

2121
describe('BrowserContext', function() {
2222
it('should create new context', async function({browser}) {
@@ -651,4 +651,36 @@ describe('Events.BrowserContext.Page', function() {
651651
]);
652652
await context.close();
653653
});
654+
it.fail(CHROMIUM || WEBKIT)('should work with Shift-clicking', async({browser, server}) => {
655+
// Chromium: Shift+Click fires frameRequestedNavigation that never materializes
656+
// because it actually opens a new window.
657+
// WebKit: Shift+Click does not open a new window.
658+
const context = await browser.newContext();
659+
const page = await context.newPage();
660+
await page.goto(server.EMPTY_PAGE);
661+
await page.setContent('<a href="/one-style.html">yo</a>');
662+
const [popup] = await Promise.all([
663+
context.waitForEvent('page'),
664+
page.click('a', { modifiers: ['Shift'] }),
665+
]);
666+
expect(await page.evaluate(() => !!window.opener)).toBe(false);
667+
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
668+
await context.close();
669+
});
670+
it.fail(CHROMIUM || WEBKIT)('should work with Ctrl-clicking', async({browser, server}) => {
671+
// Chromium: Ctrl+Click fires frameRequestedNavigation that never materializes
672+
// because it actually opens a new tab.
673+
// WebKit: Ctrl+Click does not open a new tab.
674+
const context = await browser.newContext();
675+
const page = await context.newPage();
676+
await page.goto(server.EMPTY_PAGE);
677+
await page.setContent('<a href="/one-style.html">yo</a>');
678+
const [popup] = await Promise.all([
679+
context.waitForEvent('page'),
680+
page.click('a', { modifiers: [ MAC ? 'Meta' : 'Control'] }),
681+
]);
682+
expect(await page.evaluate(() => !!window.opener)).toBe(false);
683+
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
684+
await context.close();
685+
});
654686
});

test/popup.spec.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
17+
const {FFOX, CHROMIUM, WEBKIT, MAC} = require('./utils').testOptions(browserType);
1818

1919
describe('Link navigation', function() {
2020
it('should inherit user agent from browser context', async function({browser, server}) {
@@ -304,6 +304,43 @@ describe('Page.Events.Popup', function() {
304304
expect(await popup.evaluate(() => !!window.opener)).toBe(true);
305305
await context.close();
306306
});
307+
it.fail(true)('should work with Shift-clicking', async({browser, server}) => {
308+
// Chromium:
309+
// - Shift+Click fires frameRequestedNavigation that never materializes
310+
// because it actually opens a new window.
311+
// - New window does not report an opener.
312+
// WebKit: Shift+Click does not open a new window.
313+
// Firefox: new window does not report an opener.
314+
const context = await browser.newContext();
315+
const page = await context.newPage();
316+
await page.goto(server.EMPTY_PAGE);
317+
await page.setContent('<a href="/one-style.html">yo</a>');
318+
const [popup] = await Promise.all([
319+
page.waitForEvent('popup'),
320+
page.click('a', { modifiers: ['Shift'] }),
321+
]);
322+
expect(await page.evaluate(() => !!window.opener)).toBe(false);
323+
expect(await popup.evaluate(() => !!window.opener)).toBe(true);
324+
await context.close();
325+
});
326+
it.fail(CHROMIUM || WEBKIT)('should work with Control-clicking', async({browser, server}) => {
327+
// Chromium:
328+
// - Shift+Click fires frameRequestedNavigation that never materializes
329+
// because it actually opens a new tab.
330+
// - New tab does not report an opener.
331+
// WebKit: Shift+Click does not open a new tab.
332+
const context = await browser.newContext();
333+
const page = await context.newPage();
334+
await page.goto(server.EMPTY_PAGE);
335+
await page.setContent('<a href="/one-style.html">yo</a>');
336+
const [popup] = await Promise.all([
337+
page.waitForEvent('popup'),
338+
page.click('a', { modifiers: [MAC ? 'Meta' : 'Control'] }),
339+
]);
340+
expect(await page.evaluate(() => !!window.opener)).toBe(false);
341+
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
342+
await context.close();
343+
});
307344
it('should work with fake-clicking target=_blank and rel=noopener', async({browser, server}) => {
308345
const context = await browser.newContext();
309346
const page = await context.newPage();

0 commit comments

Comments
 (0)