Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / compiler-script-mapping.html
index 1f01db8..e821b43 100644 (file)
@@ -3,21 +3,51 @@
 <script src="inspector-test.js"></script>
 <script src="debugger-test.js"></script>
 <script src="workspace-test.js"></script>
+<script src="breakpoint-manager-test.js"></script>
 
 <script>
 
 function test()
 {
-    var defaultScriptMapping;
-    var resourceScriptMapping;
+    var mockTargetId = 1;
+    var MockTarget = function(name, connection, callback)
+    {
+        WebInspector.Target.call(this, name, connection, callback);
+    }
+    MockTarget.prototype = {
+        _loadedWithCapabilities: function(callback)
+        {
+            this.debuggerModel = new WebInspector.DebuggerModel(this);
+            this.resourceTreeModel = WebInspector.targetManager.mainTarget().resourceTreeModel;
+            if (callback)
+                callback();
+        },
+
+        __proto__: WebInspector.Target.prototype
+    }
 
-    function createCompilerScriptMapping()
+    function createMockTarget(userCallback)
+    {
+        var target = new MockTarget("mock-target-" + (mockTargetId++), new InspectorBackendClass.StubConnection(), callback);
+        function callback()
+        {
+            InspectorTest.testTargetManager.addTarget(target);
+            userCallback(target);
+        }
+    }
+
+    function createWorkspaceWithTarget(userCallback)
     {
         InspectorTest.createWorkspace();
-        var compilerScriptMapping = new WebInspector.CompilerScriptMapping(WebInspector.debuggerModel, InspectorTest.testWorkspace, InspectorTest.testNetworkWorkspaceProvider);
-        resourceScriptMapping = new WebInspector.ResourceScriptMapping(WebInspector.debuggerModel, InspectorTest.testWorkspace);
-        defaultScriptMapping = new WebInspector.DefaultScriptMapping(WebInspector.debuggerModel, InspectorTest.testWorkspace);
-        return compilerScriptMapping;
+
+        InspectorTest.testWorkspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, uiSourceCodeAdded);
+        InspectorTest.testWorkspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRemoved, uiSourceCodeRemoved);
+
+        createMockTarget(callback);
+        function callback(target)
+        {
+            userCallback(target);
+        }
     }
 
     function checkMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, mapping)
@@ -30,11 +60,35 @@ function test()
 
     function checkReverseMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, mapping)
     {
-        var entry = mapping.findEntryReversed(sourceURL, sourceLineNumber);
+        var entry = mapping.findEntryReversed(sourceURL, sourceLineNumber, 5);
         InspectorTest.addResult(compiledLineNumber + " === " + entry[0]);
         InspectorTest.addResult(compiledColumnNumber + " === " + entry[1]);
     }
 
