blob: c4c81616d8b009da1ba18e018e7cc8805df83f52 [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
// SEARCHTEST: Comment in inline <script>.
function performEvals()
{
// Find the line with the search term.
eval("// SEARCH" + "TEST: Eval 1\n//# sourceURL=eval1.js");
// If the search term shows up multiple times on a single line, the line is returned once.
eval("var SEARCH" + "TEST = \"SEARCH" + "TEST\";\n//# sourceURL=eval2.js");
};
function test()
{
function sanitizeScriptURL(url) {
return url.substring(url.indexOf("LayoutTests"));
}
function chomp(line) {
return line.replace(/\n$/, "");
}
var scriptsCount = 0;
const expectedScriptsCount = 5;
WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ScriptAdded, function(event) {
var script = event.data.script;
if (!/LayoutTests/.test(script.url) && !/eval\d\.js/.test(script.sourceURL))
return;
DebuggerAgent.searchInContent(script.id, "SEARCHTEST", false, false, function(error, results) {
InspectorTest.log("");
InspectorTest.log("SCRIPT: " + sanitizeScriptURL(script.sourceURL || script.url));
InspectorTest.log("RESULTS: " + results.length);
for (var result of results) {
InspectorTest.log(" LINE: " + result.lineNumber);
InspectorTest.log(" CONTENT: " + chomp(result.lineContent));
}
if (++scriptsCount === expectedScriptsCount)
InspectorTest.completeTest();
});
});
InspectorTest.addEventListener(FrontendTestHarness.Event.TestPageDidLoad, () => {
InspectorTest.evaluateInPage("performEvals()");
});
InspectorTest.reloadPage();
}
</script>
</head>
<body onload="runTest(); // SEARCHTEST: onload attribute string">
<p>Test <code>DebuggerAgent.searchInContent</code> to search script content.</p>
</body>
</html>