import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo

This commit is contained in:
Roy Tam 2018-01-19 03:59:58 +08:00
commit dcd9973243
150858 changed files with 23884658 additions and 0 deletions

View file

@ -0,0 +1,4 @@
[DEFAULT]
support-files =
browser_deadObjectOnUnload.html
[browser_dead_object.js]

View file

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<!--
Test page for https://bugzilla.mozilla.org/show_bug.cgi?id=1242643
-->
<head>
<meta charset="utf-8">
<title>Test page for Bug 1242643</title>
</head>
<body onUnload="onUnload();">
<p><span id="samplepage">sample page</span></p>
<script type="application/javascript">
function onUnload() {
console.log('in unload');
}
</script>
</body>
</html>

View file

@ -0,0 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// For bug 773980, test that Components.utils.isDeadWrapper works as expected.
add_task(function* test() {
const url = "http://mochi.test:8888/browser/js/xpconnect/tests/browser/browser_deadObjectOnUnload.html";
let newTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, url);
let browser = gBrowser.selectedBrowser;
let contentDocDead = yield ContentTask.spawn(browser,{}, function*(browser){
let doc = content.document;
let promise = ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", true);
content.location = "about:home";
yield promise;
return Components.utils.isDeadWrapper(doc);
});
is(contentDocDead, true, "wrapper is dead");
yield BrowserTestUtils.removeTab(newTab);
});

View file

@ -0,0 +1,8 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
BROWSER_CHROME_MANIFESTS += ['browser.ini']

View file

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=503926
-->
<window title="Mozilla Bug 503926"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=503926"
target="_blank">Mozilla Bug 503926</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
var gWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
var passed = false;
var obj = { QueryInterface: function() { passed = true; } }
gWindowUtils.xpconnectArgument(obj);
var isDialog = location.hash != '#iframe';
var outer = XPCNativeWrapper.unwrap(isDialog ? opener : parent);
outer.ok(passed, "chrome/chrome test passed: " + (isDialog ? "dialog" : "iframe"));
if (isDialog)
close();
]]>
</script>
</window>

View file

@ -0,0 +1,119 @@
[DEFAULT]
skip-if = os == 'android'
support-files =
bug503926.xul
file_bug618176.xul
file_bug996069.html
file_bug1050049.xml
file_bug1281071.html
file_discardSystemSource.html
file_evalInSandbox.html
file_expandosharing.jsm
outoflinexulscript.js
subscript.js
utf8_subscript.js
worker_discardSystemSource.js
!/js/xpconnect/tests/mochitest/bug500931_helper.html
!/js/xpconnect/tests/mochitest/bug571849_helper.html
!/js/xpconnect/tests/mochitest/chrome_wrappers_helper.html
!/js/xpconnect/tests/mochitest/file_bug706301.html
!/js/xpconnect/tests/mochitest/file_bug738244.html
!/js/xpconnect/tests/mochitest/file_bug760131.html
!/js/xpconnect/tests/mochitest/file_bug795275.html
!/js/xpconnect/tests/mochitest/file_bug795275.xml
!/js/xpconnect/tests/mochitest/file_bug799348.html
!/js/xpconnect/tests/mochitest/file_bug860494.html
!/js/xpconnect/tests/mochitest/file_documentdomain.html
!/js/xpconnect/tests/mochitest/file_doublewrappedcompartments.html
!/js/xpconnect/tests/mochitest/file_empty.html
!/js/xpconnect/tests/mochitest/file_exnstack.html
!/js/xpconnect/tests/mochitest/file_expandosharing.html
!/js/xpconnect/tests/mochitest/file_nodelists.html
!/js/xpconnect/tests/mochitest/file_evalInSandbox.html
[test_APIExposer.xul]
[test_bug361111.xul]
[test_bug448587.xul]
[test_bug484459.xul]
skip-if = os == 'win' || os == 'mac' # bug 1131110
[test_bug500931.xul]
[test_bug503926.xul]
[test_bug533596.xul]
[test_bug571849.xul]
[test_bug596580.xul]
[test_bug601803.xul]
[test_bug610390.xul]
[test_bug614757.xul]
[test_bug616992.xul]
[test_bug618176.xul]
[test_bug654370.xul]
[test_bug658560.xul]
[test_bug658909.xul]
[test_bug664689.xul]
[test_bug679861.xul]
[test_bug706301.xul]
[test_bug726949.xul]
[test_bug732665.xul]
[test_bug738244.xul]
[test_bug743843.xul]
[test_bug760076.xul]
[test_bug760131.html]
[test_bug763343.xul]
[test_bug771429.xul]
[test_bug773962.xul]
[test_bug792280.xul]
[test_bug793433.xul]
[test_bug795275.xul]
[test_bug799348.xul]
[test_bug801241.xul]
[test_bug812415.xul]
[test_bug853283.xul]
[test_bug853571.xul]
[test_bug858101.xul]
[test_bug860494.xul]
[test_bug865948.xul]
[test_bug866823.xul]
[test_bug895340.xul]
[test_bug932906.xul]
[test_bug996069.xul]
[test_bug1041626.xul]
[test_bug1042436.xul]
[test_bug1050049.html]
[test_bug1065185.html]
[test_bug1074863.html]
[test_bug1092477.xul]
[test_bug1124898.html]
[test_bug1126911.html]
[test_bug1281071.xul]
[test_chrometoSource.xul]
[test_cloneInto.xul]
[test_cows.xul]
[test_discardSystemSource.xul]
[test_documentdomain.xul]
[test_doublewrappedcompartments.xul]
[test_evalInSandbox.xul]
[test_evalInWindow.xul]
[test_exnstack.xul]
[test_expandosharing.xul]
[test_exposeInDerived.xul]
[test_getweakmapkeys.xul]
[test_localstorage_with_nsEp.xul]
[test_matches.xul]
[test_nodelists.xul]
[test_nsScriptErrorWithStack.html]
[test_onGarbageCollection.html]
[test_paris_weakmap_keys.xul]
[test_precisegc.xul]
[test_sandboxImport.xul]
[test_scriptSettings.xul]
[test_watchpoints.xul]
[test_weakmap_keys_preserved.xul]
[test_weakmap_keys_preserved2.xul]
[test_weakmaps.xul]
[test_weakref.xul]
[test_windowProxyDeadWrapper.html]
[test_wrappers.xul]
[test_wrappers-2.xul]
# Disabled until this test gets updated to test the new proxy based wrappers.
skip-if = true
[test_xrayToJS.xul]

View file

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<bindings id="testBindings" xmlns="http://www.mozilla.org/xbl"
xmlns:html="http://www.w3.org/1999/xhtml">
<binding id="regularChromeBinding">
<content><html:p>Anonymous Paragraph</html:p></content>
</binding>
<binding id="whitelistedChromeBinding" bindToUntrustedContent="true">
<content><html:p>Anonymous Paragraph</html:p></content>
</binding>
</bindings>

View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<script>
function tryLocationGet() {
var desc = Object.getOwnPropertyDescriptor(window, "location");
try {
desc.get.call(parent);
return "get succeeded";
} catch (e) {
return e.message;
}
}
</script>

View file

@ -0,0 +1,44 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=618176
-->
<window title="Mozilla Bug 618176"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="start()">
<label value="Mozilla Bug 618176"/>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
const TEST_PAGE =
"data:text/html,<script>var a=[1,2,3];</script>Hi";
const FRAME_SCRIPT =
"data:,addEventListener('pageshow', function() { sendAsyncMessage('test', content.wrappedJSObject.a) }, false);";
// s/content.wrappedJSObject.a/[ 1, 2, 3]/ and the test passes
function recvTest(m) {
var a = m.json;
opener.wrappedJSObject.is(a.length, 3, "array was serialized and deserialized");
messageManager.removeMessageListener("test", recvTest);
finish();
}
function start() {
messageManager.addMessageListener("test", recvTest);
messageManager.loadFrameScript(FRAME_SCRIPT, true);
setTimeout(function () { document.getElementById("browser").loadURI(TEST_PAGE); }, 0);
}
function finish() {
opener.setTimeout("done()", 0);
window.close();
}
]]></script>
<browser id="browser" type="content" style="width: 200px; height: 200px;"/>
</window>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
if (window.opener && window.opener.finishTest) {
window.opener.finishTest();
}
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<script>
function canary() {
var someBitOfSource = 42;
}
function inner() {
throw new Error("some error");
}
function throwSomething() {
inner();
}
</script>
</head>
<body onload="someBitOfSource = 42">
</body>
</html>

View file

@ -0,0 +1 @@
<html><body><script>document.foo = 'bar';</script></body></html>

View file

@ -0,0 +1,10 @@
this.EXPORTED_SYMBOLS = ['checkFromJSM'];
this.checkFromJSM = function checkFromJSM(target, is_op) {
is_op(target.numProp, 42, "Number expando works");
is_op(target.strProp, "foo", "String expando works");
// If is_op is todo_is, target.objProp will be undefined.
try {
is_op(target.objProp.bar, "baz", "Object expando works");
} catch(e) { is_op(0, 1, "No object expando"); }
}

View file

@ -0,0 +1,12 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
MOCHITEST_CHROME_MANIFESTS += ['chrome.ini']
TEST_HARNESS_FILES.testing.mochitest.tests.js.xpconnect.tests.chrome += [
'file_discardSystemSource.html',
'worker_discardSystemSource.js',
]

View file

@ -0,0 +1,6 @@
// Some unicode characters that must be decoded:
// ………………………………………………………………………………………………………………………………
function outoflinefunction() {
return 42;
}

View file

@ -0,0 +1,6 @@
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
var ns = {};
Services.scriptloader.loadSubScript("resource://gre/modules/NetUtil.jsm", ns);
var NetUtil = ns.NetUtil;

View file

@ -0,0 +1,51 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=634156
-->
<window title="Testing API exposing capabilities"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=634156"
target="_blank">Mozilla Bug 634156</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
const Cu = Components.utils;
var sandbox = new Cu.Sandbox("about:blank");
sandbox.ok = ok;
sandbox.is = is;
Cu.evalInSandbox("Object.defineProperty(Object.prototype, 'getProp', { get: function() { throw 'FAIL: called getter' }, set: function() { throw 'FAIL: called setter'; } })", sandbox);
var obj = Cu.createObjectIn(sandbox);
is(obj, Cu.waiveXrays(obj), "createObjectIn waives");
is(Object.getPrototypeOf(obj), Cu.waiveXrays(Cu.evalInSandbox("Object.prototype", sandbox)),
"Object is a sandbox object");
function genPropDesc(value) {
return { enumerable: true, configurable: true, writable: true,
value: value };
}
const props = {
'getProp': genPropDesc(function() { ok(true, "called prop that shadowed a getter"); }),
'argument': genPropDesc(function(arg) { is(arg, 42, "can pass arguments through"); }),
'returnval': genPropDesc(function() { return 42; })
};
Object.defineProperties(obj, props);
Cu.makeObjectPropsNormal(obj);
sandbox.api = obj;
Cu.evalInSandbox("ok(Object.getPrototypeOf(api) === Object.prototype, 'we have the object we expected'); \
api.getProp(); api.argument(42); is(api.returnval(), 42, 'return value was correct');\
ok(typeof api.getProp === 'function', 'functions are functions');\
ok(Object.getPrototypeOf(api.getProp) === Function.prototype, 'functions come from our scope');", sandbox);
]]></script>
</window>

View file

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1041626
-->
<window title="Mozilla Bug 1041626"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1041626"
target="_blank">Mozilla Bug 1041626</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 1041626 **/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
function go() {
//
// Location
//
ok(Cu.isXrayWrapper(window[0].location), "Location is Xrayed");
let xrayOwnProperties = Object.getOwnPropertyNames(window[0].location);
todo(xrayOwnProperties.indexOf('toJSON') != -1,
"dummy toJSON on Location should show up in Xrayable properties");
xrayOwnProperties.push('toJSON');
let realOwnProperties = Object.getOwnPropertyNames(window[0].wrappedJSObject.location);
ok(realOwnProperties.length > 2);
is(xrayOwnProperties.sort().toSource(), realOwnProperties.sort().toSource(),
"Xray enumerates location properties properly");
//
// Document
//
ok(Cu.isXrayWrapper(window[0].document), "Document is Xrayed");
xrayOwnProperties = Object.getOwnPropertyNames(window[0].document);
realOwnProperties = Object.getOwnPropertyNames(window[0].wrappedJSObject.document);
ok(realOwnProperties.length > 0);
is(xrayOwnProperties.sort().toSource(), realOwnProperties.sort().toSource(),
"Xray enumerates document properties properly");
SimpleTest.finish();
}
]]>
</script>
<iframe onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,49 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1042436
-->
<window title="Mozilla Bug 1042436"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1042436"
target="_blank">Mozilla Bug 1042436</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 1042436 **/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
var contentSb = Cu.Sandbox('http://www.example.com');
var nonXrayableObj = new contentSb.WeakMap();
nonXrayableObj.wrappedJSObject.someExpandoProperty = 42;
nonXrayableObj.wrappedJSObject.someOtherExpandoProperty = 52;
SimpleTest.expectConsoleMessages(function() {
nonXrayableObj.someExpandoProperty;
nonXrayableObj.someOtherExpandoProperty;
var chromeSb = Cu.Sandbox(this);
var contentObjWithGetter = contentSb.eval('({ get getterProp() {return 42;}, valueProp: 42 })');
is(contentObjWithGetter.wrappedJSObject.getterProp, 42, "Getter prop set up correctly");
is(contentObjWithGetter.getterProp, undefined, "Xrays work right");
is(contentObjWithGetter.valueProp, 42, "Getter prop set up correctly");
chromeSb.contentObjWithGetter = contentObjWithGetter;
Cu.evalInSandbox('contentObjWithGetter.getterProp; contentObjWithGetter.valueProp; contentObjWithGetter.getterProp;',
chromeSb, "1.7", "http://phony.example.com/file.js", 99);
},
[{ errorMessage: /property "someExpandoProperty" \(reason: object is not safely Xrayable/, sourceName: /test_bug1042436/, isWarning: true },
{ errorMessage: /property "getterProp" \(reason: property has accessor/, sourceName: /phony/, lineNumber: 99, isWarning: true } ],
SimpleTest.finish.bind(SimpleTest));
]]>
</script>
</window>

View file

@ -0,0 +1,56 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1050049
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1050049</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1050049 **/
SimpleTest.waitForExplicitFinish();
var regularBindingURI = window.location.toString().replace("test_bug1050049.html", "file_bug1050049.xml") + "#regularChromeBinding";
var whitelistedBindingURI = window.location.toString().replace("test_bug1050049.html", "file_bug1050049.xml") + "#whitelistedChromeBinding";
function testApplyBinding(doc, bindingURI, expectBind) {
var d = doc.createElement('div');
doc.body.appendChild(d);
d.style.MozBinding = "url(" + bindingURI + ")";
return new Promise(function(resolve, reject) {
// Wait two ticks of the refresh driver for the binding to be applied.
function onceBindingWouldBeApplied() {
is(!!doc.getAnonymousNodes(d), expectBind, "Binding " + (expectBind ? "should" : "shouldn't") +
" be applied: " + bindingURI + ", " + doc.location);
resolve();
}
window.requestAnimationFrame(function() { window.requestAnimationFrame(onceBindingWouldBeApplied); });
});
}
function go() {
testApplyBinding(document, regularBindingURI, true)
.then(testApplyBinding.bind(null, window[0].document, regularBindingURI, false))
.then(testApplyBinding.bind(null, document, whitelistedBindingURI, true))
.then(testApplyBinding.bind(null, window[0].document, whitelistedBindingURI, true))
.then(SimpleTest.finish.bind(SimpleTest));
}
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1050049">Mozilla Bug 1050049</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<iframe onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"></iframe>
</body>
</html>

View file

@ -0,0 +1,64 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1065185
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1065185</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1065185 **/
SimpleTest.waitForExplicitFinish();
function doMonitor(rgxps) {
var messages = rgxps.map((x) => ({ errorMessage: x, isWarning: true }));
info("Expecting console messages: " + messages.toSource());
SimpleTest.monitorConsole(() => SimpleTest.executeSoon(() => window[0].location.reload()), messages, /* forbidUnexpected = */ true);
}
function endMonitor() {
SimpleTest.executeSoon(SimpleTest.endMonitorConsole.bind(SimpleTest));
}
var gLoadCount = 0;
function loaded() {
switch(++gLoadCount) {
case 0:
doMonitor([]);
window[0].wrappedJSObject.probe = { a: 2, __exposedProps__: { 'a': 'r' } };
is(window[0].eval('probe.a'), 2, "Accessed exposed prop");
endMonitor();
break;
case 1:
doMonitor([/access to property "a"/i]);
window[0].wrappedJSObject.probe = { a: 2 };
is(window[0].eval('probe.a'), undefined, "Non-exposed prop undefined");
is(window[0].eval('probe.a'), undefined, "Non-exposed prop undefined again");
endMonitor();
break;
case 2:
SimpleTest.finish();
break;
default:
ok(false, "Unexpected load");
SimpleTest.finish();
break;
}
}
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1065185">Mozilla Bug 1065185</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<iframe onload="loaded();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</body>
</html>

View file

@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1074863
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1074863</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1074863 **/
const Cu = Components.utils;
var sb = new Cu.Sandbox('http://www.example.com');
sb.namedCtor = Image;
ok(true, "Didn't assert");
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1074863">Mozilla Bug 1074863</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

View file

@ -0,0 +1,36 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1092477
-->
<window title="Mozilla Bug 1092477"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1092477"
target="_blank">Mozilla Bug 1092477</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
var Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
var exn;
var url = "resource://non-existent/script.js";
try {
Services.scriptloader.loadSubScript(url);
ok(false, "This line should never be reached!");
}
catch (e) {
exn = String(e);
}
var msg = "loadSubscript should throw an exception for trying to load a non-existent script"
is(exn, "Error opening input stream (invalid filename?): " + url, msg);
]]></script>
</window>

View file

