mirror of
https://github.com/wassname/RubberGlove.git
synced 2026-06-27 15:13:47 +08:00
Added QUnit-based test page and a debugging hook for it
This commit is contained in:
+5
-1
@@ -1,5 +1,9 @@
|
||||
console.log("RubberGlove: Persisting settings");
|
||||
persistConfig("persistedSettings.js", {local:{enabled:true, verbose:true}});
|
||||
persistConfig("persistedSettings.js", {
|
||||
enabled:true,
|
||||
verbose:false,
|
||||
pluginWhiteList: []
|
||||
});
|
||||
console.log("RubberGlove: Settings stored at " + getWebStorageUri("persistedSettings.js"));
|
||||
|
||||
function resetBadgeCounter(tabId) {
|
||||
|
||||
+41
-35
@@ -1,10 +1,10 @@
|
||||
function bomOverload() {
|
||||
if(config.local.verbose) console.log("RubberGlove: Creating PluginArray");
|
||||
if(settings.verbose) console.log("RubberGlove: Creating PluginArray");
|
||||
function PluginArray() { // native(PluginArray)
|
||||
if(window.navigator.plugins.constructor === PluginArray)
|
||||
throw new TypeError("Illegal constructor");
|
||||
|
||||
if(config.local.verbose) console.log("RubberGlove: Creating PluginArray instance");
|
||||
if(settings.verbose) console.log("RubberGlove: Creating PluginArray instance");
|
||||
|
||||
Object.defineProperty(this, 'length', {
|
||||
enumerable: true,
|
||||
@@ -34,21 +34,23 @@ function bomOverload() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Don't ask me why the real function has this... It's not even a prototype.
|
||||
PluginArray.toString = function toString() { // native(toString)
|
||||
return Function.prototype.toString.apply(this, Array.prototype.slice.apply(arguments));
|
||||
};
|
||||
if(config.local.verbose) console.log("RubberGlove: Creating PluginArray.prototype.item()");
|
||||
Object.defineProperty(PluginArray, "toString", {
|
||||
enumerable: true,
|
||||
value: function toString() { // native(toString)
|
||||
return "function PluginArray() { [native code] }";
|
||||
}
|
||||
});
|
||||
if(settings.verbose) console.log("RubberGlove: Creating PluginArray.prototype.item()");
|
||||
PluginArray.prototype.item = function item() { // native(item)
|
||||
return this[arguments[0]];
|
||||
};
|
||||
if(config.local.verbose) console.log("RubberGlove: Creating PluginArray.prototype.namedItem()");
|
||||
if(settings.verbose) console.log("RubberGlove: Creating PluginArray.prototype.namedItem()");
|
||||
PluginArray.prototype.namedItem = function namedItem() { // native(namedItem)
|
||||
return this[arguments[0]];
|
||||
};
|
||||
if(config.local.verbose) console.log("RubberGlove: Creating PluginArray.prototype.refresh()");
|
||||
if(settings.verbose) console.log("RubberGlove: Creating PluginArray.prototype.refresh()");
|
||||
PluginArray.prototype.refresh = (function(plugins) {
|
||||
if(config.local.verbose) console.log("RubberGlove: Returning our custom PluginArray.refresh()");
|
||||
if(settings.verbose) console.log("RubberGlove: Returning our custom PluginArray.refresh()");
|
||||
return function refresh() { // native(refresh)
|
||||
// Refresh the real plugins list
|
||||
plugins.refresh.apply(plugins, Array.prototype.slice.apply(arguments));
|
||||
@@ -72,7 +74,7 @@ function bomOverload() {
|
||||
}
|
||||
}
|
||||
})(window.navigator.plugins);
|
||||
if(config.local.verbose) console.log("RubberGlove: Replacing window.PluginArray");
|
||||
if(settings.verbose) console.log("RubberGlove: Replacing window.PluginArray");
|
||||
Object.defineProperty(window, 'PluginArray', {
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
@@ -81,12 +83,12 @@ function bomOverload() {
|
||||
});
|
||||
|
||||
// TODO: This should refresh as well when PluginArray.refresh() is called.
|
||||
if(config.local.verbose) console.log("RubberGlove: Creating MimeTypeArray");
|
||||
if(settings.verbose) console.log("RubberGlove: Creating MimeTypeArray");
|
||||
function MimeTypeArray() { // native(MimeTypeArray)
|
||||
if(window.navigator.mimeTypes.constructor === MimeTypeArray)
|
||||
throw new TypeError("Illegal constructor");
|
||||
|
||||
if(config.local.verbose) console.log("RubberGlove: Creating MimeTypeArray instance");
|
||||
if(settings.verbose) console.log("RubberGlove: Creating MimeTypeArray instance");
|
||||
|
||||
Object.defineProperty(this, 'length', {
|
||||
enumerable: true,
|
||||
@@ -116,21 +118,23 @@ function bomOverload() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Don't ask me why the real function has this... It's not even a prototype.
|
||||
MimeTypeArray.toString = function toString() { // native(toString)
|
||||
return Function.prototype.toString.apply(this, Array.prototype.slice.apply(arguments));
|
||||
};
|
||||
Object.defineProperty(MimeTypeArray, "toString", {
|
||||
enumerable: true,
|
||||
value: function toString() { // native(toString)
|
||||
return "function MimeTypeArray() { [native code] }";
|
||||
}
|
||||
});
|
||||
// Yes, these duplicate the ones for PluginArray. No, they should
|
||||
// not use the same functions as they shouldn't test as equal.
|
||||
if(config.local.verbose) console.log("RubberGlove: Creating MimeTypeArray.prototype.item()");
|
||||
if(settings.verbose) console.log("RubberGlove: Creating MimeTypeArray.prototype.item()");
|
||||
MimeTypeArray.prototype.item = function item(index) { // native(item)
|
||||
return this[arguments[0]];
|
||||
};
|
||||
if(config.local.verbose) console.log("RubberGlove: Creating MimeTypeArray.prototype.namedItem()");
|
||||
if(settings.verbose) console.log("RubberGlove: Creating MimeTypeArray.prototype.namedItem()");
|
||||
MimeTypeArray.prototype.namedItem = function namedItem(name) { // native(namedItem)
|
||||
return this[arguments[0]];
|
||||
};
|
||||
if(config.local.verbose) console.log("RubberGlove: Replacing window.MimeTypeArray");
|
||||
if(settings.verbose) console.log("RubberGlove: Replacing window.MimeTypeArray");
|
||||
Object.defineProperty(window, 'MimeTypeArray', {
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
@@ -138,12 +142,12 @@ function bomOverload() {
|
||||
value: MimeTypeArray
|
||||
});
|
||||
|
||||
if(config.local.verbose) console.log("RubberGlove: Creating Navigator");
|
||||
if(settings.verbose) console.log("RubberGlove: Creating Navigator");
|
||||
function Navigator() { // native(Navigator)
|
||||
if(window.navigator.constructor === Navigator)
|
||||
throw new TypeError("Illegal constructor");
|
||||
|
||||
if(config.local.verbose) console.log("RubberGlove: Creating Navigator instance");
|
||||
if(settings.verbose) console.log("RubberGlove: Creating Navigator instance");
|
||||
|
||||
var propertyNames = Object.getOwnPropertyNames(window.navigator);
|
||||
for(var propertyIndex = 0; propertyIndex < propertyNames.length; propertyIndex++) {
|
||||
@@ -180,15 +184,17 @@ function bomOverload() {
|
||||
Object.defineProperty(this, propertyName, descriptor);
|
||||
}
|
||||
}
|
||||
// Don't ask me why the real function has this... It's not even a prototype.
|
||||
Navigator.toString = function toString() { // native(toString)
|
||||
return Function.prototype.toString.apply(this, Array.prototype.slice.apply(arguments));
|
||||
};
|
||||
if(config.local.verbose) console.log("RubberGlove: Replacing Navigator.prototype");
|
||||
Object.defineProperty(Navigator, "toString", {
|
||||
enumerable: true,
|
||||
value: function toString() { // native(toString)
|
||||
return "function Navigator() { [native code] }";
|
||||
}
|
||||
});
|
||||
if(settings.verbose) console.log("RubberGlove: Replacing Navigator.prototype");
|
||||
for(var property in window.Navigator.prototype) {
|
||||
Navigator.prototype[property] = window.Navigator.prototype[property];
|
||||
}
|
||||
if(config.local.verbose) console.log("RubberGlove: Replacing window.Navigator");
|
||||
if(settings.verbose) console.log("RubberGlove: Replacing window.Navigator");
|
||||
Object.defineProperty(window, 'Navigator', {
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
@@ -196,16 +202,16 @@ function bomOverload() {
|
||||
value: Navigator
|
||||
});
|
||||
|
||||
if(config.local.verbose) console.log("RubberGlove: Constructing Navigator");
|
||||
if(settings.verbose) console.log("RubberGlove: Constructing Navigator");
|
||||
var navigatorProxy = new Navigator();
|
||||
if(config.local.verbose) console.log("RubberGlove: Replacing window.navigator");
|
||||
if(settings.verbose) console.log("RubberGlove: Replacing window.navigator");
|
||||
Object.defineProperty(window, 'navigator', {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
writable: true,
|
||||
value: navigatorProxy
|
||||
});
|
||||
if(config.local.verbose) console.log("RubberGlove: Replacing window.clientInformation");
|
||||
if(settings.verbose) console.log("RubberGlove: Replacing window.clientInformation");
|
||||
Object.defineProperty(window, 'clientInformation', {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
@@ -215,7 +221,7 @@ function bomOverload() {
|
||||
|
||||
// Hides source code when it contains "// native(functionName)" or
|
||||
// "/* native(functionName)" at the beginning of the function body.
|
||||
if(config.local.verbose) console.log("RubberGlove: Replacing Function.prototype.toString()");
|
||||
if(settings.verbose) console.log("RubberGlove: Replacing Function.prototype.toString()");
|
||||
Function.prototype.toString = (function(oldToString) {
|
||||
return function toString() { // native(toString) <-- yes, it handles itself
|
||||
var result = oldToString.apply(this, Array.prototype.slice.apply(arguments));
|
||||
@@ -225,9 +231,9 @@ function bomOverload() {
|
||||
return result;
|
||||
};
|
||||
})(Function.prototype.toString);
|
||||
|
||||
|
||||
// Hides named plugins and mimeTypes
|
||||
if(config.local.verbose) console.log("RubberGlove: Replacing Object.getOwnPropertyNames()");
|
||||
if(settings.verbose) console.log("RubberGlove: Replacing Object.getOwnPropertyNames()");
|
||||
Object.getOwnPropertyNames = (function(oldGetOwnPropertyNames) {
|
||||
return function getOwnPropertyNames() { // native(getOwnPropertyNames)
|
||||
var propertyNames = oldGetOwnPropertyNames.apply(this, Array.prototype.slice.apply(arguments));
|
||||
@@ -246,7 +252,7 @@ function bomOverload() {
|
||||
})(Object.getOwnPropertyNames);
|
||||
|
||||
// Makes our objects look like first class objects
|
||||
if(config.local.verbose) console.log("RubberGlove: Replacing Object.prototype.toString()");
|
||||
if(settings.verbose) console.log("RubberGlove: Replacing Object.prototype.toString()");
|
||||
Object.prototype.toString = (function(oldToString) {
|
||||
return function toString() { // native(toString)
|
||||
if(this === window.navigator) return "[object Navigator]";
|
||||
|
||||
+55
-23
@@ -1,4 +1,3 @@
|
||||
//console.log("RubberGlove: Content Script for " + window.location.href);
|
||||
function getConfig(filename) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'filesystem:' + chrome.extension.getURL('temporary/' + filename), false);
|
||||
@@ -7,23 +6,69 @@ function getConfig(filename) {
|
||||
return;
|
||||
}
|
||||
|
||||
var configText = getConfig("persistedSettings.js");
|
||||
console.log("RubberGlove: config = " + configText);
|
||||
var config = JSON.parse(configText);
|
||||
var settingsText = getConfig("persistedSettings.js");
|
||||
var settings = JSON.parse(settingsText);
|
||||
|
||||
if(config.local.enabled) {
|
||||
if(settings.verbose) {
|
||||
console.log("RubberGlove: Content Script for " + window.location.href);
|
||||
console.log("RubberGlove: settings = " + settingsText);
|
||||
}
|
||||
|
||||
// Listen for callbacks from the page script
|
||||
window.addEventListener("message", function(event) {
|
||||
if(event.source != window) return;
|
||||
if(event.data.type) {
|
||||
switch(event.data.type) {
|
||||
case "RubberGlove":
|
||||
// Tell background.js to increment the badge counter
|
||||
chrome.runtime.sendMessage({
|
||||
type: "increment-counter",
|
||||
url: window.location.href,
|
||||
message: event.data.text
|
||||
});
|
||||
break;
|
||||
case "RubberGlove_DebugInfoRequest":
|
||||
console.log("RubberGlove: DebugInfoRequest from " + event.source.location.href);
|
||||
if(event.source.location.href.indexOf("file:///") == 0) {
|
||||
var debugInfo = {
|
||||
settings: settings,
|
||||
plugins: [],
|
||||
mimeTypes: []
|
||||
};
|
||||
for(var i = 0; i < navigator.plugins.length; i++) {
|
||||
var plugin = navigator.plugins[i];
|
||||
if(typeof plugin.name != 'undefined')
|
||||
debugInfo.plugins.push(plugin.name);
|
||||
}
|
||||
for(var i = 0; i < navigator.mimeTypes.length; i++) {
|
||||
var mimeType = navigator.mimeTypes[i];
|
||||
if(typeof mimeType.type != 'undefined')
|
||||
debugInfo.mimeTypes.push(mimeType.type);
|
||||
}
|
||||
console.log("RubberGlove: Sending debug info to " + event.source.location.href);
|
||||
window.postMessage({
|
||||
type: 'RubberGlove_DebugInfo',
|
||||
debugInfo: debugInfo
|
||||
}, '*');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(settings.enabled) {
|
||||
// Create the script to be injected
|
||||
var pageScript = document.createElement('script');
|
||||
pageScript.type = 'text/javascript';
|
||||
pageScript.async = false;
|
||||
pageScript.text = "(function() {\n" +
|
||||
"var config = " + configText + ";\n" +
|
||||
"var settings = " + settingsText + ";\n" +
|
||||
"(" + bomOverload.toString() + ")();\n" +
|
||||
"(" + scriptCleanupFunction.toString() + ")();\n" +
|
||||
"})();";
|
||||
|
||||
// Locate the <head> or create a new one if there isn't one or it isn't at
|
||||
// the top of the page.
|
||||
// Locate the <head> or create a new one if there isn't one or it isn't
|
||||
// at the top of the page.
|
||||
var html = document.documentElement
|
||||
var headTags = document.getElementsByTagName("head");
|
||||
var head = headTags.length > 0 ? head = headTags[0] : null;
|
||||
@@ -33,22 +78,9 @@ if(config.local.enabled) {
|
||||
pageScript.id = "_RubberGlove_removeHead";
|
||||
}
|
||||
|
||||
// Listen for callbacks from the page script
|
||||
window.addEventListener("message", function(event) {
|
||||
if(event.source != window) return;
|
||||
if(event.data.type && event.data.type == "RubberGlove") {
|
||||
// Tell background.js to increment the badge counter
|
||||
chrome.runtime.sendMessage({
|
||||
type: "increment-counter",
|
||||
url: window.location.href,
|
||||
message: event.data.text
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Insert our script into the page. Note: This absolutely cannot under
|
||||
// any circumstances happen in an async callback otherwise scripts on the
|
||||
// page may run first and have access to the unwrapped objects.
|
||||
// any circumstances happen in an async callback otherwise scripts on
|
||||
// the page may run first and have access to the unwrapped objects.
|
||||
// Synchronous XHR requests before this seem to work fine, however.
|
||||
head.insertBefore(pageScript, head.firstChild);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>RubberGlove QUnit Tests</title>
|
||||
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.14.0.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script>
|
||||
<script>
|
||||
QUnit.module("Messaging");
|
||||
|
||||
QUnit.asyncTest("Get debugInfo from extension", function(assert) {
|
||||
expect(1);
|
||||
|
||||
window.addEventListener("message", function(event) {
|
||||
if(event.data.type && event.data.type == "RubberGlove_DebugInfo") {
|
||||
window.debugInfo = event.data.debugInfo;
|
||||
assert.ok(true, "Got response from extension:\n" + JSON.stringify(debugInfo, null, 2));
|
||||
var li = document.getElementById(QUnit.config.current.id);
|
||||
QUnit.done(function() { li.style.whiteSpace = "pre"; });
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
window.postMessage({type: 'RubberGlove_DebugInfoRequest'}, '*');
|
||||
|
||||
window.setTimeout(function() {
|
||||
if(!window.debugInfo) {
|
||||
var debugInfo = {
|
||||
settings: { enabled: false },
|
||||
plugins: [],
|
||||
mimeTypes: []
|
||||
};
|
||||
for(var i = 0; i < navigator.plugins.length; i++) {
|
||||
var plugin = navigator.plugins[i];
|
||||
if(typeof plugin.name != 'undefined')
|
||||
debugInfo.plugins.push(plugin.name);
|
||||
}
|
||||
for(var i = 0; i < navigator.mimeTypes.length; i++) {
|
||||
var mimeType = navigator.mimeTypes[i];
|
||||
if(typeof mimeType.type != 'undefined')
|
||||
debugInfo.mimeTypes.push(mimeType.type);
|
||||
}
|
||||
window.debugInfo = debugInfo;
|
||||
assert.ok(false, "No response from extension. Running remaining tests as if settings.enabled == false.");
|
||||
QUnit.start();
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
|
||||
QUnit.module("Constructors");
|
||||
|
||||
QUnit.test("Navigator", function(assert) {
|
||||
assert.equal(typeof Navigator, "function", "Navigator is a Function.");
|
||||
assert.throws(function() { new Navigator(); }, new TypeError("Illegal constructor"), "new Navigator() throws TypeError: Illegal constructor");
|
||||
assert.equal(typeof Navigator.toString, "function", "Navigator.toString() exists");
|
||||
assert.equal(Navigator.toString(), "function Navigator() { [native code] }", "Navigator.toString() claims Navigator is native code.");
|
||||
assert.equal(Function.prototype.toString.apply(Navigator), "function Navigator() { [native code] }", "Function.prototype.toString() claims Navigator is native code.");
|
||||
assert.equal(Function.prototype.toString.apply(Navigator.toString), "function toString() { [native code] }", "Function.prototype.toString() claims Navigator.toString is native code.");
|
||||
});
|
||||
|
||||
QUnit.test("Navigator.prototype", function(assert) {
|
||||
var functions = [
|
||||
"javaEnabled",
|
||||
"getStorageUpdates",
|
||||
"vibrate",
|
||||
"webkitGetGamepads",
|
||||
"getGamepads",
|
||||
"webkitGetUserMedia",
|
||||
"registerProtocolHandler"
|
||||
];
|
||||
for(var i=0; i < functions.length; i++) {
|
||||
assert.ok(Navigator.prototype.hasOwnProperty(functions[i]), "Navigator.prototype." + functions[i] + " exists");
|
||||
assert.equal(typeof Navigator.prototype[functions[i]], "function", "Navigator.prototype." + functions[i] + " is a Fucntion");
|
||||
assert.equal(Navigator.prototype[functions[i]].toString(), "function " + functions[i] + "() { [native code] }", "Navigator.prototype." + functions[i] + " claims to be native code");
|
||||
}
|
||||
assert.deepEqual(Object.keys(Navigator.prototype).sort(), functions.sort(), "Navigator.prototype has no other visible properties");
|
||||
});
|
||||
|
||||
QUnit.test("MimeTypeArray", function(assert) {
|
||||
assert.equal(typeof MimeTypeArray, "function", "MimeTypeArray is a Function.");
|
||||
assert.throws(function() { new MimeTypeArray(); }, new TypeError("Illegal constructor"), "new MimeTypeArray() throws TypeError: Illegal constructor");
|
||||
assert.equal(typeof MimeTypeArray.toString, "function", "MimeTypeArray.toString() exists");
|
||||
assert.equal(MimeTypeArray.toString(), "function MimeTypeArray() { [native code] }", "MimeTypeArray.toString() claims MimeTypeArray is native code.");
|
||||
assert.equal(Function.prototype.toString.apply(MimeTypeArray), "function MimeTypeArray() { [native code] }", "Function.prototype.toString() claims MimeTypeArray is native code.");
|
||||
assert.equal(Function.prototype.toString.apply(MimeTypeArray.toString), "function toString() { [native code] }", "Function.prototype.toString() claims MimeTypeArray.toString is native code.");
|
||||
});
|
||||
|
||||
QUnit.test("MimeTypeArray.prototype", function(assert) {
|
||||
var functions = [
|
||||
"item",
|
||||
"namedItem"
|
||||
];
|
||||
for(var i=0; i < functions.length; i++) {
|
||||
assert.ok(MimeTypeArray.prototype.hasOwnProperty(functions[i]), "MimeTypeArray.prototype." + functions[i] + " exists");
|
||||
assert.equal(typeof MimeTypeArray.prototype[functions[i]], "function", "MimeTypeArray.prototype." + functions[i] + " is a Fucntion");
|
||||
assert.equal(MimeTypeArray.prototype[functions[i]].toString(), "function " + functions[i] + "() { [native code] }", "MimeTypeArray.prototype." + functions[i] + " claims to be native code");
|
||||
}
|
||||
assert.deepEqual(Object.keys(MimeTypeArray.prototype).sort(), functions.sort(), "MimeTypeArray.prototype has no other visible properties");
|
||||
});
|
||||
|
||||
QUnit.test("PluginArray", function(assert) {
|
||||
assert.equal(typeof PluginArray, "function", "PluginArray is a Function.");
|
||||
assert.throws(function() { new PluginArray(); }, new TypeError("Illegal constructor"), "new PluginArray() throws TypeError: Illegal constructor");
|
||||
assert.equal(typeof PluginArray.toString, "function", "PluginArray.toString() exists");
|
||||
assert.equal(PluginArray.toString(), "function PluginArray() { [native code] }", "PluginArray.toString() claims PluginArray is native code.");
|
||||
assert.equal(Function.prototype.toString.apply(PluginArray), "function PluginArray() { [native code] }", "Function.prototype.toString() claims PluginArray is native code.");
|
||||
assert.equal(Function.prototype.toString.apply(PluginArray.toString), "function toString() { [native code] }", "Function.prototype.toString() claims PluginArray.toString is native code.");
|
||||
});
|
||||
|
||||
QUnit.test("PluginArray.prototype", function(assert) {
|
||||
var functions = [
|
||||
"item",
|
||||
"namedItem",
|
||||
"refresh"
|
||||
];
|
||||
for(var i=0; i < functions.length; i++) {
|
||||
assert.ok(PluginArray.prototype.hasOwnProperty(functions[i]), "PluginArray.prototype." + functions[i] + " exists");
|
||||
assert.equal(typeof PluginArray.prototype[functions[i]], "function", "PluginArray.prototype." + functions[i] + " is a Fucntion");
|
||||
assert.equal(PluginArray.prototype[functions[i]].toString(), "function " + functions[i] + "() { [native code] }", "PluginArray.prototype." + functions[i] + " claims to be native code");
|
||||
}
|
||||
assert.deepEqual(Object.keys(PluginArray.prototype).sort(), functions.sort(), "PluginArray.prototype has no other visible properties");
|
||||
});
|
||||
|
||||
QUnit.module("Objects");
|
||||
|
||||
QUnit.test("window.navigator", function(assert) {
|
||||
assert.equal(typeof navigator, "object", "navigator is an Object");
|
||||
assert.deepEqual(navigator.constructor, Navigator, "navigator is an instance of Navigator");
|
||||
});
|
||||
|
||||
QUnit.test("window.navigator.plugins", function(assert) {
|
||||
assert.equal(typeof navigator.plugins, "object", "plugins is an Object");
|
||||
assert.deepEqual(navigator.plugins.constructor, PluginArray, "plugins is an instance of PluginArray");
|
||||
assert.ok(navigator.plugins.hasOwnProperty("length"), "plugins has a length property");
|
||||
});
|
||||
|
||||
QUnit.test("window.navigator.mimeTypes", function(assert) {
|
||||
assert.equal(typeof navigator.mimeTypes, "object", "mimeTypes is an Object");
|
||||
assert.deepEqual(navigator.mimeTypes.constructor, MimeTypeArray, "mimeTypes is an instance of MimeTypeArray");
|
||||
assert.ok(navigator.mimeTypes.hasOwnProperty("length"), "mimeTypes has a length property");
|
||||
});
|
||||
|
||||
QUnit.module("Cloaking");
|
||||
|
||||
QUnit.test("window.navigator.plugins", function(assert) {
|
||||
var pluginWhiteList = debugInfo.settings.pluginWhiteList || [];
|
||||
if(!debugInfo.settings.enabled) {
|
||||
assert.ok(true, "Cloaking disabled");
|
||||
pluginWhiteList = debugInfo.plugins;
|
||||
var li = document.getElementById(QUnit.config.current.id);
|
||||
QUnit.done(function() { li.style.background = "#FFFF99"; });
|
||||
}
|
||||
var whiteList = {};
|
||||
var count = 0;
|
||||
for(var i = 0; i < navigator.plugins.length; i++) {
|
||||
var plugin = navigator.plugins[i];
|
||||
if(pluginWhiteList.indexOf(plugin.name) >= 0) {
|
||||
console.log("Adding " + plugin.name + " to whitelist");
|
||||
whiteList[count++] = plugin;
|
||||
}
|
||||
}
|
||||
whiteList.length = count;
|
||||
|
||||
assert.equal(navigator.plugins.length, whiteList.length, "Has the expected length of " + whiteList.length);
|
||||
assert.deepEqual(Object.keys(navigator.plugins), Object.keys(whiteList), "All plugins are in the white list.");
|
||||
});
|
||||
|
||||
QUnit.test("window.navigator.mimeTypes", function(assert) {
|
||||
var pluginWhiteList = debugInfo.settings.pluginWhiteList || [];
|
||||
if(!debugInfo.settings.enabled) {
|
||||
assert.ok(true, "Cloaking disabled");
|
||||
pluginWhiteList = debugInfo.plugins;
|
||||
var li = document.getElementById(QUnit.config.current.id);
|
||||
QUnit.done(function() { li.style.background = "#FFFF99"; });
|
||||
}
|
||||
var whiteList = {};
|
||||
var count = 0;
|
||||
for(var i = 0; i < navigator.plugins.length; i++) {
|
||||
var plugin = navigator.plugins[i];
|
||||
if(pluginWhiteList.indexOf(plugin.name) >= 0) {
|
||||
for(var j = 0; j < plugin.length; j++) {
|
||||
console.log("Adding " + plugin[j].type + " to whitelist");
|
||||
whiteList[count++] = plugin[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
whiteList.length = count;
|
||||
|
||||
assert.equal(navigator.mimeTypes.length, whiteList.length, "Has the expected length of " + whiteList.length);
|
||||
assert.deepEqual(Object.keys(navigator.mimeTypes), Object.keys(whiteList), "All mimeTypes are in the whitelist");
|
||||
});
|
||||
|
||||
QUnit.module("Probing");
|
||||
|
||||
QUnit.test("window.navigator.plugins", function(assert) {
|
||||
var plugins = debugInfo.plugins;
|
||||
for(var i = 0; i < plugins.length; i++) {
|
||||
assert.equal(typeof navigator.plugins[plugins[i]], 'object', "navigator.plugins['" + plugins[i] +"'] found");
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test("window.navigator.mimeTypes", function(assert) {
|
||||
var mimeTypes = debugInfo.mimeTypes;
|
||||
for(var i = 0; i < mimeTypes.length; i++) {
|
||||
assert.equal(typeof navigator.mimeTypes[mimeTypes[i]], 'object', "navigator.mimeTypes['" + mimeTypes[i] +"'] found");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user