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-11-02 20:13:26 +00:00
|
|
|
const webdriver = require("selenium-webdriver");
|
|
|
|
const by = webdriver.By;
|
|
|
|
const until = webdriver.until;
|
2017-11-11 14:03:51 +00:00
|
|
|
const Context = require("selenium-webdriver/firefox").Context;
|
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-11-02 20:13:26 +00:00
|
|
|
|
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-11-02 20:13:26 +00:00
|
|
|
this.timeout = () => 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-11-02 20:13:26 +00:00
|
|
|
|
|
|
|
it("Proxyblock does not get stuck in infinite loop", function (done) {
|
|
|
|
|
|
|
|
const [server, url] = testServer.startWithFile("infinite-loop.html");
|
|
|
|
|
|
|
|
testUrl = url;
|
|
|
|
httpServer = server;
|
|
|
|
|
|
|
|
const standardsToBlock = ["Selectors API Level 1"];
|
|
|
|
let driverReference;
|
|
|
|
|
|
|
|
utils.promiseGetDriver()
|
|
|
|
.then(function (driver) {
|
|
|
|
driverReference = driver;
|
|
|
|
return utils.promiseSetBlockingRules(driver, standardsToBlock);
|
|
|
|
})
|
|
|
|
.then(() => driverReference.get(testUrl))
|
|
|
|
.then(() => driverReference.wait(until.elementLocated(by.css("div.success-case")), 2000))
|
|
|
|
.then(function () {
|
|
|
|
driverReference.quit();
|
|
|
|
testServer.stop(httpServer);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(function (e) {
|
|
|
|
driverReference.quit();
|
|
|
|
testServer.stop(httpServer);
|
|
|
|
done(e);
|
|
|
|
});
|
|
|
|
});
|
2017-10-22 00:39:17 +00:00
|
|
|
});
|
2017-10-23 08:29:59 +00:00
|
|
|
});
|