2007-08-07 19:12:31 -07:00
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head>
|
2008-04-13 18:18:30 -07:00
|
|
|
<title>Tests XPConnect Wrappers</title>
|
2007-08-07 19:12:31 -07:00
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script class="testbody" type="text/javascript;version=1.7">
|
2009-12-23 14:09:08 -08:00
|
|
|
ok(window instanceof Object, "window is instanceof Object");
|
2010-05-12 07:33:47 -07:00
|
|
|
/*
|
2009-09-30 15:15:51 -07:00
|
|
|
location.foopy = 3;
|
|
|
|
|
|
|
|
var xow_answer = [];
|
2007-08-07 19:12:31 -07:00
|
|
|
for (let i in location)
|
2009-09-30 15:15:51 -07:00
|
|
|
xow_answer.push(i);
|
|
|
|
|
|
|
|
var xpcnw_answer = [];
|
|
|
|
var xpcnw = new XPCNativeWrapper(location);
|
|
|
|
xpcnw.barpy = 4;
|
|
|
|
for (let i in xpcnw)
|
|
|
|
xpcnw_answer.push(i);
|
|
|
|
|
2007-08-07 19:12:31 -07:00
|
|
|
var expected = [
|
|
|
|
"hash",
|
|
|
|
"host",
|
|
|
|
"hostname",
|
|
|
|
"href",
|
|
|
|
"pathname",
|
|
|
|
"port",
|
|
|
|
"protocol",
|
|
|
|
"search",
|
|
|
|
"reload",
|
|
|
|
"replace",
|
2009-09-30 15:15:51 -07:00
|
|
|
"assign",
|
|
|
|
"foopy"
|
2007-08-07 19:12:31 -07:00
|
|
|
];
|
|
|
|
|
2009-09-30 15:15:51 -07:00
|
|
|
var xpcnw_expected = expected.slice(0, expected.length - 1);
|
|
|
|
xpcnw_expected.push("barpy");
|
|
|
|
|
|
|
|
is(xow_answer.sort().toString(),
|
2007-08-07 19:12:31 -07:00
|
|
|
expected.sort().toString(),
|
2007-12-29 15:40:50 -08:00
|
|
|
'enumeration over XOWs walks the prototype chain');
|
|
|
|
|
2009-09-30 15:15:51 -07:00
|
|
|
is(xpcnw_answer.sort().toString(),
|
|
|
|
xpcnw_expected.sort().toString(),
|
|
|
|
'enumeration over XPCNWs walks the prototype chain');
|
|
|
|
|
|
|
|
let sjow_answer = [];
|
2010-01-04 22:59:46 -08:00
|
|
|
let (obj = { a: 3, next:1 }) {
|
2007-12-29 15:40:50 -08:00
|
|
|
for (let i in XPCSafeJSObjectWrapper({ __proto__: obj}))
|
2009-09-30 15:15:51 -07:00
|
|
|
sjow_answer.push(i);
|
2010-01-04 22:59:46 -08:00
|
|
|
is(sjow_answer.sort().toString(), ['a', 'next'].sort().toString(),
|
2007-12-29 15:40:50 -08:00
|
|
|
'enumeration over SJOWs walks the prototype chain');
|
|
|
|
}
|
|
|
|
|
2009-09-30 15:15:51 -07:00
|
|
|
sjow_answer = [];
|
2007-12-29 15:40:50 -08:00
|
|
|
for (let i in XPCSafeJSObjectWrapper(location))
|
2009-09-30 15:15:51 -07:00
|
|
|
sjow_answer.push(i);
|
2007-12-29 15:40:50 -08:00
|
|
|
|
2009-09-30 15:15:51 -07:00
|
|
|
is(sjow_answer.sort().toString(),
|
2007-12-29 15:40:50 -08:00
|
|
|
expected.sort().toString(),
|
|
|
|
'enumeration over SJOWs walks the prototype chain and works over XOWs');
|
2007-08-07 19:12:31 -07:00
|
|
|
|
2009-02-26 17:01:42 -08:00
|
|
|
for (let i in XPCSafeJSObjectWrapper({ 0: 0, "hi": "there" })) {
|
|
|
|
is(typeof i, "string", "enumeration on wrappers only returns strings");
|
|
|
|
}
|
|
|
|
|
2008-01-29 18:06:17 -08:00
|
|
|
ok(!(new XPCSafeJSObjectWrapper({}) == new XPCSafeJSObjectWrapper({})),
|
|
|
|
'SJOWs equality hook returns false correctly');
|
|
|
|
|
|
|
|
let (obj = {}) {
|
|
|
|
ok(new XPCSafeJSObjectWrapper(obj) == new XPCSafeJSObjectWrapper(obj),
|
|
|
|
'SJOWs equality hook returns true correctly');
|
|
|
|
}
|
|
|
|
|
2009-01-16 18:05:14 -08:00
|
|
|
ok(new XPCSafeJSObjectWrapper(window) == new XPCNativeWrapper(window),
|
|
|
|
'SJOWs equality hook returns true correctly against XPCNW');
|
2008-01-29 18:06:17 -08:00
|
|
|
ok(new XPCSafeJSObjectWrapper(window) == window,
|
|
|
|
'SJOWs equality hook returns true correctly against XOW');
|
|
|
|
|
2008-04-13 18:18:30 -07:00
|
|
|
is(typeof(new XPCSafeJSObjectWrapper(function(){})), 'function',
|
|
|
|
'SJOWs look like functions when they wrap functions');
|
|
|
|
is(typeof(new XPCSafeJSObjectWrapper({})), 'object',
|
|
|
|
'SJOWs look like objects when they wrap objects');
|
|
|
|
|
2007-08-07 19:12:31 -07:00
|
|
|
var origProto = window.__proto__;
|
|
|
|
try {
|
|
|
|
window.__proto__ = window;
|
|
|
|
ok(false, 'cyclic proto value allowed');
|
|
|
|
window.__proto__ = origProto;
|
|
|
|
} catch (e) {
|
2007-09-22 14:42:36 -07:00
|
|
|
is(e.toString(),
|
2007-12-20 15:46:08 -08:00
|
|
|
'Error: cyclic __proto__ value',
|
2007-08-07 19:12:31 -07:00
|
|
|
'throw the right exception for a cyclic proto');
|
|
|
|
is(window.__proto__, origProto, 'reset __proto__ after a cyclic proto');
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
is('PASS', window.eval("'PASS'"), 'window.eval throws an exception');
|
|
|
|
} catch (e) {
|
|
|
|
ok(false, 'window.eval does not throw an exception');
|
|
|
|
}
|
2007-08-07 19:18:05 -07:00
|
|
|
|
2009-04-02 15:01:15 -07:00
|
|
|
try {
|
|
|
|
new XPCNativeWrapper("");
|
|
|
|
ok(false, "How did we construct a wrapper around a primitive?");
|
|
|
|
} catch (e) {
|
|
|
|
ok(true, "Unable to new XPCNativeWrapper(primitive)");
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
is(XPCNativeWrapper(""), "", "XPCNativeWrapper as a function allows primitives");
|
|
|
|
} catch (e) {
|
|
|
|
ok(false, "Unable to wrap a primitive, even without 'new'");
|
|
|
|
}
|
|
|
|
|
2007-12-24 11:28:21 -08:00
|
|
|
// Some tests for SJOWs too.
|
|
|
|
is(new XPCSafeJSObjectWrapper(document.body) === document.body, true,
|
|
|
|
"triple equals ignores wrappers");
|
|
|
|
is(XPCSafeJSObjectWrapper.prototype + '',
|
|
|
|
"[object XPCSafeJSObjectWrapper]",
|
|
|
|
"able to convert XPCSafeJSObjectWrapper.prototype to string");
|
2009-08-06 20:48:57 -07:00
|
|
|
|
2009-09-14 18:26:18 -07:00
|
|
|
XPCNativeWrapper.prototype = {};
|
|
|
|
let (w = new XPCNativeWrapper(window)) {
|
|
|
|
ok(window.location, "able to set XPCNativeWrapper.prototype and do stuff with it");
|
|
|
|
}
|
|
|
|
|
|
|
|
is(new XPCNativeWrapper(window, Window).closed, false,
|
|
|
|
"able to wrap a window in a window XPCNativeWrapper");
|
|
|
|
try {
|
|
|
|
new XPCNativeWrapper(document, Window);
|
|
|
|
ok(false, "Able to wrap a document in a Window XPCNativeWrapper?")
|
|
|
|
} catch (e) {
|
|
|
|
ok(/ILLEGAL_VALUE/(e), "not able to wrap a document in a Window XPCNativeWrapper");
|
|
|
|
}
|
|
|
|
|
2009-10-13 14:14:24 -07:00
|
|
|
let (w = new XPCNativeWrapper(window)) {
|
|
|
|
w.foopybar = 5;
|
|
|
|
ok(!("foopybar" in window), "XPCNativeWrappers allow expandos through");
|
|
|
|
is(w.foopybar, 5, "can set expandos on XPCNativeWrappers, though");
|
|
|
|
|
|
|
|
ok(delete w.foopybar, "deleting properties returns true correctly");
|
|
|
|
ok(!("foopybar" in w), "Can delete properties from XPCNativeWrappers");
|
|
|
|
|
|
|
|
is(w.window, window, "w.window exists and is the window");
|
|
|
|
ok(delete w.window, "can delete builtin properties");
|
|
|
|
is(w.window, window, "w.window is automatically recreated");
|
|
|
|
|
|
|
|
window.foopy = 5;
|
|
|
|
ok(delete w.foopy, "delete returns true");
|
|
|
|
is(window.foopy, 5, "delete doesn't delete underlying properties");
|
|
|
|
ok(delete window.foopy, "can delete window.foopy");
|
|
|
|
ok(!("foopy" in window), "foopy is no longer in window");
|
|
|
|
}
|
|
|
|
|
2009-08-06 20:48:57 -07:00
|
|
|
try {
|
|
|
|
is((function(x) { return x+1; }).apply(this,
|
|
|
|
XPCSafeJSObjectWrapper([1])),
|
2009-09-14 18:26:18 -07:00
|
|
|
2, "able to call apply with an XPCSafeJSObjectWrapped array");
|
2009-08-06 20:48:57 -07:00
|
|
|
} catch (e) {
|
|
|
|
ok(false,
|
|
|
|
"Unable to call apply() with a XPCSafeJSObjectWrapped array");
|
|
|
|
}
|
2009-09-14 18:26:18 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
window.__proto__ = null;
|
|
|
|
is(window.__proto__, null,
|
|
|
|
"allowed to update window.__proto__ to null");
|
|
|
|
} catch (e) {
|
|
|
|
ok(false, "some crazy exception was thrown");
|
|
|
|
}
|
2010-05-12 07:33:47 -07:00
|
|
|
*/
|
2007-08-07 19:12:31 -07:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|