From 1fe1bca9b7f44c0a9c8032f7407db6f82a4d0158 Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Thu, 25 Feb 2021 03:47:04 +0000 Subject: [PATCH] Bug 1692385 add some memory usage testing for setSinkId() r=pehrsons Differential Revision: https://phabricator.services.mozilla.com/D106251 --- dom/media/webrtc/tests/mochitests/head.js | 30 +++++++++++++++++++ .../tests/mochitests/test_setSinkId.html | 24 +++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/dom/media/webrtc/tests/mochitests/head.js b/dom/media/webrtc/tests/mochitests/head.js index b6230e440fa5..ffdf3a19201b 100644 --- a/dom/media/webrtc/tests/mochitests/head.js +++ b/dom/media/webrtc/tests/mochitests/head.js @@ -892,6 +892,36 @@ function haveEventsButNoMore(target, name, count, cancel) { ); } +/* + * Resolves the returned promise with an object with usage and reportCount + * properties. `usage` is in the same units as reported by the reporter for + * `path`. + */ +const collectMemoryUsage = async path => { + const MemoryReporterManager = Cc[ + "@mozilla.org/memory-reporter-manager;1" + ].getService(Ci.nsIMemoryReporterManager); + + let usage = 0; + let reportCount = 0; + await new Promise(resolve => + MemoryReporterManager.getReports( + (aProcess, aPath, aKind, aUnits, aAmount, aDesc) => { + if (aPath != path) { + return; + } + ++reportCount; + usage += aAmount; + }, + null, + resolve, + null, + /* anonymized = */ false + ) + ); + return { usage, reportCount }; +}; + /** * This class executes a series of functions in a continuous sequence. * Promise-bearing functions are executed after the previous promise completes. diff --git a/dom/media/webrtc/tests/mochitests/test_setSinkId.html b/dom/media/webrtc/tests/mochitests/test_setSinkId.html index e307edaf13f1..b5ef890b188f 100644 --- a/dom/media/webrtc/tests/mochitests/test_setSinkId.html +++ b/dom/media/webrtc/tests/mochitests/test_setSinkId.html @@ -12,6 +12,8 @@ bug: "934425", }); + const memoryReportPath = 'explicit/media/media-manager-aggregates'; + /** * Run a test to verify set sink id in audio element. */ @@ -48,6 +50,28 @@ ok(true, `Set sink id expected to fail: ${error}`); is(error.name, "NotFoundError", "Verify correct error"); } + + const {usage: usage1} = + await collectMemoryUsage(memoryReportPath); // Provided by head.js + + ok(usage1 > 0, "MediaManager memory usage should be non-zero to store \ +device ids after enumerateDevices"); + + const p2 = audio.setSinkId(""); + is(audio.sinkId, audioDevices[0].deviceId, + 'sinkId after setSinkId("") return'); + is(await p2, undefined, + "promise resolution value when sinkId parameter is empty"); + is(audio.sinkId, "", 'sinkId after setSinkId("") resolution'); + + await audio.setSinkId(audioDevices[0].deviceId); + + const {usage: usage2, reportCount} = + await collectMemoryUsage(memoryReportPath); + is(reportCount, 1, + 'Expect only one MediaManager to report in content processes.'); + is(usage2, usage1, "MediaManager memory usage should return to previous \ +value after promise resolution"); });