1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-05-29 09:28:06 +02:00
CanvasBlocker/test/navigatorTest.js

97 lines
2.6 KiB
JavaScript
Raw Normal View History

2019-02-27 23:49:00 +01:00
2019-12-16 19:27:28 +01:00
const createLog = function(){
2019-02-27 23:49:00 +01:00
"use strict";
2019-12-16 19:27:28 +01:00
const div = document.getElementById("log");
2019-02-27 23:49:00 +01:00
return function createLog(){
2019-12-16 19:27:28 +01:00
const logDiv = document.createElement("div");
2019-02-27 23:49:00 +01:00
logDiv.className = "log";
div.appendChild(logDiv);
return function createLine(str){
2019-12-16 19:27:28 +01:00
const logLine = document.createElement("div");
2019-02-27 23:49:00 +01:00
logLine.className = "logLine";
logDiv.appendChild(logLine);
logLine.textContent = str;
2019-12-21 23:47:07 +01:00
return {
update: function updateLine(str){
str = str.replace("{old content}", logLine.textContent);
logLine.textContent = str;
},
mark: function mark(index){
logLine.classList.add("marked");
logLine.title += "failed test " + index + "\n";
}
2019-02-27 23:49:00 +01:00
};
};
};
}();
2019-12-21 23:47:07 +01:00
const log = createLog();
2019-02-27 23:49:00 +01:00
2019-12-21 23:47:07 +01:00
const userAgentIsConsistent = document.getElementById("serverUserAgent").text === navigator.userAgent;
const consistencyLine = log("user agent equal between server and client: " + userAgentIsConsistent);
if (!userAgentIsConsistent){
consistencyLine.mark();
}
const lines = {};
const iframeValues = [
function(){
"use strict";
return {windowToUse: window, cleanup: function(){}};
},
function(){
"use strict";
const iframe = document.createElement("iframe");
document.body.appendChild(iframe);
const windowToUse = frames[frames.length - 1];
return {windowToUse, cleanup: function(){document.body.removeChild(iframe);}};
},
function(){
"use strict";
const iframe = document.createElement("iframe");
document.body.appendChild(iframe);
const windowToUse = window[window.length - 1];
return {windowToUse, cleanup: function(){document.body.removeChild(iframe);}};
},
function(){
"use strict";
const index = window.length;
const iframe = document.createElement("iframe");
document.body.appendChild(iframe);
const windowToUse = window[index];
return {windowToUse, cleanup: function(){document.body.removeChild(iframe);}};
2019-02-27 23:49:00 +01:00
}
2019-12-21 23:47:07 +01:00
].forEach(function(getWindow, index){
2019-05-22 23:39:56 +02:00
"use strict";
2019-12-21 23:47:07 +01:00
const {windowToUse, cleanup} = getWindow();
const navigator = windowToUse.navigator;
Object.keys(navigator.__proto__).sort().forEach(function(property){
const value = navigator[property];
if ((typeof value) === "string"){
const isFirst = !lines[property];
if (!lines[property]){
lines[property] = {
values: [],
log: log(property + ": ")
};
}
const propertyLine = lines[property];
if (propertyLine.values.indexOf(value) === -1){
propertyLine.log.update("{old content}" + (propertyLine.values.length? " | ": "") + value);
propertyLine.values.push(value);
}
if (propertyLine.values[0] !== value){
propertyLine.log.mark(index);
}
}
});
cleanup();
2019-05-22 23:39:56 +02:00
});