Title: [93415] trunk
Revision
93415
Author
podivi...@chromium.org
Date
2011-08-19 08:50:19 -0700 (Fri, 19 Aug 2011)

Log Message

Web Inspector: extract breakpoint management code to a separate class and add tests.
https://bugs.webkit.org/show_bug.cgi?id=66224

Reviewed by Pavel Feldman.

Source/WebCore:

Test: inspector/debugger/breakpoint-manager.html

* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* inspector/front-end/BreakpointManager.js: Added.
(WebInspector.BreakpointManager):
(WebInspector.BreakpointManager.prototype.uiSourceCodeAdded):
(WebInspector.BreakpointManager.prototype.breakpointsForUISourceCode):
(WebInspector.BreakpointManager.prototype.setBreakpoint):
(WebInspector.BreakpointManager.prototype.removeBreakpoint):
(WebInspector.BreakpointManager.prototype._materializeBreakpoint):
(WebInspector.BreakpointManager.prototype._breakpointDebuggerLocationChanged):
(WebInspector.BreakpointManager.prototype._addBreakpointToUI):
(WebInspector.BreakpointManager.prototype._deleteBreakpointFromUI):
(WebInspector.BreakpointManager.prototype._moveBreakpointInUI):
(WebInspector.BreakpointManager.prototype._breakpoints):
(WebInspector.BreakpointManager.prototype._breakpoint):
(WebInspector.BreakpointManager.prototype._forEachBreakpoint):
(WebInspector.BreakpointManager.prototype._setBreakpointInDebugger):
(WebInspector.BreakpointManager.prototype._removeBreakpointFromDebugger):
(WebInspector.BreakpointManager.prototype._breakpointResolved):
(WebInspector.BreakpointManager.prototype.serializeBreakpoints):
(WebInspector.BreakpointManager.prototype.reset):
(WebInspector.BreakpointManager.prototype.debuggerReset):
(WebInspector.Breakpoint):
(WebInspector.Breakpoint.prototype.serialize):
(WebInspector.Breakpoint.deserialize):
* inspector/front-end/DebuggerModel.js:
(WebInspector.DebuggerModel.prototype.setBreakpointByScriptLocation):
* inspector/front-end/SourceFile.js:
(WebInspector.RawSourceCode.prototype.get rawSourceCode):
* inspector/front-end/WebKit.qrc:
* inspector/front-end/inspector.html:

LayoutTests:

* inspector/debugger/breakpoint-manager-expected.txt: Added.
* inspector/debugger/breakpoint-manager.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (93414 => 93415)


--- trunk/LayoutTests/ChangeLog	2011-08-19 15:39:55 UTC (rev 93414)
+++ trunk/LayoutTests/ChangeLog	2011-08-19 15:50:19 UTC (rev 93415)
@@ -1,3 +1,13 @@
+2011-08-18  Pavel Podivilov  <podivi...@chromium.org>
+
+        Web Inspector: extract breakpoint management code to a separate class and add tests.
+        https://bugs.webkit.org/show_bug.cgi?id=66224
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/debugger/breakpoint-manager-expected.txt: Added.
+        * inspector/debugger/breakpoint-manager.html: Added.
+
 2011-08-19  Vitaly Repeshko  <vita...@chromium.org>
 
         [chromium] Updating test expectations.

Added: trunk/LayoutTests/inspector/debugger/breakpoint-manager-expected.txt (0 => 93415)


