js/xpconnect/tests/chrome/test_chrometoSource.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/chrome/test_chrometoSource.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
     1.7 +                 type="text/css"?>
     1.8 +<window title="Mozilla Bug 761723"
     1.9 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.10 +  <script type="application/javascript"
    1.11 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +
    1.13 +  <!-- test results are displayed in the html:body -->
    1.14 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.15 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=761723" target="_blank">Mozilla Bug 761723</a>
    1.16 +  </body>
    1.17 +
    1.18 +  <!-- test code goes here -->
    1.19 +  <script type="application/javascript" src="outoflinexulscript.js"></script>
    1.20 +  <script type="application/javascript"><![CDATA[
    1.21 +const Cu = Components.utils;
    1.22 +const Cc = Components.classes;
    1.23 +const Ci = Components.interfaces;
    1.24 +Cu.import("resource://gre/modules/NetUtil.jsm");
    1.25 +Cu.import("resource://gre/modules/Services.jsm");
    1.26 +
    1.27 +function inlinefunction() {
    1.28 +         return 42;
    1.29 +}
    1.30 +
    1.31 +// 1 assertion in debug builds because bug 821726 added the ignoreCache switch and
    1.32 +// we now write to the cache more than once for the same entry
    1.33 +SimpleTest.expectAssertions(1);
    1.34 +
    1.35 +var src;
    1.36 +src = inlinefunction.toSource();
    1.37 +isnot(src.indexOf("return 42"), -1, "inline XUL script should have source");
    1.38 +is(src.charAt(src.length - 1), "}", "inline XUL source should end with '}'");
    1.39 +src = outoflinefunction.toSource();
    1.40 +isnot(src.indexOf("return 42"), -1, "out of line XUL script should have source")
    1.41 +is(src.charAt(src.length - 1), "}", "out of line XUL source should end with '}'");
    1.42 +src = NetUtil.asyncFetch.toSource();
    1.43 +isnot(src.indexOf("return"), -1, "JSM should have source");
    1.44 +var ns = {};
    1.45 +Services.scriptloader.loadSubScript("resource://gre/modules/NetUtil.jsm", ns);
    1.46 +src = ns.NetUtil.asyncFetch.toSource();
    1.47 +isnot(src.indexOf("return"), -1, "subscript should have source");
    1.48 +
    1.49 +var base = /.*\//.exec(window.location.href)[0];
    1.50 +var reg = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
    1.51 +var resolvedBase = reg.convertChromeURL(NetUtil.newURI(base)).spec;
    1.52 +
    1.53 +ns = {};
    1.54 +Services.scriptloader.loadSubScript(resolvedBase + "subscript.js", ns);
    1.55 +src = ns.NetUtil.asyncFetch.toSource();
    1.56 +isnot(src.indexOf("return"), -1, "subscript of a subscript should have source");
    1.57 +
    1.58 +ns = {};
    1.59 +Services.scriptloader.loadSubScript(resolvedBase + "utf8_subscript.js", ns, "UTF-8");
    1.60 +src = ns.f.toSource();
    1.61 +isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source");
    1.62 +
    1.63 +ns = {};
    1.64 +Services.scriptloader.loadSubScriptWithOptions(resolvedBase + "utf8_subscript.js",
    1.65 +                                               {target: ns, charset: "UTF-8", ignoreCache: true});
    1.66 +src = ns.f.toSource();
    1.67 +isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source");
    1.68 +  ]]></script>
    1.69 +</window>

mercurial