Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
add test for same origin iframes' contentWindow property, issue #20
Browse files Browse the repository at this point in the history
  • Loading branch information
pes10k committed Oct 24, 2017
1 parent 08df0c8 commit 1aad02c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
66 changes: 56 additions & 10 deletions test/functional/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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);
});
})
});
});
4 changes: 2 additions & 2 deletions test/functional/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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);
Expand Down

0 comments on commit 1aad02c

Please sign in to comment.