--- trunk/LayoutTests/inspector/debugger/breakpoint-manager-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/breakpoint-manager-expected.txt	2011-08-19 15:50:19 UTC (rev 93415)
@@ -0,0 +1,64 @@
+Tests BreakpointManager class.
+
+
+Running: uiSourceCodeAdded
+breakpointAdded(a.js, 10, foo == bar, true)
+breakpointAdded(a.js, 20, , false)
+breakpointAdded(b.js, 3, , true)
+debuggerModel.setBreakpoint(a.js:10:0)
+
+Running: setAndRemoveBreakpoints
+breakpointAdded(a.js, 10, foo == bar, true)
+breakpointAdded(a.js, 20, , false)
+breakpointAdded(b.js, 3, , true)
+debuggerModel.setBreakpoint(a.js:10:0)
+breakpointAdded(a.js, 30, , true)
+debuggerModel.setBreakpoint(a.js:30:0)
+breakpointRemoved(a.js, 30)
+breakpointRemoved(a.js, 10)
+debuggerModel.removeBreakpoint(a.js:10:0)
+breakpointRemoved(a.js, 20)
+debuggerModel.removeBreakpoint(a.js:30:0)
+
+Running: setBreakpointOnComment
+breakpointAdded(a.js, 15, , true)
+debuggerModel.setBreakpoint(a.js:15:0)
+breakpointRemoved(a.js, 15)
+breakpointAdded(a.js, 16, , true)
+
+Running: setBreakpointOutsideOfScript
+breakpointAdded(a.js, 15, , true)
+debuggerModel.setBreakpoint(a.js:15:0)
+
+Running: testNavigation
+breakpointAdded(a.js, 10, foo == bar, true)
+breakpointAdded(a.js, 20, , false)
+breakpointAdded(b.js, 3, , true)
+debuggerModel.setBreakpoint(a.js:10:0)
+
+Navigate to B.
+debuggerModel.setBreakpoint(b.js:3:0)
+
+Navigate back to A.
+breakpointRemoved(a.js, 10)
+breakpointAdded(a.js, 11, foo == bar, true)
+
+Running: testFormatting
+breakpointAdded(c.js, 4, , true)
+debuggerModel.setBreakpoint(c.js:4:0)
+
+Format source.
+debuggerModel.removeBreakpoint(c.js:4:0)
+breakpointAdded(deobfuscated:c.js, 4, , true)
+debuggerModel.setBreakpoint(c.js:2:0)
+breakpointAdded(deobfuscated:c.js, 8, , false)
+
+Change breakpoints.
+breakpointRemoved(deobfuscated:c.js, 8)
+breakpointAdded(deobfuscated:c.js, 12, , true)
+debuggerModel.setBreakpoint(c.js:6:0)
+
+Reload.
+breakpointRemoved(deobfuscated:c.js, 4)
+breakpointAdded(deobfuscated:c.js, 6, , true)
+
Property changes on: trunk/LayoutTests/inspector/debugger/breakpoint-manager-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/debugger/breakpoint-manager.html (0 => 93415)