+    function uiLocation(script, line, column)
+    {
+        var location = script.target().debuggerModel.createRawLocation(script, line, column);
+        return InspectorTest.testDebuggerWorkspaceBinding.rawLocationToUILocation(location);
+    }
+
+    function resetModels()
+    {
+        target.debuggerModel._reset();
+        InspectorTest.testDebuggerWorkspaceBinding._reset(target);
+    }
+
+    function uiSourceCodeAdded(event)
+    {
+        var uiSourceCode = event.data;
+        InspectorTest.addResult("UISourceCodeAdded: [" + uiSourceCode.project().type() + "] " + uiSourceCode.url);
+    }
+
+    function uiSourceCodeRemoved(event)
+    {
+        var uiSourceCode = event.data;
+        InspectorTest.addResult("UISourceCodeRemoved: [" + uiSourceCode.project().type() + "] " + uiSourceCode.url);
+    }
+
     InspectorTest.runTestSuite([
         function testSimpleMap(next)
         {
@@ -53,9 +107,10 @@ function test()
                 0         1         2         3
                 012345678901234567890123456789012345
                 function add(a,b){return a+b}var global="foo";
+                foo
             */
             var mappingPayload = {
-                "mappings":"AAASA,QAAAA,IAAG,CAACC,CAAD,CAAaC,CAAb,CACZ,CACI,MAAOD,EAAP,CAAoBC,CADxB,CAIA,IAAIC,OAAS;",
+                "mappings":"AAASA,QAAAA,IAAG,CAACC,CAAD,CAAaC,CAAb,CACZ,CACI,MAAOD,EAAP,CAAoBC,CADxB,CAIA,IAAIC,OAAS;A",
                 "sources":["example.js"]
             };
             var mapping = new WebInspector.SourceMap("source-map.json", mappingPayload);
@@ -66,6 +121,7 @@ function test()
             checkMapping(0, 18, "example.js", 2, 4, mapping);
             checkMapping(0, 25, "example.js", 2, 11, mapping);
             checkMapping(0, 27, "example.js", 2, 24, mapping);
+            checkMapping(1, 0, undefined, undefined, undefined, mapping);
 
             checkReverseMapping(0, 0, "example.js", 0, mapping);
             checkReverseMapping(0, 17, "example.js", 1, mapping);
@@ -191,19 +247,18 @@ function test()
         function testCompilerScriptMapping(next)
         {
             var script;
-            WebInspector.debuggerModel._reset();
-            var mapping = createCompilerScriptMapping();
             var originalUISourceCode;
-            step1();
+            var target;
+            createWorkspaceWithTarget(step1);
 
-            function step1()
+            function step1(newTarget)
             {
+                target = newTarget;
                 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalUISourceCodeAdded);
-                script = InspectorTest.createScriptMock("compiled.js", 0, 0, true, "");
-                script.sourceMapURL = "http://localhost:8000/inspector/resources/source-map.json";
-                defaultScriptMapping.addScript(script);
-                resourceScriptMapping.addScript(script);
-                mapping.addScript(script);
+                script = InspectorTest.createScriptMock("compiled.js", 0, 0, true, "", target, function(script) {
+                    script.sourceMapURL = "http://localhost:8000/inspector/resources/source-map.json";
+                });
+                InspectorTest.testDebuggerWorkspaceBinding._targetToData.get(target)._parsedScriptSource({ data: script });
             }
 
             function originalUISourceCodeAdded(uiSourceCode)
@@ -214,33 +269,47 @@ function test()
 
             function originalResourceUISourceCodeAdded(uiSourceCode)
             {
-                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(firstUISourceCodeAdded);
+                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(stubUISourceCodeAdded, 1, WebInspector.projectTypes.Service);
                 originalUISourceCode = uiSourceCode;
             }
 
+            function stubUISourceCodeAdded(uiSourceCode)
+            {
+                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(firstUISourceCodeAdded);
+            }
+
             function firstUISourceCodeAdded(uiSourceCode)
             {
+                if (!uiSourceCode.url) {
+                    InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(firstUISourceCodeAdded);
+                    return;
+                }
                 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(secondUISourceCodeAdded);
             }
 
             function secondUISourceCodeAdded(uiSourceCode)
             {
+                if (!uiSourceCode.url) {
+                    InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(secondUISourceCodeAdded);
+                    return;
+                }
                 afterScriptAdded();
             }
 
-            function afterScriptAdded(uiSourceCode)
+            function afterScriptAdded()
             {
+                InspectorTest.addResult("afterScriptAdded");
                 var uiSourceCode1 = InspectorTest.testWorkspace.uiSourceCodeForOriginURL("http://localhost:8000/inspector/resources/source1.js");
                 var uiSourceCode2 = InspectorTest.testWorkspace.uiSourceCodeForOriginURL("http://localhost:8000/inspector/resources/source2.js");
 
-                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.checkUILocation(uiSourceCode1, 4, 4, uiLocation(script, 0, 81));
+                InspectorTest.checkUILocation(uiSourceCode1, 5, 4, uiLocation(script, 0, 93));
+                InspectorTest.checkUILocation(uiSourceCode2, 7, 4, uiLocation(script, 1, 151));
+                InspectorTest.checkUILocation(originalUISourceCode, 1, 200, uiLocation(script, 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));
+                InspectorTest.checkRawLocation(script, 0, 42, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, uiSourceCode1, 3, 10));
+                InspectorTest.checkRawLocation(script, 1, 85, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, uiSourceCode2, 0, 0));
+                InspectorTest.checkRawLocation(script, 1, 110, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, uiSourceCode2, 5, 2));
 
                 uiSourceCode1.requestContent(didRequestContent1);
 
@@ -261,19 +330,18 @@ function test()
         function testCompilerScriptMappingWhenResourceWasLoadedAfterSource(next)
         {
             var script;
-            WebInspector.debuggerModel._reset();
-            var mapping = createCompilerScriptMapping();
             var originalUISourceCode;
-            step1();
+            var target;
+            createWorkspaceWithTarget(workspaceCreated);
 
-            function step1()
+            function workspaceCreated(newTarget)
             {
+                target = newTarget;
                 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(function() { });
-                script = InspectorTest.createScriptMock("compiled.js", 0, 0, true, "");
-                script.sourceMapURL = "http://localhost:8000/inspector/resources/source-map.json";
-                defaultScriptMapping.addScript(script);
-                resourceScriptMapping.addScript(script);
-                mapping.addScript(script);
+                script = InspectorTest.createScriptMock("compiled.js", 0, 0, true, "", target, function(script) {
+                    script.sourceMapURL = "http://localhost:8000/inspector/resources/source-map.json";
+                });
+                InspectorTest.testDebuggerWorkspaceBinding._targetToData.get(target)._parsedScriptSource({ data: script });
                 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalResourceUISourceCodeAdded);
                 InspectorTest.addMockUISourceCodeToWorkspace("compiled.js", WebInspector.resourceTypes.Script, "");
                 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(firstUISourceCodeAdded);
@@ -299,14 +367,14 @@ function test()
                 var uiSourceCode1 = InspectorTest.testWorkspace.uiSourceCodeForOriginURL("http://localhost:8000/inspector/resources/source1.js");
                 var uiSourceCode2 = InspectorTest.testWorkspace.uiSourceCodeForOriginURL("http://localhost:8000/inspector/resources/source2.js");
 
-                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.checkUILocation(uiSourceCode1, 4, 4, uiLocation(script, 0, 81));
+                InspectorTest.checkUILocation(uiSourceCode1, 5, 4, uiLocation(script, 0, 93));
+                InspectorTest.checkUILocation(uiSourceCode2, 7, 4, uiLocation(script, 1, 151));
+                InspectorTest.checkUILocation(originalUISourceCode, 1, 200, uiLocation(script, 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));
+                InspectorTest.checkRawLocation(script, 0, 42, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, uiSourceCode1, 3, 10));
+                InspectorTest.checkRawLocation(script, 1, 85, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, uiSourceCode2, 0, 0));
+                InspectorTest.checkRawLocation(script, 1, 110, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, uiSourceCode2, 5, 2));
 
                 uiSourceCode1.requestContent(didRequestContent1);
 
