gecko/js/xpconnect/tests/chrome/test_chrometoSource.xul
Benjamin Peterson ac41818e21 Bug 776430 - Use the rightmost URI to account for possible multiple prefixing. r=bz
--HG--
extra : rebase_source : 00d3a825d0743dc5ba61a0dbe69c6f8a75b4b208
2012-07-23 19:13:18 -07:00

51 lines
2.1 KiB
XML

<?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[
const Cu = Components.utils;
const Cc = Components.classes;
const 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");
]]></script>
</window>