@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1124898
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1124898</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1124898 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.expectAssertions(0, 1); // Dumb unrelated widget assertion - see bug 1126023.
var w = window.open("about:blank", "w", "chrome");
is(w.eval('typeof getAttention'), 'function', 'getAttention exists on regular chrome window');
is(w.eval('typeof messageManager'), 'object', 'messageManager exists on regular chrome window');
var contentURL = "http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
w.location = contentURL;
tryWindow();
function tryWindow() {
if (w.document.title != 'empty test page') {
info("Document not loaded yet - retrying");
SimpleTest.executeSoon(tryWindow);
return;
}
is(w.eval('typeof getAttention'), 'undefined', 'getAttention doesnt exist on content-in-chrome window');
is(w.eval('typeof messageManager'), 'undefined', 'messageManager doesnt exist on content-in-chrome window');
w.close();
SimpleTest.finish();
}
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1124898">Mozilla Bug 1124898</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

View file

@ -0,0 +1,41 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1126911
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1126911</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1126911 **/
const Cu = Components.utils;
var sb = new Cu.Sandbox(null);
sb.win = window;
sb.loc = location;
function checkThrows(expr) {
try {
Cu.evalInSandbox(expr, sb);
ok(false, "Should have thrown: " + expr);
} catch (e) {
ok(/denied|insecure/.test(e), "should get security exception: " + e);
}
}
checkThrows('win.top');
checkThrows('loc.replace');
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1126911">Mozilla Bug 1126911</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

View file

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1281071
-->
<window title="Mozilla Bug 1281071"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
function go() {
var w = $('ifr').contentWindow.wrappedJSObject;
is(w.tryLocationGet(), "Permission to call 'get location' denied.",
"Trying to get our location object should throw");
SimpleTest.finish();
}
]]></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<iframe type="content"
src="http://mochi.test:8888/chrome/js/xpconnect/tests/chrome/file_bug1281071.html"
onload="go()"
id="ifr">
</iframe>
</body>
</window>

View file

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=361111
-->
<window title="Mozilla Bug 361111"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=361111"
target="_blank">Mozilla Bug 361111</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 361111 **/
window.onerror = null;
SimpleTest.waitForExplicitFinish();
document.documentElement.setAttribute("onclick", "%");
is(1, 1, "Good, setting a bogus onclick did not throw.");
// Bonus test - make sure that flushPrefEnv is appropriately
// called at the end of the test. It would be nice if there were
// somewhere in the harness that this could live, but there isn't.
SpecialPowers.pushPrefEnv({set: [['testing.some_arbitrary_pref', true]]},
function() { SimpleTest.finish(); });
]]></script>
</window>

View file

@ -0,0 +1,37 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=448587.xul
-->
<window title="Mozilla Bug 503926"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=448587"
target="_blank">Mozilla Bug 448587</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
// Bonus test - collaborate with test_bug361111.xul to make sure that
// flushPrefEnv is appropriately called.
ok(!SpecialPowers.Services.prefs.prefHasUserValue('testing.some_arbitrary_pref'),
"Pref shouldn't carry over from previous test!");
/** Test for Bug 448587 **/
const Cu = Components.utils;
var sandbox = new Cu.Sandbox("about:blank");
var fwrapper = Cu.evalInSandbox("function f() {} f", sandbox);
is(Cu.unwaiveXrays(Cu.waiveXrays(fwrapper).prototype), Cu.evalInSandbox("f.prototype", sandbox),
".prototype visible through .wrappedJSObject");
is(fwrapper.prototype, undefined, ".prototype invisible through Xrays");
]]>
</script>
</window>

View file

@ -0,0 +1,38 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=484459
-->
<window title="Mozilla Bug 484459"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<iframe type="content"
src="data:text/html,&lt;script&gt;var x=3&lt;/script&gt;"
onload="go()"
id="ifr">
</iframe>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
var url = "chrome://mochitests/content/chrome/js/xpconnect/tests/chrome/test_bug484459.xul";
function go() {
var w = $('ifr').contentWindow.wrappedJSObject;
var sandbox = new Components.utils.Sandbox(w);
sandbox.__proto__ = w;
is(location.href, url, "location.href is set properly");
is(w.location.href, "data:text/html,<script>var%20x=3</script>",
"contents of w.location are correct");
is(Components.utils.evalInSandbox("x * 4", sandbox), 12,
"Unexpected return from the sandbox");
SimpleTest.finish();
}
]]></script>
</window>

View file

@ -0,0 +1,41 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=500931
-->
<window title="Mozilla Bug 500931"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=500931"
target="_blank">Mozilla Bug 500931</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 500931 **/
function go() {
var ifr = document.getElementById("ifr");
var doc = ifr.contentDocument;
ok(Components.utils.isXrayWrapper(doc), "doc is an XrayWrapper");
var weak = Components.utils.getWeakReference(doc);
ok(Components.utils.isXrayWrapper(weak.get()), "weak reference returns a wrapper");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
]]></script>
<iframe type="content"
src="http://example.org/tests/js/xpconnect/tests/mochitest/bug500931_helper.html"
onload="go()"
id="ifr">
</iframe>
</window>

View file

@ -0,0 +1,59 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=503926
-->
<window title="Mozilla Bug 503926"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=503926"
target="_blank">Mozilla Bug 503926</a>
<iframe id="ifr" type="content" onload="loaded()" src="bug503926.xul#iframe"/>
<iframe id="ifrContent" type="content" onload="loaded()" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"/>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
SimpleTest.expectAssertions(0, 1);
var gLoadCount = 0;
function loaded() {
if (++gLoadCount == 2)
go();
}
/** Test for Bug 503926 **/
function go() {
var gWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
// Try with a chrome object.
var passed = false;
var obj = { QueryInterface: function() { passed = true; } };
gWindowUtils.xpconnectArgument(obj);
ok(passed, "trusted QIs should be called");
// Try with a content object.
var contentWin = $('ifrContent').contentWindow.wrappedJSObject;
contentWin.passed = false;
var contentObj = contentWin.eval('({ QueryInterface: function() { passed = true; } })');
gWindowUtils.xpconnectArgument(contentObj);
ok(!contentWin.passed, "untrusted QI should not be called");
// Try with a dialog.
openDialog("bug503926.xul", "chromeDialog", "modal");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
]]>
</script>
</window>

View file

@ -0,0 +1,56 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=533596
-->
<window title="Mozilla Bug 533596"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=533596"
target="_blank">Mozilla Bug 533596</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 533596 **/
function go() {
try { XPCNativeWrapper.unwrap(); } catch (e) {}
try { XPCNativeWrapper.unwrap(0); } catch (e) {}
try { XPCNativeWrapper.unwrap(null); } catch (e) {}
var o = {};
is(o, XPCNativeWrapper.unwrap(o), "unwrap on a random object returns it");
var win = $('ifr').contentWindow;
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
is(utils.getClassName(win), "Proxy", "win is a Proxy");
ok("x" in XPCNativeWrapper.unwrap(win), "actually unwrapped");
is(utils.getClassName(XPCNativeWrapper.unwrap(win)), "Proxy",
"unwrap on an Proxy returns the same object");
is(utils.getClassName(XPCNativeWrapper.unwrap(new XPCNativeWrapper(win))), "Proxy",
"unwrap on an explicit NW works too");
ok(utils.getClassName(window) !== "XPCNativeWrapper", "window is not a native wrapper");
ok(utils.getClassName(XPCNativeWrapper.unwrap(new XPCNativeWrapper(window))) !== "XPCSafeJSObjectWrapper",
"unwrapping a chrome object returns the object itself");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
]]></script>
<iframe type="content"
src="http://example.org/tests/js/xpconnect/tests/mochitest/bug500931_helper.html"
onload="go()"
id="ifr">
</iframe>
</window>

View file

@ -0,0 +1,44 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=500931
-->
<window title="Mozilla Bug 500931"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=500931"
target="_blank">Mozilla Bug 500931</a>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 500931 **/
function go() {
var ifr = document.getElementById('ifr');
var docnodes = ifr.contentDocument.body.childNodes;
var index, value;
for (let i in Iterator(docnodes)) {
index = i[0], value = i[1];
}
is(index, 0, "enumerated the 0th element");
ok(value instanceof Text, "the 0th element was a text node");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
]]></script>
<iframe type="content"
src="http://example.org/tests/js/xpconnect/tests/mochitest/bug571849_helper.html"
onload="go()"
id="ifr">
</iframe>
</body>
</window>

View file

@ -0,0 +1,48 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window title="Mozilla Bug 596580"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=596580"
target="_blank">Mozilla Bug 596580</a>
</body>
<!-- test code goes here -->
<script type="application/x-javascript;version=1.8"><![CDATA[
function init() {
var f = new Function("let test = 'let is ok'; return test;");
is(f(), 'let is ok', 'let should be ok');
SimpleTest.finish();
}
Test = {
include: function(p) {
var sawError = false;
try {
Components.classes["@mozilla.org/moz/jssubscript-loader;1"].
getService(Components.interfaces["mozIJSSubScriptLoader"]).
loadSubScript(p);
} catch (e) {
sawError = true;
}
ok(sawError, 'should receive an error loading a not-found file');
}
};
// If the include method is defined as a global function, it works.
// try to load a non existing file to produce the error
Test.include("notfound.js");
// If init is called directly, it works.
setTimeout('init();', 0);
SimpleTest.waitForExplicitFinish();
]]></script>
</window>

View file

@ -0,0 +1,38 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=500931
-->
<window title="Mozilla Bug 601803"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=601803"
target="_blank">Mozilla Bug 601803</a>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 601803 **/
function go() {
var ifr = document.getElementById('ifr');
var elem = document.createElementNS("http://www.w3.org/1999/xhtml","html:div");
elem.appendChild(document.createTextNode("hello, world"));
elem.expando = 42;
ifr.contentDocument.body.appendChild(elem);
is(elem.wrappedJSObject.expando, 42, "expando is preserved");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
]]></script>
<iframe type="content" src="about:blank" onload="go()" id="ifr" />
</body>
</window>

View file

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=610390
-->
<window title="Mozilla Bug 610390"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<iframe type="content"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
src="data:text/html,&lt;script&gt;var x=3&lt;/script&gt;"
onload="go()"
id="ifr">
</iframe>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
function go() {
var w = $('ifr').contentWindow;
is(w.wrappedJSObject, w.wrappedJSObject, "wrappedJSObject identity not maintained");
SimpleTest.finish();
}
]]></script>
</window>

View file

@ -0,0 +1,34 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=614757
-->
<window title="Mozilla Bug 601803"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=614757"
target="_blank">Mozilla Bug 614757</a>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 614757 **/
function go() {
is($('ifr').contentDocument.wrappedJSObject.getElementsByTagName('body')[0].toString().indexOf('Xray'),
-1, "Properly deep wrap");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
]]></script>
<iframe type="content" src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_evalInSandbox.html" onload="go()" id="ifr" />
</body>
</window>

View file

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=616992
-->
<window title="Mozilla Bug 601803"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=616992"
target="_blank">Mozilla Bug 616992</a>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 616992 **/
const Cu = Components.utils;
var sandbox = new Cu.Sandbox(window);
sandbox.w = window;
var actual = Cu.evalInSandbox("Object.keys(w.NodeFilter)", sandbox).sort().toString();
var expected = Object.keys(NodeFilter).sort().toString();
is(actual, expected, "interface constants are visible inside sandboxes");
]]></script>
</body>
</window>

View file

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=618176
-->
<window title="Mozilla Bug 618176"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=618176"
target="_blank">Mozilla Bug 618176</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
function done() {
SimpleTest.finish();
}
addLoadEvent(function() {
window.open("file_bug618176.xul", "", "chrome");
});
]]></script>
</window>

View file

@ -0,0 +1,29 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=654370
-->
<window title="Mozilla Bug 654370"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=654370"
target="_blank">Mozilla Bug 654370</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
var Cu = Components.utils;
var sandbox = new Cu.Sandbox(window);
var script = "(function (obj, type) { return obj instanceof type; })";
var instanceOf = Cu.evalInSandbox(script, sandbox, "1.8", "Test", 1);
ok(!instanceOf({}, Window), "instanceOf from the sandbox gets the right result");
]]></script>
</window>

View file

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=658560
-->
<window title="Mozilla Bug 658560"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=658560"
target="_blank">Mozilla Bug 658560</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
function go() {
var win = $('ifr').contentWindow.wrappedJSObject;
let o = { prop: true };
win.foo = o;
is(win.foo, o, "should have === identity through a CrossOriginWrapper");
SimpleTest.finish();
}
]]></script>
<iframe
src="http://example.org/tests/js/xpconnect/tests/mochitest/file_bug658560.html"
id="ifr"
type="content"
onload="go()" />
</window>

View file

@ -0,0 +1,92 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=658909
-->
<window title="Mozilla Bug 658909"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=658909"
target="_blank">Mozilla Bug 658909</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for call/apply-ing Xray methods.**/
SimpleTest.waitForExplicitFinish();
gLoadCount = 0;
function frameLoaded() {
if (++gLoadCount == frames.length)
go();
}
function msg(a, b, testName) {
return "(" + a.name + ", " + b.name + "): " + testName;
}
var testFunctions = {
testDocumentElement: function(a, b, name) {
var getter = Object.prototype.__lookupGetter__.call(a.document, 'documentElement');
is(getter.call(b.document), b.document.documentElement, msg(a, b, name));
},
testInvalidCall: function(a, b, name) {
var getter = Object.prototype.__lookupGetter__.call(a.document, 'documentElement');
var threw = false;
try { getter.call(b.document.body); } catch (e) { threw = true; };
ok(threw, msg(a, b, name));
},
testStatus: function(a, b, name) {
var setter = Object.prototype.__lookupSetter__.call(a, 'status');
is(b.status, "", "Empty status");
setter.call(b, "foopy");
is(b.status, "foopy", msg(a, b, name));
b.status = "";
},
testCreateElement: function(a, b, name) {
is(a.document.createElement.call(b.document, 'div').ownerDocument, b.document, msg(a, b, name));
},
testWindowName: function(a, b, name) {
var getter = Object.prototype.__lookupGetter__.call(a, 'name');
is(getter.call(b), b.name, msg(a, b, name));
},
testCanvas: function(a, b, name) {
var canvasA = a.document.createElement('canvas');
var canvasB = b.document.createElement('canvas');
var contextA = canvasA.getContext('2d');
var contextB = canvasB.getContext('2d');
var getter = Object.prototype.__lookupGetter__.call(contextA, 'canvas');
is(getter.call(contextB), canvasB, msg(a, b, name));
}
};
function go() {
for (var i = 0; i < frames.length; ++i)
frames[i].name = 'frame' + i;
for (var i = 0; i < frames.length; ++i) {
for (var j = 0; j < frames.length; ++j) {
for (var k in testFunctions)
testFunctions[k](frames[i], frames[j], k);
}
}
SimpleTest.finish();
}
]]>
</script>
<iframe id="frame1" onload="frameLoaded();" type="content" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
<iframe id="frame2" onload="frameLoaded();" type="content" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
<iframe id="frame3" onload="frameLoaded();" type="content" src="http://example.com/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=658560
-->
<window title="Mozilla Bug 658560"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=658560"
target="_blank">Mozilla Bug 658560</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
const Cu = Components.utils;
var sandbox = new Cu.Sandbox("about:blank");
var contentObj = Cu.evalInSandbox("({ get foo() { return 42 } })", sandbox);
var propdesc = Object.getOwnPropertyDescriptor(Cu.waiveXrays(contentObj), "foo");
is(typeof propdesc, "object", "got a property descriptor back");
ok("get" in propdesc, "getter exists");
]]></script>
</window>

View file

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=500931
-->
<window title="Mozilla Bug 601803"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=601803"
target="_blank">Mozilla Bug 601803</a>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 601803 **/
function go() {
var doc = document.getElementById('ifr').contentDocument;
var list = doc.getElementsByTagName("body");
var zeroAsString = "0";
is(typeof list[zeroAsString], "object",
"can lookup nodelist items by string");
is(typeof list[0], "object",
"can lookup nodelist items by integer after the lookup by string");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
]]></script>
<iframe type="content" src="about:blank" onload="go()" id="ifr" />
</body>
</window>

View file

@ -0,0 +1,52 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=706301
-->
<window title="Mozilla Bug 706301"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=706301"
target="_blank">Mozilla Bug 706301</a>
<iframe id="ifr" src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug706301.html" onload="doTest();" />
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 706301 **/
SimpleTest.waitForExplicitFinish();
function getLengthInChrome(nodelist) {
// Make sure the object is Xray wrapped.
ok(nodelist === XPCNativeWrapper(nodelist), "object passed from content to chrome " +
"should be Xray-wrapped.");
// Perform the operation.
Object.getOwnPropertyDescriptor(nodelist, 'length');
return nodelist['length'] == 0;
}
function finishTestInChrome() {
SimpleTest.finish();
}
function doTest() {
// Set up the callbacks for content.
$('ifr').contentWindow.wrappedJSObject.getLengthInChrome = getLengthInChrome;
$('ifr').contentWindow.wrappedJSObject.finishTestInChrome = finishTestInChrome;
$('ifr').contentWindow.wrappedJSObject.ok = ok;
// Kick off the test.
$('ifr').contentWindow.postMessage({}, '*');
}
]]>
</script>
</window>

View file

@ -0,0 +1,49 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=720619
-->
<window title="Mozilla Bug 720619"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=720619"
target="_blank">Mozilla Bug 720619</a>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 720619 **/
const Cu = Components.utils;
var obj = {
valueOf: function () {
return 42;
},
toString: function () {
return 'str';
}
};
var content = new Cu.Sandbox("about:blank");
content.obj = obj;
ok(Cu.evalInSandbox("obj + ''", content) == "[object Object]");
ok(Cu.evalInSandbox("'' + obj", content) == "[object Object]");
ok(isNaN(Cu.evalInSandbox("obj - 0", content)));
ok(Cu.evalInSandbox("String(obj)", content) == "[object Object]");
var chrome = new Cu.Sandbox(window);
chrome.obj = obj;
ok(Cu.evalInSandbox("obj + ''", chrome) == "42");
ok(Cu.evalInSandbox("'' + obj", chrome) == "42");
ok(Cu.evalInSandbox("obj - 0", chrome) == 42);
ok(Cu.evalInSandbox("String(obj)", chrome) == "str");
]]></script>
</body>
</window>

