Bug 1549388 - Render non-string messageText with GripMessageBody. r=bgrins.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Mon, 13 May 2019 23:47:19 +0000
changeset 535618 b90c24bb6358c8ad4b0b56cd312457e0548c26f3
parent 535617 867447201d5d56927638aaed1423fb38370ddfc2
child 535619 82c168608de778da5ab22efe0d884b2b283c0edd
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1549388
milestone68.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 1549388 - Render non-string messageText with GripMessageBody. r=bgrins. Sometimes the messageText can be a longString, which was crashing the whole console output since we were always assuming messageText was a plain string. We now render non-string messageText with reps so it handles longStrings. A mocha test is added to ensure this works as expected. Differential Revision: https://phabricator.services.mozilla.com/D30875
devtools/client/webconsole/components/message-types/ConsoleApiCall.js
devtools/client/webconsole/test/components/console-api-call.log-messages.test.js
--- a/devtools/client/webconsole/components/message-types/ConsoleApiCall.js
+++ b/devtools/client/webconsole/components/message-types/ConsoleApiCall.js
@@ -88,18 +88,27 @@ function ConsoleApiCall(props) {
     messageBody = dom.span({className: "cm-variable"}, "console.table()");
   } else if (parameters) {
     messageBody = formatReps(messageBodyConfig);
     if (prefix) {
       messageBody.unshift(dom.span({
         className: "console-message-prefix",
       }, `${prefix}: `));
     }
-  } else {
+  } else if (typeof messageText === "string") {
     messageBody = messageText;
+  } else if (messageText) {
+    messageBody = GripMessageBody({
+      dispatch,
+      messageId,
+      grip: messageText,
+      serviceContainer,
+      useQuotes: false,
+      type,
+    });
   }
 
   let attachment = null;
   if (type === "table") {
     attachment = ConsoleTable({
       dispatch,
       id: message.id,
       serviceContainer,
@@ -135,16 +144,17 @@ function ConsoleApiCall(props) {
     stacktrace,
     attachment,
     serviceContainer,
     dispatch,
     indent,
     timeStamp,
     timestampsVisible,
     parameters,
+    message,
     maybeScrollToBottom,
   });
 }
 
 function formatReps(options = {}) {
   const {
     dispatch,
     loadedObjectProperties,
--- a/devtools/client/webconsole/test/components/console-api-call.log-messages.test.js
+++ b/devtools/client/webconsole/test/components/console-api-call.log-messages.test.js
@@ -3,16 +3,18 @@
 "use strict";
 
 // Test utils.
 const expect = require("expect");
 const { render } = require("enzyme");
 
 // React
 const { createFactory } = require("devtools/client/shared/vendor/react");
+const { setupStore } = require("devtools/client/webconsole/test/helpers");
+const Provider = createFactory(require("react-redux").Provider);
 
 // Components under test.
 const ConsoleApiCall = createFactory(require("devtools/client/webconsole/components/message-types/ConsoleApiCall"));
 
 const { prepareMessage } = require("devtools/client/webconsole/utils/messages");
 const serviceContainer = require("devtools/client/webconsole/test/fixtures/serviceContainer");
 
 describe("ConsoleAPICall component:", () => {
@@ -31,16 +33,29 @@ describe("ConsoleAPICall component:", ()
       const message = prepareMessage(logMessageStubPacket, {getNextId: () => "1"});
       const wrapper = render(ConsoleApiCall({ message, serviceContainer }));
 
       expect(wrapper.find(".message-body").text()).toBe("foobar test");
 
       // There should not be the location
       expect(wrapper.find(".message-location").text()).toBe("");
     });
+
+    it("renders longString logMessage grips", () => {
+      const message =
+        prepareMessage(logMessageLongStringStubPacket, {getNextId: () => "1"});
+
+      // We need to wrap the ConsoleApiElement in a Provider in order for the
+      // ObjectInspector to work.
+      const wrapper = render(
+        Provider({ store: setupStore() }, ConsoleApiCall({ message, serviceContainer }))
+      );
+
+      expect(wrapper.find(".message-body").text()).toInclude(initialText);
+    });
   });
 });
 
 // Stub packet
 const cachedLogMessageStubPacket = {
   "from": "server1.conn1.consoleActor2",
   "message": "foobar test",
   "timeStamp": "1493370184067",
@@ -48,8 +63,25 @@ const cachedLogMessageStubPacket = {
 };
 
 const logMessageStubPacket = {
   "from": "server1.conn0.consoleActor2",
   "type": "logMessage",
   "message": "foobar test",
   "timeStamp": 1519052480060,
 };
+
+const multilineFullText = `a\n${Array(20000)
+  .fill("a")
+  .join("")}`;
+const fullTextLength = multilineFullText.length;
+const initialText = multilineFullText.substring(0, 10000);
+const logMessageLongStringStubPacket = {
+  "from": "server1.conn0.consoleActor2",
+  "type": "logMessage",
+  "message": {
+    type: "longString",
+    initial: initialText,
+    length: fullTextLength,
+    actor: "server1.conn1.child1/longString58",
+  },
+  "timeStamp": 1519052480060,
+};