From 2f5cb642f992ee07d808b74829ead38174ffd8fa Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 14 Mar 2017 04:28:43 +0100 Subject: [PATCH] Bug 1342526 - quote string expression results in console; r=nchevobbe MozReview-Commit-ID: 1HFbotCZoZ6 --HG-- extra : rebase_source : f9893c940b9c0017e54bbfb2f55f7752ee264c16 --- .../components/console-table.js | 1 + .../components/grip-message-body.js | 5 +-- .../message-types/console-api-call.js | 3 +- .../message-types/evaluation-result.js | 2 +- .../test/mochitest/browser.ini | 1 + .../mochitest/browser_webconsole_string.js | 35 +++++++++++++++++++ .../test/mochitest/test-console.html | 6 +++- 7 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_string.js diff --git a/devtools/client/webconsole/new-console-output/components/console-table.js b/devtools/client/webconsole/new-console-output/components/console-table.js index 970de40a3699..64e86dce4dcb 100644 --- a/devtools/client/webconsole/new-console-output/components/console-table.js +++ b/devtools/client/webconsole/new-console-output/components/console-table.js @@ -62,6 +62,7 @@ const ConsoleTable = createClass({ GripMessageBody({ grip: item[key], mode: MODE.SHORT, + useQuotes: false, }) ) ); diff --git a/devtools/client/webconsole/new-console-output/components/grip-message-body.js b/devtools/client/webconsole/new-console-output/components/grip-message-body.js index 97fd3a4d670d..2167bcc1f2d5 100644 --- a/devtools/client/webconsole/new-console-output/components/grip-message-body.js +++ b/devtools/client/webconsole/new-console-output/components/grip-message-body.js @@ -37,6 +37,7 @@ GripMessageBody.propTypes = { createElement: PropTypes.func.isRequired, }), userProvidedStyle: PropTypes.string, + useQuotes: PropTypes.bool, }; GripMessageBody.defaultProps = { @@ -44,7 +45,7 @@ GripMessageBody.defaultProps = { }; function GripMessageBody(props) { - const { grip, userProvidedStyle, serviceContainer } = props; + const { grip, userProvidedStyle, serviceContainer, useQuotes } = props; let styleObject; if (userProvidedStyle && userProvidedStyle !== "") { @@ -63,7 +64,7 @@ function GripMessageBody(props) { typeof grip === "string" ? StringRep({ object: grip, - useQuotes: false, + useQuotes: useQuotes, mode: props.mode, style: styleObject }) diff --git a/devtools/client/webconsole/new-console-output/components/message-types/console-api-call.js b/devtools/client/webconsole/new-console-output/components/message-types/console-api-call.js index 05a7b8916147..5c3e7b092133 100644 --- a/devtools/client/webconsole/new-console-output/components/message-types/console-api-call.js +++ b/devtools/client/webconsole/new-console-output/components/message-types/console-api-call.js @@ -119,7 +119,8 @@ function formatReps(parameters, userProvidedStyles, serviceContainer) { grip, key, userProvidedStyle: userProvidedStyles ? userProvidedStyles[key] : null, - serviceContainer + serviceContainer, + useQuotes: false, })) // Interleave spaces. .reduce((arr, v, i) => { diff --git a/devtools/client/webconsole/new-console-output/components/message-types/evaluation-result.js b/devtools/client/webconsole/new-console-output/components/message-types/evaluation-result.js index d857ed444786..73db526a86c6 100644 --- a/devtools/client/webconsole/new-console-output/components/message-types/evaluation-result.js +++ b/devtools/client/webconsole/new-console-output/components/message-types/evaluation-result.js @@ -43,7 +43,7 @@ function EvaluationResult(props) { if (message.messageText) { messageBody = message.messageText; } else { - messageBody = GripMessageBody({grip: parameters, serviceContainer}); + messageBody = GripMessageBody({grip: parameters, serviceContainer, useQuotes: true}); } const topLevelClasses = ["cm-s-mozilla"]; diff --git a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini index 0baf18d6d275..a8d5a49d7539 100644 --- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini +++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini @@ -41,5 +41,6 @@ skip-if = (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32 [browser_webconsole_observer_notifications.js] [browser_webconsole_stacktrace_location_debugger_link.js] [browser_webconsole_stacktrace_location_scratchpad_link.js] +[browser_webconsole_string.js] [browser_webconsole_timestamps.js] [browser_webconsole_vview_close_on_esc_key.js] diff --git a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_string.js b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_string.js new file mode 100644 index 000000000000..ed09fb2b800b --- /dev/null +++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_string.js @@ -0,0 +1,35 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const TEST_URI = "http://example.com/browser/devtools/client/webconsole/new-console-output/test/mochitest/test-console.html"; + +add_task(function* () { + let hud = yield openNewTabAndConsole(TEST_URI); + + info("console.log with a string argument"); + let receievedMessages = waitForMessages({ + hud, + messages: [{ + // Test that the output does not include quotes. + text: "stringLog", + }], + }); + + yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function () { + content.wrappedJSObject.stringLog(); + }); + + yield receievedMessages; + + info("evaluating a string constant"); + let jsterm = hud.jsterm; + yield jsterm.execute("\"string constant\""); + let msg = yield waitFor(() => findMessage(hud, "constant")); + let body = msg.querySelector(".message-body"); + // On the other hand, a string constant result should be quoted. + ok(body.textContent.includes("\"string constant\""), "found expected text"); +}); diff --git a/devtools/client/webconsole/new-console-output/test/mochitest/test-console.html b/devtools/client/webconsole/new-console-output/test/mochitest/test-console.html index b7f358570ac5..680426ae0ed8 100644 --- a/devtools/client/webconsole/new-console-output/test/mochitest/test-console.html +++ b/devtools/client/webconsole/new-console-output/test/mochitest/test-console.html @@ -7,7 +7,7 @@

Simple webconsole test page