View file

@ -0,0 +1,41 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=726949
-->
<window title="Mozilla Bug 726949"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=726949"
target="_blank">Mozilla Bug 726949</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 726949 **/
var Cu = Components.utils;
var s = new Cu.Sandbox(window, { sandboxPrototype: window } );
var t;
var desc;
try {
t = Cu.evalInSandbox('top', s);
is(t, window.top, "Should have gotten the right thing back");
desc = Cu.evalInSandbox('Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this), "Cu")', s);
isnot(desc, undefined,
"Should have an own 'Cu' property");
is(desc.value, Cu, "Should have the right value");
var loc = Cu.evalInSandbox('location', s);
is(loc.href, location.href, "Should have the right location");
var display = Cu.evalInSandbox('getComputedStyle(document.documentElement, "").display', s);
is(display, "block", "Should be able to call getComputedStyle");
} catch (e) {
ok(false, "Should not get an exception: " + e);
}
]]>
</script>
</window>

View file

@ -0,0 +1,81 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=732665
-->
<window title="Mozilla Bug 732665"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=732665"
target="_blank">Mozilla Bug 732665</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
//
// Important! If this test starts failing after a tricky platform-y change,
// the stack quota numbers in XPCJSContext probably need twiddling. We want
// to maintain the invariants in this test (at least to some approximation)
// for security reasons.
//
// Executes f() d steps from the probed native stack limit, and returns
// the number of steps to the recursion limit from the caller.
function nearNativeStackLimit(d, f) {
f = f || function() {};
function inner() {
try {
with ({}) { // keep things predictable -- stay in the interpreter
var stepsFromLimit = eval("inner()"); // Use eval to force a number of native stackframes to be created.
}
if (stepsFromLimit == d) {
try { f(); } catch(e) { ok(false, 'nearNativeStackLimit callback threw: ' + e); }
}
return stepsFromLimit + 1;
} catch(e) {
// It would be nice to check here that the exception is actually an
// over-recursion here. But doing so would require toString()ing the
// exception, which we may not have the stack space to do.
return 0;
}
}
return inner();
}
const Cu = Components.utils;
var contentSb = new Cu.Sandbox('http://www.example.com');
var chromeSb = new Cu.Sandbox(window);
chromeSb.ok = contentSb.ok = ok;
Cu.evalInSandbox(nearNativeStackLimit.toSource(), chromeSb);
Cu.evalInSandbox(nearNativeStackLimit.toSource(), contentSb);
var chromeLimit = Cu.evalInSandbox("nearNativeStackLimit(0);", chromeSb);
var contentLimit = Cu.evalInSandbox("nearNativeStackLimit(0)", contentSb);
ok(chromeLimit >= contentLimit + 10,
"Chrome should be able to have at least 10 heavy frames more stack than content: " + chromeLimit + ", " + contentLimit);
// Exhaust the stack space in content, and then make sure we can still get 10
// heavy frames in chrome.
//
// Note that sometimes, if we pass |0| to nearNativeStackLimit, we can end up
// so close to the border in content that we can't even get ourselves together
// enough to make the cross-compartment call. So rather than exhausting the
// stack entirely and then checking for 10 chrome frames, we leave ourselves
// one frame's worth, and check for 11.
//
// If this assertion fails, the current work-around so far is to measure
// again the worst frame size, by using the JS Shell to run
// test_bug732665_meta.js . This script will output numbers to update
// XPCJSContext.cpp comment, as well as the kTrustedScriptBuffer constant.
contentSb.nnslChrome = chromeSb.nearNativeStackLimit;
var nestedLimit = Cu.evalInSandbox("nearNativeStackLimit(1, function() { nestedLimit = nnslChrome(0);}); nestedLimit;", contentSb);
ok(nestedLimit >= 11, "Chrome should be invokable from content script with an exhausted stack: " + nestedLimit);
]]>
</script>
</window>

View file

@ -0,0 +1,26 @@
var bottom = stackPointerInfo();
var top = bottom;
function nearNativeStackLimit() {
function inner() {
try {
with ({}) { // keep things predictable -- stay in the interpreter
top = stackPointerInfo();
var stepsFromLimit = eval("inner()"); // Use eval to force a number of native stackframes to be created.
}
return stepsFromLimit + 1;
} catch(e) {
// It would be nice to check here that the exception is actually an
// over-recursion here. But doing so would require toString()ing the
// exception, which we may not have the stack space to do.
return 1;
}
}
return inner();
}
var nbFrames = nearNativeStackLimit();
var frameSize = bottom - top;
print("Max stack size:", frameSize, "bytes",
"\nMaximum number of frames:", nbFrames,
"\nAverage frame size:", Math.ceil(frameSize / nbFrames), "bytes");

View file

@ -0,0 +1,59 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=533596
-->
<window title="Mozilla Bug 533596"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<iframe src="http://example.org/tests/js/xpconnect/tests/mochitest/file_bug738244.html"
onload="xrayTest(this)">
</iframe>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
function xrayTest(ifr) {
var win = ifr.contentWindow;
var doc = ifr.contentDocument;
doc.getElementById = 42;
is(doc.getElementById, 42,
"Native property cannot be shadowed on the xray");
is(doc.form1.name, "form1",
"Form elements cannot be found by name on the document through xray");
is(doc.form1.input1.name, "input1",
"Input element cannot be found by name on a form element through xray");
is(typeof doc.form1.appendChild, "function",
"Input element shadows native property with its name through xray");
is(win.frame1.name, "frame1",
"IFrames cannot be found by name on the window through xray");
is(win[0].name, "frame1",
"IFrames cannot be found by index on the window through xray");
win["1000"] = "foopy";
ok(!("1000" in win), "Shouldn't be able to add indexed expandos to xray");
win["1000a"] = "foopy";
ok("1000a" in win, "Should be able to add named expandos to xray");
SimpleTest.finish();
}
]]></script>
</window>

View file

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=743843
-->
<window title="Mozilla Bug 743843"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=743843"
target="_blank">Mozilla Bug 743843</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Components.Exception options objects. **/
// Note: We pass |window| as the 'data' field here because Components.Exception
// doesn't handle JS Objects here all that nicely. See bug 743121.
// Test the old interface.
var e1 = Components.Exception('foo', Components.results.NS_BINDING_ABORTED, null, window);
is(e1.result, Components.results.NS_BINDING_ABORTED, "Result should get set properly");
is(e1.data, window, "User data should get set properly");
// Test the options object.
var e2 = Components.Exception('foo', { result: Components.results.NS_BINDING_ABORTED,
data: window,
foobar: 2 });
is(e2.result, Components.results.NS_BINDING_ABORTED, "Result should get set properly");
is(e2.data.window, window, "User data should get set properly");
]]>
</script>
</window>

View file

@ -0,0 +1,49 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=760076
-->
<window title="Mozilla Bug 760076"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=760076"
target="_blank">Mozilla Bug 760076</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for constructing COW-ed functions in content. **/
// This gets decompiled and run in the sandbox.
function sandboxCode() {
try {
is(chromeFunction(), 42, "Should call successfully");
} catch(e) { ok(false, "Shouldn't throw when calling"); }
try {
ok(typeof (new chromeFunction()) !== 'undefined',
"Should construct successfully");
} catch(e) { ok(false, "Shouldn't throw when constructing"); }
}
// Set up the sandbox.
const Cu = Components.utils;
var sb = new Cu.Sandbox('http://www.example.com');
// Import the functions it needs.
sb.ok = ok;
sb.is = is;
sb.chromeFunction = function() { ok(true, "Called chrome function"); return 42; }
Cu.evalInSandbox(sandboxCode.toSource(), sb);
// Do the test.
Cu.evalInSandbox("sandboxCode();", sb);
]]>
</script>
</window>

View file

@ -0,0 +1,44 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=760131
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 760131</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=760131">Mozilla Bug 760131</a>
<p id="display"></p>
<div id="content" style="display: none">
<iframe id="frame"></iframe>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 760131 **/
var frame = document.getElementById("frame");
function runTest()
{
var win = frame.contentWindow;
win.wrappedJSObject.ok = ok;
var doc = win.document;
var empty = doc.createTouchList();
var event = doc.createEvent("touchevent");
event.initTouchEvent("touchstart", true, true, win, 0, false, false, false, false, empty, empty, empty);
doc.getElementById("target").dispatchEvent(event);
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
frame.onload = runTest;
frame.src = "http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug760131.html";
</script>
</pre>
</body>
</html>

View file

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=763343
-->
<window title="Mozilla Bug 763343"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=763343"
target="_blank">Mozilla Bug 763343</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Cross-compartment nsIClassInfo singleton wrapping. **/
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
// We need an object here that has singleton classinfo. For now, the console
// service works.
var singleton = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIClassInfo);
ok(singleton.flags & Ci.nsIClassInfo.SINGLETON_CLASSINFO,
"Should have singleton classinfo");
var sb = new Cu.Sandbox(window);
// Don't crash.
sb.singleton = singleton;
ok(true, "didn't crash");
]]>
</script>
</window>

View file

@ -0,0 +1,51 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=771429
-->
<window title="Mozilla Bug 771429"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=771429"
target="_blank">Mozilla Bug 771429</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 771429 **/
function f() {}
function g() { return this; }
function h() { "use strict"; return this; }
function ctor() { this.x = 1; }
f.x = 2;
f.g = g;
var Cu = Components.utils;
var s = new Cu.Sandbox(window, { sandboxPrototype: window } );
try {
is(Cu.evalInSandbox('g()', s), window,
"Should get window as this object of non-strict global function");
is(Cu.evalInSandbox('h()', s), undefined,
"Should get undefined as this object of strict global function");
is(Cu.evalInSandbox('f.x', s), 2,
"Should have gotten the right thing back");
is(Cu.evalInSandbox('f.g()', s), f,
"Should have the right function object");
is(Cu.evalInSandbox('var x = { z: 7 }; g.call(x).z', s), 7,
"Should not rebind calls that are already bound");
// And test what happens when we use the normal Function.prototype.call
// on g instead of whatever our proxies happen to return.
is(Cu.evalInSandbox('var x = { z: 7 }; Function.prototype.call.call(g, x).z', s), 7,
"Should not rebind calls that are already bound");
is(Cu.evalInSandbox('new ctor();', s).x, 1,
"Should get a properly constructed object out of the sandbox");
} catch (e) {
ok(false, "Should not get an exception: " + e);
}
]]>
</script>
</window>

View file

@ -0,0 +1,82 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=773962
-->
<window title="Mozilla Bug 773962"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=773962"
target="_blank">Mozilla Bug 773962</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for remapping Xray waivers during brain transplant. **/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
var gFramesLoaded = 0;
function frameLoaded() {
++gFramesLoaded;
if (gFramesLoaded == 2)
startTest();
if (gFramesLoaded == 3)
finishTest();
}
function startTest() {
// grab the windows and the node.
win1 = document.getElementById('frame1').contentWindow;
win2 = document.getElementById('frame2').contentWindow;
node1 = win1.document.getElementById('text');
loc1 = win1.location;
// Grab some Xray waivers.
win1Waiver = win1.wrappedJSObject;
node1Waiver = node1.wrappedJSObject;
loc1Waiver = win1Waiver.location;
// Adopt node1 into win2. This causes node1 to be transplanted.
win2.document.adoptNode(node1);
// Navigate win1. This causes win1 to be transplanted.
win1.location = 'http://test2.example.org/tests/js/xpconnect/tests/mochitest/file_empty.html';
// The above happens async. Our onload handler will call finishTest() when we're ready.
}
function finishTest() {
// Now, recompute some wrappers.
Cu.recomputeWrappers();
// First, pat ourselves on the back for not asserting/crashing. That's most of
// what we're really testing here.
ok(true, "Didnt crash!");
// Now, make sure everything is set up how we expect.
ok(win1Waiver === win1.wrappedJSObject, "waivers still work");
ok(XPCNativeWrapper(win1Waiver) === win1, "waivers still work");
ok(node1Waiver === node1.wrappedJSObject, "waivers still work");
ok(XPCNativeWrapper(node1Waiver) === node1, "waivers still work");
// The semantics of location are tricky, because win1 now has a new location object.
// In fact, loc1 should be a dead object proxy. Let's make sure we get this right.
ok(loc1 !== win1.location, "navigation means different window.location");
ok(loc1Waiver !== win1.location.wrappedJSObject, "navigation means different window.location");
// Whew.
SimpleTest.finish();
}
]]>
</script>
<iframe id="frame1" onload="frameLoaded();" type="content" src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
<iframe id="frame2" onload="frameLoaded();" type="content" src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=792280
-->
<window title="Mozilla Bug 792280"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=792280"
target="_blank">Mozilla Bug 792280</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 792280 **/
const Cu = Components.utils;
function checkSb(sb, expect) {
var target = new Cu.Sandbox('http://www.example.com');
Cu.evalInSandbox('function fun() { return arguments.callee.caller; };', target);
sb.fun = target.fun;
let allowed = false;
try {
allowed = Cu.evalInSandbox('function doTest() { return fun() == doTest; }; doTest()', sb);
isnot(expect, "throw", "Should have thrown");
} catch (e) {
is(expect, "throw", "Should expect exception");
ok(/denied|insecure/.test(e), "Should be a security exception: " + e);
}
is(allowed, expect == "allow", "should censor appropriately");
}
// Note that COWs are callable, but XOWs are not.
checkSb(new Cu.Sandbox('http://www.example.com'), "allow");
checkSb(new Cu.Sandbox('http://www.example.org'), "throw");
checkSb(new Cu.Sandbox(window), "censor");
]]>
</script>
</window>

View file

@ -0,0 +1,48 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=793433
-->
<window title="Mozilla Bug 793433"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=793433"
target="_blank">Mozilla Bug 793433</a>
<p id="display"></p>
<div id="content" style="display: none"/>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
var Cc = Components.classes;
var Ci = Components.interfaces;
function shouldThrow(fun, args, msg) {
try {
fun.apply(this, args);
ok(false, msg);
} catch (e) {
ok(true, msg+" -- "+e);
}
}
function do_registerTopLevelWindow(win) {
Cc['@mozilla.org/appshell/appShellService;1'].
getService(Ci.nsIAppShellService).registerTopLevelWindow(win);
}
shouldThrow(
do_registerTopLevelWindow, [null],
"registering null as a top-level window should throw");
shouldThrow(
do_registerTopLevelWindow, [{}],
"registering a void object as a top-level window should throw");
]]></script>
</window>

View file

@ -0,0 +1,88 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=795275
-->
<window title="Mozilla Bug 795275"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=795275"
target="_blank">Mozilla Bug 795275</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Warning in content scopes about Components. **/
SimpleTest.waitForExplicitFinish();
SimpleTest.executeSoon(startLoad);
function startLoad() {
for (var i = 1; i <= document.getElementsByTagName('iframe').length; ++i) {
var frame = document.getElementById('frame' + i);
frame.contentWindow.location = 'http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug795275.html';
frame.onload = frameLoaded;
}
}
// Set up our console listener.
var gWarnings = 0;
function onWarning(consoleMessage) {
if (/soon be removed/.test(consoleMessage.message))
gWarnings++;
}
var gListener = {
observe: onWarning,
QueryInterface: function (iid) {
if (!iid.equals(Components.interfaces.nsIConsoleListener) &&
!iid.equals(Components.interfaces.nsISupports)) {
throw Components.results.NS_ERROR_NO_INTERFACE;
}
return this;
}
};
var gConsoleService = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
gConsoleService.registerListener(gListener);
// Wait for all four child frame to load.
var gLoadCount = 0;
function frameLoaded() {
if (++gLoadCount == document.getElementsByTagName('iframe').length)
go();
}
function getWin(id) { return document.getElementById(id).contentWindow.wrappedJSObject; }
function go() {
getWin('frame1').touchComponents();
getWin('frame2').touchInterfaces();
getWin('frame4').touchComponents();
getWin('frame4').touchInterfaces();
// This shouldn't warn.
getWin('frame5').touchViaXBL();
// Warnings are dispatched async, so stick ourselves at the end of the event
// queue.
setTimeout(done, 0);
}
function done() {
gConsoleService.unregisterListener(gListener);
is(gWarnings, 3, "Got the right number of warnings");
SimpleTest.finish();
}
]]>
</script>
<iframe id="frame1"/>
<iframe id="frame2"/>
<iframe id="frame3"/>
<iframe id="frame4"/>
<iframe id="frame5"/>
</window>

View file

@ -0,0 +1,50 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=799348
-->
<window title="Mozilla Bug 799348"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=799348"
target="_blank">Mozilla Bug 799348</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 799348 **/
SimpleTest.waitForExplicitFinish();
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
gCalledOnload = false;
var myObserver = {
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIObserver]),
observe: function(win, topic, data) {
if (topic == "domwindowopened") {
ok(!gCalledOnload, "domwindowopened notification fired before onload");
win.addEventListener("load", function(evt) {
gCalledOnload = true;
win.close();
}, false);
} else if (topic == "domwindowclosed") {
ok(gCalledOnload, "should have called onload");
Services.ww.unregisterNotification(myObserver);
SimpleTest.finish();
}
else {
ok(false, "unknown topic");
}
}
};
Services.ww.registerNotification(myObserver);
]]>
</script>
<iframe id="frame" type="content" src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_bug799348.html" />
</window>

View file

