Web Inspector: No "Save Heap Snapshot" option after canceling save to file dialog.
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Nov 2012 11:31:07 +0000 (11:31 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Nov 2012 11:31:07 +0000 (11:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=100916

Patch by Eugene Klyuchnikov <eustas.bug@gmail.com> on 2012-11-22
Reviewed by Yury Semikhatsky.

Source/WebCore:

Fixed order of operations - now receiver is assigned only when save
dialog responds.

* inspector/front-end/HeapSnapshotView.js: Fixed order of operations.

LayoutTests:

Extracted "injectMockProfile" method and reused it in new test.

* inspector/profiler/heap-snapshot-loader-expected.txt: Added test case.
* inspector/profiler/heap-snapshot-loader.html:
Refactored and added new test case.

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

LayoutTests/ChangeLog
LayoutTests/inspector/profiler/heap-snapshot-loader-expected.txt
LayoutTests/inspector/profiler/heap-snapshot-loader.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/HeapSnapshotView.js

index 96e09a5..7a0b7d8 100644 (file)
@@ -1,3 +1,16 @@
+2012-11-22  Eugene Klyuchnikov  <eustas.bug@gmail.com>
+
+        Web Inspector: No "Save Heap Snapshot" option after canceling save to file dialog.
+        https://bugs.webkit.org/show_bug.cgi?id=100916
+
+        Reviewed by Yury Semikhatsky.
+
+        Extracted "injectMockProfile" method and reused it in new test.
+
+        * inspector/profiler/heap-snapshot-loader-expected.txt: Added test case.
+        * inspector/profiler/heap-snapshot-loader.html:
+        Refactored and added new test case.
+
 2012-11-23  Allan Sandfeld Jensen  <allan.jensen@digia.com>
 
         [Qt] REGRESSION(r135507): It made 13 tests fail
index 11346b0..76f8978 100644 (file)
@@ -7,3 +7,5 @@ Running: heapSnapshotSaveToFileTest
 
 Running: heapSnapshotLoadFromFileTest
 
+Running: heapSnapshotRejectToSaveToFileTest
+
index a258e10..09896fb 100644 (file)
@@ -16,6 +16,38 @@ function test()
     var sourceStringified = JSON.stringify(source);
     var partSize = sourceStringified.length >> 3;
 
+    function injectMockProfile(overrideGetProfile, callback) {
+        var dispatcher = InspectorBackend._domainDispatchers["Profiler"];
+        var panel = WebInspector.panels.profiles;
+        panel._reset();
+
+        dispatcher.addProfileHeader({
+            typeId: WebInspector.HeapSnapshotProfileType.TypeId,
+            title: "heapSnapshotSaveToFileTest",
+            uid: 42,
+            maxJSObjectId: 6
+        });
+
+        var profileHeader = panel._profiles[0];
+
+        function getProfileMock(profileTypeName, uid) {
+            for (var i = 0, l = sourceStringified.length; i < l; i += partSize)
+                dispatcher.addHeapSnapshotChunk(uid, sourceStringified.slice(i, i + partSize));
+            dispatcher.finishHeapSnapshot(uid);
+        }
+
+        function snapshotLoaded()
+        {
+            if (overrideGetProfile)
+                InspectorTest.override(ProfilerAgent, "getProfile", getProfileMock);
+            callback(profileHeader);
+        }
+        InspectorTest.addSniffer(profileHeader, "_snapshotReceived", snapshotLoaded);
+
+        InspectorTest.override(ProfilerAgent, "getProfile", getProfileMock);
+        panel.showProfile(profileHeader);
+    }
+
     InspectorTest.runTestSuite([
         function heapSnapshotLoaderTest(next)
         {
@@ -32,56 +64,31 @@ function test()
 
         function heapSnapshotSaveToFileTest(next)
         {
-            var profileUID = 42;
-
-            var dispatcher = InspectorBackend._domainDispatchers["Profiler"];
-            var panel = WebInspector.panels.profiles;
-            panel._reset();
-
-            dispatcher.addProfileHeader({
-                typeId: WebInspector.HeapSnapshotProfileType.TypeId,
-                title: "heapSnapshotSaveToFileTest",
-                uid: profileUID,
-                maxJSObjectId: 6
-            });
-
-            var profileHeader = panel._profiles[0];
-
-            var oldGetProfile = ProfilerAgent.getProfile;
-            ProfilerAgent.getProfile = function getProfileMock(profileTypeName, uid) {
-                for (var i = 0, l = sourceStringified.length; i < l; i += partSize)
-                    dispatcher.addHeapSnapshotChunk(uid, sourceStringified.slice(i, i + partSize));
-                dispatcher.finishHeapSnapshot(uid);
-            };
-
-            var savedSnapshotData;
-            var oldSave = InspectorFrontendHost.save;
-            InspectorFrontendHost.save = function saveMock(url, data)
-            {
-                savedSnapshotData = data;
-                WebInspector.fileManager.savedURL(url);
-            }
-
-            var oldAppend = InspectorFrontendHost.append;
-            InspectorFrontendHost.append = function appendMock(url, data)
+            function snapshotLoaded(profileHeader)
             {
-                savedSnapshotData += data;
-                WebInspector.fileManager.appendedToURL(url);
-            }
+                var savedSnapshotData;
+                function saveMock(url, data)
+                {
+                    savedSnapshotData = data;
+                    WebInspector.fileManager.savedURL(url);
+                }
+                InspectorTest.override(InspectorFrontendHost, "save", saveMock);
+
+                var oldAppend = InspectorFrontendHost.append;
+                InspectorFrontendHost.append = function appendMock(url, data)
+                {
+                    savedSnapshotData += data;
+                    WebInspector.fileManager.appendedToURL(url);
+                }
 
-            function parsed()
-            {
                 profileHeader.saveToFile();
                 InspectorTest.assertEquals(sourceStringified, savedSnapshotData, "Saved snapshot data");
 
-                InspectorFrontendHost.save = oldSave;
                 InspectorFrontendHost.append = oldAppend;
-                ProfilerAgent.getProfile = oldGetProfile;
                 next();
             }
-            InspectorTest.addSniffer(profileHeader, "_snapshotReceived", parsed);
 
-            panel.showProfile(profileHeader);
+            injectMockProfile(true, snapshotLoaded);
         },
 
         function heapSnapshotLoadFromFileTest(next)
@@ -121,6 +128,22 @@ function test()
             });
             InspectorTest.addSniffer(WebInspector.HeapProfileHeader.prototype, "_snapshotReceived", function() { next(); });
             panel._loadFromFile(fileMock);
+        },
+
+        function heapSnapshotRejectToSaveToFileTest(next)
+        {
+            function snapshotLoaded(profileHeader)
+            {
+                function saveMock(url, data)
+                {
+                    InspectorTest.assertTrue(profileHeader.canSaveToFile());
+                    next();
+                }
+                InspectorTest.override(InspectorFrontendHost, "save", saveMock);
+                profileHeader.saveToFile();
+            }
+
+            injectMockProfile(false, snapshotLoaded);
         }
     ]);
 }
