Improved navigator test

This commit is contained in:
kkapsner 2019-12-21 23:47:07 +01:00
parent 09286644d8
commit 627ee6d21e
2 changed files with 78 additions and 33 deletions

View File

@ -13,44 +13,84 @@ const createLog = function(){
logLine.className = "logLine";
logDiv.appendChild(logLine);
logLine.textContent = str;
return function updateLine(str){
logLine.textContent = str;
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";
}
};
};
};
}();
let log = createLog();
const log = createLog();
log("user agent equal between server and client: " + (
document.getElementById("serverUserAgent").text === navigator.userAgent
));
Object.keys(navigator.__proto__).sort().forEach(function(property){
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);}};
}
].forEach(function(getWindow, index){
"use strict";
const value = navigator[property];
if ((typeof value) === "string"){
log(property + ": " + value);
}
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();
});
const section = document.createElement("h2");
section.textContent = "Values in iFrame";
document.getElementById("log").append(section);
log = createLog();
const iframe = document.createElement("iframe");
document.body.appendChild(iframe);
const iframeWindow = frames[frames.length - 1];
Object.keys(navigator.__proto__).sort().forEach(function(property){
"use strict";
const value = iframeWindow.navigator[property];
if ((typeof value) === "string"){
log(property + "@iframe: " + value);
}
});
document.body.removeChild(iframe);

View File

@ -5,6 +5,11 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link href="testIcon.svg" type="image/png" rel="icon">
<link href="testIcon.svg" type="image/png" rel="shortcut icon">
<style>
.marked {
background-color: red;
}
</style>
</head>
<body>
<h1>Navigator test</h1>
@ -13,7 +18,7 @@ Tests the navigator properties. In the default settings of CanvasBlocker the nav
<ul>
<li>the server and client user agent match</li>
<li>the navigator properties are according to what was set in the CanvasBlocker settings</li>
<li>the values in the iFrame are equal to the normal values</li>
<li>no line is red or has multiple values (separated by a "|")</li>
</ul>
<h2>Tests</h2>
<div id="log">