Skip to content

Commit

Permalink
test: add failing popup tests (#1849)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Apr 17, 2020
1 parent 39c9a45 commit cf415bb
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
34 changes: 33 additions & 1 deletion test/browsercontext.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

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

describe('BrowserContext', function() {
it('should create new context', async function({browser}) {
Expand Down Expand Up @@ -651,4 +651,36 @@ describe('Events.BrowserContext.Page', function() {
]);
await context.close();
});
it.fail(CHROMIUM || WEBKIT)('should work with Shift-clicking', async({browser, server}) => {
// Chromium: Shift+Click fires frameRequestedNavigation that never materializes
// because it actually opens a new window.
// WebKit: Shift+Click does not open a new window.
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
await page.setContent('<a href="/one-style.html">yo</a>');
const [popup] = await Promise.all([
context.waitForEvent('page'),
page.click('a', { modifiers: ['Shift'] }),
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
await context.close();
});
it.fail(CHROMIUM || WEBKIT)('should work with Ctrl-clicking', async({browser, server}) => {
// Chromium: Ctrl+Click fires frameRequestedNavigation that never materializes
// because it actually opens a new tab.
// WebKit: Ctrl+Click does not open a new tab.
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
await page.setContent('<a href="/one-style.html">yo</a>');
const [popup] = await Promise.all([
context.waitForEvent('page'),
page.click('a', { modifiers: [ MAC ? 'Meta' : 'Control'] }),
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
await context.close();
});
});
39 changes: 38 additions & 1 deletion test/popup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

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

describe('Link navigation', function() {
it('should inherit user agent from browser context', async function({browser, server}) {
Expand Down Expand Up @@ -304,6 +304,43 @@ describe('Page.Events.Popup', function() {
expect(await popup.evaluate(() => !!window.opener)).toBe(true);
await context.close();
});
it.fail(true)('should work with Shift-clicking', async({browser, server}) => {
// Chromium:
// - Shift+Click fires frameRequestedNavigation that never materializes
// because it actually opens a new window.
// - New window does not report an opener.
// WebKit: Shift+Click does not open a new window.
// Firefox: new window does not report an opener.
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
await page.setContent('<a href="/one-style.html">yo</a>');
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.click('a', { modifiers: ['Shift'] }),
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(true);
await context.close();
});
it.fail(CHROMIUM || WEBKIT)('should work with Control-clicking', async({browser, server}) => {
// Chromium:
// - Shift+Click fires frameRequestedNavigation that never materializes
// because it actually opens a new tab.
// - New tab does not report an opener.
// WebKit: Shift+Click does not open a new tab.
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
await page.setContent('<a href="/one-style.html">yo</a>');
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.click('a', { modifiers: [MAC ? 'Meta' : 'Control'] }),
]);
expect(await page.evaluate(() => !!window.opener)).toBe(false);
expect(await popup.evaluate(() => !!window.opener)).toBe(false);
await context.close();
});
it('should work with fake-clicking target=_blank and rel=noopener', async({browser, server}) => {
const context = await browser.newContext();
const page = await context.newPage();
Expand Down

0 comments on commit cf415bb

Please sign in to comment.