mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Improved navigator test
This commit is contained in:
parent
09286644d8
commit
627ee6d21e
@ -13,44 +13,84 @@ const createLog = function(){
|
|||||||
logLine.className = "logLine";
|
logLine.className = "logLine";
|
||||||
logDiv.appendChild(logLine);
|
logDiv.appendChild(logLine);
|
||||||
logLine.textContent = str;
|
logLine.textContent = str;
|
||||||
return function updateLine(str){
|
return {
|
||||||
logLine.textContent = str;
|
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: " + (
|
const userAgentIsConsistent = document.getElementById("serverUserAgent").text === navigator.userAgent;
|
||||||
document.getElementById("serverUserAgent").text === navigator.userAgent
|
const consistencyLine = log("user agent equal between server and client: " + userAgentIsConsistent);
|
||||||
));
|
if (!userAgentIsConsistent){
|
||||||
|
consistencyLine.mark();
|
||||||
Object.keys(navigator.__proto__).sort().forEach(function(property){
|
}
|
||||||
|
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";
|
"use strict";
|
||||||
|
|
||||||
const value = navigator[property];
|
const {windowToUse, cleanup} = getWindow();
|
||||||
if ((typeof value) === "string"){
|
|
||||||
log(property + ": " + value);
|
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);
|
|
@ -5,6 +5,11 @@
|
|||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
<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="icon">
|
||||||
<link href="testIcon.svg" type="image/png" rel="shortcut icon">
|
<link href="testIcon.svg" type="image/png" rel="shortcut icon">
|
||||||
|
<style>
|
||||||
|
.marked {
|
||||||
|
background-color: red;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Navigator test</h1>
|
<h1>Navigator test</h1>
|
||||||
@ -13,7 +18,7 @@ Tests the navigator properties. In the default settings of CanvasBlocker the nav
|
|||||||
<ul>
|
<ul>
|
||||||
<li>the server and client user agent match</li>
|
<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 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>
|
</ul>
|
||||||
<h2>Tests</h2>
|
<h2>Tests</h2>
|
||||||
<div id="log">
|
<div id="log">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user