--- trunk/LayoutTests/inspector/debugger/breakpoint-manager.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/breakpoint-manager.html	2011-08-19 15:50:19 UTC (rev 93415)
@@ -0,0 +1,298 @@
+<html>
+<head>
+<script src=""
+
+<script>
+
+function test()
+{
+    var persistentBreakpoints = [];
+    var breakpointStorage = {
+        get: function() { return persistentBreakpoints; },
+        set: function(breakpoints) { persistentBreakpoints = breakpoints; }
+    };
+
+    var uiBreakpoints = {};
+    function breakpointAdded(uiSourceCodeId, lineNumber, condition, enabled)
+    {
+        InspectorTest.addResult("breakpointAdded(" + Array.prototype.join.call(arguments, ", ") + ")");
+        var breakpointId = uiSourceCodeId + ":" + lineNumber;
+        InspectorTest.assertTrue(!(breakpointId in uiBreakpoints));
+        uiBreakpoints[breakpointId] = condition + "|" + enabled;
+    }
+    function breakpointRemoved(uiSourceCodeId, lineNumber)
+    {
+        InspectorTest.addResult("breakpointRemoved(" + Array.prototype.join.call(arguments, ", ") + ")");
+        var breakpointId = uiSourceCodeId + ":" + lineNumber;
+        InspectorTest.assertTrue(breakpointId in uiBreakpoints);
+        delete uiBreakpoints[breakpointId];
+    }
+
+    var debuggerBreakpoints = {};
+    var debuggerModel = {
+        setBreakpointByScriptLocation: function(location, condition, callback)
+        {
+            var breakpointId = location.scriptId + ":" + location.lineNumber + ":" + location.columnNumber;
+            InspectorTest.addResult("debuggerModel.setBreakpoint(" + breakpointId + ")");
+            InspectorTest.assertTrue(!(breakpointId in debuggerBreakpoints));
+            debuggerBreakpoints[breakpointId] = condition;
+            var locations = debuggerModel.actualLocations ? debuggerModel.actualLocations : [location];
+            delete debuggerModel.actualLocations;
+            setTimeout(function() { callback(breakpointId, locations); }, 0);
+        },
+        removeBreakpoint: function(breakpointId)
+        {
+            InspectorTest.addResult("debuggerModel.removeBreakpoint(" + breakpointId + ")");
+            InspectorTest.assertTrue(breakpointId in debuggerBreakpoints);
+            delete debuggerBreakpoints[breakpointId];
+        }
+    };
+    debuggerModel.__proto__ = WebInspector.Object.prototype;
+
+    function createBreakpoint(uiSourceCodeId, lineNumber, condition, enabled)
+    {
+        return { sourceFileId: uiSourceCodeId, lineNumber: lineNumber, condition: condition, enabled: enabled };
+    }
+    var serializedBreakpoints = [];
+    serializedBreakpoints.push(createBreakpoint("a.js", 10, "foo == bar", true));
+    serializedBreakpoints.push(createBreakpoint("a.js", 20, "", false));
+    serializedBreakpoints.push(createBreakpoint("b.js", 3, "", true));
+
+    var uiSourceCodeA = {
+        id: "a.js",
+        url: "a.js",
+        rawSourceCode: {
+            rawLocationToUILocation: function(rawLocation) { return rawLocation; },
+            uiLocationToRawLocation: function(lineNumber, columnNumber) { return { scriptId: "a.js", lineNumber: lineNumber, columnNumber: columnNumber }; }
+        }
+    };
+    var uiSourceCodeB = {
+        id: "b.js",
+        url: "b.js",
+        rawSourceCode: {
+            rawLocationToUILocation: function(rawLocation) { return rawLocation; },
+            uiLocationToRawLocation: function(lineNumber, columnNumber) { return { scriptId: "b.js", lineNumber: lineNumber, columnNumber: columnNumber }; }
+        }
+    }
+
+    function createBreakpointManager(breakpoints)
+    {
+        breakpointStorage.set(breakpoints);
+        uiBreakpoints = {};
+        debuggerBreakpoints = {};
+        debuggerModel.removeAllListeners();
+        return new WebInspector.BreakpointManager(breakpointStorage, breakpointAdded, breakpointRemoved, debuggerModel);
+    }
+
+    InspectorTest.runTestSuite([
+        function uiSourceCodeAdded(next)
+        {
+            var breakpointManager = createBreakpointManager(serializedBreakpoints);
+
+            breakpointManager.uiSourceCodeAdded(uiSourceCodeA);
+            setTimeout(checkResults, 0);
+
+            function checkResults()
+            {
+                assertEquals({"a.js:10":"foo == bar|true","a.js:20":"|false","b.js:3":"|true"}, uiBreakpoints);
+                assertEquals({"a.js:10:0": "foo == bar"}, debuggerBreakpoints);
+                next();
+            }
+        },
+
+        function setAndRemoveBreakpoints(next)
+        {
+            var breakpointManager = createBreakpointManager(serializedBreakpoints);
+
+            breakpointManager.uiSourceCodeAdded(uiSourceCodeA);
+            setTimeout(setAndRemove, 0);
+
+            function setAndRemove()
+            {
+                breakpointManager.setBreakpoint(uiSourceCodeA, 30, "", true);
+                // Remove breakpoint immediately, breakpoint should be removed correctly from both debugger model and UI.
+                breakpointManager.removeBreakpoint(uiSourceCodeA.id, 30);
+
+                breakpointManager.removeBreakpoint(uiSourceCodeA.id, 10);
+                breakpointManager.removeBreakpoint(uiSourceCodeA.id, 20);
+                setTimeout(checkResults, 0);
+            }
+
+            function checkResults()
+            {
+                assertEquals({}, debuggerBreakpoints);
+                checkBreakpointStorage([{"sourceFileId":"b.js","lineNumber":3,"condition":"","enabled":true}]);
+                next();
+            }
+        },
+
+        function setBreakpointOnComment(next)
+        {
+            var breakpointManager = createBreakpointManager([]);
+
+            breakpointManager.uiSourceCodeAdded(uiSourceCodeA);
+
+            debuggerModel.actualLocations = [{ lineNumber: 16, columnNumber: 0 }];
+            breakpointManager.setBreakpoint(uiSourceCodeA, 15, "", true);
+            setTimeout(checkResults, 0);
+            function checkResults()
+            {
+                checkBreakpointStorage([{"sourceFileId":"a.js","lineNumber":16,"condition":"","enabled":true}]);
+                next();
+            }
+        },
+
+        function setBreakpointOutsideOfScript(next)
+        {
+            var breakpointManager = createBreakpointManager([]);
+
+            breakpointManager.uiSourceCodeAdded(uiSourceCodeA);
+
+            debuggerModel.actualLocations = [];
+            breakpointManager.setBreakpoint(uiSourceCodeA, 15, "", true);
+            setTimeout(checkResults, 0);
+            function checkResults()
+            {
+                checkBreakpointStorage([{"sourceFileId":"a.js","lineNumber":15,"condition":"","enabled":true}]);
+                next();
+            }
+        },
+
+        function testNavigation(next)
+        {
+            var breakpointManager = createBreakpointManager(serializedBreakpoints);
+
+            breakpointManager.uiSourceCodeAdded(uiSourceCodeA);
+            setTimeout(navigateToB, 0);
+
+            function navigateToB()
+            {
+                assertEquals({"a.js:10:0":"foo == bar"}, debuggerBreakpoints);
+
+                InspectorTest.addResult("\nNavigate to B.");
+                breakpointManager.debuggerReset();
+
+                breakpointManager.uiSourceCodeAdded(uiSourceCodeB);
+                setTimeout(navigateToA, 0);
+            }
+
+            function navigateToA()
+            {
+                assertEquals({"a.js:10":"foo == bar|true","a.js:20":"|false","b.js:3":"|true"}, uiBreakpoints);
+                assertEquals({"a.js:10:0":"foo == bar","b.js:3:0":""}, debuggerBreakpoints);
+
+                InspectorTest.addResult("\nNavigate back to A.");
+                breakpointManager.debuggerReset();
+
+                var eventData = { breakpointId: "a.js:10:0", location: { scriptId: "a.js", lineNumber: 11, columnNumber: 5 }};
+                debuggerModel.dispatchEventToListeners(WebInspector.DebuggerModel.Events.BreakpointResolved, eventData);
+                breakpointManager.uiSourceCodeAdded(uiSourceCodeA);
+                setTimeout(checkResults, 0);
+            }
+
+            function checkResults()
+            {
+                assertEquals({"a.js:20":"|false","b.js:3":"|true","a.js:11":"foo == bar|true"}, uiBreakpoints);
+                assertEquals({"a.js:10:0":"foo == bar","b.js:3:0":""}, debuggerBreakpoints);
+                checkBreakpointStorage([{"sourceFileId":"a.js","lineNumber":11,"condition":"foo == bar","enabled":true},
+                                        {"sourceFileId":"a.js","lineNumber":20,"condition":"","enabled":false},
+                                        {"sourceFileId":"b.js","lineNumber":3,"condition":"","enabled":true}]);
+                next();
+            }
+        },
+
+        function testFormatting(next)
+        {
+            var breakpointManager = createBreakpointManager([createBreakpoint("c.js", 4, "", true)]);
+
+            var uiSourceCodeC = {
+                id: "c.js",
+                url: "c.js",
+                rawSourceCode: {
+                    rawLocationToUILocation: function(rawLocation) { return rawLocation; },
+                    uiLocationToRawLocation: function(lineNumber, columnNumber) { return { scriptId: "c.js", lineNumber: lineNumber, columnNumber: columnNumber }; }
+                }
+            };
+            var uiSourceCodeCFormatted = {
+                id: "deobfuscated:c.js",
+                url: "c.js",
+                rawSourceCode: {
+                    rawLocationToUILocation: function(rawLocation) { return { lineNumber: rawLocation.lineNumber * 2, columnNumber: rawLocation.columnNumber * 2 }; },
+                    uiLocationToRawLocation: function(lineNumber, columnNumber) { return { scriptId: "c.js", lineNumber: Math.floor(lineNumber / 2), columnNumber: Math.floor(columnNumber / 2) }; }
+                }
+            }
+
+            breakpointManager.uiSourceCodeAdded(uiSourceCodeC);
+            setTimeout(format, 0);
+
+            function format()
+            {
+                assertEquals({"c.js:4:0":""}, debuggerBreakpoints);
+                checkBreakpointStorage([{"sourceFileId":"c.js","lineNumber":4,"condition":"","enabled":true}]);
+
+                InspectorTest.addResult("\nFormat source.");
+                breakpointManager.reset();
+
+                breakpointManager.uiSourceCodeAdded(uiSourceCodeCFormatted);
+                breakpointManager.setBreakpoint(uiSourceCodeCFormatted, 4, "", true);
+                breakpointManager.setBreakpoint(uiSourceCodeCFormatted, 8, "", false);
+                setTimeout(changeBreakpoints, 0);
+            }
+
+            function changeBreakpoints()
+            {
+                assertEquals({"c.js:2:0":""}, debuggerBreakpoints);
+
+                InspectorTest.addResult("\nChange breakpoints.");
+                breakpointManager.removeBreakpoint(uiSourceCodeCFormatted.id, 8);
+                breakpointManager.setBreakpoint(uiSourceCodeCFormatted, 12, "", true);
+                setTimeout(reload, 0);
+            }
+
+            function reload()
+            {
+                assertEquals({"c.js:2:0":"","c.js:6:0":""}, debuggerBreakpoints);
+
+                InspectorTest.addResult("\nReload.");
+                breakpointManager.debuggerReset();
+
+                breakpointManager.uiSourceCodeAdded(uiSourceCodeCFormatted);
+                var eventData = { breakpointId: "c.js:2:0", location: { scriptId: "c.js", lineNumber: 3, columnNumber: 0 }};
+                debuggerModel.dispatchEventToListeners(WebInspector.DebuggerModel.Events.BreakpointResolved, eventData);
+                eventData = { breakpointId: "c.js:6:0", location: { scriptId: "c.js", lineNumber: 6, columnNumber: 0 }};
+                debuggerModel.dispatchEventToListeners(WebInspector.DebuggerModel.Events.BreakpointResolved, eventData);
+                setTimeout(checkResults, 0);
+            }
+
+            function checkResults()
+            {
+                assertEquals({"c.js:2:0":"","c.js:6:0":""}, debuggerBreakpoints);
+                next();
+            }
+        }
+    ]);
+
+    function checkBreakpointStorage(breakpoints)
+    {
+        InspectorTest.assertEquals(JSON.stringify(breakpoints), JSON.stringify(persistentBreakpoints));
+    }
+
+    function assertEquals(expected, actual)
+    {
+        var errorMessage = "Expected: " + JSON.stringify(expected) + ", actual: " + JSON.stringify(actual) + ".";
+        for (var p in expected)
+            InspectorTest.assertTrue(p in actual, errorMessage + " <" + p + "> not in actual");
+        for (var p in actual)
+            InspectorTest.assertTrue(p in expected, errorMessage + " <" + p + "> not in expected");
+    }
+};
+
+</script>
+
+</head>
+
+<body _onload_="runTest()">
+<p>Tests BreakpointManager class.</p>
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/debugger/breakpoint-manager.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (93414 => 93415)


