test: add test on Page.evaluateOnNewDocument with CSP (#2319)

This patch adds a test that Page.evaluateOnNewDocument works
with CSP: there's been some concerns on the bugtracker before.

References #1229
This commit is contained in:
Andrey Lushnikov 2018-04-05 23:40:14 -07:00 committed by GitHub
parent 1fdd33886f
commit 4663b43a62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

1
test/assets/csp.html Normal file
View File

@ -0,0 +1 @@
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">

View File

@ -1508,6 +1508,18 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
await page.goto(server.PREFIX + '/tamperable.html'); await page.goto(server.PREFIX + '/tamperable.html');
expect(await page.evaluate(() => window.result)).toBe(123); 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() { describe('Page.setCacheEnabled', function() {