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

64 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-12-24 00:54:17 +01:00
/* globals iframeAPI*/
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;
},
2019-12-24 00:54:17 +01:00
mark: function mark(marktext){
2019-12-21 23:47:07 +01:00
logLine.classList.add("marked");
2019-12-24 00:54:17 +01:00
logLine.title += marktext + "\n";
2019-12-21 23:47:07 +01:00
}
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 = {};
2019-12-24 00:54:17 +01:00
iframeAPI.forEachMethod(function(windowToUse, name){
2019-05-22 23:39:56 +02:00
"use strict";
2019-12-21 23:47:07 +01:00
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){
2019-12-24 00:54:17 +01:00
propertyLine.log.mark("failed test " + name);
2019-12-21 23:47:07 +01:00
}
}
});
2019-05-22 23:39:56 +02:00
});