--- trunk/Source/WebCore/ChangeLog	2011-08-19 15:39:55 UTC (rev 93414)
+++ trunk/Source/WebCore/ChangeLog	2011-08-19 15:50:19 UTC (rev 93415)
@@ -1,3 +1,44 @@
+2011-08-18  Pavel Podivilov  <podivi...@chromium.org>
+
+        Web Inspector: extract breakpoint management code to a separate class and add tests.
+        https://bugs.webkit.org/show_bug.cgi?id=66224
+
+        Reviewed by Pavel Feldman.
+
+        Test: inspector/debugger/breakpoint-manager.html
+
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * inspector/front-end/BreakpointManager.js: Added.
+        (WebInspector.BreakpointManager):
+        (WebInspector.BreakpointManager.prototype.uiSourceCodeAdded):
+        (WebInspector.BreakpointManager.prototype.breakpointsForUISourceCode):
+        (WebInspector.BreakpointManager.prototype.setBreakpoint):
+        (WebInspector.BreakpointManager.prototype.removeBreakpoint):
+        (WebInspector.BreakpointManager.prototype._materializeBreakpoint):
+        (WebInspector.BreakpointManager.prototype._breakpointDebuggerLocationChanged):
+        (WebInspector.BreakpointManager.prototype._addBreakpointToUI):
+        (WebInspector.BreakpointManager.prototype._deleteBreakpointFromUI):
+        (WebInspector.BreakpointManager.prototype._moveBreakpointInUI):
+        (WebInspector.BreakpointManager.prototype._breakpoints):
+        (WebInspector.BreakpointManager.prototype._breakpoint):
+        (WebInspector.BreakpointManager.prototype._forEachBreakpoint):
+        (WebInspector.BreakpointManager.prototype._setBreakpointInDebugger):
+        (WebInspector.BreakpointManager.prototype._removeBreakpointFromDebugger):
+        (WebInspector.BreakpointManager.prototype._breakpointResolved):
+        (WebInspector.BreakpointManager.prototype.serializeBreakpoints):
+        (WebInspector.BreakpointManager.prototype.reset):
+        (WebInspector.BreakpointManager.prototype.debuggerReset):
+        (WebInspector.Breakpoint):
+        (WebInspector.Breakpoint.prototype.serialize):
+        (WebInspector.Breakpoint.deserialize):
+        * inspector/front-end/DebuggerModel.js:
+        (WebInspector.DebuggerModel.prototype.setBreakpointByScriptLocation):
+        * inspector/front-end/SourceFile.js:
+        (WebInspector.RawSourceCode.prototype.get rawSourceCode):
+        * inspector/front-end/WebKit.qrc:
+        * inspector/front-end/inspector.html:
+
 2011-08-19  Adam Roben  <aro...@apple.com>
 
         Fix typo

