diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/measure-memory/resources/checker.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/measure-memory/resources/checker.js')
-rw-r--r-- | testing/web-platform/tests/measure-memory/resources/checker.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/testing/web-platform/tests/measure-memory/resources/checker.js b/testing/web-platform/tests/measure-memory/resources/checker.js new file mode 100644 index 0000000000..25487b7b05 --- /dev/null +++ b/testing/web-platform/tests/measure-memory/resources/checker.js @@ -0,0 +1,58 @@ +function checkContainer(actual, expected) { + if (!actual) return true; + if (!expected) return false; + return actual.id == expected.id && actual.src == expected.src; +} + +function checkAttribution(attribution, expected) { + assert_own_property(attribution, 'url'); + assert_own_property(attribution, 'scope'); + let found = false; + for (const e of expected) { + if (attribution.url === e.url && + attribution.scope === e.scope && + checkContainer(attribution.container, e.container)) { + found = true; + e.found = true; + } + } + assert_true(found, JSON.stringify(attribution) + + ' is not found in ' + JSON.stringify(expected) + '.'); +} + +function checkBreakdown(breakdown, expected) { + assert_own_property(breakdown, 'bytes'); + assert_greater_than_equal(breakdown.bytes, 0); + assert_own_property(breakdown, 'types'); + for (const memoryType of breakdown.types) { + assert_equals(typeof memoryType, 'string'); + } + assert_own_property(breakdown, 'attribution'); + for (const attribution of breakdown.attribution) { + checkAttribution(attribution, expected); + } +} + +function isEmptyBreakdownEntry(entry) { + return entry.bytes === 0 && entry.attribution.length === 0 && + entry.types.length === 0; +} + +function checkMeasureMemory(result, expected) { + assert_own_property(result, 'bytes'); + assert_own_property(result, 'breakdown'); + let bytes = 0; + for (let breakdown of result.breakdown) { + checkBreakdown(breakdown, expected); + bytes += breakdown.bytes; + } + assert_equals(bytes, result.bytes); + for (const e of expected) { + if (e.required) { + assert_true(e.found, + JSON.stringify(e) + ' did not appear in the result.'); + } + } + assert_true(result.breakdown.some(isEmptyBreakdownEntry), + 'The result must include an empty breakdown entry.'); +}
\ No newline at end of file |