add test for same origin iframes' contentWindow property, issue #20

This commit is contained in:
Peter Snyder 2017-10-23 21:35:47 -05:00
parent 08df0c89af
commit 1aad02cb75
2 changed files with 58 additions and 12 deletions

View file

@ -15,19 +15,15 @@ describe("Basic", function () {
return 10000;
};
beforeEach(function () {
const [server, url] = testServer.start();
testUrl = url;
httpServer = server;
});
afterEach(function () {
testServer.stop(httpServer);
});
describe("blocking", function () {
it("SVG Not Blocking", function (done) {
const [server, url] = testServer.start();
testUrl = url;
httpServer = server;
const standardsToBlock = [];
let driverReference;
@ -40,18 +36,25 @@ describe("Basic", function () {
.then(() => driverReference.executeAsyncScript(svgTestScript))
.then(function () {
driverReference.quit();
testServer.stop(httpServer);
done(new Error("SVG acted as if it was being blocked"));
})
.catch(function () {
// Since we're not blocking the SVG API, then the sample
// SVG code should throw an exception.
driverReference.quit();
testServer.stop(httpServer);
done();
});
});
it("SVG blocking", function (done) {
const [server, url] = testServer.start();
testUrl = url;
httpServer = server;
const standardsToBlock = utils.constants.svgBlockRule;
let driverReference;
@ -64,12 +67,55 @@ describe("Basic", function () {
.then(() => driverReference.executeAsyncScript(svgTestScript))
.then(function () {
driverReference.quit();
testServer.stop(httpServer);
done();
})
.catch(function (e) {
driverReference.quit();
testServer.stop(httpServer);
done(e);
});
});
it("iFrame contentWindow without src", function (done) {
const testHtml = `<!DOCTYPE "html">
<html>
<head>
<title>Test Page</title>
</head>
<body>
<iframe></iframe>
</body>
</html>`;
const iframeContentWindowScript = 'document.getElementsByTagName("iframe")[0].contentWindow.SVGGraphicsElement.prototype.getBBox().bartSimpson';
const [server, url] = testServer.start(undefined, testHtml);
testUrl = url;
httpServer = server;
const standardsToBlock = utils.constants.svgBlockRule;
let driverReference;
utils.promiseGetDriver()
.then(function (driver) {
driverReference = driver;
return utils.promiseSetBlockingRules(driver, standardsToBlock);
})
.then(() => driverReference.get(testUrl))
.then(() => driverReference.executeAsyncScript(iframeContentWindowScript))
.then(function (output) {
driverReference.quit();
testServer.stop(httpServer);
done();
})
.catch(function (e) {
driverReference.quit();
testServer.stop(httpServer);
done(e);
});
})
});
});

View file

@ -16,7 +16,7 @@ const staticResponse = `<!DOCTYPE "html">
</html>
`;
module.exports.start = function (callback) {
module.exports.start = function (callback, html) {
const httpServer = http.createServer(function (req, res) {
@ -27,7 +27,7 @@ module.exports.start = function (callback) {
}
res.writeHead(200, headers);
res.write(staticResponse);
res.write(html || staticResponse);
res.end();
});
httpServer.listen(8989);