Skip to content

Commit

Permalink
test: add test for page.waitForFunction with script CSP (#2305)
Browse files Browse the repository at this point in the history
This patch adds a test to fixate page.waitForFunction behavior
for pages with CSP.

References #1229.
  • Loading branch information
aslushnikov committed Apr 3, 2018
1 parent 94c32e4 commit f925158
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion test/frame.spec.js
Expand Up @@ -110,6 +110,13 @@ module.exports.addTests = function({testRunner, expect}) {
await page.evaluate(() => window.__FOO = 'hit');
await watchdog;
});
xit('should work with strict CSP policy', async({page, server}) => {
server.setCSP('/empty.html', 'script-src ' + server.PREFIX);
await page.goto(server.EMPTY_PAGE);
const watchdog = page.waitForFunction(() => window.__FOO === 'hit', {polling: 'raf'});
await page.evaluate(() => window.__FOO = 'hit');
await watchdog;
});
it('should throw on bad polling value', async({page, server}) => {
let error = null;
try {
Expand Down Expand Up @@ -469,4 +476,4 @@ module.exports.addTests = function({testRunner, expect}) {
expect(page.frames()[2].parentFrame()).toBe(page.mainFrame());
});
});
};
};
13 changes: 13 additions & 0 deletions test/server/SimpleServer.js
Expand Up @@ -78,6 +78,8 @@ class SimpleServer {
this._routes = new Map();
/** @type {!Map<string, !{username:string, password:string}>} */
this._auths = new Map();
/** @type {!Map<string, string>} */
this._csp = new Map();
/** @type {!Map<string, !Promise>} */
this._requestSubscribers = new Map();
}
Expand Down Expand Up @@ -109,6 +111,14 @@ class SimpleServer {
this._auths.set(path, {username, password});
}

/**
* @param {string} path
* @param {string} csp
*/
setCSP(path, csp) {
this._csp.set(path, csp);
}

async stop() {
this.reset();
for (const socket of this._sockets)
Expand Down Expand Up @@ -158,6 +168,7 @@ class SimpleServer {
reset() {
this._routes.clear();
this._auths.clear();
this._csp.clear();
const error = new Error('Static Server has been reset');
for (const subscriber of this._requestSubscribers.values())
subscriber[rejectSymbol].call(null, error);
Expand Down Expand Up @@ -214,6 +225,8 @@ class SimpleServer {
} else {
response.setHeader('Cache-Control', 'no-cache, no-store');
}
if (this._csp.has(pathName))
response.setHeader('Content-Security-Policy', this._csp.get(pathName));

fs.readFile(filePath, function(err, data) {
if (err) {
Expand Down

0 comments on commit f925158

Please sign in to comment.