Web Inspector: [regression] dynamically created script tab is bound to the document...
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 May 2012 13:55:10 +0000 (13:55 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 May 2012 13:55:10 +0000 (13:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=87119

Reviewed by Vsevolod Vlasov.

Source/WebCore:

Test: inspector/debugger/dynamic-script-tag.html

* inspector/front-end/BreakpointManager.js:
(WebInspector.BreakpointManager.Breakpoint.prototype._setInDebugger.didSetBreakpoint):
(WebInspector.BreakpointManager.Breakpoint.prototype._setInDebugger):
* inspector/front-end/DebuggerModel.js:
(WebInspector.DebuggerModel.prototype.rawLocationToUILocation):
* inspector/front-end/ResourceScriptMapping.js:
(WebInspector.ResourceScriptMapping.prototype.addScript):
(WebInspector.ResourceScriptMapping.prototype._shouldBindScriptToContentProvider):
* inspector/front-end/Script.js:
(WebInspector.Script.prototype.rawLocationToUILocation):
(WebInspector.Script.Location.prototype.update):

LayoutTests:

* inspector/debugger/dynamic-script-tag-expected.txt: Added.
* inspector/debugger/dynamic-script-tag.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@117966 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/debugger/dynamic-script-tag-expected.txt [new file with mode: 0644]
LayoutTests/inspector/debugger/dynamic-script-tag.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/BreakpointManager.js
Source/WebCore/inspector/front-end/DebuggerModel.js
Source/WebCore/inspector/front-end/ResourceScriptMapping.js
Source/WebCore/inspector/front-end/Script.js

index 008aaaf..4304ac9 100644 (file)
@@ -1,3 +1,13 @@
+2012-05-22  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: [regression] dynamically created script tab is bound to the document resource.
+        https://bugs.webkit.org/show_bug.cgi?id=87119
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/debugger/dynamic-script-tag-expected.txt: Added.
+        * inspector/debugger/dynamic-script-tag.html: Added.
+
 2012-05-22  Mikhail Pozdnyakov  <mikhail.pozdnyakov@intel.com>
 
         [EFL][DRT] Gardening of fast/spatial-navigation tests.
 2012-05-22  Mikhail Pozdnyakov  <mikhail.pozdnyakov@intel.com>
 
         [EFL][DRT] Gardening of fast/spatial-navigation tests.
diff --git a/LayoutTests/inspector/debugger/dynamic-script-tag-expected.txt b/LayoutTests/inspector/debugger/dynamic-script-tag-expected.txt
new file mode 100644 (file)
index 0000000..6930c8f
--- /dev/null
@@ -0,0 +1,12 @@
+CONSOLE MESSAGE: line 1: 123
+Tests that dynamically added script tag gets its own JavaScriptSource and is not bound to the resource. Bug 87119
+
+Debugger was enabled.
+Is anonymous:false
+Is inline script:false
+dynamic-script-tag.html
+UI name: dynamic-script-tag.html
+UI resource: null
+UI content: console.log(123)
+Debugger was disabled.
+
diff --git a/LayoutTests/inspector/debugger/dynamic-script-tag.html b/LayoutTests/inspector/debugger/dynamic-script-tag.html
new file mode 100644 (file)
index 0000000..b45368c
--- /dev/null
@@ -0,0 +1,63 @@
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/debugger-test.js"></script>
+
+<script>
+
+function createScriptTag()
+{
+    var script = document.createElement("script");
+    script.innerHTML = "console.log(123)";
+    document.head.appendChild(script);
+}
+
+function test()
+{
+    InspectorTest.startDebuggerTest(step1);
+
+    function step1()
+    {
+        InspectorTest.evaluateInPage("createScriptTag()");
+        WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, step2);
+    }
+
+    function step2(event)
+    {
+        var script = event.data;
+        script.requestContent(callback);
+        function callback(content)
+        {
+            if (content !== "console.log(123)")
+                return;
+            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);
+        }
+    }
+
+    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)
+        {
+            InspectorTest.addResult("UI content: " + content);
+            InspectorTest.completeDebuggerTest();
+        }
+    }
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>
+Tests that dynamically added script tag gets its own JavaScriptSource and is not bound to the resource.
+<a href="https://bugs.webkit.org/show_bug.cgi?id=87119">Bug 87119</a>
+</p>
+</body>
+
+</html>
index 8c7ed47..bbba9a7 100644 (file)
@@ -1,3 +1,24 @@
+2012-05-22  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: [regression] dynamically created script tab is bound to the document resource.
+        https://bugs.webkit.org/show_bug.cgi?id=87119
+
+        Reviewed by Vsevolod Vlasov.
+
+        Test: inspector/debugger/dynamic-script-tag.html
+
+        * inspector/front-end/BreakpointManager.js:
+        (WebInspector.BreakpointManager.Breakpoint.prototype._setInDebugger.didSetBreakpoint):
+        (WebInspector.BreakpointManager.Breakpoint.prototype._setInDebugger):
+        * inspector/front-end/DebuggerModel.js:
+        (WebInspector.DebuggerModel.prototype.rawLocationToUILocation):
+        * inspector/front-end/ResourceScriptMapping.js:
+        (WebInspector.ResourceScriptMapping.prototype.addScript):
+        (WebInspector.ResourceScriptMapping.prototype._shouldBindScriptToContentProvider):
+        * inspector/front-end/Script.js:
+        (WebInspector.Script.prototype.rawLocationToUILocation):
+        (WebInspector.Script.Location.prototype.update):
+
 2012-05-22  Vsevolod Vlasov  <vsevik@chromium.org>
 
         Web Inspector: JavaScript breakpoints disappear when Ctrl+S is pressed for the script without changes.
 2012-05-22  Vsevolod Vlasov  <vsevik@chromium.org>
 
         Web Inspector: JavaScript breakpoints disappear when Ctrl+S is pressed for the script without changes.