Modified: trunk/Source/WebCore/WebCore.gypi (93414 => 93415)


--- trunk/Source/WebCore/WebCore.gypi	2011-08-19 15:39:55 UTC (rev 93414)
+++ trunk/Source/WebCore/WebCore.gypi	2011-08-19 15:50:19 UTC (rev 93415)
@@ -6330,6 +6330,7 @@
             'inspector/front-end/AuditsPanel.js',
             'inspector/front-end/BinarySearch.js',
             'inspector/front-end/BottomUpProfileDataGridTree.js',
+            'inspector/front-end/BreakpointManager.js',
             'inspector/front-end/BreakpointsSidebarPane.js',
             'inspector/front-end/CallStackSidebarPane.js',
             'inspector/front-end/Checkbox.js',

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (93414 => 93415)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-08-19 15:39:55 UTC (rev 93414)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-08-19 15:50:19 UTC (rev 93415)
@@ -68737,6 +68737,10 @@
 					>
 				</File>
 				<File
+					RelativePath="..\inspector\front-end\BreakpointManager.js"
+					>
+				</File>
+				<File
 					RelativePath="..\inspector\front-end\BreakpointsSidebarPane.js"
 					>
 				</File>

Added: trunk/Source/WebCore/inspector/front-end/BreakpointManager.js (0 => 93415)


