Bug 1283247 - New console frontend: Add support for console.count(). r=linclark

MozReview-Commit-ID: 2b9cBXXMLMW
This commit is contained in:
Nicolas Chevobbe 2016-06-25 14:32:37 +02:00
parent b4787fd138
commit 9cc375021b
2 changed files with 40 additions and 7 deletions

View File

@ -25,7 +25,7 @@ function ConsoleApiCall(props) {
const { message } = props;
const messageBody =
dom.span({className: "message-body devtools-monospace"},
formatTextContent(message.data.arguments));
formatTextContent(message.data));
const icon = MessageIcon({severity: message.severity});
const repeat = MessageRepeat({repeat: message.repeat});
const children = [
@ -53,8 +53,13 @@ function ConsoleApiCall(props) {
);
}
function formatTextContent(args) {
return args.map(function (arg, i, arr) {
function formatTextContent(data) {
return data.arguments.map(function (arg, i, arr) {
if (data.counter) {
let {label, count} = data.counter;
arg = `${label}: ${count}`;
}
const str = dom.span({className: "console-string"}, arg);
if (i < arr.length - 1) {
return [str, " "];

View File

@ -20,14 +20,42 @@ window.onload = Task.async(function* () {
const message = prepareMessage(packet);
const rendered = renderComponent(ConsoleApiCall, {message});
const queryPath = "div.message.cm-s-mozilla span span.message-flex-body span.message-body.devtools-monospace";
const messageBody = rendered.querySelectorAll(queryPath);
const consoleStringNodes = messageBody[0].querySelectorAll("span.console-string");
const messageBody = getMessageBody(rendered);
const consoleStringNodes = getConsoleStringNodes(messageBody);
is(consoleStringNodes.length, 2, "ConsoleApiCall outputs expected HTML structure");
is(messageBody[0].textContent, "foobar test", "ConsoleApiCall outputs expected text");
is(messageBody.textContent, "foobar test", "ConsoleApiCall outputs expected text");
for (let i = 0; i < 3; i++) {
const countPacket = yield getPacket("console.count('bar')", "consoleAPICall");
const countMessage = prepareMessage(countPacket);
const countRendered = renderComponent(ConsoleApiCall, {message: countMessage});
testConsoleCountRenderedElement(countRendered, `bar: ${i + 1}`);
}
SimpleTest.finish()
});
function getMessageBody(renderedComponent) {
const queryPath = "div.message.cm-s-mozilla span span.message-flex-body " +
"span.message-body.devtools-monospace";
return renderedComponent.querySelector(queryPath);
}
function getConsoleStringNodes(messageBody) {
return messageBody.querySelectorAll("span.console-string");
}
function testConsoleCountRenderedElement(renderedComponent, expectedTextContent) {
info("Testing console.count rendered element");
const messageBody = getMessageBody(renderedComponent);
const consoleStringNodes = getConsoleStringNodes(messageBody);
is(consoleStringNodes.length, 1,
"console.count rendered element has the expected HTML structure");
is(messageBody.textContent, expectedTextContent,
"console.count rendered element has the expected text content");
}
</script>
</body>
</html>