Test for bug 638178 - new feature getExecutableLines (r=timeless)

--HG--
extra : rebase_source : d29194bf998a6dfcb2fadd5e2186d4d64396bd6f
This commit is contained in:
Steve Fink 2011-03-03 10:11:54 -08:00
parent 715faebf0e
commit 457647eddb
4 changed files with 144 additions and 1 deletions

View File

@ -1038,7 +1038,7 @@ interface jsdIScript : jsdIEphemeral
*/
void getExecutableLines(in unsigned long pcmap,
in unsigned long startLine, in unsigned long maxLines,
out unsigned long count,
[optional] out unsigned long count,
[array, size_is(count), retval] out unsigned long executableLines);
/**

View File

@ -49,6 +49,7 @@ include $(topsrcdir)/config/rules.mk
_TEST_FILES = test_bug507448.html bug507448.js \
test_bug617870-callhooks.html test-bug617870-callhooks.js jsd-test.js \
test_bug638178-execlines.html test-bug638178-execlines.js \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,95 @@
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var jsdIScript = Components.interfaces.jsdIScript;
function f1() {
var x;
}
function f2() {
var x; var y; x = 1;
}
function f3() {
var x;
var y; var y2; y = 1;
var z;
}
var jsdIFilter = Components.interfaces.jsdIFilter;
function testJSD(jsd) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
ok(jsd.isOn, "JSD needs to be running for this test.");
jsd.functionHook = ({
onCall: function(frame, type) {
//console.log("Got " + type);
console.log("Got " + frame.script.fileName);
}
});
console.log("Triggering functions");
f1();
f2();
f3();
console.log("Done with functions");
var linemap = {};
var firsts = {};
var rests = {};
var startlines = {};
jsd.enumerateScripts({
enumerateScript: function(script) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (/execlines\.js$/.test(script.fileName)) {
console.log("script: " + script.fileName + " " + script.functionName);
var execLines = script.getExecutableLines(jsdIScript.PCMAP_SOURCETEXT, 0, 10000);
console.log(execLines.toSource());
linemap[script.functionName] = execLines;
startlines[script.functionName] = script.baseLineNumber;
execLines = script.getExecutableLines(jsdIScript.PCMAP_SOURCETEXT, 0, 1);
firsts[script.functionName] = execLines;
execLines = script.getExecutableLines(jsdIScript.PCMAP_SOURCETEXT, execLines[0]+1, 10000);
rests[script.functionName] = execLines;
}
}
});
var checklines = function (funcname, linemap, rellines) {
var base = startlines[funcname];
var b = [];
for (var i = 0; i < rellines.length; ++i) {
b[i] = rellines[i] + base;
}
is(linemap[funcname].toSource(), b.toSource(), funcname + " lines");
};
checklines('f1', linemap, [ 1 ]);
checklines('f2', linemap, [ 3 ]);
checklines('f3', linemap, [ 3, 5, 6 ]);
checklines('f1', firsts, [ 1 ]);
checklines('f1', rests, []);
checklines('f3', firsts, [ 3 ]);
checklines('f3', rests, [ 5, 6 ]);
jsd.functionHook = null;
if (!jsdOnAtStart) {
// turn JSD off if it wasn't on when this test started
jsd.off();
ok(!jsd.isOn, "JSD shouldn't be running at the end of this test.");
}
SimpleTest.finish();
}
testJSD(jsd);

View File

@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html>
<head>
<!-- The bug number is pulled from the test URL -->
<title>JSD Test for Bug AUTOFILLED</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="jsd-test.js"></script>
<script type="application/javascript">
var BUG = 638178;
var TEST_SCRIPT = "test-bug638178-execlines.js";
document.getElementsByTagName("title")[0].innerHTML = "JSD Test for Bug " + BUG;
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
SimpleTest.waitForExplicitFinish();
function runTest() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
console.log("start of runTest, loading script");
loadScript(TEST_SCRIPT, document.getElementById("test"));
console.log("end of runTest");
}
function setupTest() {
var buglink = document.getElementById("buglink");
buglink.href = "https://bugzilla.mozilla.org/show_bug.cgi?id=" + BUG;
buglink.innerHTML = "Mozilla Bug " + BUG;
}
</script>
</head>
<body onLoad='setupTest(); setupJSD();'>
<a id="buglink" target="_blank"></a>
<p id="display"></p>
<div id="content" style="display: none">
<pre id='test'>
</pre>
</div>
<div id='test-output'>
</div>
</body>
</html>