@ -0,0 +1,46 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=801241
-->
<window title="Mozilla Bug 801241"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=801241"
target="_blank">Mozilla Bug 801241</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 801241 **/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
// This is decompiled and run inside the sandbox;
function sbCode() {
try {
win.location = win.location;
ok(true, "Didn't throw setting from location");
} catch (e) {
ok(false, "Threw setting location from sandbox");
}
}
function go() {
document.getElementById('ifr').onload = null;
var sb = new Cu.Sandbox(this);
sb.win = document.getElementById('ifr').contentWindow;
sb.ok = ok;
Cu.evalInSandbox('(' + sbCode.toSource() + ')()', sb);
SimpleTest.finish();
}
]]>
</script>
<iframe id="ifr" onload="go();" type="content" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,91 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=812415
-->
<window title="Mozilla Bug 812415"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=812415"
target="_blank">Mozilla Bug 812415</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 812415 and Bug 823348 **/
const Cu = Components.utils;
SimpleTest.waitForExplicitFinish();
function testWaiving(iwin, sb) {
sb.win = iwin;
is(Cu.evalInSandbox('win', sb), iwin, "Basic identity works");
is(Cu.evalInSandbox('win.wrappedJSObject.expando', sb), 42, "Waivers work via .wrappedJSObject");
is(Cu.evalInSandbox('XPCNativeWrapper.unwrap(win).expando', sb), 42, "Waivers work via XPCNativeWrapper.unwrap");
is(Cu.evalInSandbox('win.wrappedJSObject.document.defaultView.expando', sb), 42, "Waivers are deep");
}
function checkThrows(expression, sb, msg) {
var result = Cu.evalInSandbox('(function() { try { ' + expression + '; return "allowed"; } catch (e) { return e.toString(); }})();', sb);
ok(!!/denied/.exec(result), msg);
}
function testAsymmetric(regular, expanded) {
// Set up objects.
expanded.regFun = Cu.evalInSandbox('function reg() { return 42; }; reg', regular);
expanded.regObj = Cu.evalInSandbox('new Object({foo: 2})', regular);
regular.expFun = Cu.evalInSandbox('function exp() { return 41; }; exp', expanded);
regular.expObj = Cu.evalInSandbox('new Object({bar: 3})', expanded);
// Check objects.
is(Cu.evalInSandbox('regObj.foo', expanded), 2, "Expanded can see regular object prop");
checkThrows('expObj.bar', regular, "Regular shouldn't read properties");
Cu.evalInSandbox('regObj.foo = 20', expanded);
is(expanded.regObj.foo, 20, "Expanded can set properties");
checkThrows('expFun.bar = 0', regular, "Regular shouldn't write properties");
// Check functions.
is(Cu.evalInSandbox('regFun()', expanded), 42, "Expanded can call regular function");
checkThrows('expFun()', regular, "Regular cannot call expanded function");
is(Cu.evalInSandbox('regFun.name', expanded), 'reg', "Expanded can see regular function's name");
checkThrows('expFun.name', regular, "Regular can't see expanded function's name");
Cu.evalInSandbox('regFun.expando = 30', expanded);
is(Cu.evalInSandbox('regFun.expando', expanded), 30, "Expanded can set expandos");
checkThrows('expFun.expando = 29', regular, "Regular can't set expandos");
// Check __proto__ stuff.
is(Cu.evalInSandbox('regFun.__proto__', expanded), regular.Function.prototype, "expanded can get __proto__");
checkThrows('expFun.__proto__', regular, "regular can't use __proto__");
checkThrows('expFun.__proto__ = {}', regular, "regular can't mutate __proto__");
}
function go() {
var iwin = document.getElementById('ifr').contentWindow;
iwin.wrappedJSObject.expando = 42;
// Make our sandboxes. We pass wantXrays=false for the nsEP to ensure that
// the Xrays we get are the result of being an nsEP, not from the wantXrays
// flag.
var regular = new Components.utils.Sandbox(iwin);
var expanded = new Components.utils.Sandbox([iwin], {wantXrays: false});
// Because of the crazy secret life of wantXrays, passing wantXrays=false
// has the side effect of waiving Xrays on the returned sandbox. Undo that.
expanded = XPCNativeWrapper(expanded);
testWaiving(iwin, regular);
testWaiving(iwin, expanded);
testAsymmetric(regular, expanded);
SimpleTest.finish();
}
]]>
</script>
<iframe id="ifr" onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,41 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=853283
-->
<window title="Mozilla Bug 853283"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=853283"
target="_blank">Mozilla Bug 853283</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test nsNavigatorSH::Resolve in conjunction with Xrays.**/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
function go() {
// This chrome document already has Xrays to the content scope, but we use a
// a sandbox anyway to make sure that the global in play here isn't an
// nsIDOMWindow. Otherwise, the resolve hook might just end up squeaking by
// with the chrome window.
var iwin = $('ifr').contentWindow;
var sb = new Cu.Sandbox(window);
sb.iwin = iwin;
sb.ok = ok;
Cu.evalInSandbox('try {iwin.navigator.mozContacts; ok(true, "Didnt throw"); } catch (e) { ok(false, "Threw: " + e);}', sb);
SimpleTest.finish();
}
]]>
</script>
<iframe id="ifr" onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=853571
-->
<window title="Mozilla Bug 853571"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=853571"
target="_blank">Mozilla Bug 853571</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 853571 **/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
function mainTest() {
var iwin = $('ifr').contentWindow;
// Test with a simple sandbox with no prototype.
checkSource(iwin, new Cu.Sandbox(iwin), null, "should get null source with no sandboxPrototype");
yield;
// Test with a sandboxPrototype.
checkSource(iwin, new Cu.Sandbox(iwin, { sandboxPrototype: iwin }), iwin, "should be able to impersonate the prototype");
yield;
SimpleTest.finish();
yield; // Prevent StopIteration from being thrown.
}
var gen;
function runTest() {
gen = mainTest();
gen.next();
}
function checkSource(target, sb, expectedSource, message) {
target.addEventListener("message", function listener(event) {
target.removeEventListener("message", listener);
is(event.source, expectedSource, message);
try {
gen.next();
} catch (e if e instanceof StopIteration) {
// We're done.
}
});
sb.target = target;
Cu.evalInSandbox("target.postMessage('foo', '*');", sb);
}
]]>
</script>
<iframe id="ifr" type="content" onload="runTest()" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,55 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=858101
-->
<window title="Mozilla Bug 858101"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=858101"
target="_blank">Mozilla Bug 858101</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for [[DefaultValue]] on XrayWrappers. **/
SimpleTest.waitForExplicitFinish();
function muckWithToString() {
function tricky() { return "hah"; };
window.toString = document.toString = document.body.toString = tricky;
window.valueOf = document.valueOf = document.body.valueOf = tricky;
Window.prototype.toString = Window.prototype.valueOf = tricky;
Document.prototype.toString = Document.prototype.valueOf = tricky;
HTMLBodyElement.toString = HTMLBodyElement.valueOf = tricky;
}
function go() {
var iwin = $('ifr').contentWindow;
iwin.wrappedJSObject.eval('(' + muckWithToString.toSource() + ')()');
// Check behavior with vanilla CCWs.
ok(!!/hah/.exec(iwin.wrappedJSObject + ""), "Waivers should get content-defined window stringification");
ok(!!/hah/.exec(iwin.document.wrappedJSObject + ""), "Waivers should get content-defined document stringification");
ok(!!/hah/.exec(iwin.document.body.wrappedJSObject + ""), "Waivers should get content-defined body stringification");
// Check Xray behavior.
ok(!/hah/.exec(iwin + ""), "Xrays should not get content-defined window stringification");
ok(!/hah/.exec(iwin.document + ""), "Xrays should not get content-defined document stringification");
ok(!/hah/.exec(iwin.document.body + ""), "Xrays should not get content-defined body stringification");
SimpleTest.finish();
}
]]>
</script>
<iframe id="ifr" onload="go();" type="content" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,57 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=860494
-->
<window title="Mozilla Bug 860494"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=860494"
target="_blank">Mozilla Bug 860494</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 860494 **/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
function go() {
var iwin = $('ifr').contentWindow;
// NB: mochitest-chrome actually runs the test as a content docshell.
is(iwin.top, window.top, "iframe names shouldn't shadow |top| via Xray");
is(iwin.parent, window, "iframe names shouldn't shadow |parent| via Xray");
ok(!!/http/.exec(iwin.location), "iframe names shouldn't shadow |location| via Xray");
is(iwin.length, 7, "iframe names shouldn't shadow |length| via Xray");
is(iwin.window, iwin, "iframe names shouldn't shadow |window| via Xray");
is(iwin.navigator, XPCNativeWrapper(iwin.wrappedJSObject.navigator),
"iframe names shouldn't shadow |navigator| via Xray");
ok(iwin.alert instanceof Function,
"iframe names shouldn't shadow |alert| via Xray");
// Now test XOWs.
var sb = new Cu.Sandbox('http://www.example.com');
sb.win = iwin;
sb.topWin = top;
sb.parentWin = window;
sb.is = is;
sb.ok = ok;
Cu.evalInSandbox('ok(win.top === topWin, "iframe names shouldnt shadow |top| via cross-origin Xray");', sb);
Cu.evalInSandbox('ok(win.parent === parentWin, "iframe names shouldnt shadow |parent| via cross-origin Xray");', sb);
Cu.evalInSandbox('is(win.length, 7, "iframe names shouldnt shadow |length| via cross-origin Xray");', sb);
Cu.evalInSandbox('ok(win.window === win, "iframe names shouldnt shadow |window| via cross-origin Xray");', sb);
Cu.evalInSandbox('var exn = "nothrow"; try { win.navigator; } catch (e) { exn = e; } ok(!!/denied/.exec(exn), "cross-origin Xray blocks subframes that shadow: navigator: " + exn);', sb);
Cu.evalInSandbox('var exn = "nothrow"; try { win.alert; } catch (e) { exn = e; } ok(!!/denied/.exec(exn), "cross-origin Xray blocks subframes that shadow: alert: " + exn);', sb);
SimpleTest.finish();
}
]]>
</script>
<iframe id="ifr" type="content" onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_bug860494.html" />
</window>

View file

@ -0,0 +1,36 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=865948
-->
<window title="Mozilla Bug 865948"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=865948"
target="_blank">Mozilla Bug 865948</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 865948 **/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
function go() {
$('ifr').onload = null;
var sb = Cu.Sandbox(['http://example.com', 'http://example.org']);
sb.iwin = $('ifr').contentWindow;
sb.ok = ok;
Cu.evalInSandbox('try { iwin.location = "about:"; ok(false, "didnt throw"); } catch (e) { ok(!!/denied/.exec(e), "threw: " + e); }', sb);
SimpleTest.finish();
}
]]>
</script>
<iframe id="ifr" type="content" onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,50 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=866823
-->
<window title="Mozilla Bug 866823"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=866823"
target="_blank">Mozilla Bug 866823</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 866823 **/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
function go() {
var iwin = $('ifr').contentWindow;
// Make sure that Xray waivers can't be transitively extended onto objects
// for whom the extender may not waive.
var sb = new Cu.Sandbox(iwin, { wantXrays: true });
sb.iwin = iwin;
ok(Cu.evalInSandbox('iwin.wrappedJSObject.top == iwin.top', sb), "Waiver does not propagate");
Cu.evalInSandbox('iwin.wrappedJSObject.waiver = iwin.wrappedJSObject', sb);
ok(iwin.wrappedJSObject.eval('waiver == window'), "Waivers disappear same-compartment");
// Make sure that standard prototypes don't get COWs.
sb.objProto = Object.prototype;
try {
sb.eval('objProto.toString;', sb);
ok(false, "Should have thrown");
} catch (e) {
ok(/denied|insecure/, "No silent failure when accessing properties on forbidden prototype");
}
SimpleTest.finish();
}
]]>
</script>
<iframe id="ifr" onload="go();" type="content" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=895340
-->
<window title="Mozilla Bug 895340"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=895340 "
target="_blank">Mozilla Bug 895340 </a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
SimpleTest.expectUncaughtException();
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm", this);
var finished = false;
var console = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
let listener = {
QueryInterface: function(iid) {
if (!iid.equals(Components.interfaces.nsIConsoleListener) &&
!iid.equals(Components.interfaces.nsISupports))
{
throw Components.results.NS_ERROR_NO_INTERFACE;
}
return this;
}
};
listener.observe = function(aMessage) {
if (aMessage.message.indexOf("Will you report me?") != -1 && !finished) {
finished = true;
ok(true, "exception reported");
console.unregisterListener(listener);
SimpleTest.finish();
}
};
console.registerListener(listener);
/* Throw an exception and verify that it gets reported. */
let foo_obs = function() {
throw new Error("Will you report me?");
};
Services.obs.addObserver(foo_obs, "foo", false);
Services.obs.notifyObservers(null, "foo", "foo");
Services.obs.removeObserver(foo_obs, "foo");
]]></script>
</window>

View file

@ -0,0 +1,72 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=932906
-->
<window title="Mozilla Bug 932906"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=932906"
target="_blank">Mozilla Bug 932906</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
const Cu = Components.utils;
Cu.import('resource://gre/modules/Services.jsm');
/** Test for Bug 932906 **/
SimpleTest.waitForExplicitFinish();
function passToContent(shouldThrow) {
try {
$('ifr').contentWindow.obs = Services.obs;
ok(!shouldThrow, "Didn't throw when passing non-DOM XPCWN to content");
} catch (e) {
ok(shouldThrow, "Threw when passing non-DOM XPCWN to content");
ok(/denied/.test(e), "Threw correct exception: " + e);
}
}
var gLoadCount = 0;
function loaded() {
++gLoadCount;
if (gLoadCount == 1)
part1();
else if (gLoadCount == 2)
part2();
else
ok(false, "Didn't expect three loads");
}
function part1() {
// Make sure that the pref is what we expect for mochitests.
is(Services.prefs.getBoolPref('dom.use_xbl_scopes_for_remote_xul'), true,
"Test harness set up like we expect");
// First, test that we can't normally pass non-DOM XPCWNs to content.
passToContent(/* shouldThrow = */ true);
// Now, make sure we _can_ for the remote xul case. We use SpecialPowers
// for the pref munging because it cleans up after us.
SpecialPowers.pushPrefEnv({set: [['dom.use_xbl_scopes_for_remote_xul', false]]}, function() {
$('ifr').contentWindow.location.reload();
});
}
function part2() {
passToContent(/* shouldThrow = */ false);
SimpleTest.finish();
}
]]>
</script>
<iframe id="ifr" onload="loaded();" type="content" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,53 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=996069
-->
<window title="Mozilla Bug 996069"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=996069"
target="_blank">Mozilla Bug 996069</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
const Cu = Components.utils;
/** Test for Bug 996069 **/
SimpleTest.waitForExplicitFinish();
function loaded() {
var ifr = document.getElementById("ifr").contentWindow;
var sb = new Cu.Sandbox([ifr],
{ sandboxPrototype: ifr });
ifr.wrappedJSObject.finishTest = function() {
// If we got here we did not hit the NS_ReleaseAssert...
ok(true, "nsExpandedPrincipal should not be inherited by content windows");
// But let's be sure that the new window does not have nsEP
newWin.wrappedJSObject.obj = Cu.evalInSandbox("var obj = { foo: 'bar' }; obj", sb);
try {
newWin.eval("obj.foo");
ok(false, "newWin should not have access to object from a scope with nsExpandedPrincipal");
} catch (e) {
ok(/Permission denied/.exec(e.message), "newWin should not have access to object from a scope with nsExpandedPrincipal");
}
newWin.close();
SimpleTest.finish();
};
var newWin = Cu.evalInSandbox(
"window.open('http://example.org/chrome/js/xpconnect/tests/chrome/file_bug996069.html');",
sb);
}
]]>
</script>
<iframe id="ifr" onload="loaded();" type="content" src="http://example.org/chrome/js/xpconnect/tests/chrome/file_bug996069.html" />
</window>

View file

@ -0,0 +1,62 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window title="Mozilla Bug 761723"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=761723" target="_blank">Mozilla Bug 761723</a>
</body>
<!-- test code goes here -->
<script type="application/javascript" src="outoflinexulscript.js"></script>
<script type="application/javascript"><![CDATA[
var Cu = Components.utils;
var Cc = Components.classes;
var Ci = Components.interfaces;
Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/Services.jsm");
function inlinefunction() {
return 42;
}
var src;
src = inlinefunction.toSource();
isnot(src.indexOf("return 42"), -1, "inline XUL script should have source");
is(src.charAt(src.length - 1), "}", "inline XUL source should end with '}'");
src = outoflinefunction.toSource();
isnot(src.indexOf("return 42"), -1, "out of line XUL script should have source")
is(src.charAt(src.length - 1), "}", "out of line XUL source should end with '}'");
src = NetUtil.asyncFetch.toSource();
isnot(src.indexOf("return"), -1, "JSM should have source");
var ns = {};
Services.scriptloader.loadSubScript("resource://gre/modules/NetUtil.jsm", ns);
src = ns.NetUtil.asyncFetch.toSource();
isnot(src.indexOf("return"), -1, "subscript should have source");
var base = /.*\//.exec(window.location.href)[0];
var reg = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
var resolvedBase = reg.convertChromeURL(NetUtil.newURI(base)).spec;
ns = {};
Services.scriptloader.loadSubScript(resolvedBase + "subscript.js", ns);
src = ns.NetUtil.asyncFetch.toSource();
isnot(src.indexOf("return"), -1, "subscript of a subscript should have source");
ns = {};
Services.scriptloader.loadSubScript(resolvedBase + "utf8_subscript.js", ns, "UTF-8");
src = ns.f.toSource();
isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source");
ns = {};
Services.scriptloader.loadSubScriptWithOptions(resolvedBase + "utf8_subscript.js",
{target: ns, charset: "UTF-8", ignoreCache: true});
src = ns.f.toSource();
isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source");
]]></script>
</window>

View file

