Skip to content

Commit

Permalink
test: add test on Page.evaluateOnNewDocument with CSP (#2319)
Browse files Browse the repository at this point in the history
This patch adds a test that Page.evaluateOnNewDocument works
with CSP: there's been some concerns on the bugtracker before.

References #1229
  • Loading branch information
aslushnikov committed Apr 6, 2018
1 parent 1fdd338 commit 4663b43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/assets/csp.html
@@ -0,0 +1 @@
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
12 changes: 12 additions & 0 deletions test/page.spec.js
Expand Up @@ -1508,6 +1508,18 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
await page.goto(server.PREFIX + '/tamperable.html');
expect(await page.evaluate(() => window.result)).toBe(123);
});
it('should work with CSP', async({page, server}) => {
server.setCSP('/empty.html', 'script-src ' + server.PREFIX);
await page.evaluateOnNewDocument(function(){
window.injected = 123;
});
await page.goto(server.PREFIX + '/empty.html');
expect(await page.evaluate(() => window.injected)).toBe(123);

// Make sure CSP works.
await page.addScriptTag({content: 'window.e = 10;'}).catch(e => void e);
expect(await page.evaluate(() => window.e)).toBe(undefined);
});
});

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

0 comments on commit 4663b43

Please sign in to comment.