--- trunk/Source/WebCore/inspector/front-end/BreakpointManager.js	                        (rev 0)
+++ trunk/Source/WebCore/inspector/front-end/BreakpointManager.js	2011-08-19 15:50:19 UTC (rev 93415)
@@ -0,0 +1,264 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.BreakpointManager = function(breakpointStorage, breakpointAddedDelegate, breakpointRemovedDelegate, debuggerModel)
+{
+    this._breakpointStorage = breakpointStorage;
+    this._breakpointAddedDelegate = breakpointAddedDelegate;
+    this._breakpointRemovedDelegate = breakpointRemovedDelegate;
+    this._breakpointsByUILocation = {};
+
+    this._debuggerModel = debuggerModel;
+    this._breakpointsByDebuggerId = {};
+    this._debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointResolved, this._breakpointResolved, this);
+
+    var breakpoints = this._breakpointStorage.get();
+    for (var i = 0; i < breakpoints.length; ++i) {
+        var breakpoint = WebInspector.Breakpoint.deserialize(breakpoints[i]);
+        if (!this._breakpoint(breakpoint.uiSourceCodeId, breakpoint.lineNumber))
+            this._addBreakpointToUI(breakpoint);
+    }
+}
+
+WebInspector.BreakpointManager.prototype = {
+    uiSourceCodeAdded: function(uiSourceCode)
+    {
+        var breakpoints = this._breakpoints(uiSourceCode.id);
+        for (var lineNumber in breakpoints) {
+            var breakpoint = breakpoints[lineNumber];
+            this._materializeBreakpoint(breakpoint, uiSourceCode);
+            if (breakpoint._debuggerLocation)
+                this._breakpointDebuggerLocationChanged(breakpoint, breakpoint._debuggerLocation);
+        }
+    },
+
+    breakpointsForUISourceCode: function(uiSourceCodeId)
+    {
+        return this._breakpoints(uiSourceCodeId);
+    },
+
+    setBreakpoint: function(uiSourceCode, lineNumber, condition, enabled)
+    {
+        if (this._breakpoint(uiSourceCode.id, lineNumber))
+            return;
+
+        var persistent = !!uiSourceCode.url;
+        var breakpoint = new WebInspector.Breakpoint(uiSourceCode.id, lineNumber, condition, enabled, persistent);
+        this._addBreakpointToUI(breakpoint);
+        this._materializeBreakpoint(breakpoint, uiSourceCode);
+    },
+
+    removeBreakpoint: function(uiSourceCodeId, lineNumber)
+    {
+        var breakpoint = this._breakpoint(uiSourceCodeId, lineNumber);
+        if (!breakpoint)
+            return;
+        this._deleteBreakpointFromUI(breakpoint);
+        this._removeBreakpointFromDebugger(breakpoint);
+    },
+
+    _materializeBreakpoint: function(breakpoint, uiSourceCode)
+    {
+        breakpoint._uiSourceCode = uiSourceCode;
+        if (!breakpoint.enabled || breakpoint._debuggerId)
+            return;
+
+        var rawLocation = uiSourceCode.rawSourceCode.uiLocationToRawLocation(breakpoint.lineNumber, 0);
+        this._setBreakpointInDebugger(breakpoint, rawLocation);
+    },
+
+    _breakpointDebuggerLocationChanged: function(breakpoint)
+    {
+        if (!breakpoint._uiSourceCode)
+            return;
+        var uiLocation = breakpoint._uiSourceCode.rawSourceCode.rawLocationToUILocation(breakpoint._debuggerLocation);
+        if (uiLocation.lineNumber === breakpoint.lineNumber)
+            return;
+
+        if (!this._moveBreakpointInUI(breakpoint, uiLocation.lineNumber))
+            this._removeBreakpointFromDebugger(breakpoint);
+    },
+
+    _addBreakpointToUI: function(breakpoint)
+    {
+        console.assert(!this._breakpoint(breakpoint.uiSourceCodeId, breakpoint.lineNumber));
+        this._breakpoints(breakpoint.uiSourceCodeId)[breakpoint.lineNumber] = breakpoint;
+        this._saveBreakpoints();
+        this._breakpointAddedDelegate(breakpoint.uiSourceCodeId, breakpoint.lineNumber, breakpoint.condition, breakpoint.enabled);
+    },
+
+    _deleteBreakpointFromUI: function(breakpoint)
+    {
+        console.assert(this._breakpoint(breakpoint.uiSourceCodeId, breakpoint.lineNumber) === breakpoint);
+        delete this._breakpoints(breakpoint.uiSourceCodeId)[breakpoint.lineNumber];
+        this._saveBreakpoints();
+        this._breakpointRemovedDelegate(breakpoint.uiSourceCodeId, breakpoint.lineNumber);
+    },
+
+    _moveBreakpointInUI: function(breakpoint, lineNumber)
+    {
+        this._deleteBreakpointFromUI(breakpoint);
+        if (this._breakpoint(breakpoint.uiSourceCodeId, lineNumber))
+            return false;
+        breakpoint.lineNumber = lineNumber;
+        this._addBreakpointToUI(breakpoint);
+        return true;
+    },
+
+    _breakpoints: function(uiSourceCodeId)
+    {
+        if (!this._breakpointsByUILocation[uiSourceCodeId])
+            this._breakpointsByUILocation[uiSourceCodeId] = {};
+        return this._breakpointsByUILocation[uiSourceCodeId];
+    },
+
+    _breakpoint: function(uiSourceCodeId, lineNumber)
+    {
+        return this._breakpoints(uiSourceCodeId)[lineNumber];
+    },
+
+    _forEachBreakpoint: function(handler)
+    {
+        for (var uiSourceCodeId in this._breakpointsByUILocation) {
+            var breakpoints = this._breakpointsByUILocation[uiSourceCodeId];
+            for (var lineNumber in breakpoints)
+                handler(breakpoints[lineNumber]);
+        }
+    },
+
+    _setBreakpointInDebugger: function(breakpoint, rawLocation)
+    {
+        function didSetBreakpoint(breakpointId, locations)
+        {
+            if (breakpoint === this._breakpoint(breakpoint.uiSourceCodeId, breakpoint.lineNumber)) {
+                if (!breakpointId) {
+                    this._deleteBreakpointFromUI(breakpoint);
+                    return;
+                }
+            } else {
+                if (breakpointId)
+                    this._debuggerModel.removeBreakpoint(breakpointId);
+                return;
+            }
+
+            this._breakpointsByDebuggerId[breakpointId] = breakpoint;
+            breakpoint._debuggerId = breakpointId;
+            breakpoint._debuggerLocation = locations[0];
+            if (breakpoint._debuggerLocation)
+                this._breakpointDebuggerLocationChanged(breakpoint);
+        }
+        this._debuggerModel.setBreakpointByScriptLocation(rawLocation, breakpoint.condition, didSetBreakpoint.bind(this));
+    },
+
+    _removeBreakpointFromDebugger: function(breakpoint)
+    {
+        if (!("_debuggerId" in breakpoint))
+            return;
+        this._debuggerModel.removeBreakpoint(breakpoint._debuggerId);
+        delete this._breakpointsByDebuggerId[breakpoint._debuggerId];
+        delete breakpoint._debuggerId;
+        delete breakpoint._debuggerLocation;
+    },
+
+    _breakpointResolved: function(event)
+    {
+        var breakpoint = this._breakpointsByDebuggerId[event.data.breakpointId];
+        breakpoint._debuggerLocation = event.data.location;
+        this._breakpointDebuggerLocationChanged(breakpoint);
+    },
+
+    _saveBreakpoints: function()
+    {
+        var serializedBreakpoints = [];
+        function serializePersistent(breakpoint)
+        {
+            if (breakpoint.persistent)
+                serializedBreakpoints.push(breakpoint.serialize());
+        }
+        this._forEachBreakpoint(serializePersistent.bind(this));
+        this._breakpointStorage.set(serializedBreakpoints);
+    },
+
+    reset: function()
+    {
+        function resetBreakpoint(breakpoint)
+        {
+            delete breakpoint._uiSourceCode;
+            this._removeBreakpointFromDebugger(breakpoint);
+        }
+        this._forEachBreakpoint(resetBreakpoint.bind(this));
+    },
+
+    debuggerReset: function()
+    {
+        function resetOrDeleteBreakpoint(breakpoint)
+        {
+            if (breakpoint.persistent) {
+                delete breakpoint._uiSourceCode;
+                delete breakpoint._debuggerLocation;
+            } else {
+                this._deleteBreakpointFromUI(breakpoint);
+                delete this._breakpointsByDebuggerId[breakpoint._debuggerId];
+            }
+        }
+        this._forEachBreakpoint(resetOrDeleteBreakpoint.bind(this));
+    }
+}
+
+WebInspector.Breakpoint = function(uiSourceCodeId, lineNumber, condition, enabled, persistent)
+{
+    this.uiSourceCodeId = uiSourceCodeId;
+    this.lineNumber = lineNumber;
+    this.condition = condition;
+    this.enabled = enabled;
+    this.persistent = persistent;
+}
+
+WebInspector.Breakpoint.prototype = {
+    serialize: function()
+    {
+        var serializedBreakpoint = {};
+        serializedBreakpoint.sourceFileId = this.uiSourceCodeId;
+        serializedBreakpoint.lineNumber = this.lineNumber;
+        serializedBreakpoint.condition = this.condition;
+        serializedBreakpoint.enabled = this.enabled;
+        return serializedBreakpoint;
+    }
+}
+
+WebInspector.Breakpoint.deserialize = function(serializedBreakpoint)
+{
+    return new WebInspector.Breakpoint(
+            serializedBreakpoint.sourceFileId,
+            serializedBreakpoint.lineNumber,
+            serializedBreakpoint.condition,
+            serializedBreakpoint.enabled,
+            true);
+}
Property changes on: trunk/Source/WebCore/inspector/front-end/BreakpointManager.js
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/inspector/front-end/DebuggerModel.js (93414 => 93415)


