test_chrometoSource.xul 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 type="application/javascript"
  8. src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  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. <!-- test code goes here -->
  14. <script type="application/javascript" src="outoflinexulscript.js"></script>
  15. <script type="application/javascript"><![CDATA[
  16. var Cu = Components.utils;
  17. var Cc = Components.classes;
  18. var Ci = Components.interfaces;
  19. Cu.import("resource://gre/modules/NetUtil.jsm");
  20. Cu.import("resource://gre/modules/Services.jsm");
  21. function inlinefunction() {
  22. return 42;
  23. }
  24. var src;
  25. src = inlinefunction.toSource();
  26. isnot(src.indexOf("return 42"), -1, "inline XUL script should have source");
  27. is(src.charAt(src.length - 1), "}", "inline XUL source should end with '}'");
  28. src = outoflinefunction.toSource();
  29. isnot(src.indexOf("return 42"), -1, "out of line XUL script should have source")
  30. is(src.charAt(src.length - 1), "}", "out of line XUL source should end with '}'");
  31. src = NetUtil.asyncFetch.toSource();
  32. isnot(src.indexOf("return"), -1, "JSM should have source");
  33. var ns = {};
  34. Services.scriptloader.loadSubScript("resource://gre/modules/NetUtil.jsm", ns);
  35. src = ns.NetUtil.asyncFetch.toSource();
  36. isnot(src.indexOf("return"), -1, "subscript should have source");
  37. var base = /.*\//.exec(window.location.href)[0];
  38. var reg = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
  39. var resolvedBase = reg.convertChromeURL(NetUtil.newURI(base)).spec;
  40. ns = {};
  41. Services.scriptloader.loadSubScript(resolvedBase + "subscript.js", ns);
  42. src = ns.NetUtil.asyncFetch.toSource();
  43. isnot(src.indexOf("return"), -1, "subscript of a subscript should have source");
  44. ns = {};
  45. Services.scriptloader.loadSubScript(resolvedBase + "utf8_subscript.js", ns, "UTF-8");
  46. src = ns.f.toSource();
  47. isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source");
  48. ns = {};
  49. Services.scriptloader.loadSubScriptWithOptions(resolvedBase + "utf8_subscript.js",
  50. {target: ns, charset: "UTF-8", ignoreCache: true});
  51. src = ns.f.toSource();
  52. isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source");
  53. ]]></script>
  54. </window>