@ -0,0 +1,198 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<window title="Mozilla Bug 503926"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=964293"
target="_blank">Cu.cloneInto()</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
const Cu = Components.utils;
const Ci = Components.interfaces;
const TypedArrayThings = [
'Int8Array',
'Uint8Array',
'Uint8ClampedArray',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array',
];
function checkThrows(f, msg, rgxp) {
try {
f();
ok(false, "Should have thrown: " + msg);
} catch (e) {
ok(true, "Threw correctly - " + msg + " - " + e);
if (rgxp)
ok(rgxp.test(e), "Should throw correct exception: " + e);
}
}
function getType(a) {
if (a === null || a === undefined)
return 'null';
if (Array.isArray(a))
return 'array';
if (a instanceof File)
return 'file';
if (a instanceof Ci.nsIDOMBlob)
return 'blob';
if (TypedArrayThings.indexOf(a.constructor.name) !== -1)
return a.constructor.name;
if (typeof a == 'object')
return 'object';
if (typeof a == 'function')
return 'function';
return 'primitive';
}
function compare(a, b) {
is (getType(a), getType(b), 'Type matches');
var type = getType(a);
if (type == 'array') {
is (a.length, b.length, 'Array.length matches');
for (var i = 0; i < a.length; ++i) {
compare(a[i], b[i]);
}
return;
}
if (type == 'file' || type == 'blob') {
ok ( a === b, 'They should match');
return;
}
if (type == 'object') {
ok ( a !== b, 'They should not match');
var aProps = [];
for (var p in a) aProps.push(p);
var bProps = [];
for (var p in b) bProps.push(p);
is (aProps.length, bProps.length, 'Props match');
is (aProps.sort().toSource(), bProps.sort().toSource(), 'Props match - using toSource()');
for (var p in a) {
compare(a[p], b[p]);
}
return;
}
if (type == 'function') {
ok ( a !== b, 'They should not match');
return;
}
if (type != 'null') {
is (a.toSource(), b.toSource(), 'Matching using toSource()');
}
}
var sandboxOptions = {
wantXrays: true,
wantExportHelpers: true,
};
var sandbox = new Cu.Sandbox(window, sandboxOptions);
// The second sandbox is for testing the exportHelper version of the cloneInto
var sandbox2 = new Cu.Sandbox("http://example.com", sandboxOptions);
sandbox.sandbox2 = sandbox2;
sandbox2.sandbox = sandbox;
function cloneAndTest(test) {
var output = sandbox.test = Cu.cloneInto(test, sandbox);
compare(test, output);
output = Cu.evalInSandbox('cloneInto(test, sandbox2)', sandbox);
compare(test, output);
}
function cloneAndTestWithFunctions(test) {
var output = sandbox.test = Cu.cloneInto(test, sandbox, { cloneFunctions: true });
compare(test, output);
output = Cu.evalInSandbox('cloneInto(test, sandbox2, { cloneFunctions: true })', sandbox);
// Note - We need to waive here, because functions are filtered out by object Xrays.
compare(test, Cu.waiveXrays(output));
}
var tests = [
1,
null,
true,
'hello world',
[1, 2, 3],
{ a: 1, b: 2 },
new Date(),
{ a: 1, b: {}, c: [1, 2, 3, {} ], e: 'hello world' },
];
for (var i = 0; i < tests.length; ++i) {
cloneAndTest(tests[i]);
}
checkThrows(function() { Cu.cloneInto({ a: function() {} }, sandbox); },
'Function should not be cloned by default');
checkThrows(function() { Cu.cloneInto({ a: document }, sandbox); },
'Reflectors should not be wrapped by default');
var withReflectors = Cu.cloneInto({ doc: document, win: window }, sandbox,
{ wrapReflectors: true });
is(Cu.unwaiveXrays(Cu.waiveXrays(withReflectors).doc), document, "Document passes");
is(Cu.unwaiveXrays(Cu.waiveXrays(withReflectors).win), window, "Window passes");
checkThrows(function() { Cu.evalInSandbox('cloneInto({}, sandbox)', sandbox2); },
'CloneInto should only work on less privileged target scopes.',
/denied|insecure/);
var cloneTarget = new Cu.Sandbox('http://example.com');
var sameOriginSB = new Cu.Sandbox('http://example.com', { wantGlobalProperties: ['XMLHttpRequest'] });
var crossOriginSB = new Cu.Sandbox('http://example.net', { wantGlobalProperties: ['XMLHttpRequest'] });
sandbox2.cloneTarget = cloneTarget;
sandbox2.soXHR = Cu.evalInSandbox('new XMLHttpRequest()', sameOriginSB);
sandbox2.xoXHR = Cu.evalInSandbox('new XMLHttpRequest()', crossOriginSB);
sandbox2.chromeDoc = document;
Cu.evalInSandbox('function tryToClone(x) { return cloneInto({val: x}, cloneTarget, { wrapReflectors: true }).val; }', sandbox2);
is(Cu.evalInSandbox('tryToClone(soXHR)', sandbox2), sandbox2.soXHR, 'Same-origin wrapReflectors works');
checkThrows(function() { Cu.evalInSandbox('tryToClone(chromeDoc)', sandbox2); },
'wrapReflectors may not wrap cross-origin reflectors', /unsupported value type/);
var test = { a: function() { return 42; } };
cloneAndTestWithFunctions(test);
// Check that inputs are properly passed through cloned functions:
test = { a: function(obj) { return obj; } };
var clonedTest = Cu.cloneInto(test, sandbox, {cloneFunctions: true});
var testInput = {};
is(clonedTest.a(testInput), testInput, "Objects should be identical");
]]>
</script>
</window>

View file

@ -0,0 +1,266 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=500931
-->
<window title="Mozilla Bug 522764"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=522764 "
target="_blank">Mozilla Bug 522764 </a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
var Ci = Components.interfaces;
var Cu = Components.utils;
var sandbox = new Cu.Sandbox("about:blank");
var test_utils = window.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils);
function getCOW(x) {
if (typeof x != 'object' && typeof x != 'function')
return x;
x = Cu.waiveXrays(x);
var rval = {};
if (typeof x == "function")
rval = eval(uneval(x));
for (var i in x) {
if (x.__lookupGetter__(i))
rval.__defineGetter__(i, eval(uneval(x.__lookupGetter__(i))))
else
rval[i] = getCOW(x[i]);
}
return rval;
}
// Give the sandbox a way to create ChromeObjectWrapped objects.
sandbox.getCOW = getCOW;
// Define test API functions in the sandbox.
const TEST_API = ['is', 'isnot', 'ok', 'todo_is', 'todo_isnot', 'todo'];
TEST_API.forEach(function(name) { sandbox[name] = window[name]; });
sandbox.alienObject = {
__exposedProps__: {funProp: 'r'},
funProp: function foo(x) {
return x + 1;
}
};
sandbox.chromeGet = function (obj, prop) { return obj[prop]; };
function COWTests() {
function getNames(cow) {
let names = [];
for (let name in cow) {
names.push(name);
}
return names;
}
// This function is actually decompiled and run inside a
// sandbox with content privileges.
// TODO: This could use some refactoring; creating helper
// functions like assertIsWritable(myObj, 'someproperty') might
// be useful.
function isProp(obj, propName, value, desc) {
try {
is(obj[propName], value, "getting " + propName + " on " + desc);
ok(propName in obj,
propName + " on " + desc + " should exist");
ok(Object.hasOwnProperty.call(obj, propName),
propName + " on " + desc + " should exist");
} catch (e) {
ok(false, "getting " + propName + " on " + desc + " threw " + e);
}
}
function isPropHidden(obj, propName, desc) {
try {
is(obj[propName], undefined,
"getting " + propName + " on " + desc + " should return undefined");
ok(!(propName in obj),
propName + " on " + desc + " should act as if it doesn't exist");
ok(!Object.hasOwnProperty.call(obj, propName),
propName + " on " + desc + " should act as if it doesn't exist");
} catch (e) {
ok(false, "getting " + propName + " on " + desc + " threw " + e);
}
}
const PROPS_TO_TEST = ['foo', 'bar', 'prototype'];
var empty = {};
var nonempty = {foo: 42, bar: 33};
is(getCOW(empty).foo, undefined,
"shouldn't throw when accessing exposed properties that doesn't exist");
PROPS_TO_TEST.forEach(function(name) {
isPropHidden(getCOW(nonempty), name, "object without exposedProps");
});
// Test function objects.
var func = function(x) { return 42; };
func.__exposedProps__ = { foo: "r" };
func.foo = "foo property";
var funcCOW = getCOW(func);
try {
funcCOW.foo;
ok(false, 'Functions are no longer COWable');
} catch (e) {
ok(/denied|insecure/.test(e), 'Functions are no longer COWable');
}
is(funcCOW(), 42, "Chrome functions should be callable");
// Test object with empty exposedProps
var strict = { __exposedProps__: {}, foo: "foo property" };
var strictCOW = getCOW(strict);
PROPS_TO_TEST.forEach(function(name) {
isPropHidden(strictCOW, name, "object with empty exposedProps");
});
is(getNames(strictCOW).length, 0,
"object with empty exposedProps shouldn't have any properties");
// Test object with one exposed property
var strict = { __exposedProps__: { foo: "r" }, foo: "foo property" };
var strictCOWr = getCOW(strict);
PROPS_TO_TEST.forEach(function(name) {
if (name == "foo") {
isProp(strictCOWr, name, "foo property",
"object with exposed 'foo'");
}
else {
isPropHidden(strictCOW, name, "object with exposed 'foo'");
}
});
is(getNames(strictCOWr).length, 1,
"object with exposedProps only enumerate exposed props");
is(getNames(strictCOWr)[0], "foo",
"object with exposedProps only enumerate exposed props");
// Test writable property
var writable = getCOW({ __exposedProps__: {foo: 'w'}});
try {
ok(!("foo" in writable),
"non-existing write-only property shouldn't exist");
writable.foo = 5;
is(chromeGet(writable, "foo"), 5, "writing to a write-only exposed prop works");
todo("foo" in writable,
"existing write-only property should exist");
} catch (e) {
ok(false, "writing to a write-only exposed prop shouldn't throw " + e);
}
try {
writable.foo;
todo(false, "reading from a write-only exposed prop should throw");
} catch (e) {
todo(/Permission denied/.test(e),
"reading from a write-only exposed prop should throw");
}
try {
delete writable.foo;
is(chromeGet(writable, "foo"), undefined,
"deleting a write-only exposed prop works");
} catch (e) {
ok(false, "deleting a write-only exposed prop shouldn't throw " + e);
}
// Test readable property
var readable = { __exposedProps__: {foo: 'r'},
foo: 5,
bar: 6 };
try {
isProp(getCOW(readable), "foo", 5,
"reading from a readable exposed prop works");
} catch (e) {
ok(false, "reading from a readable exposed prop shouldn't throw " + e);
}
try {
getCOW(readable).foo = 1;
ok(false, "writing to a read-only exposed prop should fail");
} catch (e) {
ok(/Permission denied/.test(e),
"writing to a read-only exposed prop should fail");
}
try {
delete getCOW(readable).foo;
ok(false, "deleting a read-only exposed prop shouldn't work");
} catch (e) {
ok(/Permission denied/.test(e),
"deleting a read-only exposed prop should throw error");
}
try {
var props = getNames(getCOW(readable));
is(props.length, 1, "COW w/ one exposed prop should enumerate once");
is(props[0], 'foo', "COW w/ one exposed prop should enumerate it");
} catch (e) {
ok(false, "COW w/ a readable prop should not raise exc " +
"on enumeration: " + e);
}
// Test read/write property
var readwrite = getCOW({ __exposedProps__: {foo: 'rw'}});
try {
ok(!("foo" in readwrite),
"non-existing readwrite property shouldn't exist");
readwrite.foo = 5;
is(readwrite.foo, 5, "writing to a readwrite exposed prop looks like it worked");
is(chromeGet(readwrite, "foo"), 5, "writing to a readwrite exposed prop works");
ok("foo" in readwrite,
"existing readwrite property should exist");
} catch (e) {
ok(false, "writing to a readwrite exposed prop shouldn't throw " + e);
}
try {
delete readwrite.foo;
is(readwrite.foo, undefined, "deleting readwrite prop looks like it worked");
ok(!("foo" in readwrite), "deleting readwrite prop looks like it really worked");
is(chromeGet(readwrite, "foo"), undefined,
"deleting a readwrite exposed prop works");
} catch (e) {
ok(false, "deleting a readwrite exposed prop shouldn't throw " + e);
}
// Readables and functions
try {
var COWFunc = getCOW((function() { return 5; }));
is(COWFunc(), 5, "COWed functions should be callable");
} catch (e) {
todo(false, "COWed functions should not raise " + e);
}
}
// Decompile the COW test suite, re-evaluate it in the sandbox and execute it.
Cu.evalInSandbox('(' + uneval(COWTests) + ')()', sandbox);
// Test that COWed objects passing from content to chrome get unwrapped.
function returnCOW() {
return getCOW({__exposedProps__: {},
bar: 6});
}
var unwrapped = Cu.evalInSandbox(
'(' + uneval(returnCOW) + ')()',
sandbox
);
try {
is(unwrapped.bar, 6,
"COWs should be unwrapped when entering chrome space");
} catch (e) {
todo(false, "COWs should be unwrapped when entering chrome space, " +
"not raise " + e);
}
]]></script>
</window>

View file

@ -0,0 +1,81 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=990353
-->
<window title="Mozilla Bug 990353"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=990353"
target="_blank">Mozilla Bug 990353</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 990353 **/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
function canary() {
var someBitOfSource = 42;
}
var gLoadCount = 0;
function frameLoaded() {
switch (++gLoadCount) {
case 1:
ok(/sourceless/.test(window[0].canary.toSource()), "System function should be sourceless: " + window[0].canary.toSource());
ok(/sourceless/.test(window[0].onload.toSource()), "System event handler should be sourceless: " + window[0].onload.toSource());
var sb = new Cu.Sandbox('http://www.example.com', { discardSource: true });
Cu.evalInSandbox('function canary() { var someBitOfSource = 42; }', sb);
ok(/sourceless/.test(sb.canary.toSource()), "Function from sandbox with explicit discarding should be sourceless");
try {
window[0].throwSomething();
ok(false, "should have thrown");
} catch (e) {
ok(/some error/.test(e), "Threw exception as expected: " + e);
ok(/throwSomething/.test(e.stack), "Exception stack trace works: " + e.stack);
}
window[0].location = "http://example.org/tests/js/xpconnect/tests/chrome/file_discardSystemSource.html";
break;
case 2:
ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).canary.toSource()), "Content function should have source");
ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).onload.toSource()), "Content event handler should have source");
testWorker();
break;
}
}
function testWorker() {
var worker = new window[0].wrappedJSObject.Worker('worker_discardSystemSource.js');
worker.onmessage = function(evt) {
ok(/someBitOfSource/.test(evt.data), "Non-chrome worker should have source: " + evt.data);
var chromeWorker = new Worker('worker_discardSystemSource.js');
chromeWorker.onmessage = function(evt) {
ok(/sourceless/.test(evt.data), "Chrome worker should not have source: " + evt.data);
SimpleTest.finish();
}
}
}
function go() {
// We should have our own source, because the pref wasn't enabled when we
// were loaded.
ok(/someBitOfSource/.test(canary.toSource()), "Should have own source");
window[0].frameElement.onload = frameLoaded;
window[0].location = "file_discardSystemSource.html";
}
addLoadEvent(function() {
SpecialPowers.pushPrefEnv({set: [['javascript.options.discardSystemSource', true]]}, go);
});
]]>
</script>
<iframe></iframe>
</window>

View file

@ -0,0 +1,101 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=601277
-->
<window title="Mozilla Bug 601277"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=601277"
target="_blank">Mozilla Bug 601277</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Tests for document.domain. **/
const Cu = Components.utils;
SimpleTest.waitForExplicitFinish();
// Wait for the frames to load.
var gFramesLoaded = 0;
function frameLoaded() {
gFramesLoaded++;
if (gFramesLoaded == document.getElementsByTagName('iframe').length)
startTest();
}
function startTest() {
// Grab all the content windows and waive Xray. Xray waivers only apply to
// chrome, so we can pass these references directly to content.
var win1A = document.getElementById('test1A').contentWindow.wrappedJSObject;
var win1B = document.getElementById('test1B').contentWindow.wrappedJSObject;
var win2 = document.getElementById('test2').contentWindow.wrappedJSObject;
var winBase = document.getElementById('base').contentWindow.wrappedJSObject;
// Check the basics.
ok(win1A.tryToAccess(win1B),
"Same-origin windows should grant access");
ok(!win1A.tryToAccess(win2),
"Cross-origin windows should not grant access");
ok(!win1A.tryToAccess(winBase),
"Subdomain windows should not receive access");
// Store references now, while test1A and test1B are same-origin.
win1A.storeReference(win1B);
win1B.storeReference(win1A);
ok(win1A.tryToAccessStored(), "Stored references work when same-origin");
win1A.evalFromB = Cu.unwaiveXrays(win1B.eval); // Crashtest for bug 1040181.
win1B.functionFromA = Cu.unwaiveXrays(win1A.Function); // Crashtest for bug 1040181.
ok(!win1A.invokingFunctionThrowsSecurityException('evalFromB'), "Should allow before document.domain");
ok(!win1B.invokingFunctionThrowsSecurityException('functionFromA'), "Should allow before document.domain");
// Set document.domain on test1A. This should grant no access, since nobody
// else set it.
win1A.setDomain('example.org');
ok(!win1A.tryToAccess(winBase), "base must collaborate too");
ok(!winBase.tryToAccess(win1A), "base must collaborate too");
ok(!win1A.tryToAccess(win1B), "No longer same-origin");
ok(!win1A.tryToAccessStored(), "No longer same-origin");
ok(!win1B.tryToAccess(win1A), "No longer same-origin");
ok(!win1B.tryToAccessStored(), "No longer same-origin");
ok(win1A.invokingFunctionThrowsSecurityException('evalFromB'), "No longer same-origin");
ok(win1B.invokingFunctionThrowsSecurityException('functionFromA'), "No longer same-origin");
// Set document.domain on test1B. Now we're cooking with gas.
win1B.setDomain('example.org');
ok(!win1B.tryToAccess(winBase), "base must collaborate too");
ok(!winBase.tryToAccess(win1B), "base must collaborate too");
ok(win1A.tryToAccess(win1B), "same-origin");
ok(win1A.tryToAccessStored(), "same-origin");
ok(win1B.tryToAccess(win1A), "same-origin");
ok(win1B.tryToAccessStored(), "same-origin");
// Explicitly collaborate with base.
winBase.setDomain('example.org');
ok(winBase.tryToAccess(win1A), "base collaborates");
ok(win1A.tryToAccess(winBase), "base collaborates");
// All done.
SimpleTest.finish();
}
]]>
</script>
<iframe id="test1A" onload="frameLoaded();" type="content"
src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" />
<iframe id="test1B" onload="frameLoaded();" type="content"
src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" />
<iframe id="test2" onload="frameLoaded();" type="content"
src="http://test2.example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" />
<iframe id="base" onload="frameLoaded();" type="content"
src="http://example.org/tests/js/xpconnect/tests/mochitest/file_documentdomain.html" />
</window>

