Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for page.waitForFunction with script CSP #2305

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion test/frame.spec.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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