|
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 |
|
10 <!-- test results are displayed in the html:body --> |
|
11 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
12 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=761723" target="_blank">Mozilla Bug 761723</a> |
|
13 </body> |
|
14 |
|
15 <!-- test code goes here --> |
|
16 <script type="application/javascript" src="outoflinexulscript.js"></script> |
|
17 <script type="application/javascript"><![CDATA[ |
|
18 const Cu = Components.utils; |
|
19 const Cc = Components.classes; |
|
20 const Ci = Components.interfaces; |
|
21 Cu.import("resource://gre/modules/NetUtil.jsm"); |
|
22 Cu.import("resource://gre/modules/Services.jsm"); |
|
23 |
|
24 function inlinefunction() { |
|
25 return 42; |
|
26 } |
|
27 |
|
28 // 1 assertion in debug builds because bug 821726 added the ignoreCache switch and |
|
29 // we now write to the cache more than once for the same entry |
|
30 SimpleTest.expectAssertions(1); |
|
31 |
|
32 var src; |
|
33 src = inlinefunction.toSource(); |
|
34 isnot(src.indexOf("return 42"), -1, "inline XUL script should have source"); |
|
35 is(src.charAt(src.length - 1), "}", "inline XUL source should end with '}'"); |
|
36 src = outoflinefunction.toSource(); |
|
37 isnot(src.indexOf("return 42"), -1, "out of line XUL script should have source") |
|
38 is(src.charAt(src.length - 1), "}", "out of line XUL source should end with '}'"); |
|
39 src = NetUtil.asyncFetch.toSource(); |
|
40 isnot(src.indexOf("return"), -1, "JSM should have source"); |
|
41 var ns = {}; |
|
42 Services.scriptloader.loadSubScript("resource://gre/modules/NetUtil.jsm", ns); |
|
43 src = ns.NetUtil.asyncFetch.toSource(); |
|
44 isnot(src.indexOf("return"), -1, "subscript should have source"); |
|
45 |
|
46 var base = /.*\//.exec(window.location.href)[0]; |
|
47 var reg = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry); |
|
48 var resolvedBase = reg.convertChromeURL(NetUtil.newURI(base)).spec; |
|
49 |
|
50 ns = {}; |
|
51 Services.scriptloader.loadSubScript(resolvedBase + "subscript.js", ns); |
|
52 src = ns.NetUtil.asyncFetch.toSource(); |
|
53 isnot(src.indexOf("return"), -1, "subscript of a subscript should have source"); |
|
54 |
|
55 ns = {}; |
|
56 Services.scriptloader.loadSubScript(resolvedBase + "utf8_subscript.js", ns, "UTF-8"); |
|
57 src = ns.f.toSource(); |
|
58 isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source"); |
|
59 |
|
60 ns = {}; |
|
61 Services.scriptloader.loadSubScriptWithOptions(resolvedBase + "utf8_subscript.js", |
|
62 {target: ns, charset: "UTF-8", ignoreCache: true}); |
|
63 src = ns.f.toSource(); |
|
64 isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source"); |
|
65 ]]></script> |
|
66 </window> |