tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_chrometoSource.xhtml (2583B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
      4                 type="text/css"?>
      5 <window title="Mozilla Bug 761723"
      6  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
      7  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      8 
      9  <!-- test results are displayed in the html:body -->
     10  <body xmlns="http://www.w3.org/1999/xhtml">
     11  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=761723" target="_blank">Mozilla Bug 761723</a>
     12  </body>
     13 
     14  <!-- test code goes here -->
     15  <script type="application/javascript" src="outoflinexulscript.js"></script>
     16  <script type="application/javascript"><![CDATA[
     17 const {NetUtil} = ChromeUtils.importESModule(
     18  "resource://gre/modules/NetUtil.sys.mjs"
     19 );
     20 let base = /.*\//.exec(window.location.href)[0];
     21 const {checkFromESM} = ChromeUtils.importESModule(base + "file_expandosharing.sys.mjs");
     22 
     23 function inlinefunction() {
     24         return 42;
     25 }
     26 
     27 var src;
     28 src = inlinefunction.toSource();
     29 isnot(src.indexOf("return 42"), -1, "inline XUL script should have source");
     30 is(src.charAt(src.length - 1), "}", "inline XUL source should end with '}'");
     31 src = outoflinefunction.toSource();
     32 isnot(src.indexOf("return 42"), -1, "out of line XUL script should have source")
     33 is(src.charAt(src.length - 1), "}", "out of line XUL source should end with '}'");
     34 src = checkFromESM.toSource();
     35 isnot(src.indexOf("catch"), -1, "ESM should have source");
     36 var ns = {};
     37 Services.scriptloader.loadSubScript(base + "file_expandosharing.js", ns);
     38 src = ns.checkFromESM.toSource();
     39 isnot(src.indexOf("catch"), -1, "subscript should have source");
     40 
     41 var reg = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
     42 var resolvedBase = reg.convertChromeURL(NetUtil.newURI(base)).spec;
     43 
     44 ns = {
     45  base,
     46 };
     47 Services.scriptloader.loadSubScript(resolvedBase + "subscript.js", ns);
     48 src = ns.checkFromESM.toSource();
     49 isnot(src.indexOf("catch"), -1, "subscript of a subscript should have source");
     50 
     51 ns = {};
     52 Services.scriptloader.loadSubScript(resolvedBase + "utf8_subscript.js", ns);
     53 src = ns.f.toSource();
     54 isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source");
     55 
     56 ns = {};
     57 Services.scriptloader.loadSubScriptWithOptions(resolvedBase + "utf8_subscript.js",
     58                                               {target: ns, ignoreCache: true});
     59 src = ns.f.toSource();
     60 isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source");
     61  ]]></script>
     62 </window>