mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Added iframeAPI script for tests
This commit is contained in:
parent
3dc39e11a5
commit
372ee755f7
130
test/iframeAPI.js
Normal file
130
test/iframeAPI.js
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
const iframeAPI = function(){
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const methods = [
|
||||||
|
{
|
||||||
|
name: "own window",
|
||||||
|
prepare: function(){
|
||||||
|
return {
|
||||||
|
window,
|
||||||
|
cleanup: function(){}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "simple",
|
||||||
|
prepare: function(){
|
||||||
|
const iframe = document.createElement("iframe");
|
||||||
|
iframe.style.display = "none";
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
|
||||||
|
return {
|
||||||
|
window: iframe.contentWindow,
|
||||||
|
cleanup: function(){
|
||||||
|
iframe.parentNode.removeChild(iframe);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "window.frames",
|
||||||
|
prepare: function(){
|
||||||
|
const iframe = document.createElement("iframe");
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
const window = frames[frames.length - 1];
|
||||||
|
return {
|
||||||
|
window,
|
||||||
|
cleanup: function(){
|
||||||
|
document.body.removeChild(iframe);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "window[window.length - 1]",
|
||||||
|
prepare: function(){
|
||||||
|
const iframe = document.createElement("iframe");
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
const iframeWindow = window[window.length - 1];
|
||||||
|
return {
|
||||||
|
window: iframeWindow,
|
||||||
|
cleanup: function(){
|
||||||
|
document.body.removeChild(iframe);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sneaky window[...]",
|
||||||
|
prepare: function(){
|
||||||
|
const index = window.length;
|
||||||
|
const iframe = document.createElement("iframe");
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
const iframeWindow = window[index];
|
||||||
|
return {
|
||||||
|
window: iframeWindow,
|
||||||
|
cleanup: function(){
|
||||||
|
document.body.removeChild(iframe);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "nested iFrames",
|
||||||
|
prepare: function(){
|
||||||
|
const index = window.length;
|
||||||
|
const iframe = document.createElement("iframe");
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
const iframeWindow = window[index];
|
||||||
|
iframeWindow.document.write("<iframe></iframe>");
|
||||||
|
return {
|
||||||
|
window: iframeWindow[0],
|
||||||
|
cleanup: function(){
|
||||||
|
document.body.removeChild(iframe);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "window.open",
|
||||||
|
prepare: async function openWindow(){
|
||||||
|
const newWindow = window.open("/");
|
||||||
|
if (newWindow){
|
||||||
|
return {
|
||||||
|
window: newWindow,
|
||||||
|
cleanup: function(){
|
||||||
|
newWindow.close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new Promise(function(resolve){
|
||||||
|
window.addEventListener("click", function openWindowEventListener(){
|
||||||
|
window.removeEventListener("click", openWindowEventListener);
|
||||||
|
resolve(openWindow());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
function getPerformer(callback){
|
||||||
|
return async function perform(method){
|
||||||
|
const api = await method.prepare();
|
||||||
|
callback(api.window, method.name);
|
||||||
|
api.cleanup();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
forEachMethod: function(callback){
|
||||||
|
methods.forEach(getPerformer(callback));
|
||||||
|
},
|
||||||
|
performMethod: function(callback, name){
|
||||||
|
methods.filter(function(method){
|
||||||
|
return method.name === name;
|
||||||
|
}).forEach(getPerformer(callback));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}();
|
@ -1,4 +1,4 @@
|
|||||||
|
/* globals iframeAPI*/
|
||||||
const createLog = function(){
|
const createLog = function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -18,9 +18,9 @@ const createLog = function(){
|
|||||||
str = str.replace("{old content}", logLine.textContent);
|
str = str.replace("{old content}", logLine.textContent);
|
||||||
logLine.textContent = str;
|
logLine.textContent = str;
|
||||||
},
|
},
|
||||||
mark: function mark(index){
|
mark: function mark(marktext){
|
||||||
logLine.classList.add("marked");
|
logLine.classList.add("marked");
|
||||||
logLine.title += "failed test " + index + "\n";
|
logLine.title += marktext + "\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -35,41 +35,9 @@ if (!userAgentIsConsistent){
|
|||||||
consistencyLine.mark();
|
consistencyLine.mark();
|
||||||
}
|
}
|
||||||
const lines = {};
|
const lines = {};
|
||||||
const iframeValues = [
|
|
||||||
function(){
|
iframeAPI.forEachMethod(function(windowToUse, name){
|
||||||
"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 {windowToUse, cleanup} = getWindow();
|
|
||||||
|
|
||||||
const navigator = windowToUse.navigator;
|
const navigator = windowToUse.navigator;
|
||||||
Object.keys(navigator.__proto__).sort().forEach(function(property){
|
Object.keys(navigator.__proto__).sort().forEach(function(property){
|
||||||
@ -88,9 +56,8 @@ const iframeValues = [
|
|||||||
propertyLine.values.push(value);
|
propertyLine.values.push(value);
|
||||||
}
|
}
|
||||||
if (propertyLine.values[0] !== value){
|
if (propertyLine.values[0] !== value){
|
||||||
propertyLine.log.mark(index);
|
propertyLine.log.mark("failed test " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
cleanup();
|
|
||||||
});
|
});
|
||||||
|
@ -29,5 +29,6 @@ Tests the navigator properties. In the default settings of CanvasBlocker the nav
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script id="serverUserAgent" type="text/data"><?php echo htmlentities($_SERVER["HTTP_USER_AGENT"], ENT_QUOTES, "UTF-8");?></script>
|
<script id="serverUserAgent" type="text/data"><?php echo htmlentities($_SERVER["HTTP_USER_AGENT"], ENT_QUOTES, "UTF-8");?></script>
|
||||||
|
<script src="iframeAPI.js"></script>
|
||||||
<script src="navigatorTest.js"></script>
|
<script src="navigatorTest.js"></script>
|
||||||
</body></html>
|
</body></html>
|
Loading…
x
Reference in New Issue
Block a user