blob: 51dfc0646ce5fca30764ebf1c04bed21726ffe14 [file] [log] [blame]
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/debugger-test.js"></script>
<script>
function keepAliveInInlineScript() { }
//@ sourceURL=inlineScriptURL.js
</script>
<script>
function doEval()
{
eval("function keepAlive() {}\n//@ sourceURL=evalURL.js");
}
function doEvalWithNonRelativeURL()
{
eval("function relativeURLScript() {}\n//@ sourceURL=/js/nonRelativeURL.js");
}
function doEvalWithHashSyntax()
{
eval("function hashSyntax() {}\n//# sourceURL=hashSyntax.js");
}
function doDynamicScript()
{
var scriptElement = document.createElement("script");
scriptElement.textContent = "function keepAliveInDynamicScript() {}\n//@ sourceURL=dynamicScriptURL.js";
document.body.appendChild(scriptElement);
}
function test()
{
function forEachScriptMatchingURL(url, handler)
{
var scripts = WebInspector.debuggerModel.scripts;
for (var i = 0; i < scripts.length; ++i) {
if (scripts[i].sourceURL.indexOf(url) !== -1)
handler(scripts[i]);
}
}
InspectorTest.runDebuggerTestSuite([
function testSourceURLCommentInInlineScript(next)
{
InspectorTest.showScriptSource("source-url-comment.html", didShowScriptSource);
function didShowScriptSource(sourceFrame)
{
function checkScriptDoesNotHaveSourceURL(script)
{
InspectorTest.assertTrue(!script.hasSourceURL, "hasSourceURL flag is set for inline script");
}
var panel = WebInspector.panel("scripts");
var uiSourceCodes = panel._workspace.uiSourceCodes();
for (var i = 0; i < uiSourceCodes.length; ++i)
InspectorTest.assertTrue(uiSourceCodes[i].originURL().indexOf("inlineScriptURL.js") === -1, "sourceURL comment in inline script was used as a script name");
forEachScriptMatchingURL("source-url-comment.html", checkScriptDoesNotHaveSourceURL)
next();
}
},
function testSourceURLComment(next)
{
InspectorTest.showScriptSource("evalURL.js", didShowScriptSource);
InspectorTest.evaluateInPage("setTimeout(doEval, 0)");
function didShowScriptSource(sourceFrame)
{
function checkScriptHasSourceURL(script)
{
InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for eval with sourceURL comment");
}
InspectorTest.addResult(sourceFrame.textEditor.text());
forEachScriptMatchingURL("evalURL.js", checkScriptHasSourceURL);
next();
}
},
function testSourceURLCommentInDynamicScript(next)
{
InspectorTest.showScriptSource("dynamicScriptURL.js", didShowScriptSource);
InspectorTest.evaluateInPage("setTimeout(doDynamicScript, 0)");
function didShowScriptSource(sourceFrame)
{
function checkScriptHasSourceURL(script)
{
InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for dynamic script with sourceURL comment");
}
InspectorTest.addResult(sourceFrame.textEditor.text());
forEachScriptMatchingURL("dynamicScriptURL.js", checkScriptHasSourceURL);
next();
}
},
function testNonRelativeURL(next)
{
InspectorTest.showScriptSource("/js/nonRelativeURL.js", didShowScriptSource);
InspectorTest.evaluateInPage("setTimeout(doEvalWithNonRelativeURL, 0)");
function didShowScriptSource(sourceFrame)
{
function checkScriptHasSourceURL(script)
{
InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for eval with a non-relative URL in a sourceURL comment");
}
InspectorTest.addResult(sourceFrame.textEditor.text());
forEachScriptMatchingURL("nonRelativeURL.js", checkScriptHasSourceURL);
next();
}
},
function testHashSyntax(next)
{
InspectorTest.showScriptSource("hashSyntax.js", didShowScriptSource);
InspectorTest.evaluateInPage("setTimeout(doEvalWithHashSyntax, 0)");
function didShowScriptSource(sourceFrame)
{
function checkScriptHasSourceURL(script)
{
InspectorTest.assertTrue(script.hasSourceURL, "hasSourceURL flag is not set for eval with a non-relative URL in a sourceURL comment");
}
InspectorTest.addResult(sourceFrame.textEditor.text());
forEachScriptMatchingURL("hashSyntax.js", checkScriptHasSourceURL);
next();
}
}
]);
};
</script>
</head>
<body onload="runTest()">
<p>Tests that evals with sourceURL comment are shown in scripts panel.</p>
</body>
</html>