Web Inspector: group scripts by folder in the scripts selector.
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Aug 2011 08:17:05 +0000 (08:17 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Aug 2011 08:17:05 +0000 (08:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=65321

Reviewed by Yury Semikhatsky.

Source/WebCore:

Test: inspector/debugger/scripts-sorting.html

* inspector/front-end/ScriptsPanel.js:
(WebInspector.ScriptsPanel.prototype._sourceFileAdded.get if):
(WebInspector.ScriptsPanel.prototype._addOptionToFilesSelect.insertOrdered.optionCompare):
(WebInspector.ScriptsPanel.prototype._addOptionToFilesSelect.insertOrdered):
(WebInspector.ScriptsPanel.prototype._addOptionToFilesSelect):
(WebInspector.ScriptsPanel.prototype._folderAndDisplayNameForScriptURL):
(WebInspector.ScriptsPanel.prototype.reset):
(WebInspector.SourceFrameDelegateForScriptsPanel.prototype.suggestedFileName):

LayoutTests:

* http/tests/inspector/debugger-test.js:
(initialize_DebuggerTest):
* inspector/debugger/scripts-sorting-expected.txt: Added.
* inspector/debugger/scripts-sorting.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/debugger-test.js
LayoutTests/inspector/debugger/scripts-sorting-expected.txt [new file with mode: 0644]
LayoutTests/inspector/debugger/scripts-sorting.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/ScriptsPanel.js

index 4ebeae3..54782e3 100644 (file)
@@ -1,3 +1,15 @@
+2011-08-01  Pavel Feldman  <pfeldman@google.com>
+
+        Web Inspector: group scripts by folder in the scripts selector.
+        https://bugs.webkit.org/show_bug.cgi?id=65321
+
+        Reviewed by Yury Semikhatsky.
+
+        * http/tests/inspector/debugger-test.js:
+        (initialize_DebuggerTest):
+        * inspector/debugger/scripts-sorting-expected.txt: Added.
+        * inspector/debugger/scripts-sorting.html: Added.
+
 2011-07-28  Pavel Feldman  <pfeldman@google.com>
 
         Web Inspector: [protocol] methods where all parameters are optional should not require empty params object.
index 105eea1..fd0824f 100644 (file)
@@ -159,7 +159,7 @@ InspectorTest.showScriptSource = function(scriptName, callback)
 {
     var filesSelect = document.getElementById("scripts-files");
     for (var i = 0; i < filesSelect.length; ++i) {
-        if (filesSelect[i].text === scriptName) {
+        if (filesSelect[i].scriptNameForTest === scriptName) {
             filesSelect.selectedIndex = i;
             WebInspector.panels.scripts._filesSelectChanged();
             var sourceFrame = WebInspector.panels.scripts.visibleView;
diff --git a/LayoutTests/inspector/debugger/scripts-sorting-expected.txt b/LayoutTests/inspector/debugger/scripts-sorting-expected.txt
new file mode 100644 (file)
index 0000000..d908669
--- /dev/null
@@ -0,0 +1,23 @@
+Tests scripts sorting in the scripts panel.
+
+Debugger was enabled.
+    *Non*URL*path
+    block.js?block=foo
+    ga.js
+    lenta.ban?pg=4883&ifr=1
+    lenta.ban?pg=5309&ifr=1
+    top100.jcn?80674
+/_js/production
+    motor.js?1308927432
+/i
+    xgemius.js
+/i/js
+    jquery-1.5.1.min.js
+    jquery.cookie.js
+…cal/google/code/chromium/src/third_party/WebKit/LayoutTests/http/tests/inspector
+    debugger-test.js
+    inspector-test.js
+…local/google/code/chromium/src/third_party/WebKit/LayoutTests/inspector/debugger
+    scripts-sorting.html
+Debugger was disabled.
+
diff --git a/LayoutTests/inspector/debugger/scripts-sorting.html b/LayoutTests/inspector/debugger/scripts-sorting.html
new file mode 100644 (file)
index 0000000..bcb0591
--- /dev/null
@@ -0,0 +1,48 @@
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/debugger-test.js"></script>
+
+<script>
+var scripts = [
+    "block.js?block=foo",
+    "ga.js",
+    "lenta.ban?pg=4883&ifr=1",
+    "lenta.ban?pg=5309&ifr=1",
+    "top100.jcn?80674",
+    "_js/production/motor.js?1308927432",
+    "i/xgemius.js",
+    "i/js/jquery-1.5.1.min.js",
+    "i/js/jquery.cookie.js" ];
+
+for (var i = 0; i < scripts.length; ++i)
+    window.eval("function func" + i + "() {} //@ sourceURL=http://foo.com/" + scripts[i]);
+
+window.eval("function funcNonURL() {} //@ sourceURL=*Non*URL*path");
+
+</script>
+
+<script>
+function test()
+{
+    var scripts = [];
+    InspectorTest.startDebuggerTest(step1);
+
+    function step1()
+    {
+        var select = WebInspector.panels.scripts._filesSelectElement;
+        for (var i = 0; i < select.length; ++i)
+            InspectorTest.addResult(select[i].textContent.replace(/\u00a0/g, " "));
+        InspectorTest.completeDebuggerTest();
+    }
+}
+</script>
+
+</head>
+<body onload="runTest()">
+<p>
+Tests scripts sorting in the scripts panel.
+</p>
+</body>
+
+</html>
index 108192f..ef4806f 100644 (file)
@@ -1,3 +1,21 @@
+2011-08-01  Pavel Feldman  <pfeldman@google.com>
+
+        Web Inspector: group scripts by folder in the scripts selector.
+        https://bugs.webkit.org/show_bug.cgi?id=65321
+
+        Reviewed by Yury Semikhatsky.
+
+        Test: inspector/debugger/scripts-sorting.html
+
+        * inspector/front-end/ScriptsPanel.js:
+        (WebInspector.ScriptsPanel.prototype._sourceFileAdded.get if):
+        (WebInspector.ScriptsPanel.prototype._addOptionToFilesSelect.insertOrdered.optionCompare):
+        (WebInspector.ScriptsPanel.prototype._addOptionToFilesSelect.insertOrdered):
+        (WebInspector.ScriptsPanel.prototype._addOptionToFilesSelect):
+        (WebInspector.ScriptsPanel.prototype._folderAndDisplayNameForScriptURL):
+        (WebInspector.ScriptsPanel.prototype.reset):
+        (WebInspector.SourceFrameDelegateForScriptsPanel.prototype.suggestedFileName):
+
 2011-07-28  Pavel Feldman  <pfeldman@google.com>
 
         Web Inspector: [protocol] methods where all parameters are optional should not require empty params object.
index 2b9dac9..616fdb8 100644 (file)
@@ -240,7 +240,8 @@ WebInspector.ScriptsPanel.prototype = {
         this._addOptionToFilesSelect(sourceFile);
 
         var lastViewedURL = WebInspector.settings.lastViewedScriptFile.get();
-        if (this._filesSelectElement.length === 1) {
+        if (!this._filesSelectElement.initialSelectionProcessed) {
+            this._filesSelectElement.initialSelectionProcessed = true;
             // Option we just added is the only option in files select.
             // We have to show corresponding source frame immediately.
             this._showSourceFrameAndAddToHistory(sourceFile.id);
@@ -254,59 +255,77 @@ WebInspector.ScriptsPanel.prototype = {
     _addOptionToFilesSelect: function(sourceFile)
     {
         var select = this._filesSelectElement;
+        if (!select.folderOptions)
+            select.folderOptions = {};
+
         var option = document.createElement("option");
-        option.text = this._displayNameForScriptURL(sourceFile.url) || WebInspector.UIString("(program)");
+        var parsedURL = sourceFile.url.asParsedURL();
+
+        var names = this._folderAndDisplayNameForScriptURL(sourceFile.url);
+        option.text = names.displayName ? "\u00a0\u00a0\u00a0\u00a0" + names.displayName : WebInspector.UIString("(program)");
+        option.scriptNameForTest = names.displayName;
+        var folderNameForSorting = (sourceFile.isContentScript ? "2" : "0") + names.folderName;
+        option.nameForSorting = folderNameForSorting + "\t/\t" + names.displayName; // Use '\t' to make files stick to their folder.
         option.title = sourceFile.url;
-        option.isContentScript = sourceFile.isContentScript;
         if (sourceFile.isContentScript)
             option.addStyleClass("extension-script");
-        function compare(a, b)
-        {
-            return a < b ? -1 : (a > b ? 1 : 0);
-        }
-        function optionCompare(a, b)
-        {
-            if (a === select.contentScriptSection)
-                return b.isContentScript ? -1 : 1;
-            if (b === select.contentScriptSection)
-                return a.isContentScript ? 1 : -1;
 
-            if (a.isContentScript && !b.isContentScript)
-                return 1;
-            if (!a.isContentScript && b.isContentScript)
-                return -1;
-
-            return compare(a.text, b.text) || compare(a.title, b.title);
+        function insertOrdered(option)
+        {
+            function optionCompare(a, b)
+            {
+                return a.nameForSorting.localeCompare(b.nameForSorting);
+            }
+            var insertionIndex = insertionIndexForObjectInListSortedByFunction(option, select.childNodes, optionCompare);
+            select.insertBefore(option, insertionIndex < 0 ? null : select.childNodes.item(insertionIndex));
         }
 
-        var insertionIndex = insertionIndexForObjectInListSortedByFunction(option, select.childNodes, optionCompare);
-        select.insertBefore(option, insertionIndex < 0 ? null : select.childNodes.item(insertionIndex));
+        insertOrdered(option);
 
         if (sourceFile.isContentScript && !select.contentScriptSection) {
             var contentScriptSection = document.createElement("option");
             contentScriptSection.text = WebInspector.UIString("Content scripts");
             contentScriptSection.disabled = true;
+            option.nameForSorting = "1/ContentScriptSeparator";
             select.contentScriptSection = contentScriptSection;
+            insertOrdered(contentScriptSection);
+        }
 
-            var insertionIndex = insertionIndexForObjectInListSortedByFunction(contentScriptSection, select.childNodes, optionCompare);
-            select.insertBefore(contentScriptSection, insertionIndex < 0 ? null : select.childNodes.item(insertionIndex));
+        if (names.folderName && !select.folderOptions[names.folderName]) {
+            var folderOption = document.createElement("option");
+            folderOption.text = names.folderName;
+            folderOption.nameForSorting = folderNameForSorting;
+            folderOption.disabled = true;
+            select.folderOptions[names.folderName] = folderOption;
+            insertOrdered(folderOption);
         }
+
         option._sourceFileId = sourceFile.id;
         this._sourceFileIdToFilesSelectOption[sourceFile.id] = option;
     },
 
-    _displayNameForScriptURL: function(url)
+    _folderAndDisplayNameForScriptURL: function(url)
     {
+        var parsedURL = url.asParsedURL();
+        if (parsedURL)
+            url = parsedURL.path;
+
+        var folderName = "";
         var displayName = url;
-        var indexOfQuery = displayName.indexOf("?");
-        if (indexOfQuery > 0)
-            displayName = displayName.substring(0, indexOfQuery);
+
         var fromIndex = displayName.lastIndexOf("/", displayName.length - 2);
-        if (fromIndex !== -1)
+        if (fromIndex !== -1) {
+            folderName = displayName.substring(0, fromIndex);
             displayName = displayName.substring(fromIndex + 1);
-        if (displayName.length > 100)
-            displayName = displayName.substring(0, 80) + "...";
-        return displayName;
+        }
+
+        if (displayName.length > 80)
+            displayName = "\u2026" + displayName.substring(displayName.length - 80);
+
+        if (folderName.length > 80)
+            folderName = "\u2026" + folderName.substring(folderName.length - 80);
+        return { folderName: folderName, displayName: displayName};
     },
 
     setScriptSourceIsBeingEdited: function(sourceFileId, inEditMode)
@@ -495,6 +514,11 @@ WebInspector.ScriptsPanel.prototype = {
         this._sourceFileIdToSourceFrame = {};
         this._sourceFileIdToFilesSelectOption = {};
         this._filesSelectElement.removeChildren();
+        this._filesSelectElement.removeChildren();
+        this._filesSelectElement.folderOptions = {};
+        delete this._filesSelectElement.initialSelectionProcessed;
+        delete this._filesSelectElement.contentScriptSection;
+
         this.functionsSelectElement.removeChildren();
         this.viewsContainerElement.removeChildren();
 
@@ -1181,7 +1205,8 @@ WebInspector.SourceFrameDelegateForScriptsPanel.prototype = {
     suggestedFileName: function()
     {
         var sourceFile = this._model.sourceFile(this._sourceFileId);
-        return WebInspector.panels.scripts._displayNameForScriptURL(sourceFile.url) || "untitled.js";
+        var names = WebInspector.panels.scripts._folderAndDisplayNameForScriptURL(sourceFile.url);
+        return names.displayName || "untitled.js";
     }
 }