2017-10-22 00:39:17 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const utils = require("./lib/utils");
|
|
|
|
const injected = require("./lib/injected");
|
2017-10-23 05:17:23 +00:00
|
|
|
const testServer = require("./lib/server");
|
2017-10-22 00:39:17 +00:00
|
|
|
|
2017-10-26 04:02:06 +00:00
|
|
|
describe("Basic Functionality", function () {
|
2017-10-22 00:39:17 +00:00
|
|
|
|
|
|
|
const svgTestScript = injected.testSVGTestScript();
|
|
|
|
|
|
|
|
let httpServer;
|
2017-10-23 05:17:23 +00:00
|
|
|
let testUrl;
|
2017-10-22 00:39:17 +00:00
|
|
|
|
2017-10-22 05:40:39 +00:00
|
|
|
describe("blocking", function () {
|
2017-10-22 00:39:17 +00:00
|
|
|
|
2017-10-26 04:02:06 +00:00
|
|
|
this.timeout = function () {
|
|
|
|
return 20000;
|
|
|
|
};
|
|
|
|
|
2017-10-22 00:39:17 +00:00
|
|
|
it("SVG Not Blocking", function (done) {
|
2017-10-24 02:35:47 +00:00
|
|
|
|
2017-10-26 04:02:06 +00:00
|
|
|
this.timeout = function () {
|
|
|
|
return 10000;
|
|
|
|
};
|
|
|
|
|
2017-10-24 02:35:47 +00:00
|
|
|
const [server, url] = testServer.start();
|
|
|
|
|
|
|
|
testUrl = url;
|
|
|
|
httpServer = server;
|
|
|
|
|
2017-10-22 00:39:17 +00:00
|
|
|
const standardsToBlock = [];
|
|
|
|
let driverReference;
|
|
|
|
|
|
|
|
utils.promiseGetDriver()
|
2017-10-22 05:40:39 +00:00
|
|
|
.then(function (driver) {
|
2017-10-22 00:39:17 +00:00
|
|
|
driverReference = driver;
|
|
|
|
return utils.promiseSetBlockingRules(driver, standardsToBlock);
|
|
|
|
})
|
2017-10-22 05:40:39 +00:00
|
|
|
.then(() => driverReference.get(testUrl))
|
|
|
|
.then(() => driverReference.executeAsyncScript(svgTestScript))
|
2017-10-22 00:39:17 +00:00
|
|
|
.then(function () {
|
2017-10-22 05:40:39 +00:00
|
|
|
driverReference.quit();
|
2017-10-24 02:35:47 +00:00
|
|
|
testServer.stop(httpServer);
|
2017-10-22 05:40:39 +00:00
|
|
|
done(new Error("SVG acted as if it was being blocked"));
|
2017-10-22 00:39:17 +00:00
|
|
|
})
|
|
|
|
.catch(function () {
|
|
|
|
// Since we're not blocking the SVG API, then the sample
|
|
|
|
// SVG code should throw an exception.
|
|
|
|
driverReference.quit();
|
2017-10-24 02:35:47 +00:00
|
|
|
testServer.stop(httpServer);
|
2017-10-22 00:39:17 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-22 05:40:39 +00:00
|
|
|
it("SVG blocking", function (done) {
|
|
|
|
|
2017-10-26 04:02:06 +00:00
|
|
|
this.timeout = function () {
|
|
|
|
return 10000;
|
|
|
|
};
|
|
|
|
|
2017-10-24 02:35:47 +00:00
|
|
|
const [server, url] = testServer.start();
|
|
|
|
|
|
|
|
testUrl = url;
|
|
|
|
httpServer = server;
|
|
|
|
|
2017-10-22 05:40:39 +00:00
|
|
|
const standardsToBlock = utils.constants.svgBlockRule;
|
2017-10-22 00:39:17 +00:00
|
|
|
let driverReference;
|
2017-10-22 05:40:39 +00:00
|
|
|
|
2017-10-22 00:39:17 +00:00
|
|
|
utils.promiseGetDriver()
|
2017-10-22 05:40:39 +00:00
|
|
|
.then(function (driver) {
|
2017-10-22 00:39:17 +00:00
|
|
|
driverReference = driver;
|
|
|
|
return utils.promiseSetBlockingRules(driver, standardsToBlock);
|
|
|
|
})
|
2017-10-22 05:40:39 +00:00
|
|
|
.then(() => driverReference.get(testUrl))
|
|
|
|
.then(() => driverReference.executeAsyncScript(svgTestScript))
|
2017-10-22 00:39:17 +00:00
|
|
|
.then(function () {
|
|
|
|
driverReference.quit();
|
2017-10-24 02:35:47 +00:00
|
|
|
testServer.stop(httpServer);
|
2017-10-22 00:39:17 +00:00
|
|
|
done();
|
2017-10-22 05:40:39 +00:00
|
|
|
})
|
|
|
|
.catch(function (e) {
|
|
|
|
driverReference.quit();
|
2017-10-24 02:35:47 +00:00
|
|
|
testServer.stop(httpServer);
|
2017-10-22 05:40:39 +00:00
|
|
|
done(e);
|
2017-10-22 00:39:17 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-24 02:35:47 +00:00
|
|
|
|
2017-10-26 04:02:06 +00:00
|
|
|
it("iframe contentWindow without src", function (done) {
|
2017-10-24 02:35:47 +00:00
|
|
|
|
2017-10-26 04:02:06 +00:00
|
|
|
this.timeout = function () {
|
|
|
|
return 10000;
|
|
|
|
};
|
|
|
|
|
2017-10-24 02:35:47 +00:00
|
|
|
const testHtml = `<!DOCTYPE "html">
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test Page</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<iframe></iframe>
|
|
|
|
</body>
|
|
|
|
</html>`;
|
|
|
|
|
2017-10-26 04:02:06 +00:00
|
|
|
const iframeContentWindowScript = "document.getElementsByTagName('iframe')[0].contentWindow.SVGGraphicsElement.prototype.getBBox()";
|
2017-10-24 02:35:47 +00:00
|
|
|
|
|
|
|
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))
|
2017-10-26 04:02:06 +00:00
|
|
|
.then(() => driverReference.executeScript(iframeContentWindowScript))
|
|
|
|
.then(function () {
|
2017-10-24 02:35:47 +00:00
|
|
|
driverReference.quit();
|
|
|
|
testServer.stop(httpServer);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(function (e) {
|
|
|
|
driverReference.quit();
|
|
|
|
testServer.stop(httpServer);
|
|
|
|
done(e);
|
|
|
|
});
|
2017-10-26 04:02:06 +00:00
|
|
|
});
|
|
|
|
|
2017-10-22 00:39:17 +00:00
|
|
|
});
|
2017-10-23 08:29:59 +00:00
|
|
|
});
|