View file

@ -0,0 +1,42 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=533596
-->
<window title="Mozilla Bug 533596"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<iframe type="content"
src="http://example.org/tests/js/xpconnect/tests/mochitest/file_doublewrappedcompartments.html"
onload="go()"
id="ifr">
</iframe>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
const utils = SpecialPowers.DOMWindowUtils;
function go() {
var wrappedWin = $('ifr').contentWindow;
is(typeof wrappedWin.expando, 'undefined', "Shouldn't be able to see the expando");
var unwrapped = wrappedWin.wrappedJSObject;
var expando = unwrapped.expando;
isnot(expando, 'undefined', 'properly wrapped');
is(typeof expando.querySelector, 'function', 'double wrapped');
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
]]></script>
</window>

View file

@ -0,0 +1,202 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=533596
-->
<window title="Mozilla Bug 533596"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<iframe src="http://example.org/tests/js/xpconnect/tests/mochitest/file_evalInSandbox.html"
onload="checkCrossOrigin(this)">
</iframe>
<iframe src="chrome://mochitests/content/chrome/js/xpconnect/tests/chrome/file_evalInSandbox.html"
onload="checkSameOrigin(this)">
</iframe>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
const Cu = Components.utils;
const Ci = Components.interfaces;
const utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
function checkCrossOriginSandbox(sandbox)
{
is(utils.getClassName(sandbox),
"Proxy",
"sandbox was wrapped correctly");
is(utils.getClassName(Cu.evalInSandbox("this.document", sandbox)),
"Proxy",
"return value was rewrapped correctly");
}
function checkCrossOriginXrayedSandbox(sandbox)
{
ok(Cu.evalInSandbox("!('windowfoo' in window);", sandbox),
"the window itself Xray is an XrayWrapper");
ok(Cu.evalInSandbox("('wrappedJSObject' in this.document);", sandbox),
"wrappers inside eIS are Xrays");
ok(Cu.evalInSandbox("!('foo' in this.document);", sandbox),
"must not see expandos");
ok('wrappedJSObject' in Cu.evalInSandbox("this.document", sandbox),
"wrappers returned from the sandbox are Xrays");
ok(!("foo" in Cu.evalInSandbox("this.document", sandbox)),
"must not see expandos in wrappers returned from the sandbox");
ok('wrappedJSObject' in sandbox.document,
"values obtained from the sandbox are Xrays");
ok(!("foo" in sandbox.document),
"must not see expandos in wrappers obtained from the sandbox");
}
function checkCrossOrigin(ifr) {
var win = ifr.contentWindow;
var sandbox =
new Cu.Sandbox(win, { sandboxPrototype: win, wantXrays: true } );
checkCrossOriginSandbox(sandbox);
checkCrossOriginXrayedSandbox(sandbox);
sandbox =
new Cu.Sandbox(win, { sandboxPrototype: win } );
checkCrossOriginSandbox(sandbox);
checkCrossOriginXrayedSandbox(sandbox);
sandbox =
new Cu.Sandbox(win, { sandboxPrototype: win, wantXrays: false } );
checkCrossOriginSandbox(sandbox);
ok(Cu.evalInSandbox("('foo' in this.document);", sandbox),
"can see expandos");
ok(("foo" in Cu.evalInSandbox("this.document", sandbox)),
"must see expandos in wrappers returned from the sandbox");
ok(("foo" in sandbox.document),
"must see expandos in wrappers obtained from the sandbox");
testDone();
}
function checkSameOrigin(ifr) {
var win = ifr.contentWindow;
var sandbox =
new Cu.Sandbox(win, { sandboxPrototype: win, wantXrays: true } );
ok(Cu.evalInSandbox("('foo' in this.document);", sandbox),
"must see expandos for a chrome sandbox");
sandbox =
new Cu.Sandbox(win, { sandboxPrototype: win } );
ok(Cu.evalInSandbox("('foo' in this.document);", sandbox),
"must see expandos for a chrome sandbox");
sandbox =
new Cu.Sandbox(win, { sandboxPrototype: win, wantXrays: false } );
ok(Cu.evalInSandbox("('foo' in this.document);", sandbox),
"can see expandos for a chrome sandbox");
testDone();
}
var testsRun = 0;
function testDone() {
if (++testsRun == 2)
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
try {
var sandbox = new Cu.Sandbox(this, { sandboxPrototype: undefined } );
ok(false, "undefined is not a valid prototype");
}
catch (e) {
ok(true, "undefined is not a valid prototype");
}
try {
var sandbox = new Cu.Sandbox(this, { wantXrays: undefined } );
ok(false, "undefined is not a valid value for wantXrays");
}
catch (e) {
ok(true, "undefined is not a valid value for wantXrays");
}
// Crash test for bug 601829.
try {
Components.utils.evalInSandbox('', null);
} catch (e) {
ok(true, "didn't crash on a null sandbox object");
}
try {
var sandbox = new Cu.Sandbox(this, { sameZoneAs: this } );
ok(true, "sameZoneAs works");
}
catch (e) {
ok(false, "sameZoneAs works");
}
// The 'let' keyword only appears with JS 1.7 and above. We use this fact
// to make sure that sandboxes get explict JS versions and don't inherit
// them from the most recent scripted frame.
function checkExplicitVersions() {
const Cu = Components.utils;
var sb = new Cu.Sandbox(sop);
Cu.evalInSandbox('let someVariable = 42', sb, '1.7');
ok(true, "Didn't throw with let");
try {
Cu.evalInSandbox('let someVariable = 42', sb);
ok(false, "Should have thrown with let");
} catch (e) {
ok(true, "Threw with let: " + e);
}
try {
Cu.evalInSandbox('let someVariable = 42', sb, '1.5');
ok(false, "Should have thrown with let");
} catch (e) {
ok(true, "Threw with let: " + e);
}
}
var outerSB = new Cu.Sandbox(this);
Cu.evalInSandbox(checkExplicitVersions.toSource(), outerSB, '1.7');
outerSB.ok = ok;
outerSB.sop = this;
Cu.evalInSandbox('checkExplicitVersions();', outerSB);
Cu.import("resource://gre/modules/jsdebugger.jsm");
addDebuggerToGlobal(this);
try {
let dbg = new Debugger();
let sandbox = new Cu.Sandbox(this, { invisibleToDebugger: false });
dbg.addDebuggee(sandbox);
ok(true, "debugger added visible value");
} catch(e) {
ok(false, "debugger could not add visible value");
}
try {
let dbg = new Debugger();
let sandbox = new Cu.Sandbox(this, { invisibleToDebugger: true });
dbg.addDebuggee(sandbox);
ok(false, "debugger added invisible value");
} catch(e) {
ok(true, "debugger did not add invisible value");
}
]]></script>
</window>

View file

@ -0,0 +1,73 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=877673
-->
<window title="Mozilla Bug 877673"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
var sb = new Cu.Sandbox("http://example.org", {wantExportHelpers: true});
sb.ok = ok;
function executeIn(frame, script, exceptionCb) {
sb.frame = frame;
sb.exceptionCb = exceptionCb;
if (exceptionCb) {
return Cu.evalInSandbox("try {frame.eval('" + script + "'); ok(false, 'Exception should have been thrown.')} catch(e) {exceptionCb(e)}", sb);
}
return Cu.evalInSandbox("frame.eval('" + script + "')", sb);
}
function testSameOrigin(frame) {
frame.contentWindow.document.wrappedJSObject.str = "foobar";
is(executeIn(frame.contentWindow, "document.str"), "foobar",
"Same origin string property access.");
executeIn(frame.contentWindow, 'document.obj = {prop: "foobar"}');
is((executeIn(frame.contentWindow, "document.obj")).prop, "foobar",
"Same origin object property access (cloning).");
isnot(executeIn(frame.contentWindow, "document.obj"), frame.contentWindow.document.wrappedJSObject.obj,
"Ensure cloning for js objects.");
is(executeIn(frame.contentWindow, "document"), frame.contentWindow.document,
"Xrayables should just pass without cloning.");
is( executeIn(frame.contentWindow, "({a:{doc: document}})").a.doc, frame.contentWindow.document,
"Deep cloning works.");
executeIn(frame.contentWindow, "throw 42", function(e){is(e, 42,
"Exception was thrown from script.")});
testDone();
}
function testCrossOrigin(frame) {
executeIn(frame.contentWindow, "var a = 42;", function(e){ok(e.toString().indexOf("Permission denied") > -1,
"Executing script in a window from cross origin should throw.");});
testDone();
}
var testsRun = 0;
function testDone() {
if (++testsRun == 2)
SimpleTest.finish();
}
]]></script>
<iframe src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"
onload="testSameOrigin(this)">
</iframe>
<iframe src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_empty.html"
onload="testCrossOrigin(this)">
</iframe>
</window>

View file

@ -0,0 +1,68 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=735544
-->
<window title="Mozilla Bug 735544"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=735544"
target="_blank">Mozilla Bug 735544</a>
<iframe id='ifr0' onload="frameDone(0);" src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_exnstack.html" />
<iframe id='ifr1' onload="frameDone(1);" src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_exnstack.html" />
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 735544 - Allow exception stacks to cross compartment boundaries **/
SimpleTest.waitForExplicitFinish();
var gFramesDone = [false, false];
function frameDone(idx) {
gFramesDone[idx] = true;
if (gFramesDone[0] && gFramesDone[1])
startTest();
}
function throwAsChrome() {
// Grab the iframe content windows.
var cwin0 = document.getElementById('ifr0').contentWindow;
var cwin1 = document.getElementById('ifr1').contentWindow;
// Have cwin0 call a function on cwin1 that throws.
cwin0.wrappedJSObject.doThrow(cwin1);
}
function startTest() {
try {
throwAsChrome();
ok(false, "should throw");
} catch (e) {
stackFrames = e.stack.split("\n");
ok(/throwAsInner/.exec(stackFrames[0]),
"The bottom frame should be thrown by the inner");
ok(/throwAsOuter/.exec(stackFrames[2]),
"The 3rd-from-bottom frame should be thrown by the other");
ok(!/throwAsChrome/.exec(e.stack),
"The entire stack should not cross into chrome.");
}
SimpleTest.finish();
}
]]>
</script>
</window>

View file

@ -0,0 +1,145 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=758415
-->
<window title="Mozilla Bug 758415"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=758415"
target="_blank">Mozilla Bug 758415</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Cross-Origin Xray Expando Sharing. **/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
// Import our test JSM. We first strip the filename off
// the chrome url, then append the jsm filename.
var base = /.*\//.exec(window.location.href)[0];
Cu.import(base + "file_expandosharing.jsm");
// Wait for all child frames to load.
var gLoadCount = 0;
function frameLoaded() {
if (++gLoadCount == window.frames.length)
go();
}
function go() {
// Empower the content windows with some functions.
var wins = document.getElementsByTagName('iframe');
for (var i = 0; i < wins.length; ++i) {
var win = wins[i].contentWindow.wrappedJSObject;
win.ok = ok;
win.is = is;
}
// Grab references to the content windows. We abbreviate the origins as follows:
// A: test1.example.org
// B: test2.example.org
// C: sub1.test1.example.org
window.gWinA1 = document.getElementById('frameA1').contentWindow;
window.gWinA2 = document.getElementById('frameA2').contentWindow;
window.gWinA3 = document.getElementById('frameA3').contentWindow;
window.gWinB = document.getElementById('frameB').contentWindow;
window.gWinC = document.getElementById('frameC').contentWindow;
// Test expando sharing with a JSM for different types of Xrays.
testJSM(XPCNativeWrapper(gWinC.wrappedJSObject.targetWN));
testJSM(XPCNativeWrapper(gWinC.wrappedJSObject.targetDOM));
testJSM(XPCNativeWrapper(gWinC.wrappedJSObject.targetJS));
// Make sure sandboxes never share expandos with anyone else.
testSandbox(XPCNativeWrapper(gWinB.wrappedJSObject.targetWN));
testSandbox(XPCNativeWrapper(gWinB.wrappedJSObject.targetDOM));
testSandbox(XPCNativeWrapper(gWinB.wrappedJSObject.targetJS));
// Test Content Xrays.
testContentXrays();
SimpleTest.finish();
}
// Make sure that expandos are shared between us and a JSM.
function testJSM(target) {
target.numProp = 42;
target.strProp = "foo";
target.objProp = { bar: "baz" };
checkFromJSM(target, is);
}
function testSandbox(target) {
// This gets both run in this scope and the sandbox scope.
var name = "harness";
function placeExpando() {
target.prop = name;
}
// Set up the sandboxes.
sb1 = Cu.Sandbox(window);
sb2 = Cu.Sandbox(window);
sb1.target = target;
sb2.target = target;
sb1.name = "sandbox1";
sb2.name = "sandbox2";
placeExpando();
Cu.evalInSandbox(placeExpando.toSource() + "placeExpando();", sb1);
Cu.evalInSandbox(placeExpando.toSource() + "placeExpando();", sb2);
// Make sure everyone sees a different value.
is(target.prop, "harness", "Harness sees its own value");
is(Cu.evalInSandbox("target.prop", sb1), "sandbox1", "Sandbox 1 sees its own value");
is(Cu.evalInSandbox("target.prop", sb2), "sandbox2", "Sandbox 2 sees its own value");
}
// Make sure that the origin tagging machinery works correctly and that we don't
// mix up chrome and content expandos.
function testContentXrays() {
// Give A1 and A3 xrays to (same-origin) A2.
Components.utils.setWantXrays(gWinA1);
Components.utils.setWantXrays(gWinA3);
gWinA1.wrappedJSObject.placeExpando('A1_expando', 11, gWinA2.document);
gWinA3.wrappedJSObject.placeExpando('A3_expando', 33, gWinA2.document);
gWinA2.document.Chrome_expando = 33;
is(gWinA2.document.Chrome_expando, 33, "Read chrome expando properly");
is(typeof gWinA2.document.A1_expando, 'undefined', "Chrome doesn't see content expandos");
is(typeof gWinA2.document.A3_expando, 'undefined', "Chrome doesn't see content expandos");
gWinA1.wrappedJSObject.checkExpando('A1_expando', 11, gWinA2.document, "Content sees proper expandos");
gWinA3.wrappedJSObject.checkExpando('A1_expando', 11, gWinA2.document, "Content sees proper expandos");
gWinA1.wrappedJSObject.checkExpando('A3_expando', 33, gWinA2.document, "Content sees proper expandos");
gWinA3.wrappedJSObject.checkExpando('A3_expando', 33, gWinA2.document, "Content sees proper expandos");
gWinA1.wrappedJSObject.checkExpando('Chrome_expando', null, gWinA2.document, "Content doesn't see chrome expandos");
gWinA3.wrappedJSObject.checkExpando('Chrome_expando', null, gWinA2.document, "Content doesn't see chrome expandos");
// We very explicitly do not support expando sharing via document.domain.
// A comment in the implementation explains why.
gWinA1.document.domain = 'test1.example.org';
gWinA2.document.domain = 'test1.example.org';
gWinA3.document.domain = 'test1.example.org';
gWinC.document.domain = 'test1.example.org';
gWinC.wrappedJSObject.checkExpando('A1_expando', null, gWinA2.document, "document.domain should have no effect here");
gWinC.wrappedJSObject.checkExpando('A3_expando', null, gWinA2.document, "document.domain should have no effect here");
}
]]>
</script>
<iframe id="frameA1" onload="frameLoaded();" type="content" src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_expandosharing.html" />
<iframe id="frameA2" onload="frameLoaded();" type="content" src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_expandosharing.html" />
<iframe id="frameA3" onload="frameLoaded();" type="content" src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_expandosharing.html" />
<iframe id="frameB" onload="frameLoaded();" type="content" src="http://test2.example.org/tests/js/xpconnect/tests/mochitest/file_expandosharing.html" />
<iframe id="frameC" onload="frameLoaded();" type="content" src="http://sub1.test1.example.org/tests/js/xpconnect/tests/mochitest/file_expandosharing.html" />
</window>

View file

@ -0,0 +1,46 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=804630
-->
<window title="Mozilla Bug 804630"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=804630"
target="_blank">Mozilla Bug 804630</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test to make sure that COWed objects can expose properties from their prototypes. **/
const Cu = Components.utils;
// Set up the sandbox.
var sb = new Cu.Sandbox('http://www.example.com');
sb.ok = ok;
sb.is = is;
// Make a chrome object that exposes objects off its prototype.
sb.proto = { read: 42, readWrite: 32, __exposedProps__: {} };
sb.obj = { __exposedProps__: { read: 'r', readWrite: 'rw' } };
sb.obj.__proto__ = sb.proto;
// Make sure we can't access any of the properties on the prototype directly.
Cu.evalInSandbox('is(proto.read, undefined, "proto.read inaccessible");', sb);
Cu.evalInSandbox('var wrote = false; ' +
'try { proto.readWrite = 12; wrote = true; } catch(e) {} ' +
' ok(!wrote, "Should not write proto property");', sb);
// Make sure we can access the exposed properties via the derived object.
Cu.evalInSandbox('is(obj.read, 42, "obj.read accessible");', sb);
Cu.evalInSandbox('is(obj.readWrite, 32, "obj.readWrite is readable");', sb);
Cu.evalInSandbox('obj.readWrite = 8; is(obj.readWrite, 8, "obj.readWrite is writable");', sb);
]]>
</script>
</window>

