Bug 1557895 - Provide a tooltip for directories in the sources tree r=jlast
authorDavid Walsh <dwalsh@mozilla.com>
Wed, 26 Jun 2019 18:19:24 +0000
changeset 543797 a368350c9582f52cc32ff3c38b3d8337510cdbdf
parent 543796 d0823ee61ef55e7f2f7ff8d03d5df501bb5cb52a
child 543798 c638a6eed13d86b777338b6b0102b2717db36971
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlast
bugs1557895
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1557895 - Provide a tooltip for directories in the sources tree r=jlast Differential Revision: https://phabricator.services.mozilla.com/D34264
devtools/client/debugger/src/components/PrimaryPanes/SourcesTreeItem.js
devtools/client/debugger/src/utils/sources-tree/tests/utils.spec.js
devtools/client/debugger/src/utils/sources-tree/utils.js
--- a/devtools/client/debugger/src/components/PrimaryPanes/SourcesTreeItem.js
+++ b/devtools/client/debugger/src/components/PrimaryPanes/SourcesTreeItem.js
@@ -25,17 +25,17 @@ import {
 import actions from "../../actions";
 
 import {
   isOriginal as isOriginalSource,
   getSourceQueryString,
   isUrlExtension,
   shouldBlackbox,
 } from "../../utils/source";
-import { isDirectory } from "../../utils/sources-tree";
+import { isDirectory, getPathWithoutThread } from "../../utils/sources-tree";
 import { copyToTheClipboard } from "../../utils/clipboard";
 import { features } from "../../utils/prefs";
 import { downloadFile } from "../../utils/utils";
 
 import type { TreeNode } from "../../utils/sources-tree/types";
 import type {
   Source,
   Context,
@@ -291,17 +291,19 @@ class SourceTreeItem extends Component<P
 
   renderItemTooltip() {
     const { item, depth, extensionName } = this.props;
 
     if (isExtensionDirectory(depth, extensionName)) {
       return item.name;
     }
 
-    return item.type === "source" ? unescape(item.contents.url) : "";
+    return item.type === "source"
+      ? unescape(item.contents.url)
+      : getPathWithoutThread(item.path);
   }
 
   render() {
     const {
       item,
       depth,
       source,
       focused,
--- a/devtools/client/debugger/src/utils/sources-tree/tests/utils.spec.js
+++ b/devtools/client/debugger/src/utils/sources-tree/tests/utils.spec.js
@@ -9,16 +9,17 @@ import { makeMockSource } from "../../te
 
 import {
   createDirectoryNode,
   getRelativePath,
   isExactUrlMatch,
   isDirectory,
   addToTree,
   isNotJavaScript,
+  getPathWithoutThread,
 } from "../index";
 
 describe("sources tree", () => {
   describe("isExactUrlMatch", () => {
     it("recognizes root url match", () => {
       const rootA = "http://example.com/path/to/file.html";
       const rootB = "https://www.demo.com/index.html";
 
@@ -96,9 +97,51 @@ describe("sources tree", () => {
       expect(isNotJavaScript(source)).toBe(true);
     });
 
     it("png file", () => {
       const source = makeMockSource("http://example.com/foo.png");
       expect(isNotJavaScript(source)).toBe(true);
     });
   });
+
+  describe("getPathWithoutThread", () => {
+    it("main thread pattern", () => {
+      const path = getPathWithoutThread("server1.conn0.child1/context18");
+      expect(path).toBe("");
+    });
+
+    it("main thread host", () => {
+      const path = getPathWithoutThread(
+        "server1.conn0.child1/context18/dbg-workers.glitch.me"
+      );
+      expect(path).toBe("dbg-workers.glitch.me");
+    });
+
+    it("main thread children", () => {
+      const path = getPathWithoutThread(
+        "server1.conn0.child1/context18/dbg-workers.glitch.me/more"
+      );
+      expect(path).toBe("dbg-workers.glitch.me/more");
+    });
+
+    it("worker thread", () => {
+      const path = getPathWithoutThread(
+        "server1.conn0.child1/workerTarget25/context1"
+      );
+      expect(path).toBe("");
+    });
+
+    it("worker thread with children", () => {
+      const path = getPathWithoutThread(
+        "server1.conn0.child1/workerTarget25/context1/dbg-workers.glitch.me/utils"
+      );
+      expect(path).toBe("dbg-workers.glitch.me/utils");
+    });
+
+    it("worker thread with file named like pattern", () => {
+      const path = getPathWithoutThread(
+        "server1.conn0.child1/workerTarget25/context1/dbg-workers.glitch.me/utils/context38/index.js"
+      );
+      expect(path).toBe("dbg-workers.glitch.me/utils/context38/index.js");
+    });
+  });
 });
--- a/devtools/client/debugger/src/utils/sources-tree/utils.js
+++ b/devtools/client/debugger/src/utils/sources-tree/utils.js
@@ -128,8 +128,16 @@ export function getRelativePath(url: str
   const { pathname } = parse(url);
   if (!pathname) {
     return url;
   }
   const path = pathname.split("/");
   path.shift();
   return path.join("/");
 }
+
+export function getPathWithoutThread(path: string) {
+  const pathParts = path.split(/(context\d+?\/)/).splice(2);
+  if (pathParts && pathParts.length > 0) {
+    return pathParts.join("");
+  }
+  return "";
+}