summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/common/performance-timeline-utils.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/common/performance-timeline-utils.js
parentInitial commit. (diff)
downloadfirefox-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/common/performance-timeline-utils.js')
-rw-r--r--testing/web-platform/tests/common/performance-timeline-utils.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/testing/web-platform/tests/common/performance-timeline-utils.js b/testing/web-platform/tests/common/performance-timeline-utils.js
new file mode 100644
index 0000000000..b20241cc61
--- /dev/null
+++ b/testing/web-platform/tests/common/performance-timeline-utils.js
@@ -0,0 +1,56 @@
+/*
+author: W3C http://www.w3.org/
+help: http://www.w3.org/TR/navigation-timing/#sec-window.performance-attribute
+*/
+var performanceNamespace = window.performance;
+var namespace_check = false;
+function wp_test(func, msg, properties)
+{
+ // only run the namespace check once
+ if (!namespace_check)
+ {
+ namespace_check = true;
+
+ if (performanceNamespace === undefined || performanceNamespace == null)
+ {
+ // show a single error that window.performance is undefined
+ // The window.performance attribute provides a hosting area for performance related attributes.
+ test(function() { assert_true(performanceNamespace !== undefined && performanceNamespace != null, "window.performance is defined and not null"); }, "window.performance is defined and not null.");
+ }
+ }
+
+ test(func, msg, properties);
+}
+
+function test_true(value, msg, properties)
+{
+ wp_test(function () { assert_true(value, msg); }, msg, properties);
+}
+
+function test_equals(value, equals, msg, properties)
+{
+ wp_test(function () { assert_equals(value, equals, msg); }, msg, properties);
+}
+
+// assert for every entry in `expectedEntries`, there is a matching entry _somewhere_ in `actualEntries`
+function test_entries(actualEntries, expectedEntries) {
+ test_equals(actualEntries.length, expectedEntries.length)
+ expectedEntries.forEach(function (expectedEntry) {
+ var foundEntry = actualEntries.find(function (actualEntry) {
+ return typeof Object.keys(expectedEntry).find(function (key) {
+ return actualEntry[key] !== expectedEntry[key]
+ }) === 'undefined'
+ })
+ test_true(!!foundEntry, `Entry ${JSON.stringify(expectedEntry)} could not be found.`)
+ if (foundEntry) {
+ assert_object_equals(foundEntry.toJSON(), expectedEntry)
+ }
+ })
+}
+
+function delayedLoadListener(callback) {
+ window.addEventListener('load', function() {
+ // TODO(cvazac) Remove this setTimeout when spec enforces sync entries.
+ step_timeout(callback, 0)
+ })
+}