View file

@ -0,0 +1,67 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=688277
-->
<window title="Mozilla Bug "
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id="
target="_blank">Mozilla Bug 688277</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 688277 **/
let Cu = Components.utils;
/* Fail gracefully if junk is passed in. */
is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(11), undefined,
"nondeterministicGetWeakMapKeys should return undefined for non-objects");
is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys({}), undefined,
"nondeterministicGetWeakMapKeys should return undefined for non-weakmap objects");
is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(null), undefined,
"nondeterministicGetWeakMapKeys should return undefined for null");
/* return an empty array for an empty WeakMap */
let mempty = new WeakMap();
is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(mempty).length, 0,
"nondeterministicGetWeakMapKeys should return empty array for empty weakmap");
/* Test freeing/nonfreeing. */
let m = new WeakMap();
let liveKeys = new Array();
let add_elements = function () {
let k1 = {};
m.set(k1, "live1");
liveKeys.push(k1);
let k2 = {};
m.set(k2, "dead1");
let k = {};
m.set(k, k); /* simple cycle */
};
add_elements();
Cu.schedulePreciseGC(function () {
let keys = ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(m);
is(liveKeys.length, 1, "Wrong number of live keys.");
is(keys.length, 1, "Should have one weak map key.");
is(m.get(keys[0]), "live1", "live1 should be live");
SimpleTest.finish();
});
SimpleTest.waitForExplicitFinish();
]]>
</script>
</window>

View file

@ -0,0 +1,38 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=980023
-->
<window title="Mozilla Bug 980023 "
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=980023"
target="_blank">Mozilla Bug 980023 </a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for localstorage access with expanded principal. **/
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
function go() {
var iwin = document.getElementById('ifr').contentWindow;
var sb = new Cu.Sandbox([iwin], {sandboxPrototype: iwin});
Cu.evalInSandbox("window.localStorage.test_localstorage_with_nsEp = 3",sb);
is(Cu.evalInSandbox("window.localStorage.test_localstorage_with_nsEp",sb), "3");
is(iwin.localStorage.test_localstorage_with_nsEp, "3");
iwin.localStorage.removeItem("test_localstorage_with_nsEp");
SimpleTest.finish();
}
]]>
</script>
<iframe id="ifr" onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
</window>

View file

@ -0,0 +1,50 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=533596
-->
<window title="Mozilla Bug 533596"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<iframe src="http://example.org/tests/js/xpconnect/tests/mochitest/file_matches.html"
onload="runTest(this)">
</iframe>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
function runTest(ifr)
{
var doc = ifr.contentDocument;
var docElem = doc.documentElement;
var res = doc.createElement('div').matches('div');
is(res, true, "matches call through xray, regular case");
res = docElem.matches.call(
doc.createElement('div'), 'div');
is(res, true, "matches call through xray, with .call");
var sb = new Components.utils.Sandbox(ifr.contentWindow);
sb.doc = doc;
var str = "doc.documentElement.matches.call(doc.createElement( 'div' ),'div')";
res = Components.utils.evalInSandbox(str, sb);
is(res, true, "matches call through xray (same origin), with .call");
docElem.matches = function(){return false};
res = docElem.matches.call(doc.createElement( 'div' ),'div');
is(res, false, "shadowing matches with an expando on the xray wrapper");
SimpleTest.finish();
}
]]></script>
</window>

View file

@ -0,0 +1,52 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window title="Test nodelists from chrome"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
function go() {
var win = $('ifr').contentWindow;
var list = win.document.getElementsByTagName('p');
is(list.length, 3, "can get the length");
ok(list[0] instanceof HTMLParagraphElement, "can get list[0]");
is(list[0], list.item(0), "list.item works");
is(list.item, list.item, "don't recreate functions for each get");
var list2 = list[2];
ok(list[2] instanceof HTMLParagraphElement, "list[2] exists");
ok("2" in list, "in operator works");
is(win.document.body.removeChild(win.document.body.lastChild), list2, "remove last paragraph element");
ok(!("2" in list), "in operator doesn't see phantom element");
is(list[2], undefined, "no node there!");
var optionList = win.document.createElement("select").options;
var option = win.document.createElement("option");
optionList[0] = option;
is(optionList.item(0), option, "Creators work");
option = win.document.createElement("option");
optionList[0] = option;
is(optionList.item(0), option, "Setters work");
SimpleTest.finish();
}
]]></script>
<iframe id="ifr"
src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_nodelists.html"
onload="go()" />
</window>

View file

@ -0,0 +1,63 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test for 814497</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<div id="log"></div>
<script>
var c = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
SimpleTest.waitForExplicitFinish();
SimpleTest.expectUncaughtException();
// /!\ Line number is important in this test,
// we are asserting the following functions line #
function failingStack() {
nestedFunction();
}
function nestedFunction() {
doesntExistsAndThrow();
}
var TestObserver = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
observe: function test_observe(aSubject)
{
if (!(aSubject instanceof Ci.nsIScriptError)) {
return;
}
dump("stack: "+aSubject.stack+"\n");
// Main assertions
var s = aSubject.stack;
ok(!!s, "has first frame");
ok(s.source.indexOf("test_nsScriptErrorWithStack.html") !== -1, "source is correct");
is(s.line, 23, "line is correct");
is(s.column, 5, "column is correct");
is(s.functionDisplayName, "nestedFunction");
s = s.parent;
ok(!!s, "has second frame");
ok(s.source.indexOf("test_nsScriptErrorWithStack.html") !== -1, "source is correct");
is(s.line, 20, "line is correct");
is(s.column, 5, "column is correct");
is(s.functionDisplayName, "failingStack");
// We shouldn't have any more frame as we used setTimeout
ok(!s.parent, "has no more frames");
// Cleanup
Services.console.unregisterListener(TestObserver);
SimpleTest.finish();
}
};
Services.console.registerListener(TestObserver);
// use setTimeout in order to prevent throwing from test frame
// and so have a clean stack frame with just our method calls
setTimeout(failingStack, 0);
</script>

View file

@ -0,0 +1,35 @@
<!doctype html>
<html>
<head>
<title>Bug 1150253 - Sanity test for the SpiderMonkey Debugger API's onGarbageCollection hook</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js">
</script>
</head>
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1150253"
target="_blank">Mozilla Bug 1150253</a>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
const Cu = Components.utils;
Cu.import("resource://devtools/shared/Loader.jsm");
const require = devtools.require;
const { gc } = Cu.getJSTestingFunctions();
const Debugger = require("Debugger");
const dbg = new Debugger(this);
dbg.memory.onGarbageCollection = function (data) {
// Don't keep calling this hook after we finish.
dbg.enabled = false;
ok(data, "The onGarbageCollection hook was fired.");
SimpleTest.finish();
};
gc();
</script>
</body>
</html>

View file

@ -0,0 +1,80 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=777385
-->
<window title="Mozilla Bug 777385"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<div></div>
<div id="mydivname"></div>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id="
target="_blank">Mozilla Bug 777385</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 777385 **/
let Cu = Components.utils;
let live_map = new WeakMap;
let get_div_style = function () {
return document.getElementById("mydivname").style;
}
let make_live_map = function () {
let my_div_style = get_div_style();
let div_fail = false;
try {
live_map.set(my_div_style, 12345);
} catch (e) {
div_fail = true;
}
ok(!div_fail, "Using elem.style as a weak map key should not produce an exception.");
is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value before GC.");
}
make_live_map();
// RGBColor is a non-nsISupports refCounted class using WebIDL bindings.
// non-nsISupports cycle-collected classes should fail as weak map keys.
let context = window.getComputedStyle(document.documentElement, null).getPropertyCSSValue("color").getRGBColorValue();
let contextFail = false;
try {
live_map.set(context, 2);
} catch (e) {
contextFail = true;
}
ok(contextFail, "Cycle collected non-nsISupports classes aren't allowed as weak map keys.");
/* Set up for running precise GC/CC then check the results. */
SimpleTest.waitForExplicitFinish();
Cu.schedulePreciseGC(function () {
SpecialPowers.DOMWindowUtils.cycleCollect();
SpecialPowers.DOMWindowUtils.garbageCollect();
SpecialPowers.DOMWindowUtils.garbageCollect();
is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(live_map).length, 1,
"Live nsISupports new DOM bindings wrappercached native weak map key should not be removed.");
is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value after GC.");
SimpleTest.finish();
});
]]>
</script>
</window>

View file

@ -0,0 +1,27 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=533596
-->
<window title="Mozilla Bug 661927"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
Components.utils.schedulePreciseGC(
function() {
ok(true, "callback executed");
SimpleTest.finish();
});
SimpleTest.waitForExplicitFinish();
]]></script>
</window>

View file

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=533596
-->
<window title="Mozilla Bug 533596"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
function checkWrapped(obj) {
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
is(utils.getClassName(obj), "Proxy", "right type of wrapper");
}
var sandbox = new Components.utils.Sandbox("about:blank");
sandbox.importFunction(function() { return "PASS"; }, "foo");
sandbox.importFunction(function bar() { return "PASS"; });
sandbox.importFunction(checkWrapped);
is(Components.utils.evalInSandbox("foo()", sandbox), "PASS", "importFunction works");
is(Components.utils.evalInSandbox("bar()", sandbox), "PASS", "importFunction works");
Components.utils.evalInSandbox("checkWrapped({})", sandbox);
var importer = sandbox.importFunction;
importer(function() { return "PASS"; }, "bar");
is(Components.utils.evalInSandbox("bar()", sandbox), "PASS", "unbound importFunction works");
is(typeof this.bar, "undefined", "didn't import into our global");
]]></script>
</window>

View file

@ -0,0 +1,127 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=937317
-->
<window title="Mozilla Bug 937317"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=937317"
target="_blank">Mozilla Bug 937317</a>
</body>
<!-- test code goes here -->
<iframe src="data:text/html,"></iframe>
<script type="application/javascript">
<![CDATA[
/** Test for the script settings stack. **/
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
const Cu = Components.utils;
Cu.import("resource://gre/modules/Promise.jsm");
iwin = window[0];
// Smoketest.
is(Cu.getIncumbentGlobal(), window, "smoketest");
// Calling a cross-compartment non-scripted function changes the
// compartment, but not the incumbent script settings object.
var sb = new Cu.Sandbox(window, { wantComponents: true });
is(sb.Components.utils.getIncumbentGlobal(), window, "cross-compartment sb non-scripted");
is(iwin.Components.utils.getIncumbentGlobal(), window, "cross-compartment win non-scripted");
// If we call a scripted function in the other compartment, that becomes
// the incumbent script.
function gib() { return Components.utils.getIncumbentGlobal(); };
Cu.evalInSandbox(gib.toSource(), sb);
iwin.eval(gib.toSource());
is(sb.gib(), sb, "cross-compartment sb scripted");
is(iwin.gib(), iwin, "cross-compartment win scripted");
// Eval-ing top-level script in another component makes that compartment the
// incumbent script.
is(Cu.evalInSandbox('Components.utils.getIncumbentGlobal()', sb), sb, 'eval sb');
is(iwin.eval('Components.utils.getIncumbentGlobal()'), iwin, 'eval iwin');
// Make sure that the callback mechanism works.
function makeCallback(expectedGlobal, deferred, kind) {
function cb(incumbentGlobal) {
is(incumbentGlobal, expectedGlobal, "Callback got the right incumbent global: " + kind);
if (deferred)
deferred.resolve();
}
info("Generated callback: " + kind);
return cb;
}
var bound = Cu.getIncumbentGlobal.bind(Cu, makeCallback(window, undefined, "simple bound"));
is(bound(), window, "Bound method returns the right global");
// Callbacks grab the incumbent script at the time of invocation.
//
// Note - We avoid calling the initial defer |d| so that it's not in-scope for everything below.
let initialDefer = Promise.defer();
setTimeout(Cu.getIncumbentGlobal.bind(Cu, makeCallback(window, initialDefer, "same-global setTimeout")), 0);
initialDefer.promise.then(function() {
// Try cross-global setTimeout where |window| is the incumbent script when the callback is created.
let d = Promise.defer();
iwin.setTimeout(Cu.getIncumbentGlobal.bind(Cu, makeCallback(window, d, "cross-global setTimeout by |window|")), 0);
return d.promise;
}).then(function() {
// Try cross-global setTimeout where |iwin| is the incumbent script when the callback is created.
let d = Promise.defer();
iwin.wrappedJSObject.timeoutFun = Cu.getIncumbentGlobal.bind(Cu, makeCallback(iwin, d, "cross-global setTimeout by |iwin|"));
iwin.eval('setTimeout(timeoutFun, 0);');
return d.promise;
}).then(function() {
// The incumbent script override doesn't take effect if the callback is scripted.
let d = Promise.defer();
iwin.wrappedJSObject.timeoutFun2 = Cu.getIncumbentGlobal.bind(Cu, makeCallback(iwin, d, "cross-global setTimeout of scripted function"));
iwin.eval('var timeoutFun2Wrapper = function() { timeoutFun2(); }');
setTimeout(iwin.wrappedJSObject.timeoutFun2Wrapper, 0);
return d.promise;
}).then(function() {
// Try event listeners.
let d = Promise.defer();
let body = iwin.document.body;
body.addEventListener('click', Cu.getIncumbentGlobal.bind(Cu, makeCallback(window, d, "cross-global event listener")));
body.dispatchEvent(new iwin.MouseEvent('click'));
return d.promise;
}).then(function() {
// Try an event handler set by |iwin|.
let d = Promise.defer();
let body = iwin.document.body;
iwin.wrappedJSObject.handler = Cu.getIncumbentGlobal.bind(Cu, makeCallback(iwin, d, "cross-global event handler"));
iwin.eval('document.body.onmousemove = handler');
body.dispatchEvent(new iwin.MouseEvent('mousemove'));
return d.promise;
}).then(function() {
// Try an event handler compiled by a content attribute.
let d = Promise.defer();
let body = iwin.document.body;
iwin.wrappedJSObject.innerHandler = Cu.getIncumbentGlobal.bind(Cu, makeCallback(iwin, d, "cross-global compiled event handler"));
iwin.eval("document.body.setAttribute('onmouseout', 'innerHandler()')");
body.dispatchEvent(new iwin.MouseEvent('mouseout'));
return d.promise;
}).then(function() {
SimpleTest.finish();
});
});
]]>
</script>
</window>

View file

@ -0,0 +1,75 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=693527
-->
<window title="Mozilla Bug "
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id="
target="_blank">Mozilla Bug 693527</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 693527 **/
let Cu = Components.utils;
let Ci = Components.interfaces;
/* Create a weak reference, with a single-element weak map. */
let make_weak_ref = function (obj) {
let m = new WeakMap;
m.set(obj, {});
return m;
};
/* Check to see if a weak reference is dead. */
let weak_ref_dead = function (r) {
return ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(r).length == 0;
}
let make_cycle = function () {
var p = document.createElement("p");
p.children.x = p;
var f = function() { };
p.watch("y", f);
var d = document.createElement("div");
d.appendChild(p);
f.loop = d;
f.bar = {}; // observing f directly makes the leak go away even without the CC somehow
return make_weak_ref(f.bar);
};
var cycle_ref = make_cycle();
/* set up for running precise GC/CC then checking the results */
SimpleTest.waitForExplicitFinish();
Cu.schedulePreciseGC(function () {
window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.cycleCollect();
window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.garbageCollect();
window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.garbageCollect();
ok(weak_ref_dead(cycle_ref), "Garbage gray watchpoint cycle should be collected.");
SimpleTest.finish();
});
]]>
</script>
</window>

View file

@ -0,0 +1,37 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=673468
-->
<window title="Mozilla Bug "
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id="
target="_blank">Mozilla Bug 673468</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 673468 **/
let Cc = Components.classes;
let Cu = Components.utils;
let Ci = Components.interfaces;
let system = Cc["@mozilla.org/systemprincipal;1"].createInstance();
let sandbox = Cu.Sandbox(system);
let map = new sandbox.WeakMap();
let obj = {};
map.set(obj, {});
Cu.forceGC();
ok(map.has(obj), "Weakmap still contains our wrapper!");
]]>
</script>
</window>

View file

@ -0,0 +1,84 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=673468
-->
<window title="Mozilla Bug "
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a id="testelem" href="https://bugzilla.mozilla.org/show_bug.cgi?id="
target="_blank">Mozilla Bug 673468</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 673468 **/
let Cc = Components.classes;
let Cu = Components.utils;
let Ci = Components.interfaces;
SpecialPowers.DOMWindowUtils.garbageCollect();
let get_live_dom = function () {
return document.getElementById("testelem");
};
let wrappers_as_keys_test = function () {
let e = new MessageEvent("foo", { bubbles: false, cancellable: false,
data: { dummy: document.createElement("foo") }});
window.eeeevent = e;
let live_dom = e.data.dummy;
let dead_dom = document.createElement("div");
let dead_child = document.createElement("div");
dead_dom.appendChild(dead_child);
is(dead_dom.children.length, 1, "children have wrong length");
let wrappee = new Object();
dead_dom.abcxyz = wrappee;
let system = Cc["@mozilla.org/systemprincipal;1"].createInstance();
let sandbox = Cu.Sandbox(system);
sandbox.wrapper = wrappee;
sandbox.value = dead_dom;
let map = Cu.evalInSandbox("wm = new WeakMap(); wm.set(wrapper, value); wm", sandbox);
sandbox.wrapper = null;
sandbox.value = null;
live_dom.xyzabc = {wrappee: wrappee, m: map, sb: sandbox};
let key = ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(map)[0];
let value = map.get(key);
is(value.children.length, 1, "children have wrong length");
}
wrappers_as_keys_test();
let check_wrappers_as_keys = function () {
let live_dom = window.eeeevent.data.dummy;
let live_map = live_dom.xyzabc.m;
let sandbox = live_dom.xyzabc.sb;
is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(live_map).length, 1,
"Map should not be empty.");
let key = ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(live_map)[0];
let value = live_map.get(key);
is(value.children.length, 1, "children have wrong length");
}
Cu.schedulePreciseGC(function () {
SpecialPowers.DOMWindowUtils.cycleCollect();
SpecialPowers.DOMWindowUtils.garbageCollect();
check_wrappers_as_keys();
});
]]>
</script>
</window>

