зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1310408 - Add a mochitest for batched consoleAPI calls. r=linclark;
MozReview-Commit-ID: HQTjOSDLMnN --HG-- extra : rebase_source : 5c7c2e3f7494aa6220a872829ebb05b3012ac232
This commit is contained in:
Родитель
c841d66e5e
Коммит
a3d5b575a3
|
@ -108,6 +108,10 @@ NewConsoleOutputWrapper.prototype = {
|
|||
dispatchMessagesClear: function () {
|
||||
store.dispatch(actions.messagesClear());
|
||||
},
|
||||
// Should be used for test purpose only.
|
||||
getStore: function () {
|
||||
return store;
|
||||
}
|
||||
};
|
||||
|
||||
function batchedMessageAdd(action) {
|
||||
|
|
|
@ -3,12 +3,14 @@ tags = devtools
|
|||
subsuite = devtools
|
||||
support-files =
|
||||
head.js
|
||||
test-batching.html
|
||||
test-console.html
|
||||
test-console-filters.html
|
||||
test-console-group.html
|
||||
test-console-table.html
|
||||
!/devtools/client/framework/test/shared-head.js
|
||||
|
||||
[browser_webconsole_batching.js]
|
||||
[browser_webconsole_console_group.js]
|
||||
[browser_webconsole_console_table.js]
|
||||
[browser_webconsole_filters.js]
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/* -*- 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";
|
||||
|
||||
// Check adding console calls as batch keep the order of the message.
|
||||
|
||||
const TEST_URI = "http://example.com/browser/devtools/client/webconsole/new-console-output/test/mochitest/test-batching.html";
|
||||
const { l10n } = require("devtools/client/webconsole/new-console-output/utils/messages");
|
||||
|
||||
add_task(function* () {
|
||||
let hud = yield openNewTabAndConsole(TEST_URI);
|
||||
|
||||
const store = hud.ui.newConsoleOutput.getStore();
|
||||
// Adding loggin each time the store is modified in order to check
|
||||
// the store state in case of failure.
|
||||
store.subscribe(() => {
|
||||
const messages = store.getState().messages.messagesById.toJS()
|
||||
.map(message => {
|
||||
return {
|
||||
id: message.id,
|
||||
type: message.type,
|
||||
parameters: message.parameters,
|
||||
messageText: message.messageText
|
||||
};
|
||||
}
|
||||
);
|
||||
info("messages : " + JSON.stringify(messages));
|
||||
});
|
||||
|
||||
const messageNumber = 100;
|
||||
yield testSimpleBatchLogging(hud, messageNumber);
|
||||
yield testBatchLoggingAndClear(hud, messageNumber);
|
||||
});
|
||||
|
||||
function* testSimpleBatchLogging(hud, messageNumber) {
|
||||
yield ContentTask.spawn(gBrowser.selectedBrowser, messageNumber,
|
||||
function (numMessages) {
|
||||
content.wrappedJSObject.batchLog(numMessages);
|
||||
}
|
||||
);
|
||||
|
||||
for (let i = 0; i < messageNumber; i++) {
|
||||
let node = yield waitFor(() => findMessageAtIndex(hud, i, i));
|
||||
is(node.textContent, i.toString(), `message at index "${i}" is the expected one`);
|
||||
}
|
||||
}
|
||||
|
||||
function* testBatchLoggingAndClear(hud, messageNumber) {
|
||||
yield ContentTask.spawn(gBrowser.selectedBrowser, messageNumber,
|
||||
function (numMessages) {
|
||||
content.wrappedJSObject.batchLogAndClear(numMessages);
|
||||
}
|
||||
);
|
||||
yield waitFor(() => findMessage(hud, l10n.getStr("consoleCleared")));
|
||||
ok(true, "console cleared message is displayed");
|
||||
|
||||
// Passing the text argument as an empty string will returns all the message,
|
||||
// whatever their content is.
|
||||
const messages = findMessages(hud, "");
|
||||
is(messages.length, 1, "console was cleared as expected");
|
||||
}
|
||||
|
||||
function findMessageAtIndex(hud, text, index) {
|
||||
const selector = `.message:nth-of-type(${index + 1}) .message-body`;
|
||||
return findMessage(hud, text, selector);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Webconsole batch console calls test page</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>batch console calls test page</p>
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
function batchLog(numMessages = 0) {
|
||||
for (let i = 0; i < numMessages; i++) {
|
||||
console.log(i);
|
||||
}
|
||||
}
|
||||
|
||||
function batchLogAndClear(numMessages = 0) {
|
||||
for (let i = 0; i < numMessages; i++) {
|
||||
console.log(i);
|
||||
if (i === numMessages - 1) {
|
||||
console.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче