Commit 192582ad authored by vsevik@chromium.org's avatar vsevik@chromium.org

Web Inspector: Create JavaScriptSources based on network resources.

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

Reviewed by Pavel Feldman.

Source/WebCore:

Introduced NetworkUISourceCodeProvider that is listening for ResourceTreeModel and creates UISourceCodes for them.
RawSourceCode does not create uiSourceCodes based on resource anymore (this is done by NetworkUISourceCodeProvider instead).
Moved script <-> uiSourceCode binding logic from RawSourceCode to ResourceScriptMapping.
Removed rawSourceCode as it was not needed anymore.

Tests: inspector/debugger/network-uisourcecode-provider.html
       inspector/debugger/resource-script-mapping.html

* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* inspector/compile-front-end.py:
* inspector/front-end/CompilerScriptMapping.js:
* inspector/front-end/DebuggerModel.js:
(WebInspector.DebuggerDispatcher.prototype.scriptFailedToParse):
* inspector/front-end/JavaScriptSource.js:
(WebInspector.JavaScriptSource):
* inspector/front-end/NetworkUISourceCodeProvider.js: Renamed from Source/WebCore/inspector/front-end/StylesUISourceCodeProvider.js.
(WebInspector.NetworkUISourceCodeProvider):
(WebInspector.NetworkUISourceCodeProvider.prototype._populate):
(WebInspector.NetworkUISourceCodeProvider.prototype._styleResourceAdded):
(WebInspector.NetworkUISourceCodeProvider.prototype._scriptResourceAdded.resourceFinished):
(WebInspector.NetworkUISourceCodeProvider.prototype._scriptResourceAdded):
(WebInspector.NetworkUISourceCodeProvider.prototype._addJavaScriptSource):
(WebInspector.NetworkUISourceCodeProvider.prototype._addUISourceCode):
(WebInspector.NetworkUISourceCodeProvider.prototype._resourceAdded):
(WebInspector.NetworkUISourceCodeProvider.prototype._reset):
* inspector/front-end/RawSourceCode.js:
* inspector/front-end/ResourceScriptMapping.js:
(WebInspector.ResourceScriptMapping):
(WebInspector.ResourceScriptMapping.prototype.rawLocationToUILocation):
(WebInspector.ResourceScriptMapping.prototype._bindUISourceCodeToScripts):
(WebInspector.ResourceScriptMapping.prototype._scriptsForSourceURL):
(WebInspector.ResourceScriptMapping.prototype._addOrReplaceTemporaryUISourceCode.get var):
(WebInspector.ResourceScriptMapping.prototype._addOrReplaceTemporaryUISourceCode):
(WebInspector.ResourceScriptMapping.prototype.get _uiSourceCodeReplaced):
(WebInspector.ResourceScriptMapping.prototype._reset):
* inspector/front-end/ScriptSnippetModel.js:
(WebInspector.ScriptSnippetModel.prototype._addScriptSnippet):
(WebInspector.ScriptSnippetModel.prototype._createUISourceCodeForScript):
(WebInspector.SnippetJavaScriptSource):
* inspector/front-end/UISourceCode.js:
(WebInspector.UISourceCode):
(WebInspector.UISourceCode.prototype.uiLocationToRawLocation):
(WebInspector.UISourceCode.prototype.setSourceMapping):
* inspector/front-end/WebKit.qrc:
* inspector/front-end/Workspace.js: Drive-by: fixed duplicating uiSourceCodes in workspace.
* inspector/front-end/inspector.html:
* inspector/front-end/inspector.js:

LayoutTests:

Removed raw-source-code.html test as RawSourceCode was removed by this patch.
Added resource-script-mapping.html to test script <-> uiSourceCode binding behavior.
Added network-uisourcecode-provider.html to test uiSourceCode creation behavior.
Updated dynamic-script-tag.html to better match expected behavior.