--- trunk/Source/WebCore/inspector/front-end/DebuggerModel.js	2011-08-19 15:39:55 UTC (rev 93414)
+++ trunk/Source/WebCore/inspector/front-end/DebuggerModel.js	2011-08-19 15:50:19 UTC (rev 93415)
@@ -73,6 +73,15 @@
         DebuggerAgent.continueToLocation(location);
     },
 
+    setBreakpointByScriptLocation: function(location, condition, callback)
+    {
+        var script = this.scriptForSourceID(location.scriptId);
+        if (script.sourceURL)
+            this.setBreakpoint(script.sourceURL, location.lineNumber, location.columnNumber, condition, callback);
+        else
+            this.setBreakpointBySourceId(location, condition, callback);
+    },
+
     setBreakpoint: function(url, lineNumber, columnNumber, condition, callback)
     {
         // Adjust column if needed.

Modified: trunk/Source/WebCore/inspector/front-end/SourceFile.js (93414 => 93415)


--- trunk/Source/WebCore/inspector/front-end/SourceFile.js	2011-08-19 15:39:55 UTC (rev 93414)
+++ trunk/Source/WebCore/inspector/front-end/SourceFile.js	2011-08-19 15:50:19 UTC (rev 93415)
@@ -66,6 +66,12 @@
         return this;
     },
 
