Extend dumpInspectorHighlightJSON to accept a replacer for JSON.stringify

Based on the discussion in https://chromium-review.googlesource.com/c/chromium/src/+/2683860/2/third_party/blink/web_tests/http/tests/devtools/elements/highlight/highlight-css-flex-item.js#28

Bug: 1173995
Change-Id: I0365be80158b7b4a1b4d39244f0bbc9d8ad15317
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2687055
Reviewed-by: Mathias Bynens <mathias@chromium.org>
Reviewed-by: Patrick Brosset <patrick.brosset@microsoft.com>
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
This commit is contained in:
Alex Rudenko
2021-02-11 15:56:07 +00:00
committed by Commit Bot
parent 7f3180d06d
commit ecf4502bfc
@@ -1213,12 +1213,24 @@ function onBlankSection(selector, callback) {
ElementsTestRunner.waitForSelectorCommitted(callback.bind(null, section));
}
ElementsTestRunner.dumpInspectorHighlightJSON = function(idValue, callback) {
/**
* The function accepts 2 or 3 arguments. Callback is the last one and the second argument is optional.
*
* To dump all highlight properties: dumpInspectorHighlightJSON(idValue, callback).
* To pick which properties to dump: dumpInspectorHighlightJSON(idValue, ['prop'], callback).
*
* @param {string} idValue
* @param {!Function|!Array<string>} replacerOrCallback
* @param {?Function=} maybeCallback
*/
ElementsTestRunner.dumpInspectorHighlightJSON = function(idValue, replacerOrCallback, maybeCallback) {
const callback = arguments.length === 3 ? maybeCallback : replacerOrCallback;
const replacer = arguments.length === 3 ? replacerOrCallback : null;
ElementsTestRunner.nodeWithId(idValue, nodeResolved);
async function nodeResolved(node) {
const result = await TestRunner.OverlayAgent.getHighlightObjectForTest(node.id);
TestRunner.addResult(idValue + JSON.stringify(result, null, 2));
TestRunner.addResult(idValue + JSON.stringify(result, replacer, 2));
callback();
}
};