Web Inspector: Remove CPU profile from a group causes exception
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Feb 2013 15:22:39 +0000 (15:22 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Feb 2013 15:22:39 +0000 (15:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=110466

Patch by Alexei Filippov <alph@chromium.org> on 2013-02-25
Reviewed by Yury Semikhatsky.

WebInspector.ProfilesPanel._removeProfileHandle did not handle
profile removal from a group. The fix takes care of this case.

Test: inspector/profiler/cpu-profiler-profile-removal.html

Source/WebCore:

* inspector/front-end/ProfilesPanel.js:
(WebInspector.ProfilesPanel.prototype.addProfileHeader):
(WebInspector.ProfilesPanel.prototype._removeProfileHeader):

LayoutTests:

* inspector/profiler/cpu-profiler-profile-removal-expected.txt: Added.
* inspector/profiler/cpu-profiler-profile-removal.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/inspector/profiler/cpu-profiler-profile-removal-expected.txt [new file with mode: 0644]
LayoutTests/inspector/profiler/cpu-profiler-profile-removal.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/ProfilesPanel.js

index 7dfbbe5..8dc3105 100644 (file)
@@ -1,3 +1,18 @@
+2013-02-25  Alexei Filippov  <alph@chromium.org>
+
+        Web Inspector: Remove CPU profile from a group causes exception
+        https://bugs.webkit.org/show_bug.cgi?id=110466
+
+        Reviewed by Yury Semikhatsky.
+
+        WebInspector.ProfilesPanel._removeProfileHandle did not handle
+        profile removal from a group. The fix takes care of this case.
+
+        Test: inspector/profiler/cpu-profiler-profile-removal.html
+
+        * inspector/profiler/cpu-profiler-profile-removal-expected.txt: Added.
+        * inspector/profiler/cpu-profiler-profile-removal.html: Added.
+
 2013-02-25  Mike West  <mkwst@chromium.org>
 
         XSSAuditor tests shouldn't depend on IFrames's load order.
diff --git a/LayoutTests/inspector/profiler/cpu-profiler-profile-removal-expected.txt b/LayoutTests/inspector/profiler/cpu-profiler-profile-removal-expected.txt
new file mode 100644 (file)
index 0000000..734fe1c
--- /dev/null
@@ -0,0 +1,7 @@
+Tests that CPU profile removal from a group works. Bug 110466
+
+Profiler was enabled.
+Profile groups after removal:
+
+Profiler was disabled.
+
diff --git a/LayoutTests/inspector/profiler/cpu-profiler-profile-removal.html b/LayoutTests/inspector/profiler/cpu-profiler-profile-removal.html
new file mode 100644 (file)
index 0000000..39d4400
--- /dev/null
@@ -0,0 +1,46 @@
+<html>
+<head>
+  <script src="../../http/tests/inspector/inspector-test.js"></script>
+  <script src="profiler-test.js"></script>
+<script>
+
+function pageFunction() {
+    console.profile("p1");
+    console.profileEnd("p1");
+    console.profile("p1");
+    console.profileEnd("p1");
+    console.profile("p2");
+    console.profileEnd("p2");
+}
+
+function test()
+{
+    InspectorTest.startProfilerTest(function() {
+        function viewLoaded(view) {
+            var profiles = WebInspector.panels.profiles;
+            var type = profiles.getProfileType("CPU");
+            while (type.getProfiles().length !== 0)
+                profiles._removeProfileHeader(type.getProfiles()[0]);
+            InspectorTest.addResult("Profile groups after removal:");
+            for (var key in profiles._profileGroups)
+                InspectorTest.addResult(key + ": " + profiles._profileGroups[key].length);
+            InspectorTest.assertEquals(0, type.treeElement.children.length, "All children has been removed");
+            InspectorTest.completeProfilerTest();
+        }
+        WebInspector.showPanel("profiles");
+        InspectorTest.evaluateInConsole("pageFunction()", function() {});
+        InspectorTest.showProfileWhenAdded("p2");
+        InspectorTest.waitUntilProfileViewIsShown("p2", viewLoaded);
+    });
+}
+
+</script>
+</head>
+<body onload="runTest()">
+<p>
+Tests that CPU profile removal from a group works.
+
+<a href="https://bugs.webkit.org/show_bug.cgi?id=110466">Bug 110466</a>
+</p>
+</body>
+</html>
index c6d6f95..feedffa 100644 (file)
@@ -1,3 +1,19 @@
+2013-02-25  Alexei Filippov  <alph@chromium.org>
+
+        Web Inspector: Remove CPU profile from a group causes exception
+        https://bugs.webkit.org/show_bug.cgi?id=110466
+
+        Reviewed by Yury Semikhatsky.
+
+        WebInspector.ProfilesPanel._removeProfileHandle did not handle
+        profile removal from a group. The fix takes care of this case.
+
+        Test: inspector/profiler/cpu-profiler-profile-removal.html
+
+        * inspector/front-end/ProfilesPanel.js:
+        (WebInspector.ProfilesPanel.prototype.addProfileHeader):
+        (WebInspector.ProfilesPanel.prototype._removeProfileHeader):
+
 2013-02-23  Ilya Tikhonovsky  <loislo@chromium.org>
 
         Web Inspector: Native Memory Instrumentation: replace String with const char* in MemoryObjectInfo
index 18c3705..b50a4f2 100644 (file)
@@ -640,7 +640,7 @@ WebInspector.ProfilesPanel.prototype = {
         var small = false;
         var alternateTitle;
 
-        if (!WebInspector.ProfilesPanelDescriptor.isUserInitiatedProfile(profile.title)) {
+        if (!WebInspector.ProfilesPanelDescriptor.isUserInitiatedProfile(profile.title) && !profile.isTemporary) {
             var profileTitleKey = this._makeTitleKey(profile.title, typeId);
             if (!(profileTitleKey in this._profileGroups))
                 this._profileGroups[profileTitleKey] = [];
@@ -704,12 +704,20 @@ WebInspector.ProfilesPanel.prototype = {
         var profileTitleKey = this._makeTitleKey(profile.title, profile.profileType().id);
         var group = this._profileGroups[profileTitleKey];
         if (group) {
-            var index = group.indexOf(profile);
-            sidebarParent = group._profilesTreeElement || sidebarParent;
-            if (index !== -1)
-                group.splice(index, 1);
+            group.splice(group.indexOf(profile), 1);
+            if (group.length === 1) {
+                // Move the last profile out of its group and remove the group.
+                var index = sidebarParent.children.indexOf(group._profilesTreeElement);
+                sidebarParent.insertChild(group[0]._profilesTreeElement, index);
+                group[0]._profilesTreeElement.small = false;
+                group[0]._profilesTreeElement.mainTitle = group[0].title;
+                sidebarParent.removeChild(group._profilesTreeElement);
+            }
+            if (group.length !== 0)
+                sidebarParent = group._profilesTreeElement;
+            else
+                delete this._profileGroups[profileTitleKey];
         }
-
         sidebarParent.removeChild(profile._profilesTreeElement);
 
         // No other item will be selected if there aren't any other profiles, so