+    get rawSourceCode()
+    {
+        // FIXME: extract UISourceCode from RawSourceCode (currently RawSourceCode implements methods from both interfaces).
+        return this;
+    },
+
     rawLocationToUILocation: function(rawLocation)
     {
         var uiLocation = this._mapping ? this._mapping.originalToFormatted(rawLocation) : rawLocation;

Modified: trunk/Source/WebCore/inspector/front-end/WebKit.qrc (93414 => 93415)


--- trunk/Source/WebCore/inspector/front-end/WebKit.qrc	2011-08-19 15:39:55 UTC (rev 93414)
+++ trunk/Source/WebCore/inspector/front-end/WebKit.qrc	2011-08-19 15:50:19 UTC (rev 93415)
@@ -10,6 +10,7 @@
     <file>AuditsPanel.js</file>
     <file>BinarySearch.js</file>
     <file>BottomUpProfileDataGridTree.js</file>
+    <file>BreakpointManager.js</file>
     <file>BreakpointsSidebarPane.js</file>
     <file>CallStackSidebarPane.js</file>
     <file>Checkbox.js</file>

Modified: trunk/Source/WebCore/inspector/front-end/inspector.html (93414 => 93415)


--- trunk/Source/WebCore/inspector/front-end/inspector.html	2011-08-19 15:39:55 UTC (rev 93414)
+++ trunk/Source/WebCore/inspector/front-end/inspector.html	2011-08-19 15:50:19 UTC (rev 93415)
@@ -155,6 +155,7 @@
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
+    <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to