@@ -326,20 +394,24 @@ function test()
 
         function testInlinedSourceMap(next)
         {
-            WebInspector.debuggerModel._reset();
-            var mapping = createCompilerScriptMapping();
-            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));
-            InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(compiledUISourceCodeAdded);
-            defaultScriptMapping.addScript(script);
-            resourceScriptMapping.addScript(script);
-            mapping.addScript(script);
+            var target;
+            var script;
+            createWorkspaceWithTarget(workspaceCreated);
+
+            function workspaceCreated(newTarget) {
+                target = newTarget;
+                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(compiledUISourceCodeAdded);
+                 script = InspectorTest.createScriptMock("http://example.com/compiled.js", 0, 0, true, "", target, function(script) {
+                    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));
+                });
+                InspectorTest.testDebuggerWorkspaceBinding._targetToData.get(target)._parsedScriptSource({ data: script });
+            }
 
             function compiledUISourceCodeAdded(uiSourceCode)
             {
@@ -350,8 +422,8 @@ function test()
             {
                 var uiSourceCode = InspectorTest.testWorkspace.uiSourceCodeForOriginURL("http://example.com/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));
+                InspectorTest.checkUILocation(uiSourceCode, 2, 4, uiLocation(script, 0, 18));
+                InspectorTest.checkRawLocation(script, 0, 18, InspectorTest.testDebuggerWorkspaceBinding.uiLocationToRawLocation(target, uiSourceCode, 2, 4));
 
                 uiSourceCode.requestContent(didRequestContent);
 
@@ -366,26 +438,26 @@ function test()
         function testSourceMapCouldNotBeLoaded(next)
         {
             WebInspector.settings.jsSourceMapsEnabled.get = function() { return true; }
-            WebInspector.debuggerModel._reset();
-            InspectorTest.createWorkspace();
-            var debuggerScriptMapping = new WebInspector.DebuggerScriptMapping(WebInspector.debuggerModel, InspectorTest.testWorkspace, InspectorTest.testNetworkWorkspaceProvider);
-
-            InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(compiledUISourceCodeAdded);
-            var script = InspectorTest.createScriptMock("compiled.js", 0, 0, true, "");
-
-            function compiledUISourceCodeAdded(uiSourceCode)
+            createWorkspaceWithTarget(workspaceCreated);
+            function workspaceCreated(target)
             {
-                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalUISourceCodeAdded);
-            }
+                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(compiledUISourceCodeAdded);
+                var script = InspectorTest.createScriptMock("compiled.js", 0, 0, true, "", target);
+
+                function compiledUISourceCodeAdded(uiSourceCode)
+                {
+                    InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(originalUISourceCodeAdded);
+                }
 
-            function originalUISourceCodeAdded(uiSourceCode) { }
+                function originalUISourceCodeAdded(uiSourceCode) { }
 
-            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.originURL());
-            next();
+                script.sourceMapURL = "http://localhost:8000/inspector/resources/source-map.json_";
+                console.error = function() {}; // Error message is platform dependent.
+                InspectorTest.testDebuggerWorkspaceBinding._targetToData.get(target)._parsedScriptSource({ data: script });
+                var location = uiLocation(script, 0, 0);
+                InspectorTest.addResult(location.uiSourceCode.originURL());
+                next();
+            }
         },
 
         function testSourceRoot(next)