Skip to content

Commit

Permalink
test: ensure Page.setBypassCSP works with iFrames (#4155)
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov committed Mar 12, 2019
1 parent e3a4f34 commit 6474b3f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/page.spec.js
Expand Up @@ -781,6 +781,25 @@ module.exports.addTests = function({testRunner, expect, headless, Errors, Device
await page.addScriptTag({content: 'window.__injected = 42;'});
expect(await page.evaluate(() => window.__injected)).toBe(42);
});
it('should bypass CSP in iframes as well', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
{
// Make sure CSP prohibits addScriptTag in an iframe.
const frame = await utils.attachFrame(page, 'frame1', server.PREFIX + '/csp.html');
await frame.addScriptTag({content: 'window.__injected = 42;'}).catch(e => void e);
expect(await frame.evaluate(() => window.__injected)).toBe(undefined);
}

// By-pass CSP and try one more time.
await page.setBypassCSP(true);
await page.reload();

{
const frame = await utils.attachFrame(page, 'frame1', server.PREFIX + '/csp.html');
await frame.addScriptTag({content: 'window.__injected = 42;'}).catch(e => void e);
expect(await frame.evaluate(() => window.__injected)).toBe(42);
}
});
});

describe('Page.addScriptTag', function() {
Expand Down

0 comments on commit 6474b3f

Please sign in to comment.