index 7646219..c425727 100644 (file)
@@ -381,7 +381,7 @@ WebInspector.BreakpointManager.Breakpoint.prototype = {
             this._resetLocations();
             for (var i = 0; i < locations.length; ++i) {
                 var script = this._breakpointManager._debuggerModel.scriptForId(locations[i].scriptId);
             this._resetLocations();
             for (var i = 0; i < locations.length; ++i) {
                 var script = this._breakpointManager._debuggerModel.scriptForId(locations[i].scriptId);
-                var uiLocation = script.rawLocationToUILocation(locations[i]);
+                var uiLocation = script.rawLocationToUILocation(locations[i].lineNumber, locations[i].columnNumber);
                 if (this._breakpointManager.findBreakpoint(uiLocation.uiSourceCode, uiLocation.lineNumber)) {
                     // location clash
                     this.remove();
                 if (this._breakpointManager.findBreakpoint(uiLocation.uiSourceCode, uiLocation.lineNumber)) {
                     // location clash
                     this.remove();
index d69cea1..c03b89a 100644 (file)
@@ -535,7 +535,7 @@ WebInspector.DebuggerModel.prototype = {
         var script = this._scripts[rawLocation.scriptId];
         if (!script)
             return null;
         var script = this._scripts[rawLocation.scriptId];
         if (!script)
             return null;
-        return script.rawLocationToUILocation(rawLocation);
+        return script.rawLocationToUILocation(rawLocation.lineNumber, rawLocation.columnNumber);
     }
 }
 
     }
 }
 
index 1e4dcd6..95debaa 100644 (file)
@@ -93,9 +93,15 @@ WebInspector.ResourceScriptMapping.prototype = {
             // Ignore resource in case it has not yet finished loading.
             if (resource && resource.request && !resource.request.finished)
                 resource = null;
             // Ignore resource in case it has not yet finished loading.
             if (resource && resource.request && !resource.request.finished)
                 resource = null;
+            // Only bind inline and standalone scripts.
+            if (resource && !this._shouldBindScriptToContentProvider(script, resource))
+                resource = null;
             if (!resource) {
                 // When there is no resource, lookup in-flight requests.
                 request = WebInspector.networkManager.inflightRequestForURL(script.sourceURL);
             if (!resource) {
                 // When there is no resource, lookup in-flight requests.
                 request = WebInspector.networkManager.inflightRequestForURL(script.sourceURL);
+                // Only bind inline and standalone scripts.
+                if (request && !this._shouldBindScriptToContentProvider(script, request))
+                  request = null;
             }
         }
         console.assert(!resource || !request);
             }
         }
         console.assert(!resource || !request);
@@ -123,6 +129,18 @@ WebInspector.ResourceScriptMapping.prototype = {
     },
 
     /**
     },
 
     /**
+     * @param {WebInspector.Script} script
+     * @param {WebInspector.ContentProvider} contentProvider
+     * @return {boolean}
+     */
+    _shouldBindScriptToContentProvider: function(script, contentProvider)
+    {
+        if (script.isInlineScript())
+            return contentProvider.contentType() === WebInspector.resourceTypes.Document;
+        return contentProvider.contentType() === WebInspector.resourceTypes.Script;
+    },
+
+    /**
      * @param {WebInspector.Event} event
      */
     _handleUISourceCodeChanged: function(event)
      * @param {WebInspector.Event} event
      */
     _handleUISourceCodeChanged: function(event)
index f8ba4d5..4372004 100644 (file)
@@ -167,13 +167,13 @@ WebInspector.Script.prototype = {
     },
 
     /**
     },
 
     /**
-     * @param {DebuggerAgent.Location} rawLocation
+     * @param {number} lineNumber
+     * @param {number=} columnNumber
      * @return {WebInspector.UILocation}
      */
      * @return {WebInspector.UILocation}
      */
-    rawLocationToUILocation: function(rawLocation)
+    rawLocationToUILocation: function(lineNumber, columnNumber)
     {
     {
-        console.assert(rawLocation.scriptId === this.scriptId);
-        var uiLocation = this._sourceMapping.rawLocationToUILocation(rawLocation);
+        var uiLocation = this._sourceMapping.rawLocationToUILocation(new WebInspector.DebuggerModel.Location(this, lineNumber, columnNumber || 0));
         return uiLocation.uiSourceCode.overrideLocation(uiLocation);
     },
 
         return uiLocation.uiSourceCode.overrideLocation(uiLocation);
     },
 
@@ -219,7 +219,7 @@ WebInspector.Script.Location = function(script, rawLocation, updateDelegate)
 WebInspector.Script.Location.prototype = {
     update: function()
     {
 WebInspector.Script.Location.prototype = {
     update: function()
     {
-        var uiLocation = this._script.rawLocationToUILocation(this._rawLocation);
+        var uiLocation = this._script.rawLocationToUILocation(this._rawLocation.lineNumber, this._rawLocation.columnNumber);
         if (uiLocation) {
             var uiSourceCode = uiLocation.uiSourceCode;
             if (this._uiSourceCodes.indexOf(uiSourceCode) === -1) {
         if (uiLocation) {
             var uiSourceCode = uiLocation.uiSourceCode;
             if (this._uiSourceCodes.indexOf(uiSourceCode) === -1) {