View file

@ -0,0 +1,272 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=668855
-->
<window title="Mozilla Bug "
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id="
target="_blank">Mozilla Bug 668855</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 668855 **/
let Cu = Components.utils;
let Ci = Components.interfaces;
/* Create a weak reference, with a single-element weak map. */
let make_weak_ref = function (obj) {
let m = new WeakMap;
m.set(obj, {});
return m;
};
/* Check to see if a weak reference is dead. */
let weak_ref_dead = function (r) {
return ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(r).length == 0;
}
/* Deterministically grab an arbitrary DOM element. */
let get_live_dom = function () {
let elems = document.getElementsByTagName("a");
return elems[0];
};
/* Test case from bug 653248, adapted into a standard test.
This is a dead cycle involving a DOM edge, so the cycle collector can free it. Keys and
values reachable only from XPConnect must be marked gray for this to work, and the cycle collector
must know the proper structure of the heap.
*/
let make_gray_loop = function () {
let map = new WeakMap;
let div = document.createElement("div");
let key = {};
div.setUserData("entrain", {m:map, k:key}, null);
//div.entrain = {m:map, k:key}; This is not sufficient to cause a leak in Fx9
map.set(key, div);
return make_weak_ref(map);
};
let weakref = make_gray_loop();
/* Combinations of live and dead gray maps/keys. */
let basic_weak_ref = null;
let basic_map_weak_ref = null;
let black_map = new WeakMap;
let black_key = {};
let basic_unit_tests = function () {
let live_dom = get_live_dom();
let dead_dom = document.createElement("div");
let live_map = new WeakMap;
let dead_map = new WeakMap;
let live_key = {};
let dead_key = {};
// put the live/dead maps/keys into the appropriate DOM elements
live_dom.basic_unit_tests = {m:live_map, k:live_key};
dead_dom.setUserData("hook", {m:dead_map, k:dead_key}, null);
// dead_dom.hook = {m:dead_map, k:dead_key};
// Create a dead value, and a weak ref to it.
// The loop keeps dead_dom alive unless the CC is smart enough to kill it.
let dead_val = {loop:dead_dom};
basic_weak_ref = make_weak_ref(dead_val);
basic_map_weak_ref = make_weak_ref(dead_map);
// set up the actual entries. most will die.
live_map.set(live_key, {my_key:'live_live'});
live_map.set(dead_key, dead_val);
live_map.set(black_key, {my_key:'live_black'});
dead_map.set(live_key, dead_val);
dead_map.set(dead_key, dead_val);
dead_map.set(black_key, dead_val);
black_map.set(live_key, {my_key:'black_live'});
black_map.set(dead_key, dead_val);
black_map.set(black_key, {my_key:'black_black'});
};
basic_unit_tests();
let check_basic_unit = function () {
let live_dom = get_live_dom();
let live_map = live_dom.basic_unit_tests.m;
let live_key = live_dom.basic_unit_tests.k;
// check the dead elements
ok(weak_ref_dead(basic_weak_ref), "Dead value was kept alive.");
ok(weak_ref_dead(basic_map_weak_ref), "Dead map was kept alive.");
// check the live gray map
is(live_map.get(live_key).my_key, 'live_live',
"Live key should have the same value in live map.");
is(live_map.get(black_key).my_key, 'live_black',
"Black key should have the same value in live map.");
is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(live_map).length, 2,
"Live map should have two entries.");
// check the live black map
is(black_map.get(live_key).my_key, 'black_live',
"Live key should have the same value in black map.");
is(black_map.get(black_key).my_key, 'black_black',
"Black key should have the same value in black map.");
is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(black_map).length, 2,
"Black map should have two entries.");
};
/* live gray chained weak map entries, involving the cycle collector. */
let chainm = new WeakMap;
let num_chains = 5;
let nested_cc_maps = function () {
let dom = get_live_dom();
for(let i = 0; i < num_chains; i++) {
let k = {count:i};
dom.key = k;
dom0 = document.createElement("div");
chainm.set(k, {d:dom0});
dom = document.createElement("div");
dom0.appendChild(dom);
};
};
let check_nested_cc_maps = function () {
let dom = get_live_dom();
let all_ok = true;
for(let i = 0; i < num_chains; i++) {
let k = dom.key;
all_ok = all_ok && k.count == i;
dom = chainm.get(k).d.firstChild;
};
ok(all_ok, "Count was invalid on a key in chained weak map entries.");
};
nested_cc_maps();
/* black weak map, chained garbage cycle involving DOM */
let garbage_map = new WeakMap;
let chained_garbage_maps = function () {
let dom0 = document.createElement("div");
let dom = dom0;
for(let i = 0; i < num_chains; i++) {
let k = {};
dom.key = k;
let new_dom = document.createElement("div");
garbage_map.set(k, {val_child:new_dom});
dom = document.createElement("div");
new_dom.appendChild(dom);
};
// tie the knot
dom.appendChild(dom0);
};
chained_garbage_maps();
/* black weak map, chained garbage cycle involving DOM, XPCWN keys */
let wn_garbage_map = new WeakMap;
let wn_chained_garbage_maps = function () {
let dom0 = document.createElement("div");
let dom = dom0;
for(let i = 0; i < num_chains; i++) {
let new_dom = document.createElement("div");
wn_garbage_map.set(dom, {wn_val_child:new_dom});
dom = document.createElement("div");
new_dom.appendChild(dom);
};
// tie the knot
dom.appendChild(dom0);
};
wn_chained_garbage_maps();
/* The cycle collector shouldn't remove a live wrapped native key. */
let wn_live_map = new WeakMap;
let make_live_map = function () {
let live = get_live_dom();
wn_live_map.set(live, {});
ok(wn_live_map.has(get_live_dom()), "Live map should have live DOM node before GC.");
}
make_live_map();
let unpreservable_native_key = function () {
// We only allow natives that support wrapper preservation to be used as weak
// map keys. We should be able to try to add unpreservable natives as keys without
// crashing (bug 711616), but we should throw an error (bug 761620).
let dummy_test_map = new WeakMap;
let rule_fail = false;
let got_rule = false;
try {
var rule = document.styleSheets[0].cssRules[0];
got_rule = true;
dummy_test_map.set(rule, 1);
} catch (e) {
rule_fail = true;
}
ok(got_rule, "Got the CSS rule");
ok(rule_fail, "Using a CSS rule as a weak map key should produce an exception because it can't be wrapper preserved.");
}
unpreservable_native_key();
/* set up for running precise GC/CC then checking the results */
SimpleTest.waitForExplicitFinish();
Cu.schedulePreciseGC(function () {
SpecialPowers.DOMWindowUtils.cycleCollect();
SpecialPowers.DOMWindowUtils.garbageCollect();
SpecialPowers.DOMWindowUtils.garbageCollect();
ok(weak_ref_dead(weakref), "Garbage gray cycle should be collected.");
check_nested_cc_maps();
is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(garbage_map).length, 0, "Chained garbage weak map entries should not leak.");
check_basic_unit();
// fixed by Bug 680937
is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(wn_garbage_map).length, 0,
"Chained garbage WN weak map entries should not leak.");
// fixed by Bug 680937
is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(wn_live_map).length, 1,
"Live weak map wrapped native key should not be removed.");
ok(wn_live_map.has(get_live_dom()), "Live map should have live dom.");
SimpleTest.finish();
});
]]>
</script>
</window>

View file

@ -0,0 +1,34 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=484459
-->
<window title="Weakrefs"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<iframe type="content" id="ifr">
</iframe>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
SimpleTest.waitForExplicitFinish();
var util = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
var weakUtil = Components.utils.getWeakReference(util);
util = null;
function callback() {
ok(weakUtil.get(), "Should still be alive here");
SimpleTest.finish();
}
SpecialPowers.exactGC(callback);
]]></script>
</window>

View file

@ -0,0 +1,72 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1223372
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1223372</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1223372 **/
function go() {
SimpleTest.waitForExplicitFinish();
var frame = $('subframe');
frame.onload = null;
var w = frame.contentWindow;
w.eval("checkDead = function() { return Components.utils.isDeadWrapper(this); };");
var checkDead = w.checkDead;
w.eval("getObject = function() { return {}; }");
var getObject = w.getObject;
ok(!checkDead(), "WindowProxy shouldn't be dead yet");
// Load a content page in the chrome frame.
w.location = "http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
tryWindow();
function tryWindow() {
if (w.document.title != 'empty test page') {
info("Document not loaded yet - retrying");
SimpleTest.executeSoon(tryWindow);
return;
}
// Remove the frame. This will nuke the WindowProxy wrapper from our chrome
// document's global, so evaluating 'this' in it will return a dead wrapper.
frame.remove();
SimpleTest.executeSoon(function() {
ok(checkDead(), "Expected a dead object wrapper");
// Wrapping the Window should throw now.
var exc;
try {
Components.utils.getGlobalForObject(getObject());
} catch(e) {
exc = e;
}
is(exc.message, "Can't wrap dead object");
SimpleTest.finish();
});
}
}
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1223372">Mozilla Bug 1223372</a>
<iframe id="subframe" src="data:text/html," onload="go()"></iframe>
</body>
</html>

View file

@ -0,0 +1,215 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=500931
-->
<window title="Mozilla Bug 500931"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=403005"
target="_blank">Mozilla Bug 403005</a>
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=409298"
target="_blank">Mozilla Bug 409298</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 403005 and 409298 **/
SimpleTest.waitForExplicitFinish();
function go()
{
ok(window instanceof Object, "window is instanceof Object");
let wrap = $('ifr').contentWindow.wrappedJSObject;
ok(!('obj' in XPCNativeWrapper(wrap)), "XPCNativeWrapper constructor works");
let iwin = $('ifr').contentWindow;
is(iwin.document.ELEMENT_NODE, 1, 'constants work through XrayWrapper');
is(iwin.document.nodeName, "#document", 'attributes work through XrayWrappe
location.foopy = 3;
var xow_answer = [];
for (let i in location)
xow_answer.push(i);
var xpcnw_answer = [];
var xpcnw = new XPCNativeWrapper(location);
xpcnw.barpy = 4;
for (let i in xpcnw)
xpcnw_answer.push(i);
var expected = [
"hash",
"host",
"hostname",
"href",
"pathname",
"port",
"protocol",
"search",
"reload",
"replace",
"assign",
"foopy"
];
var xpcnw_expected = expected.slice(0, expected.length - 1);
xpcnw_expected.push("barpy");
is(xow_answer.sort().toString(),
expected.sort().toString(),
'enumeration over XOWs walks the prototype chain');
is(xpcnw_answer.sort().toString(),
xpcnw_expected.sort().toString(),
'enumeration over XPCNWs walks the prototype chain');
var for_each_expected = [];
for each (let i in new XPCNativeWrapper(location))
for_each_expected.push(typeof i);
var for_each_answer = [];
for each (let i in Iterator(new XPCNativeWrapper(location)))
for_each_answer.push(typeof i);
is(for_each_answer.sort().toString(),
for_each_expected.sort().toString(),
'wrapper iterators are properly iterators');
let sjow_answer = [];
let (obj = { a: 3, next:1 }) {
for (let i in wrap.to_iterate)
sjow_answer.push(i);
is(sjow_answer.sort().toString(), ['a', 'next'].sort().toString(),
'enumeration over SJOWs walks the prototype chain');
}
sjow_answer = [];
for (let i in wrap.location)
sjow_answer.push(i);
is(sjow_answer.sort().toString(),
expected.sort().toString(),
'enumeration over SJOWs walks the prototype chain and works over XOWs');
for (let i in wrap.enumerate) {
is(typeof i, "string", "enumeration on wrappers only returns strings");
}
isnot(wrap, new XPCNativeWrapper(iwin),
'SJOWs equality hook returns false correctly against XPCNW');
is(typeof(wrap.func), 'function',
'SJOWs look like functions when they wrap functions');
is(typeof(wrap.o), 'object',
'SJOWs look like objects when they wrap objects');
ok(wrap.o === wrap.o,
"Identity holds when accessing the same object twice");
var origProto = iwin.__proto__;
try {
iwin.__proto__ = iwin;
ok(false, 'cyclic proto value allowed');
iwin.__proto__ = origProto;
} catch (e) {
is(e.toString(),
'TypeError: cyclic __proto__ value',
'throw the right exception for a cyclic proto');
is(iwin.__proto__, origProto, 'reset __proto__ after a cyclic proto');
}
try {
is('PASS', iwin.eval("'PASS'"), 'iwin.eval throws an exception');
} catch (e) {
ok(false, 'iwin.eval does not throw an exception');
}
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'");
}
// Some tests for SJOWs too.
isnot(wrap.document.body != document.body, "body should not be the same");
XPCNativeWrapper.prototype = {};
let (w = new XPCNativeWrapper(iwin)) {
ok(iwin.location, "able to set XPCNativeWrapper.prototype and do stuff with it");
}
is(new XPCNativeWrapper(iwin, Window).closed, false,
"able to wrap a window in a window XPCNativeWrapper");
try {
new XPCNativeWrapper(document, Window);
todo(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");
}
let (w = new XPCNativeWrapper($('ifr').contentWindow)) {
w.foopybar = 5;
ok(!("foopybar" in iwin), "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, iwin, "w.window exists and is the window");
ok(delete w.iwin, "can delete builtin properties");
is(w.window, iwin, "w.window is automatically recreated");
iwin.foopy = 5;
ok(delete w.foopy, "delete returns true");
is(iwin.foopy, 5, "delete doesn't delete underlying properties");
ok(delete iwin.foopy, "can delete window.foopy");
ok(!("foopy" in iwin), "foopy is no longer in window");
}
try {
is((function(x) { return x+1; }).apply(this, wrap.a), 2,
"able to call apply with an XPCSafeJSObjectWrapped array");
} catch (e) {
ok(false,
"Unable to call apply() with a XPCSafeJSObjectWrapped array");
}
try {
iwin.__proto__ = null;
is(iwin.__proto__, null,
"allowed to update iwin.__proto__ to null");
} catch (e) {
ok(false, "some crazy exception was thrown");
}
try {
new XPCSafeJSObjectWrapped(<x />).foo;
ok(false, "Allowed to wrap E4X in SJOWs?");
} catch (e) {
}
SimpleTest.finish();
}
]]></script>
<iframe type="content"
src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_wrappers-2.html"
onload="go()"
id="ifr">
</iframe>
</window>

View file

@ -0,0 +1,96 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=500931
-->
<window title="Mozilla Bug 500931"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=533596"
target="_blank">Mozilla Bug 533596</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 533596 **/
function go() {
var win = $('ifr').contentWindow;
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
is(utils.getClassName(window), "Proxy", "our window is wrapped correctly")
is(utils.getClassName(location), "Location", "chrome doesn't have location wrappers")
is(utils.getClassName(win), "Proxy", "win is an Proxy");
is(utils.getClassName(win.location), "Proxy", "deep wrapping works");
is(win.location.href, "http://example.org/tests/js/xpconnect/tests/mochitest/chrome_wrappers_helper.html",
"can still get strings out");
var unsafeWin = win.wrappedJSObject;
is(utils.getClassName(unsafeWin), "Proxy", "can get a Proxy");
is(utils.getClassName(unsafeWin.location), "Proxy", "deep wrapping works");
Object.defineProperty(unsafeWin, "defprop1", { value: 1, writable: true, enumerable: true, configurable: true });
/* TODO (bug 552854): the getter isn't visible in content.
function checkWrapper(val) {
ok(utils.getClassName(val) == "Proxy", "wrapped properly");
}
Object.defineProperty(unsafeWin, "defprop2", { set: checkWrapper, enumerable: true, configurable: true });
*/
unsafeWin.run_test(ok, win, unsafeWin);
win.setTimeout(function() {
is(utils.getClassName(this), "Proxy",
"this is wrapped correctly");
SimpleTest.finish();
}, 0)
var saw0 = false;
for (let i in $('ifr').contentDocument.getElementsByTagName('body')) {
if (i === "0")
saw0 = true;
}
ok(saw0, "properly enumerated the 0 value");
ok(win.XPathEvaluator.toString().indexOf("XPathEvaluator") >= 0,
"Can access content window.XPathEvaluator");
var nativeToString =
("" + String.replace).replace("replace", "EventTarget");
var eventTargetToString = "" + win.EventTarget;
ok(eventTargetToString.indexOf(nativeToString) > -1,
"Stringifying a DOM interface object should return the same string as " +
"stringifying a native function." + " " + eventTargetToString + " " + nativeToString);
is(win.XPathResult.NUMBER_TYPE, 1, "can access constants on constructors");
is(typeof win.IDBKeyRange.bound, "function", "can access crazy IDBKeyRange static functions");
// Test getter/setter lookup on Xray wrappers.
ok(Object.prototype.__lookupGetter__.call(win.document, 'title'), 'found getter on document');
ok(Object.prototype.__lookupGetter__.call(win.document, 'title'), 'found getter on document');
// Test QI on new dom bindings.
var contentXHR = XPCNativeWrapper(win.wrappedJSObject.xhr);
try {
var QIed = contentXHR.QueryInterface(Components.interfaces.nsIClassInfo);
ok(false, "Should throw for new binding objects not having classinfo");
} catch(e) {
ok(true, "Threw while QI-ing on wrapper");
}
}
SimpleTest.waitForExplicitFinish();
]]></script>
<iframe type="content"
src="http://example.org/tests/js/xpconnect/tests/mochitest/chrome_wrappers_helper.html"
onload="go()"
id="ifr">
</iframe>
</window>

Some files were not shown because too many files have changed in this diff Show more