2010-12-22 08:39:29 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test for SpecialPowers extension</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body onload="starttest();">
|
|
|
|
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
2011-03-25 06:39:23 -07:00
|
|
|
|
|
|
|
var eventCount = 0;
|
|
|
|
function testEventListener(e) {
|
|
|
|
++eventCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
function testEventListener2(e) {
|
|
|
|
++eventCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchTestEvent() {
|
|
|
|
var e = document.createEvent("Event");
|
|
|
|
e.initEvent("TestEvent", true, true);
|
|
|
|
window.dispatchEvent(e);
|
|
|
|
}
|
|
|
|
|
2010-12-22 08:39:29 -08:00
|
|
|
dump("\nSPECIALPTEST:::Test script loaded " + (new Date).getTime() + "\n");
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
2011-09-19 11:52:06 -07:00
|
|
|
var startTime = new Date();
|
2010-12-22 08:39:29 -08:00
|
|
|
function starttest(){
|
|
|
|
dump("\nSPECIALPTEST:::Test script running after load " + (new Date).getTime() + "\n");
|
2011-09-19 11:52:06 -07:00
|
|
|
|
2010-12-22 08:39:29 -08:00
|
|
|
/** Test for SpecialPowers extension **/
|
|
|
|
is(SpecialPowers.sanityCheck(), "foo", "check to see whether the Special Powers extension is installed.");
|
|
|
|
|
|
|
|
// Test a sync call into chrome
|
|
|
|
SpecialPowers.setBoolPref('extensions.checkCompatibility', true);
|
|
|
|
is(SpecialPowers.getBoolPref('extensions.checkCompatibility'), true, "Check to see if we can set a preference properly");
|
|
|
|
|
|
|
|
// Test a int pref
|
|
|
|
SpecialPowers.setIntPref('extensions.foobar', 42);
|
|
|
|
is(SpecialPowers.getIntPref('extensions.foobar'), 42, "Check int pref");
|
|
|
|
|
|
|
|
// Test a string pref
|
|
|
|
SpecialPowers.setCharPref("extensions.foobaz", "hi there");
|
|
|
|
is(SpecialPowers.getCharPref("extensions.foobaz"), "hi there", "Check string pref");
|
|
|
|
|
2011-07-21 13:21:25 -07:00
|
|
|
// Test an invalid pref
|
|
|
|
var retVal = null;
|
|
|
|
try {
|
|
|
|
retVal = SpecialPowers.getBoolPref('extensions.checkCompat0123456789');
|
|
|
|
} catch (ex) {
|
|
|
|
retVal = ex;
|
|
|
|
}
|
|
|
|
is(retVal, 'Error getting pref', "received an exception trying to get an unset preference value");
|
|
|
|
|
2011-03-25 06:39:23 -07:00
|
|
|
SpecialPowers.addChromeEventListener("TestEvent", testEventListener, true, true);
|
|
|
|
SpecialPowers.addChromeEventListener("TestEvent", testEventListener2, true, false);
|
|
|
|
dispatchTestEvent();
|
|
|
|
is(eventCount, 1, "Should have got an event!");
|
|
|
|
|
|
|
|
SpecialPowers.removeChromeEventListener("TestEvent", testEventListener, true);
|
|
|
|
SpecialPowers.removeChromeEventListener("TestEvent", testEventListener2, true);
|
|
|
|
dispatchTestEvent();
|
|
|
|
is(eventCount, 1, "Shouldn't have got an event!");
|
|
|
|
|
2010-12-22 08:39:29 -08:00
|
|
|
// Test Complex Pref - TODO: Without chrome access, I don't know how you'd actually
|
|
|
|
// set this preference since you have to create an XPCOM object.
|
|
|
|
// Leaving untested for now.
|
2011-03-25 11:12:23 -07:00
|
|
|
|
|
|
|
// Test a DOMWindowUtils method and property
|
|
|
|
is(SpecialPowers.DOMWindowUtils.getClassName(window), "Proxy");
|
|
|
|
is(SpecialPowers.DOMWindowUtils.docCharsetIsForced, false);
|
|
|
|
|
2011-09-19 11:52:06 -07:00
|
|
|
//Run the createSystemXHR method
|
|
|
|
var xhr = SpecialPowers.createSystemXHR();
|
|
|
|
ok(xhr, "createSystemXHR should not return null");
|
|
|
|
is(xhr.readyState, XMLHttpRequest.UNSENT, "createSystemXHR should create an unsent XMLHttpRequest object");
|
|
|
|
|
2011-10-14 11:24:10 -07:00
|
|
|
// QueryInterface and getPrivilegedProps tests
|
|
|
|
is(SpecialPowers.can_QI(SpecialPowers), false);
|
|
|
|
ok(SpecialPowers.can_QI(window));
|
|
|
|
ok(SpecialPowers.do_QueryInterface(window, "nsIDOMWindow"));
|
|
|
|
is(SpecialPowers.getPrivilegedProps(SpecialPowers.do_QueryInterface(window, "nsIDOMWindow"), "document.nodeName"), "#document");
|
|
|
|
|
2011-09-19 11:52:06 -07:00
|
|
|
//try to run garbage collection
|
|
|
|
SpecialPowers.gc();
|
|
|
|
|
2012-01-18 19:10:04 -08:00
|
|
|
//
|
|
|
|
// Test the SpecialPowers wrapper.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Try some basic stuff with XHR.
|
|
|
|
var xhr2 = SpecialPowers.wrap(Components).classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
|
|
|
|
is(xhr2.toString(), SpecialPowers.unwrap(xhr2).toString(), "toString should be transparently delegated");
|
|
|
|
is(xhr.readyState, XMLHttpRequest.UNSENT, "Should be able to get props off privileged objects");
|
|
|
|
var testURI = SpecialPowers.wrap(Components).classes['@mozilla.org/network/standard-url;1']
|
|
|
|
.createInstance(Components.interfaces.nsIURI);
|
|
|
|
testURI.spec = "http://www.foobar.org/";
|
|
|
|
is(testURI.spec, "http://www.foobar.org/", "Getters/Setters should work correctly");
|
|
|
|
is(SpecialPowers.wrap(document).getElementsByTagName('details').length, 0, "Should work with proxy-based DOM bindings.");
|
|
|
|
|
|
|
|
// Play with the window object.
|
|
|
|
var webnav = SpecialPowers.wrap(window).QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIWebNavigation);
|
|
|
|
webnav.QueryInterface(Components.interfaces.nsIDocShell);
|
|
|
|
ok(webnav.allowJavascript, "Able to pull properties off of docshell!");
|
|
|
|
|
|
|
|
// Make sure Xray-wrapped functions work.
|
|
|
|
try {
|
|
|
|
SpecialPowers.wrap(Components).ID('{00000000-0000-0000-0000-000000000000}');
|
|
|
|
ok(true, "Didn't throw");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(false, "Threw while trying to call Xray-wrapped function.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check functions that return null.
|
|
|
|
var returnsNull = function() { return null; }
|
|
|
|
is(SpecialPowers.wrap(returnsNull)(), null, "Should be able to handle functions that return null.");
|
|
|
|
|
|
|
|
// Play around with a JS object to check the non-xray path.
|
|
|
|
var noxray_proto = {a: 3, b: 12};
|
|
|
|
var noxray = {a: 5, c: 32};
|
|
|
|
noxray.__proto__ = noxray_proto;
|
|
|
|
var noxray_wrapper = SpecialPowers.wrap(noxray);
|
|
|
|
is(noxray_wrapper.c, 32, "Regular properties should work.");
|
|
|
|
is(noxray_wrapper.a, 5, "Shadow properties should work.");
|
|
|
|
is(noxray_wrapper.b, 12, "Proto properties should work.");
|
|
|
|
noxray.b = 122;
|
|
|
|
is(noxray_wrapper.b, 122, "Should be able to shadow.");
|
|
|
|
|
2012-02-19 15:47:12 -08:00
|
|
|
// Check that the wrapper preserves identity.
|
|
|
|
var someIdentityObject = {a: 2};
|
|
|
|
ok(SpecialPowers.wrap(someIdentityObject) === SpecialPowers.wrap(someIdentityObject),
|
|
|
|
"SpecialPowers wrapping should preserve identity!");
|
|
|
|
ok(webnav === SpecialPowers.wrap(SpecialPowers.unwrap(webnav)),
|
|
|
|
"SpecialPowers wrapping should preserve identity!");
|
|
|
|
|
2012-02-01 10:11:53 -08:00
|
|
|
info("\nProfile::SpecialPowersRunTime: " + (new Date() - startTime) + "\n");
|
2010-12-22 08:39:29 -08:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|