Bug 1255908 - Replaced "/" with hostname when for root document in webconsole; r=jsnajdr, a=sylvestre
authorJaideep Bhoosreddy <jaideepb@buffalo.edu>
Wed, 22 Jun 2016 20:30:00 +0200
changeset 391549 cdb052e0c1e465c68440f04ab02ffc7175acfc1a
parent 391548 0e888cae95ca4b6b51037121ad241bd3901ba3e1
child 391550 fd8d4ad885aa3adcc5d620d2a03aab15577664fc
push id23905
push usermozilla@buttercookie.de
push dateFri, 22 Jul 2016 19:26:20 +0000
reviewersjsnajdr, sylvestre
bugs1255908
milestone49.0a2
Bug 1255908 - Replaced "/" with hostname when for root document in webconsole; r=jsnajdr, a=sylvestre
devtools/client/shared/components/frame.js
devtools/client/shared/components/test/mochitest/test_frame_01.html
devtools/client/webconsole/webconsole.js
--- a/devtools/client/shared/components/frame.js
+++ b/devtools/client/shared/components/frame.js
@@ -15,34 +15,37 @@ module.exports = createClass({
 
   propTypes: {
     // SavedFrame, or an object containing all the required properties.
     frame: PropTypes.shape({
       functionDisplayName: PropTypes.string,
       source: PropTypes.string.isRequired,
       line: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
       column: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
+      showEmptyPathAsHost: PropTypes.bool,
     }).isRequired,
     // Clicking on the frame link -- probably should link to the debugger.
     onClick: PropTypes.func.isRequired,
     // Option to display a function name before the source link.
     showFunctionName: PropTypes.bool,
     // Option to display a host name after the source link.
     showHost: PropTypes.bool,
   },
 
   getDefaultProps() {
     return {
       showFunctionName: false,
       showHost: false,
+      showEmptyPathAsHost: false,
     };
   },
 
   render() {
     let { onClick, frame, showFunctionName, showHost } = this.props;
+    let { showEmptyPathAsHost } = frame;
     let source = frame.source ? String(frame.source) : "";
     let line = frame.line != void 0 ? Number(frame.line) : null;
     let column = frame.column != void 0 ? Number(frame.column) : null;
 
     const { short, long, host } = getSourceNames(source);
     // Reparse the URL to determine if we should link this; `getSourceNames`
     // has already cached this indirectly. We don't want to attempt to
     // link to "self-hosted" and "(unknown)". However, we do want to link
@@ -72,19 +75,23 @@ module.exports = createClass({
 
     if (showFunctionName && frame.functionDisplayName) {
       elements.push(
         dom.span({ className: "frame-link-function-display-name" },
                  frame.functionDisplayName)
       );
     }
 
+    let displaySource = short;
+    if (showEmptyPathAsHost && (short === "" || short === "/")) {
+      displaySource = host;
+    }
     sourceElements.push(dom.span({
       className: "frame-link-filename",
-    }, short));
+    }, displaySource));
 
     // If source is linkable, and we have a line number > 0
     if (isLinkable && line) {
       sourceElements.push(dom.span({ className: "frame-link-colon" }, ":"));
       sourceElements.push(dom.span({ className: "frame-link-line" }, line));
       // Intentionally exclude 0
       if (column) {
         sourceElements.push(dom.span({ className: "frame-link-colon" }, ":"));
--- a/devtools/client/shared/components/test/mochitest/test_frame_01.html
+++ b/devtools/client/shared/components/test/mochitest/test_frame_01.html
@@ -136,16 +136,40 @@ window.onload = Task.async(function* () 
       line: "0",
       column: "55",
     }, {
       file: "mahscripts.js",
       shouldLink: true,
       tooltip: "View source in Debugger → http://myfile.com/mahscripts.js",
     });
 
+    // Check if file is rendered with "/" for root documents when showEmptyPathAsHost is false
+    yield checkFrameComponent({
+      source: "http://www.cnn.com/",
+      line: "1",
+      showEmptyPathAsHost: false,
+    }, {
+      file: "/",
+      line: "1",
+      shouldLink: true,
+      tooltip: "View source in Debugger → http://www.cnn.com/:1",
+    });
+
+    // Check if file is rendered with hostname for root documents when showEmptyPathAsHost is true
+    yield checkFrameComponent({
+      source: "http://www.cnn.com/",
+      line: "1",
+      showEmptyPathAsHost: true,
+    }, {
+      file: "www.cnn.com",
+      line: "1",
+      shouldLink: true,
+      tooltip: "View source in Debugger → http://www.cnn.com/:1",
+    });
+
     function* checkFrameComponent (input, expected) {
       let frame = ReactDOM.render(Frame({
         frame: input,
         onClick: () => {},
       }), window.document.body);
       yield forceRender(frame);
       let source = input.source;
       checkFrameString(Object.assign({ frame, source }, expected));
--- a/devtools/client/webconsole/webconsole.js
+++ b/devtools/client/webconsole/webconsole.js
@@ -2605,18 +2605,19 @@ WebConsoleFrame.prototype = {
       this.owner.viewSource(fullURL, line);
     };
 
     this.ReactDOM.render(this.FrameView({
       frame: {
         source: fullURL,
         line,
         column,
+        showEmptyPathAsHost: true,
       },
-      onClick
+      onClick,
     }), locationNode);
 
     return locationNode;
   },
 
   /**
    * Adjusts the category and severity of the given message.
    *