Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / jsd / test / test_bug507448.html
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=507448
5 -->
6 <head>
7   <title>Test for Bug 507448</title>
8   <script type="application/javascript" src="/MochiKit/packed.js"></script>
9   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=507448">Mozilla Bug 507448</a>
14 <p id="display"></p>
15 <div id="content" style="display: none">
16   
17 </div>
18 <pre id="test">
19 <script type="application/javascript">
20 function f() {}
21 function g(a,b) {}
22 function h(me, too, here) { var x = 1; }
23 function annoying(a, b, a, b, b, a) {}
24 function manyLocals(a, b, c, d, e, f, g, h, i, j, k, l, m) {
25   var n, o, p, q, r, s, t, u, v, w, x, y, z;
26 }
27 </script>
28 <script type="application/javascript">
29
30 SimpleTest.waitForExplicitFinish();
31
32 function loadScript(url) {
33     var d = new MochiKit.Async.Deferred();
34     var head = document.getElementsByTagName("head")[0];
35     var script = MochiKit.DOM.createDOM("script", { type: "text/javascript", src: url });
36     script.onload = function() {
37         script.onload = null;
38         script.onerror = null;
39         script.onreadystatechange = null;
40         d.callback();
41     };
42     script.onerror = function(msg) {
43         script.onload = null;
44         script.onerror = null;
45         script.onreadystatechange = null;
46         msg = "Failed to load script at " + url + ": " + msg;
47         d.errback(new URIError(msg, url));
48     }
49     script.onreadystatechange = function() {
50         if (script.readyState == "loaded" || script.readyState == "complete") {
51             script.onload();
52         } else {
53             // IE doesn't bother to report errors...
54             MochiKit.Async.callLater(10, script.onerror, "Script loading timed out")
55         }
56     };
57     head.appendChild(script);
58     return d;
59 }
60
61 /** Test for Bug 507448 **/
62 function assertArraysEqual(arr1, arr2) {
63   is(arr1.length, arr2.length, "Lengths not equal");
64   for (var i = 0 ; i < arr1.length; ++i) {
65     is(arr1[i], arr2[i], "Element " + i + " not equal");
66   }
67 }
68
69 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
70 var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
71 var jsd = Components.classes['@mozilla.org/js/jsd/debugger-service;1']
72                     .getService(jsdIDebuggerService);
73 var jsdOnAtStart = false;
74
75 function setupJSD() {
76   // This is somewhat unfortunate: jsd only deals with scripts that have a
77   // nonzero line number, so we can't just createElement a script here.
78   // So break the test up into three <script>s, of which the middle one has our test functions.
79
80   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
81
82   jsdOnAtStart = jsd.isOn;
83   if (jsdOnAtStart) {
84     testJSD();
85   } else {
86     jsd.asyncOn(
87       {
88         onDebuggerActivated: function() {
89             testJSD();
90         }
91       }  
92     );
93   }
94 }
95
96 addLoadEvent(setupJSD);
97
98 </script>
99 <script>
100 function testJSD() {
101   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
102
103   ok(jsd.isOn, "JSD needs to be running for this test.");
104
105   var deferred = loadScript("bug507448.js");
106 }
107 </script>
108 </pre>
109 </body>
110 </html>