* http/tests/inspector/network/network-request-revision-content.html:
* http/tests/inspector/workspace-test.js: Added.
(initialize_WorkspaceTest.InspectorTest.createWorkspace):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent.uiSourceCodeReplaced):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeAddedEvent.uiSourceCodeAdded):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeAddedEvent):
(initialize_WorkspaceTest.InspectorTest.addMockUISourceCodeToWorkspace):
(initialize_WorkspaceTest.InspectorTest._defaultUISourceCodeProviderEventHandler):
(initialize_WorkspaceTest.InspectorTest.dumpUISourceCode.didRequestContent):
(initialize_WorkspaceTest.InspectorTest.dumpUISourceCode):
(initialize_WorkspaceTest):
* inspector/debugger/breakpoint-manager.html:
* inspector/debugger/dynamic-script-tag-expected.txt:
* inspector/debugger/dynamic-script-tag.html:
* inspector/debugger/network-uisourcecode-provider-expected.txt: Added.
* inspector/debugger/network-uisourcecode-provider.html: Added.
* inspector/debugger/raw-source-code-expected.txt: Removed.
* inspector/debugger/raw-source-code.html: Removed.
* inspector/debugger/resource-script-mapping-expected.txt: Added.
* inspector/debugger/resource-script-mapping.html: Added.
* inspector/debugger/scripts-panel.html:
* inspector/debugger/source-frame-count.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127454 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9a34e845
2012-09-04 Vsevolod Vlasov <vsevik@chromium.org>
Web Inspector: Create JavaScriptSources based on network resources.
https://bugs.webkit.org/show_bug.cgi?id=95352
Reviewed by Pavel Feldman.
Removed raw-source-code.html test as RawSourceCode was removed by this patch.
Added resource-script-mapping.html to test script <-> uiSourceCode binding behavior.
Added network-uisourcecode-provider.html to test uiSourceCode creation behavior.
Updated dynamic-script-tag.html to better match expected behavior.
* http/tests/inspector/network/network-request-revision-content.html:
* http/tests/inspector/workspace-test.js: Added.
(initialize_WorkspaceTest.InspectorTest.createWorkspace):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent.uiSourceCodeReplaced):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeAddedEvent.uiSourceCodeAdded):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeAddedEvent):
(initialize_WorkspaceTest.InspectorTest.addMockUISourceCodeToWorkspace):
(initialize_WorkspaceTest.InspectorTest._defaultUISourceCodeProviderEventHandler):
(initialize_WorkspaceTest.InspectorTest.dumpUISourceCode.didRequestContent):
(initialize_WorkspaceTest.InspectorTest.dumpUISourceCode):
(initialize_WorkspaceTest):
* inspector/debugger/breakpoint-manager.html:
* inspector/debugger/dynamic-script-tag-expected.txt:
* inspector/debugger/dynamic-script-tag.html:
* inspector/debugger/network-uisourcecode-provider-expected.txt: Added.
* inspector/debugger/network-uisourcecode-provider.html: Added.
* inspector/debugger/raw-source-code-expected.txt: Removed.
* inspector/debugger/raw-source-code.html: Removed.
* inspector/debugger/resource-script-mapping-expected.txt: Added.
* inspector/debugger/resource-script-mapping.html: Added.
* inspector/debugger/scripts-panel.html:
* inspector/debugger/source-frame-count.html:
2012-09-04 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r127447.
......@@ -14,7 +14,7 @@ function loadStylesheet()
function test()
{
InspectorTest.addConsoleSniffer(step2, true);
InspectorTest.addSniffer(WebInspector.StylesUISourceCodeProvider.prototype, "_resourceAdded", true);
InspectorTest.addSniffer(WebInspector.NetworkUISourceCodeProvider.prototype, "_resourceAdded", true);
InspectorTest.evaluateInPage("loadStylesheet()");
var resource;
......
var initialize_WorkspaceTest = function() {
InspectorTest.testWorkspace;
InspectorTest.createWorkspace = function()
{
InspectorTest.testWorkspace = new WebInspector.Workspace();
InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, InspectorTest._defaultUISourceCodeProviderEventHandler);
InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeReplaced, InspectorTest._defaultUISourceCodeProviderEventHandler);
InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, InspectorTest._defaultUISourceCodeProviderEventHandler);
}
InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent = function(callback)
{
InspectorTest.testWorkspace.removeEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeReplaced, InspectorTest._defaultUISourceCodeProviderEventHandler);
InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeReplaced, uiSourceCodeReplaced);
function uiSourceCodeReplaced(event)
{
InspectorTest.testWorkspace.removeEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeReplaced, uiSourceCodeReplaced);
InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeReplaced, InspectorTest._defaultUISourceCodeProviderEventHandler);
callback(event.data.uiSourceCode, event.data.oldUISourceCode);
}
}
InspectorTest.waitForWorkspaceUISourceCodeAddedEvent = function(callback)
{
InspectorTest.testWorkspace.removeEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, InspectorTest._defaultUISourceCodeProviderEventHandler);
InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCodeAdded);
function uiSourceCodeAdded(event)
{
InspectorTest.testWorkspace.removeEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCodeAdded);
InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, InspectorTest._defaultUISourceCodeProviderEventHandler);
callback(event.data);
}
}
InspectorTest.addMockUISourceCodeToWorkspace = function(url, type, content)
{
var isDocument = type === WebInspector.resourceTypes.Document;
var mockContentProvider = new WebInspector.StaticContentProvider(type, content);
var uiSourceCode = new WebInspector.JavaScriptSource(url, null, mockContentProvider, !isDocument);
InspectorTest.testWorkspace.project().addUISourceCode(uiSourceCode);
}
InspectorTest._defaultUISourceCodeProviderEventHandler = function(event)
{
throw new Error("Unexpected UISourceCodeProvider event: " + event.type + ".");
}
InspectorTest.dumpUISourceCode = function(uiSourceCode, callback)
{
InspectorTest.addResult("UISourceCode: " + uiSourceCode.url);
if (uiSourceCode instanceof WebInspector.JavaScriptSource) {
InspectorTest.addResult("UISourceCode is editable: " + uiSourceCode._isEditable);
InspectorTest.addResult("UISourceCode is content script: " + uiSourceCode.isContentScript);
}
uiSourceCode.requestContent(didRequestContent);
function didRequestContent(content, contentEncoded, mimeType)
{
InspectorTest.addResult("Mime type: " + mimeType);
InspectorTest.addResult("UISourceCode content: " + content);
callback();
}
}
};
......@@ -111,7 +111,8 @@ function test()
WorkspaceMock.prototype = {
_addUISourceCode: function(url)
{
var uiSourceCode = new WebInspector.JavaScriptSource(url, null, null, defaultMapping, false);
var uiSourceCode = new WebInspector.JavaScriptSource(url, null, null, false);
uiSourceCode.setSourceMapping(defaultMapping);
uiSourceCodes[url] = uiSourceCode;
this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCode);
return uiSourceCode;
......
CONSOLE MESSAGE: line 1: 123
Tests that dynamically added script tag gets its own JavaScriptSource and is not bound to the resource. Bug 87119
Tests that inline scripts and document.write scripts get different uiSourceCodes with different URLs. Bug 87119
Debugger was enabled.
Dumping scripts:
script1: file:///usr/local/google/home/vsevik/chromium/src/third_party/WebKit/LayoutTests/inspector/debugger/dynamic-script-tag.html
Is anonymous:false
Is inline script:false
dynamic-script-tag.html
UI name: dynamic-script-tag.html
script2: file:///usr/local/google/home/vsevik/chromium/src/third_party/WebKit/LayoutTests/inspector/debugger/dynamic-script-tag.html
Is anonymous:false
Is inline script:false
Dumping uiSourceCodes:
UISourceCode: file:///usr/local/google/home/vsevik/chromium/src/third_party/WebKit/LayoutTests/inspector/debugger/dynamic-script-tag.html (1)
UISourceCode is editable: true
UISourceCode is content script: false
Mime type: text/javascript
UISourceCode content: function foo() { }
UI resource: null
UISourceCode: file:///usr/local/google/home/vsevik/chromium/src/third_party/WebKit/LayoutTests/inspector/debugger/dynamic-script-tag.html (2)
UISourceCode is editable: true
UISourceCode is content script: false
Mime type: text/javascript
UISourceCode content: function bar() { }
UI resource: null
UI content: console.log(123)
Debugger was disabled.
......@@ -2,51 +2,85 @@
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/debugger-test.js"></script>
<script src="../../http/tests/inspector/workspace-test.js"></script>
<script>
document.write("<scrip" + "t>function foo() { }</sc" + "ript>");
function createScriptTag()
{
var script = document.createElement("script");
script.innerHTML = "console.log(123)";
document.head.appendChild(script);
var scriptElement = document.createElement("script");
scriptElement.textContent = "function bar() { }";
document.head.appendChild(scriptElement);
}
function test()
var test = function()
{
InspectorTest.startDebuggerTest(step1);
var scripts;
function step1()
{
InspectorTest.evaluateInPage("createScriptTag()");
WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, step2);
InspectorTest.evaluateInPage("createScriptTag()", step2);
}
function step2(event)
function step2()
{
WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, step3);
step3();
}
function step3()
{
var script = event.data;
script.requestContent(callback);
function callback(content)
scripts = Object.values(WebInspector.debuggerModel.scripts);
function filterOutStandaloneAndInlineScripts(script)
{
if (content !== "console.log(123)")
return;
return !script.isInlineScript() && script.sourceURL.indexOf("dynamic-script-tag.html") !== -1;
}
scripts = scripts.filter(filterOutStandaloneAndInlineScripts);
if (scripts.length >= 2) {
WebInspector.debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, step3);
step4();
}
}
function step4()
{
var uiSourceCodes = [];
InspectorTest.addResult("Dumping scripts:");
for (var i = 0; i < scripts.length; ++i) {
var script = scripts[i];
InspectorTest.addResult("script" + (i+1) + ": " + script.sourceURL);
InspectorTest.addResult("Is anonymous:" + script.isAnonymousScript());
InspectorTest.addResult("Is inline script:" + script.isInlineScript());
InspectorTest.addResult(new WebInspector.ParsedURL(script.sourceURL).displayName);
// Invoke post source map install.
setTimeout(step3.bind(this, script), 0);
uiSourceCodes.push(script.rawLocationToUILocation(0, 0).uiSourceCode);
}
}
function step3(script)
{
var uiLocation = script.rawLocationToUILocation(0, 0);
InspectorTest.addResult("UI name: " + uiLocation.uiSourceCode.parsedURL.displayName);
InspectorTest.addResult("UI resource: " + uiLocation.uiSourceCode.resource());
uiLocation.uiSourceCode.requestContent(callback);
function callback(content)
var seenUISourceCodes = new Map();
InspectorTest.addResult("Dumping uiSourceCodes:");
var index = 0;
dumpNextUISourceCode();
function dumpNextUISourceCode()
{
if (index >= uiSourceCodes.length) {
uiSourceCodesDumped();
return;
}
var uiSourceCode = uiSourceCodes[index];
InspectorTest.dumpUISourceCode(uiSourceCode, uiSourceCodeDumped);
function uiSourceCodeDumped()
{
InspectorTest.addResult("UI resource: " + uiSourceCode.resource());
InspectorTest.assertTrue(!seenUISourceCodes.get(uiSourceCode), "UISourceCode matches two scripts: " + uiSourceCode.url);
seenUISourceCodes.put(uiSourceCode, uiSourceCode);
++index;
dumpNextUISourceCode();
}
}
function uiSourceCodesDumped()
{
InspectorTest.addResult("UI content: " + content);
InspectorTest.completeDebuggerTest();
}
}
......@@ -54,10 +88,7 @@ function test()
</script>
</head>
<body onload="runTest()">
<p>
Tests that dynamically added script tag gets its own JavaScriptSource and is not bound to the resource.
<p>Tests that inline scripts and document.write scripts get different uiSourceCodes with different URLs.
<a href="https://bugs.webkit.org/show_bug.cgi?id=87119">Bug 87119</a>
</p>
</body>
</html>
Tests NetworkUISourceCodeProvider class.
Running: testDocumentResourceWithPendingRequest
Creating request.
Finishing request.
UISourceCode: http://fake.url/2
UISourceCode is editable: false
UISourceCode is content script: false
Mime type: text/html
UISourceCode content: <document request content>
Running: testDocumentResource
Creating resource.
UISourceCode: http://fake.url/3
UISourceCode is editable: false
UISourceCode is content script: false
Mime type: text/html
UISourceCode content: <document resource content>
Running: testScriptResourceWithPendingRequest
Creating request.
Finishing request.
UISourceCode: http://fake.url/4
UISourceCode is editable: true
UISourceCode is content script: false
Mime type: text/javascript
UISourceCode content: <script request content>
Running: testScriptResource
Creating resource.
UISourceCode: http://fake.url/5
UISourceCode is editable: true
UISourceCode is content script: false
Mime type: text/javascript
UISourceCode content: <script resource content>
Running: testStylesheetResourceWithPendingRequest
Creating request.
UISourceCode: http://fake.url/6
Finishing request.
Mime type: text/css
UISourceCode content: <stylesheet request content>
Running: testStylesheetResource
Creating resource.
UISourceCode: http://fake.url/7
Mime type: text/css
UISourceCode content: <stylesheet resource content>
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/debugger-test.js"></script>
<script src="../../http/tests/inspector/workspace-test.js"></script>
<script>
function test()
{
var mockContentsMap = {};
var lastResouceId = 1;
NetworkAgent.getResponseBody = function(requestId, callback)
{
callback(undefined, mockContentsMap[requestId], false);
}
PageAgent.getResourceContent = function(frameId, url, callback)
{
callback(undefined, mockContentsMap[url], false);
}
function createResourceMock(type, withPendingRequest, content)
{
var documentURL = "http://fake.url";
var resourceId = ++lastResouceId + "";
var url = documentURL + "/" + resourceId;
var frameId = "frame-id";
var loaderId = "loader-id";
var mimeType;
switch (type) {
case WebInspector.resourceTypes.Document:
mimeType = "text/html";
break;
case WebInspector.resourceTypes.Script:
mimeType = "text/javascript";
break;
case WebInspector.resourceTypes.Stylesheet:
mimeType = "text/css";
break;
}
if (withPendingRequest) {
var request = new WebInspector.NetworkRequest(resourceId, url, "http://fake.url", frameId, loaderId);
request.type = type;
request.mimeType = mimeType;
mockContentsMap[resourceId] = content;
}
var resource = new WebInspector.Resource(request, url, documentURL, frameId, loaderId, type, mimeType);
mockContentsMap[url] = content;
WebInspector.resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, resource);
return resource;
}
function finishResource(resource)
{
resource.request.finished = true;
resource.request.dispatchEventToListeners(WebInspector.NetworkRequest.Events.FinishedLoading, resource.request);
}
function createNetworkUISourceCodeProvider()
{
InspectorTest.createWorkspace();
WebInspector.resourceTreeModel = new WebInspector.Object();
var networkUISourceCodeProvider = new WebInspector.NetworkUISourceCodeProvider(InspectorTest.testWorkspace);
return networkUISourceCodeProvider;
}
InspectorTest.runTestSuite([
function testDocumentResourceWithPendingRequest(next)
{
var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
InspectorTest.addResult("Creating request.");
var resource = createResourceMock(WebInspector.resourceTypes.Document, true, "<document request content>");
InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
InspectorTest.addResult("Finishing request.");
finishResource(resource);
function uiSourceCodeAdded(uiSourceCode)
{
InspectorTest.dumpUISourceCode(uiSourceCode, next);
}
},
function testDocumentResource(next)
{
var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
InspectorTest.addResult("Creating resource.");
InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
var resource = createResourceMock(WebInspector.resourceTypes.Document, false, "<document resource content>");
function uiSourceCodeAdded(uiSourceCode)
{
InspectorTest.dumpUISourceCode(uiSourceCode, next);
}
},
function testScriptResourceWithPendingRequest(next)
{
var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
InspectorTest.addResult("Creating request.");
var resource = createResourceMock(WebInspector.resourceTypes.Script, true, "<script request content>");
InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
InspectorTest.addResult("Finishing request.");
finishResource(resource);
function uiSourceCodeAdded(uiSourceCode)
{
InspectorTest.dumpUISourceCode(uiSourceCode, next);
}
},
function testScriptResource(next)
{
var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
InspectorTest.addResult("Creating resource.");
InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
var resource = createResourceMock(WebInspector.resourceTypes.Script, false, "<script resource content>");
function uiSourceCodeAdded(uiSourceCode)
{
InspectorTest.dumpUISourceCode(uiSourceCode, next);
}
},
function testStylesheetResourceWithPendingRequest(next)
{
var endTestCallsLeft = 2;
var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
InspectorTest.addResult("Creating request.");
var resource = createResourceMock(WebInspector.resourceTypes.Stylesheet, true, "<stylesheet request content>");
InspectorTest.addResult("Finishing request.");
finishResource(resource);
endTest();
function uiSourceCodeAdded(uiSourceCode)
{
InspectorTest.dumpUISourceCode(uiSourceCode, endTest);
}
function endTest()
{
if (--endTestCallsLeft)
return;
next();
}
},
function testStylesheetResource(next)
{
var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
InspectorTest.addResult("Creating resource.");
InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
var resource = createResourceMock(WebInspector.resourceTypes.Stylesheet, false, "<stylesheet resource content>");
function uiSourceCodeAdded(uiSourceCode)
{
InspectorTest.dumpUISourceCode(uiSourceCode, next);
}
},
]);
};
</script>
</head>
<body onload="runTest()">
<p>Tests NetworkUISourceCodeProvider class.</p>
</body>
</html>
Tests RawSourceCode class.
Running: testScriptWithoutResource
UISourceCode: foo.js
UISourceCode is content script: true
Mime type: text/javascript
Script source: <script source>
Running: testHTMLWithPendingResource
Adding first script for pending request.
UISourceCode: index.html
UISourceCode is content script: false
Mime type: text/html
Script source: <script><script source 1></script>
Adding second script for pending request.
UISourceCode: index.html
UISourceCode is content script: false
Mime type: text/html
Script source: <script><script source 1></script> <script><script source 2></script>
Finishing request.
UISourceCode: index.html
UISourceCode is content script: false
Mime type: text/html
Script source: <resource content>
Running: testHTMLWithFinishedResource
UISourceCode: index.html
UISourceCode is content script: false
Mime type: text/html
Script source: <resource content>
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/debugger-test.js"></script>
<script>
function test()
{
var mockContentsMap = {};
var lastRequestId = 1;
NetworkAgent.getResponseBody = function(requestId, callback)
{
callback(undefined, mockContentsMap[requestId], false);
}
PageAgent.getResourceContent = function(frameId, url, callback)
{
callback(undefined, mockContentsMap[url], false);
}
function createRequestMock(type, finished, content)
{
var requestId = ++lastRequestId + "";
var url = "http://fake.url/" + requestId;
WebInspector.resourceTreeModel._addFrame(new WebInspector.ResourceTreeFrame(WebInspector.resourceTreeModel, null, {id: "frame-id"}));
var request = new WebInspector.NetworkRequest(requestId, url, "http://fake.url", "frame-id", "loader-id");
request.type = type === "document" ? WebInspector.resourceTypes.Document : WebInspector.resourceTypes.Script;
request.mimeType = type === "document" ? "text/html" : "text/javascript";
WebInspector.networkManager._dispatcher._startNetworkRequest(request);
if (finished)
finishRequest(request);
mockContentsMap[requestId] = content;
mockContentsMap[url] = content;
return request;
}
function finishRequest(request) { WebInspector.networkManager._dispatcher._updateNetworkRequest(request); WebInspector.networkManager._dispatcher._finishNetworkRequest(request); }
function createPendingRequestMock(type, content) { return createRequestMock(type, false, content); }
function createFinishedRequestMock(type, content) { return createRequestMock(type, true, content); }
function createScriptFormatterMock()
{
var mapping = {
originalToFormatted: function(lineNumber, columnNumber) { return [lineNumber * 2, columnNumber * 2]; },
formattedToOriginal: function(lineNumber, columnNumber) { return [Math.floor(lineNumber / 2), Math.floor(columnNumber / 2)]; }
};
var formatter = {
formatContent: function(mimeType, content, callback) { formatter._callback = callback.bind(null, "<formatted> " + content, mapping); },
finish: function() { formatter._callback(); }
};