blob: e4c35bb3e55970298f478f7f97f8ee11a8059e34 [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// OTHER" + "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\";\nvar OTHER" + "TEST = \"OTHER" + "TEST\";\n//# sourceURL=eval2.js");
};
function test()
{
function chomp(line) {
return line.replace(/\n$/, "");
}
function searchInContent(script, query, options = {}) {
return DebuggerAgent.searchInContent(script.id, query, options.caseSensitive, options.isRegex)
.then(({result}) => {
InspectorTest.log("");
InspectorTest.log("QUERY: " + query + " " + JSON.stringify(options));
InspectorTest.log("SCRIPT: " + sanitizeURL(script.sourceURL || script.url));
InspectorTest.log("RESULTS: " + result.length);
for (let item of result) {
InspectorTest.log(" LINE: " + item.lineNumber);
InspectorTest.log(" CONTENT: " + chomp(item.lineContent));
}
});
}
let scripts = new Map;
WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ScriptAdded, function(event) {
let {script} = event.data;
let url = script.sourceURL || script.url;
if (!/LayoutTests/.test(url) && !/eval\d\.js/.test(url))
return;
if (url.endsWith("inspector-test.js"))
return;
InspectorTest.log("Script added: " + sanitizeURL(url));
scripts.set(url, script);
if (url === "eval2.js") {
let promiseCallbacks = [];
for (let item of scripts.values()) {
for (let query of ["search" + "test", "SEARCH" + "test", "(search|OTHER)" + "TEST"]) {
promiseCallbacks.push(() => searchInContent(item, query));
promiseCallbacks.push(() => searchInContent(item, query, {caseSensitive: true}));
promiseCallbacks.push(() => searchInContent(item, query, {isRegex: true}));
promiseCallbacks.push(() => searchInContent(item, query, {caseSensitive: true, isRegex: true}));
}
}
Promise.chain(promiseCallbacks).then(() => {
InspectorTest.completeTest();
});
}
});
InspectorTest.addEventListener(FrontendTestHarness.Event.TestPageDidLoad, () => {
InspectorTest.evaluateInPage("performEvals()");
});
InspectorTest.reloadPage();
}
</script>
</head>
<body onload="runTest(); // SEARCHTEST: onload attribute string // OTHERTEST: onload attribute string">
<p>Test <code>DebuggerAgent.searchInContent</code> to search script content.</p>
</body>
</html>