index 8a79797..43f73c0 100644 (file)
@@ -1,3 +1,15 @@
+2012-11-22  Eugene Klyuchnikov  <eustas.bug@gmail.com>
+
+        Web Inspector: No "Save Heap Snapshot" option after canceling save to file dialog.
+        https://bugs.webkit.org/show_bug.cgi?id=100916
+
+        Reviewed by Yury Semikhatsky.
+
+        Fixed order of operations - now receiver is assigned only when save
+        dialog responds.
+
+        * inspector/front-end/HeapSnapshotView.js: Fixed order of operations.
+
 2012-11-23  Allan Sandfeld Jensen  <allan.jensen@digia.com>
 
         [Qt] REGRESSION(r135507): It made 13 tests fail
index 6b718fc..2d638e7 100644 (file)
@@ -962,16 +962,18 @@ WebInspector.HeapProfileHeader.prototype = {
     saveToFile: function()
     {
         this._numberOfChunks = 0;
+
+        var fileOutputStream = new WebInspector.FileOutputStream();
         function onOpen()
         {
+            this._receiver = fileOutputStream;
             this._savedChunks = 0;
             this._updateTransferProgress(0, this._totalNumberOfChunks);
             ProfilerAgent.getProfile(this.profileType().id, this.uid);
         }
         this._savingToFile = true;
         this._fileName = this._fileName || "Heap-" + new Date().toISO8601Compact() + ".heapsnapshot";
-        this._receiver = new WebInspector.FileOutputStream();
-        this._receiver.open(this._fileName, onOpen.bind(this));
+        fileOutputStream.open(this._fileName, onOpen.bind(this));
     },
 
     /**