| <html> |
| <head> |
| <script src="inspector-test.js"></script> |
| <script src="debugger-test.js"></script> |
| <script src="workspace-test.js"></script> |
| |
| <script> |
| |
| function test() |
| { |
| function createCompilerScriptMapping() |
| { |
| InspectorTest.createWorkspace(); |
| var compilerScriptMapping = new WebInspector.CompilerScriptMapping(InspectorTest.testWorkspace); |
| var resourceScriptMapping = new WebInspector.ResourceScriptMapping(InspectorTest.testWorkspace); |
| return compilerScriptMapping; |
| } |
| |
| function checkMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, mapping) |
| { |
| var entry = mapping.findEntry(compiledLineNumber, compiledColumnNumber); |
| InspectorTest.assertEquals(sourceURL, entry[2]); |
| InspectorTest.assertEquals(sourceLineNumber, entry[3]); |
| InspectorTest.assertEquals(sourceColumnNumber, entry[4]); |
| } |
| |
| function checkReverseMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, mapping) |
| { |
| var entry = mapping.findEntryReversed(sourceURL, sourceLineNumber); |
| InspectorTest.assertEquals(compiledLineNumber, entry[0]); |
| InspectorTest.assertEquals(compiledColumnNumber, entry[1]); |
| } |
| |
| InspectorTest.runTestSuite([ |
| function testSimpleMap(next) |
| { |
| /* |
| example.js: |
| 0 1 2 3 |
| 012345678901234567890123456789012345 |
| function add(variable_x, variable_y) |
| { |
| return variable_x + variable_y; |
| } |
| |
| var global = "foo"; |
| ---------------------------------------- |
| example-compiled.js: |
| 0 1 2 3 |
| 012345678901234567890123456789012345 |
| function add(a,b){return a+b}var global="foo"; |
| */ |
| var mappingPayload = { |
| "mappings":"AAASA,QAAAA,IAAG,CAACC,CAAD,CAAaC,CAAb,CACZ,CACI,MAAOD,EAAP,CAAoBC,CADxB,CAIA,IAAIC,OAAS;", |
| "sources":["example.js"] |
| }; |
| var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload); |
| |
| checkMapping(0, 9, "example.js", 0, 9, mapping); |
| checkMapping(0, 13, "example.js", 0, 13, mapping); |
| checkMapping(0, 15, "example.js", 0, 25, mapping); |
| checkMapping(0, 18, "example.js", 2, 4, mapping); |
| checkMapping(0, 25, "example.js", 2, 11, mapping); |
| checkMapping(0, 27, "example.js", 2, 24, mapping); |
| |
| checkReverseMapping(0, 0, "example.js", 0, mapping); |
| checkReverseMapping(0, 17, "example.js", 1, mapping); |
| checkReverseMapping(0, 18, "example.js", 2, mapping); |
| checkReverseMapping(0, 29, "example.js", 4, mapping); |
| checkReverseMapping(0, 29, "example.js", 5, mapping); |
| |
| next(); |
| }, |
| |
| function testNoMappingEntry(next) |
| { |
| var mappingPayload = { |
| "mappings":"AAAA,C,CAAE;", |
| "sources":["example.js"] |
| }; |
| var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload); |
| checkMapping(0, 0, "example.js", 0, 0, mapping); |
| var entry = mapping.findEntry(0, 1); |
| InspectorTest.assertEquals(2, entry.length); |
| checkMapping(0, 2, "example.js", 0, 2, mapping); |
| next(); |
| }, |
| |
| function testEmptyLine(next) |
| { |
| var mappingPayload = { |
| "mappings":"AAAA;;;CACA", |
| "sources":["example.js"] |
| }; |
| var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload); |
| checkMapping(0, 0, "example.js", 0, 0, mapping); |
| checkReverseMapping(3, 1, "example.js", 1, mapping); |
| next(); |
| }, |
| |
| function testSections(next) |
| { |
| var mappingPayload = { |
| "sections": [{ |
| "offset": { "line": 0, "column": 0 }, |
| "map": { |
| "mappings":"AAAA,CAEC", |
| "sources":["source1.js", "source2.js"] |
| } |
| }, { |
| "offset": { "line": 2, "column": 10 }, |
| "map": { |
| "mappings":"AAAA,CAEC", |
| "sources":["source2.js"] |
| } |
| } |
| ]}; |
| var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload); |
| InspectorTest.assertEquals(2, mapping.sources().length); |
| checkMapping(0, 0, "source1.js", 0, 0, mapping); |
| checkMapping(0, 1, "source1.js", 2, 1, mapping); |
| checkMapping(2, 10, "source2.js", 0, 0, mapping); |
| checkMapping(2, 11, "source2.js", 2, 1, mapping); |
| next(); |
| }, |
| |
| function testResolveSourceMapURL(next) |
| { |
| var func = WebInspector.SourceMapParser.prototype._canonicalizeURL; |
| InspectorTest.assertEquals("http://example.com/map.json", func("http://example.com/map.json", "http://example.com/script.js")); |
| InspectorTest.assertEquals("http://example.com/map.json", func("/map.json", "http://example.com/script.js")); |
| InspectorTest.assertEquals("http://example.com/scripts/../maps/map.json", func("../maps/map.json", "http://example.com/scripts/script.js")); |
| next(); |
| }, |
| |
| function testCompilerScriptMapping(next) |
| { |
| var script; |
| WebInspector.debuggerModel._reset(); |
| var mapping = createCompilerScriptMapping(); |
| step1(); |
| |
| function step1() |
| { |
| InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalUISourceCodeAdded); |
| script = InspectorTest.createScriptMock("compiled.js", 0, 0, true, ""); |
| script.sourceMapURL = "http://localhost:8000/inspector/resources/source-map.json"; |
| script.setSourceMapping(mapping); |
| mapping.addScript(script); |
| } |
| |
| function originalUISourceCodeAdded(uiSourceCode) |
| { |
| InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(firstUISourceCodeAdded); |
| } |
| |
| function firstUISourceCodeAdded(uiSourceCode) |
| { |
| InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(secondUISourceCodeAdded); |
| } |
| |
| function secondUISourceCodeAdded(uiSourceCode) |
| { |
| InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalResourceUISourceCodeAdded); |
| InspectorTest.addMockUISourceCodeToWorkspace("compiled.js", WebInspector.resourceTypes.Script, ""); |
| } |
| |
| function originalResourceUISourceCodeAdded(uiSourceCode) |
| { |
| var uiSourceCode1 = mapping._uiSourceCodeByURL["http://localhost:8000/inspector/resources/source1.js"]; |
| var uiSourceCode2 = mapping._uiSourceCodeByURL["http://localhost:8000/inspector/resources/source2.js"]; |
| var originalUISourceCode = mapping._originalUISourceCodeForScriptId[script.scriptId]; |
| |
| InspectorTest.checkUILocation(uiSourceCode1, 4, 4, script.rawLocationToUILocation(0, 81)); |
| InspectorTest.checkUILocation(uiSourceCode1, 5, 4, script.rawLocationToUILocation(0, 93)); |
| InspectorTest.checkUILocation(uiSourceCode2, 7, 4, script.rawLocationToUILocation(1, 151)); |
| InspectorTest.checkUILocation(originalUISourceCode, 1, 200, script.rawLocationToUILocation(1, 200)); |
| |
| InspectorTest.checkRawLocation(script, 0, 42, uiSourceCode1.uiLocationToRawLocation(3, 10)); |
| InspectorTest.checkRawLocation(script, 1, 85, uiSourceCode2.uiLocationToRawLocation(0, 0)); |
| InspectorTest.checkRawLocation(script, 1, 110, uiSourceCode2.uiLocationToRawLocation(5, 2)); |
| |
| uiSourceCode1.requestContent(didRequestContent1); |
| |
| function didRequestContent1(content, contentEncoded, mimeType) |
| { |
| InspectorTest.assertEquals(0, content.indexOf("window.addEventListener")); |
| uiSourceCode2.requestContent(didRequestContent2); |
| } |
| |
| function didRequestContent2(content, contentEncoded, mimeType) |
| { |
| InspectorTest.assertEquals(0, content.indexOf("function ClickHandler()")); |
| next(); |
| } |
| } |
| }, |
| |
| function testInlinedSourceMap(next) |
| { |
| WebInspector.debuggerModel._reset(); |
| var workspace = new WebInspector.Workspace(); |
| var mapping = new WebInspector.CompilerScriptMapping(workspace); |
| var script = InspectorTest.createScriptMock("http://example.com/compiled.js", 0, 0, true, ""); |
| var sourceMap = { |
| "file":"compiled.js", |
| "mappings":"AAASA,QAAAA,IAAG,CAACC,CAAD,CAAaC,CAAb,CACZ,CACI,MAAOD,EAAP,CAAoBC,CADxB,CAIA,IAAIC,OAAS;", |
| "sources":["source.js"], |
| "sourcesContent":["<source content>"] |
| }; |
| script.sourceMapURL = "data:application/json;base64," + btoa(JSON.stringify(sourceMap)); |
| mapping.addScript(script); |
| |
| var uiSourceCode = mapping._uiSourceCodeByURL["source.js"]; |
| |
| InspectorTest.checkUILocation(uiSourceCode, 2, 4, mapping.rawLocationToUILocation(WebInspector.debuggerModel.createRawLocation(script, 0, 18))); |
| InspectorTest.checkRawLocation(script, 0, 18, mapping.uiLocationToRawLocation(uiSourceCode, 2, 4)); |
| |
| uiSourceCode.requestContent(didRequestContent); |
| |
| function didRequestContent(content, contentEncoded, mimeType) |
| { |
| InspectorTest.assertEquals("<source content>", content); |
| next(); |
| } |
| }, |
| |
| function testSourceMapCouldNotBeLoaded(next) |
| { |
| WebInspector.settings.sourceMapsEnabled.set(true); |
| WebInspector.debuggerModel._reset(); |
| var workspace = new WebInspector.Workspace(); |
| var debuggerScriptMapping = new WebInspector.DebuggerScriptMapping(workspace); |
| |
| var script = InspectorTest.createScriptMock("compiled.js", 0, 0, true, ""); |
| script.sourceMapURL = "http://localhost:8000/inspector/resources/source-map.json_"; |
| console.error = function() {}; // Error message is platform dependent. |
| debuggerScriptMapping._parsedScriptSource({data:script}); |
| var uiLocation = script.rawLocationToUILocation(0, 0); |
| InspectorTest.addResult(uiLocation.uiSourceCode.url); |
| next(); |
| } |
| ]); |
| }; |
| |
| </script> |
| |
| </head> |
| |
| <body onload="runTest()"> |
| <p>Tests SourceMapParser and CompilerScriptMapping.</p> |
| </body> |
| </html> |