Commit 0f5457c6 authored by vsevik@chromium.org's avatar vsevik@chromium.org

Web Inspector: Add support for backend search in script content.

https://bugs.webkit.org/show_bug.cgi?id=69015

Reviewed by Pavel Feldman.

Source/WebCore:

Tests: http/tests/inspector/search/search-in-concatenated-script.html
       http/tests/inspector/search/search-in-script.html

* inspector/Inspector.json:
* inspector/InspectorDebuggerAgent.cpp:
(WebCore::InspectorDebuggerAgent::searchInContent):
(WebCore::InspectorDebuggerAgent::getScriptSource):
* inspector/InspectorDebuggerAgent.h:
* inspector/front-end/ContentProviders.js:
(WebInspector.ScriptContentProvider.prototype.requestContent):
(WebInspector.ScriptContentProvider.prototype.searchInContent):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.maybeCallback):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.searchCallback):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent):
* inspector/front-end/Script.js:
(WebInspector.Script.prototype.requestSource):
(WebInspector.Script.prototype.searchInContent):

LayoutTests:

* http/tests/inspector/resource-tree/resource-tree-test.js:
(initialize_ResourceTreeTest):
* http/tests/inspector/resources-test.js:
(initialize_ResourceTest.InspectorTest.runAfterResourcesAreFinished):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.maybeCallback):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.addSniffer):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.resourceAddedToFrame):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.visit):
(initialize_ResourceTest):
* http/tests/inspector/search/resources/search-concatenated.html: Added.
* http/tests/inspector/search/search-in-concatenated-script-expected.txt: Added.
* http/tests/inspector/search/search-in-concatenated-script.html: Added.
* http/tests/inspector/search/search-in-resource.html:
* http/tests/inspector/search/search-in-script-expected.txt: Added.
* http/tests/inspector/search/search-in-script.html: Added.
* http/tests/inspector/search/search-test.js:
(initialize_SearchTest):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96491 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8b7f04f3
2011-10-03 Vsevolod Vlasov <vsevik@chromium.org>
Web Inspector: Add support for backend search in script content.
https://bugs.webkit.org/show_bug.cgi?id=69015
Reviewed by Pavel Feldman.
* http/tests/inspector/resource-tree/resource-tree-test.js:
(initialize_ResourceTreeTest):
* http/tests/inspector/resources-test.js:
(initialize_ResourceTest.InspectorTest.runAfterResourcesAreFinished):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.maybeCallback):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.addSniffer):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.resourceAddedToFrame):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.visit):
(initialize_ResourceTest):
* http/tests/inspector/search/resources/search-concatenated.html: Added.
* http/tests/inspector/search/search-in-concatenated-script-expected.txt: Added.
* http/tests/inspector/search/search-in-concatenated-script.html: Added.
* http/tests/inspector/search/search-in-resource.html:
* http/tests/inspector/search/search-in-script-expected.txt: Added.
* http/tests/inspector/search/search-in-script.html: Added.
* http/tests/inspector/search/search-test.js:
(initialize_SearchTest):
2011-10-03 Kristóf Kosztyó <kkristof@inf.u-szeged.hu>
Unreviewed Qt gardening after r96404
......@@ -86,32 +86,4 @@ InspectorTest.dumpResourceTreeEverything = function()
InspectorTest.dumpResourcesTree();
}
InspectorTest.runAfterResourcesAreFinished = function(resourceURLs, callback)
{
InspectorTest._runAfterResourcesAreFinished(resourceURLs.keySet(), callback);
}
InspectorTest._runAfterResourcesAreFinished = function(resourceURLs, callback)
{
function visit(resource)
{
if (!resource.finished)
return true;
for (var url in resourceURLs) {
if (resource.url.indexOf(url) !== -1)
delete resourceURLs[url];
}
if (!Object.keys(resourceURLs).length) {
callback();
return true;
}
}
var succeeded = WebInspector.resourceTreeModel.forAllResources(visit);
if (!succeeded)
setTimeout(InspectorTest._runAfterResourcesAreFinished.bind(InspectorTest, resourceURLs, callback), 0);
}
};
......@@ -27,4 +27,50 @@ InspectorTest.resourceURLComparer = function(r1, r2)
return r1.request.url.localeCompare(r2.request.url);
}
InspectorTest.runAfterResourcesAreFinished = function(resourceURLs, callback)
{
InspectorTest._runAfterResourcesAreFinished(resourceURLs.keySet(), callback);
}
InspectorTest._runAfterResourcesAreFinished = function(resourceURLs, callback)
{
function checkResource(resource)
{
for (var url in resourceURLs) {
if (resource.url.indexOf(url) !== -1)
delete resourceURLs[url];
}
}
function maybeCallback()
{
if (!Object.keys(resourceURLs).length) {
callback();
return true;
}
}
function addSniffer(resource)
{
InspectorTest.addSniffer(WebInspector.ResourceTreeModel.prototype, "_addResourceToFrame", resourceAddedToFrame.bind(this));
}
function resourceAddedToFrame(resource)
{
checkResource(resource);
if (!maybeCallback())
addSniffer();
}
function visit(resource)
{
checkResource(resource);
return maybeCallback();
}
var succeeded = WebInspector.resourceTreeModel.forAllResources(visit);
if (!succeeded)
addSniffer();
}
}
<html>
<head>
<script>
function searchTestUniqueString()
{
var variable = 0;
// searchTestUniqueString two occurences on the same line searchTestUniqueString
var variable2 = 0;
}
</script><script>
function doSomething()
{
searchTestUniqueString();
// SEARCHTestUniqueString();
}
</script>
<link href="search.css" rel="stylesheet" type="text/css">
<script>
function searchTestUniqueString2()
{
var variable = 0;
/* searchTestUniqueString two occurences on the same line searchTestUniqueString */ } </script><script> function doSomething2() { searchTestUniqueString();
// SEARCHTestUniqueString();
}
</script>
</script>
<body>
</body>
</html>
Tests concatenated script search in inspector debugger agent.
Bug 69015
http://127.0.0.1:8000/inspector/search/resources/search-concatenated.html
Search matches:
lineNumber: 3, line: 'function searchTestUniqueString()'
lineNumber: 6, line: ' // searchTestUniqueString two occurences on the same line searchTestUniqueString'
lineNumber: 12, line: ' searchTestUniqueString();'
lineNumber: 13, line: ' // SEARCHTestUniqueString();'
lineNumber: 18, line: 'function searchTestUniqueString2()'
lineNumber: 21, line: ' /* searchTestUniqueString two occurences on the same line searchTestUniqueString */ } '
lineNumber: 21, line: ' function doSomething2() { searchTestUniqueString();'
lineNumber: 22, line: ' // SEARCHTestUniqueString();'
<html>
<head>
<script src="../inspector-test.js"></script>
<script src="../resources-test.js"></script>
<script src="search-test.js"></script>
<script>
function test()
{
// This file should not match search query.
var text = "searchTest" + "UniqueString";
InspectorTest.runAfterResourcesAreFinished(["search-concatenated.html"], step2);
function step2()
{
var url = "http://127.0.0.1:8000/inspector/search/resources/search-concatenated.html";
var scripts = WebInspector.debuggerModel.scriptsForURL(url);
var contentProvider = new WebInspector.ConcatenatedScriptsContentProvider(scripts);
InspectorTest.addResult(url);
contentProvider.searchInContent(text, step3);
}
function step3(searchMatches)
{
InspectorTest.dumpSearchMatches(searchMatches);
InspectorTest.completeTest();
}
}
</script>
</head>
<body>
<p>Tests concatenated script search in inspector debugger agent.</p>
<a href="https://bugs.webkit.org/show_bug.cgi?id=69015">Bug 69015</a>
<iframe src="resources/search-concatenated.html" onload="runTest()">
</body>
</html>
<html>
<head>
<script src="../inspector-test.js"></script>
<script src="../resources-test.js"></script>
<script src="search-test.js"></script>
<script>
function test()
{
// This file should not match search query.
var text = "searchTest" + "UniqueString";
InspectorTest.runAfterResourcesAreCreated(["search.js"], step2);
InspectorTest.runAfterResourcesAreFinished(["search.js"], step2);
function step2()
{
......
Tests script search in inspector debugger agent.
Bug 69015
http://127.0.0.1:8000/inspector/search/resources/search.js
Search matches:
lineNumber: 0, line: 'function searchTestUniqueString()'
lineNumber: 3, line: ' // searchTestUniqueString two occurences on the same line searchTestUniqueString'
lineNumber: 9, line: ' searchTestUniqueString();'
lineNumber: 10, line: ' // SEARCHTestUniqueString();'
<html>
<head>
<script src="../inspector-test.js"></script>
<script src="../resources-test.js"></script>
<script src="search-test.js"></script>
<script>
function test()
{
// This file should not match search query.
var text = "searchTest" + "UniqueString";
InspectorTest.runAfterResourcesAreFinished(["search.js"], step2);
function step2()
{
var scripts = WebInspector.debuggerModel.scriptsForURL("http://127.0.0.1:8000/inspector/search/resources/search.js");
var script = scripts[0];
InspectorTest.addResult(script.sourceURL);
script.searchInContent(text, step3);
}
function step3(searchMatches)
{
InspectorTest.dumpSearchMatches(searchMatches);
InspectorTest.completeTest();
}
}
</script>
</head>
<body>
<p>Tests script search in inspector debugger agent.</p>
<a href="https://bugs.webkit.org/show_bug.cgi?id=69015">Bug 69015</a>
<iframe src="resources/search.html" onload="runTest()">
</body>
</html>
......@@ -16,50 +16,4 @@ InspectorTest.dumpSearchMatches = function(searchMatches)
InspectorTest.addResult("");
};
InspectorTest.runAfterResourcesAreCreated = function(resourceURLs, callback)
{
InspectorTest._runAfterResourcesAreCreated(resourceURLs.keySet(), callback);
}
InspectorTest._runAfterResourcesAreCreated = function(resourceURLs, callback)
{
function checkResource(resource)
{
for (var url in resourceURLs) {
if (resource.url.indexOf(url) !== -1)
delete resourceURLs[url];
}
}
function maybeCallback()
{
if (!Object.keys(resourceURLs).length) {
callback();
return true;
}
}
function addSniffer(resource)
{
InspectorTest.addSniffer(WebInspector.ResourceTreeModel.prototype, "_bindResourceURL", onResourceBind.bind(this));
}
function onResourceBind(resource)
{
checkResource(resource);
if (!maybeCallback())
addSniffer();
}
function visit(resource)
{
checkResource(resource);
return maybeCallback();
}
var succeeded = WebInspector.resourceTreeModel.forAllResources(visit);
if (!succeeded)
addSniffer();
}
};
2011-10-03 Vsevolod Vlasov <vsevik@chromium.org>
Web Inspector: Add support for backend search in script content.
https://bugs.webkit.org/show_bug.cgi?id=69015
Reviewed by Pavel Feldman.
Tests: http/tests/inspector/search/search-in-concatenated-script.html
http/tests/inspector/search/search-in-script.html
* inspector/Inspector.json:
* inspector/InspectorDebuggerAgent.cpp:
(WebCore::InspectorDebuggerAgent::searchInContent):
(WebCore::InspectorDebuggerAgent::getScriptSource):
* inspector/InspectorDebuggerAgent.h:
* inspector/front-end/ContentProviders.js:
(WebInspector.ScriptContentProvider.prototype.requestContent):
(WebInspector.ScriptContentProvider.prototype.searchInContent):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.maybeCallback):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.searchCallback):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent):
* inspector/front-end/Script.js:
(WebInspector.Script.prototype.requestSource):
(WebInspector.Script.prototype.searchInContent):
2011-10-03 Pavel Feldman <pfeldman@google.com>
Web Inspector: move console message formatting from ConsoleView.js into ConsoleMessage.js
......@@ -1741,6 +1741,17 @@
"name": "resume",
"description": "Resumes JavaScript execution."
},
{
"name": "searchInContent",
"parameters": [
{ "name": "scriptId", "$ref": "ScriptId", "description": "Id of the script to search in." },
{ "name": "query", "type": "string", "description": "String to search for." }
],
"returns": [
{ "name": "result", "type": "array", "items": { "$ref": "Page.SearchMatch" }, "description": "List of search matches." }
],
"description": "Searches for given string in script content."
},
{
"name": "setScriptSource",
"parameters": [
......
......@@ -31,6 +31,7 @@
#include "InspectorDebuggerAgent.h"
#if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
#include "ContentSearchUtils.h"
#include "InjectedScript.h"
#include "InjectedScriptManager.h"
#include "InspectorFrontend.h"
......@@ -320,6 +321,15 @@ static PassRefPtr<InspectorObject> scriptToInspectorObject(ScriptObject scriptOb
return value->asObject();
}
void InspectorDebuggerAgent::searchInContent(ErrorString* error, const String& scriptId, const String& query, RefPtr<InspectorArray>* results)
{
ScriptsMap::iterator it = m_scripts.find(scriptId);
if (it != m_scripts.end())
*results = ContentSearchUtils::searchInTextByLines(query, it->second.source);
else
*error = "No script for id: " + scriptId;
}
void InspectorDebuggerAgent::setScriptSource(ErrorString* error, const String& scriptId, const String& newContent, const bool* const preview, RefPtr<InspectorArray>* newCallFrames, RefPtr<InspectorObject>* result)
{
bool previewOnly = preview && *preview;
......@@ -332,9 +342,13 @@ void InspectorDebuggerAgent::setScriptSource(ErrorString* error, const String& s
*result = object;
}
void InspectorDebuggerAgent::getScriptSource(ErrorString*, const String& scriptId, String* scriptSource)
void InspectorDebuggerAgent::getScriptSource(ErrorString* error, const String& scriptId, String* scriptSource)
{
*scriptSource = m_scripts.get(scriptId).source;
ScriptsMap::iterator it = m_scripts.find(scriptId);
if (it != m_scripts.end())
*scriptSource = it->second.source;
else
*error = "No script for id: " + scriptId;
}
void InspectorDebuggerAgent::schedulePauseOnNextStatement(const String& breakReason, PassRefPtr<InspectorObject> data)
......
......@@ -81,6 +81,7 @@ public:
void removeBreakpoint(ErrorString*, const String& breakpointId);
void continueToLocation(ErrorString*, PassRefPtr<InspectorObject> location);
void searchInContent(ErrorString*, const String& scriptId, const String& query, RefPtr<InspectorArray>*);
void setScriptSource(ErrorString*, const String& scriptId, const String& newContent, const bool* const preview, RefPtr<InspectorArray>* newCallFrames, RefPtr<InspectorObject>* result);
void getScriptSource(ErrorString*, const String& scriptId, String* scriptSource);
void schedulePauseOnNextStatement(const String& breakReason, PassRefPtr<InspectorObject> data);
......
......@@ -46,6 +46,11 @@ WebInspector.ScriptContentProvider.prototype = {
callback(this._mimeType, source);
}
this._script.requestSource(didRequestSource.bind(this));
},
searchInContent: function(query, callback)
{
this._script.searchInContent(query, callback);
}
}
......@@ -77,6 +82,39 @@ WebInspector.ConcatenatedScriptsContentProvider.prototype = {
scripts[i].requestSource(didRequestSource.bind(this));
},
searchInContent: function(query, callback)
{
var results = {};
var scriptsLeft = this._scripts.length;
function maybeCallback()
{
if (!scriptsLeft) {
var result = [];
for (var i = 0; i < this._scripts.length; ++i)
result = result.concat(results[this._scripts[i].scriptId]);
callback(result);
}
}
function searchCallback(script, searchMatches)
{
results[script.scriptId] = [];
for (var i = 0; i < searchMatches.length; ++i) {
var searchMatch = {};
searchMatch.lineNumber = searchMatches[i].lineNumber + script.lineOffset;
searchMatch.lineContent = searchMatches[i].lineContent;
results[script.scriptId].push(searchMatch);
}
scriptsLeft--;
maybeCallback.call(this);
}
maybeCallback();
for (var i = 0; i < this._scripts.length; ++i)
this._scripts[i].searchInContent(query, searchCallback.bind(this, this._scripts[i]));
},
_concatenateScriptsContent: function(scripts, sources)
{
var content = "";
......
......@@ -49,12 +49,26 @@ WebInspector.Script.prototype = {
function didGetScriptSource(error, source)
{
if (error)
console.error(error);
this._source = source;
callback(this._source);
}
DebuggerAgent.getScriptSource(this.scriptId, didGetScriptSource.bind(this));
},
searchInContent: function(query, callback)
{
function innerCallback(error, searchMatches)
{
if (error)
console.error(error);
callback(searchMatches);
}
DebuggerAgent.searchInContent(this.scriptId, query, innerCallback.bind(this));
},
editSource: function(newSource, callback)
{
function didEditScriptSource(error, callFrames)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment