From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- testing/web-platform/tests/user-timing/META.yml | 4 + .../tests/user-timing/buffered-flag.any.js | 27 ++ .../tests/user-timing/case-sensitivity.any.js | 25 ++ .../web-platform/tests/user-timing/clearMarks.html | 84 +++++ .../tests/user-timing/clearMeasures.html | 77 +++++ .../tests/user-timing/clear_all_marks.any.js | 17 + .../tests/user-timing/clear_all_measures.any.js | 21 ++ .../user-timing/clear_non_existent_mark.any.js | 26 ++ .../user-timing/clear_non_existent_measure.any.js | 29 ++ .../tests/user-timing/clear_one_mark.any.js | 26 ++ .../tests/user-timing/clear_one_measure.any.js | 29 ++ .../tests/user-timing/entry_type.any.js | 13 + .../user-timing/idlharness-shadowrealm.window.js | 2 + .../tests/user-timing/idlharness.any.js | 33 ++ .../user-timing/invoke_with_timing_attributes.html | 35 ++ .../invoke_with_timing_attributes.worker.js | 25 ++ .../user-timing/invoke_without_parameter.html | 26 ++ .../user-timing/mark-entry-constructor.any.js | 40 +++ .../tests/user-timing/mark-errors.any.js | 50 +++ .../web-platform/tests/user-timing/mark-l3.any.js | 39 +++ .../mark-measure-feature-detection.html | 36 ++ .../user-timing/mark-measure-return-objects.any.js | 37 +++ testing/web-platform/tests/user-timing/mark.any.js | 118 +++++++ testing/web-platform/tests/user-timing/mark.html | 58 ++++ .../tests/user-timing/mark_exceptions.html | 41 +++ .../tests/user-timing/measure-exceptions.html | 49 +++ .../tests/user-timing/measure-l3.any.js | 35 ++ .../tests/user-timing/measure-with-dict.any.js | 112 +++++++ .../web-platform/tests/user-timing/measure.html | 362 +++++++++++++++++++++ .../measure_associated_with_navigation_timing.html | 66 ++++ .../tests/user-timing/measure_exception.html | 34 ++ .../measure_exceptions_navigation_timing.html | 70 ++++ .../user-timing/measure_navigation_timing.html | 205 ++++++++++++ .../tests/user-timing/measure_syntax_err.any.js | 33 ++ .../web-platform/tests/user-timing/measures.html | 66 ++++ .../performance-measure-invalid.worker.js | 16 + .../user-timing/resources/user-timing-helper.js | 30 ++ .../user-timing/resources/webperftestharness.js | 124 +++++++ .../resources/webperftestharnessextension.js | 202 ++++++++++++ .../user-timing/structured-serialize-detail.any.js | 66 ++++ .../user-timing/supported-usertiming-types.any.js | 37 +++ .../tests/user-timing/user-timing-tojson.html | 44 +++ .../tests/user-timing/user_timing_exists.any.js | 12 + 43 files changed, 2481 insertions(+) create mode 100644 testing/web-platform/tests/user-timing/META.yml create mode 100644 testing/web-platform/tests/user-timing/buffered-flag.any.js create mode 100644 testing/web-platform/tests/user-timing/case-sensitivity.any.js create mode 100644 testing/web-platform/tests/user-timing/clearMarks.html create mode 100644 testing/web-platform/tests/user-timing/clearMeasures.html create mode 100644 testing/web-platform/tests/user-timing/clear_all_marks.any.js create mode 100644 testing/web-platform/tests/user-timing/clear_all_measures.any.js create mode 100644 testing/web-platform/tests/user-timing/clear_non_existent_mark.any.js create mode 100644 testing/web-platform/tests/user-timing/clear_non_existent_measure.any.js create mode 100644 testing/web-platform/tests/user-timing/clear_one_mark.any.js create mode 100644 testing/web-platform/tests/user-timing/clear_one_measure.any.js create mode 100644 testing/web-platform/tests/user-timing/entry_type.any.js create mode 100644 testing/web-platform/tests/user-timing/idlharness-shadowrealm.window.js create mode 100644 testing/web-platform/tests/user-timing/idlharness.any.js create mode 100644 testing/web-platform/tests/user-timing/invoke_with_timing_attributes.html create mode 100644 testing/web-platform/tests/user-timing/invoke_with_timing_attributes.worker.js create mode 100644 testing/web-platform/tests/user-timing/invoke_without_parameter.html create mode 100644 testing/web-platform/tests/user-timing/mark-entry-constructor.any.js create mode 100644 testing/web-platform/tests/user-timing/mark-errors.any.js create mode 100644 testing/web-platform/tests/user-timing/mark-l3.any.js create mode 100644 testing/web-platform/tests/user-timing/mark-measure-feature-detection.html create mode 100644 testing/web-platform/tests/user-timing/mark-measure-return-objects.any.js create mode 100644 testing/web-platform/tests/user-timing/mark.any.js create mode 100644 testing/web-platform/tests/user-timing/mark.html create mode 100644 testing/web-platform/tests/user-timing/mark_exceptions.html create mode 100644 testing/web-platform/tests/user-timing/measure-exceptions.html create mode 100644 testing/web-platform/tests/user-timing/measure-l3.any.js create mode 100644 testing/web-platform/tests/user-timing/measure-with-dict.any.js create mode 100644 testing/web-platform/tests/user-timing/measure.html create mode 100644 testing/web-platform/tests/user-timing/measure_associated_with_navigation_timing.html create mode 100644 testing/web-platform/tests/user-timing/measure_exception.html create mode 100644 testing/web-platform/tests/user-timing/measure_exceptions_navigation_timing.html create mode 100644 testing/web-platform/tests/user-timing/measure_navigation_timing.html create mode 100644 testing/web-platform/tests/user-timing/measure_syntax_err.any.js create mode 100644 testing/web-platform/tests/user-timing/measures.html create mode 100644 testing/web-platform/tests/user-timing/performance-measure-invalid.worker.js create mode 100644 testing/web-platform/tests/user-timing/resources/user-timing-helper.js create mode 100644 testing/web-platform/tests/user-timing/resources/webperftestharness.js create mode 100644 testing/web-platform/tests/user-timing/resources/webperftestharnessextension.js create mode 100644 testing/web-platform/tests/user-timing/structured-serialize-detail.any.js create mode 100644 testing/web-platform/tests/user-timing/supported-usertiming-types.any.js create mode 100644 testing/web-platform/tests/user-timing/user-timing-tojson.html create mode 100644 testing/web-platform/tests/user-timing/user_timing_exists.any.js (limited to 'testing/web-platform/tests/user-timing') diff --git a/testing/web-platform/tests/user-timing/META.yml b/testing/web-platform/tests/user-timing/META.yml new file mode 100644 index 0000000000..5cb2a789c0 --- /dev/null +++ b/testing/web-platform/tests/user-timing/META.yml @@ -0,0 +1,4 @@ +spec: https://w3c.github.io/user-timing/ +suggested_reviewers: + - plehegar + - igrigorik diff --git a/testing/web-platform/tests/user-timing/buffered-flag.any.js b/testing/web-platform/tests/user-timing/buffered-flag.any.js new file mode 100644 index 0000000000..f938c8522d --- /dev/null +++ b/testing/web-platform/tests/user-timing/buffered-flag.any.js @@ -0,0 +1,27 @@ +async_test(t => { + // First observer creates second in callback to ensure the entry has been dispatched by the time + // the second observer begins observing. + new PerformanceObserver(() => { + // Second observer requires 'buffered: true' to see an entry. + new PerformanceObserver(t.step_func_done(list => { + const entries = list.getEntries(); + assert_equals(entries.length, 1, 'There should be 1 mark entry.'); + assert_equals(entries[0].entryType, 'mark'); + })).observe({type: 'mark', buffered: true}); + }).observe({entryTypes: ['mark']}); + performance.mark('foo'); +}, 'PerformanceObserver with buffered flag sees previous marks'); + +async_test(t => { + // First observer creates second in callback to ensure the entry has been dispatched by the time + // the second observer begins observing. + new PerformanceObserver(() => { + // Second observer requires 'buffered: true' to see an entry. + new PerformanceObserver(t.step_func_done(list => { + const entries = list.getEntries(); + assert_equals(entries.length, 1, 'There should be 1 measure entry.'); + assert_equals(entries[0].entryType, 'measure'); + })).observe({type: 'measure', buffered: true}); + }).observe({entryTypes: ['measure']}); + performance.measure('bar'); +}, 'PerformanceObserver with buffered flag sees previous measures'); diff --git a/testing/web-platform/tests/user-timing/case-sensitivity.any.js b/testing/web-platform/tests/user-timing/case-sensitivity.any.js new file mode 100644 index 0000000000..1c0b0dcac3 --- /dev/null +++ b/testing/web-platform/tests/user-timing/case-sensitivity.any.js @@ -0,0 +1,25 @@ + test(function () { + assert_equals(typeof self.performance, "object"); + assert_equals(typeof self.performance.getEntriesByType, "function"); + + self.performance.mark("mark1"); + self.performance.measure("measure1"); + + const type = [ + 'mark', + 'measure', + ]; + type.forEach(function(entryType) { + if (PerformanceObserver.supportedEntryTypes.includes(entryType)) { + const entryTypeUpperCased = entryType.toUpperCase(); + const entryTypeCapitalized = entryType[0].toUpperCase() + entryType.substring(1); + const lowerList = self.performance.getEntriesByType(entryType); + const upperList = self.performance.getEntriesByType(entryTypeUpperCased); + const mixedList = self.performance.getEntriesByType(entryTypeCapitalized); + + assert_greater_than(lowerList.length, 0, "Entries exist"); + assert_equals(upperList.length, 0, "getEntriesByType('" + entryTypeCapitalized + "').length"); + assert_equals(mixedList.length, 0, "getEntriesByType('" + entryTypeCapitalized + "').length"); + } + }); + }, "getEntriesByType values are case sensitive"); diff --git a/testing/web-platform/tests/user-timing/clearMarks.html b/testing/web-platform/tests/user-timing/clearMarks.html new file mode 100644 index 0000000000..92c60a3bbb --- /dev/null +++ b/testing/web-platform/tests/user-timing/clearMarks.html @@ -0,0 +1,84 @@ + + + + +functionality test of window.performance.clearMarks + + + + + + + + + + +

Description

+

This test validates functionality of the interface window.performance.clearMarks.

+
+ + diff --git a/testing/web-platform/tests/user-timing/clearMeasures.html b/testing/web-platform/tests/user-timing/clearMeasures.html new file mode 100644 index 0000000000..54d4100569 --- /dev/null +++ b/testing/web-platform/tests/user-timing/clearMeasures.html @@ -0,0 +1,77 @@ + + + + +functionality test of window.performance.clearMeasures + + + + + + + + + + +

Description

+

This test validates functionality of the interface window.performance.clearMeasures.

+
+ + diff --git a/testing/web-platform/tests/user-timing/clear_all_marks.any.js b/testing/web-platform/tests/user-timing/clear_all_marks.any.js new file mode 100644 index 0000000000..35cd2a04f6 --- /dev/null +++ b/testing/web-platform/tests/user-timing/clear_all_marks.any.js @@ -0,0 +1,17 @@ +test(function() { + self.performance.mark("mark1"); + self.performance.mark("mark2"); + + // test that two marks have been created + var entries = self.performance.getEntriesByType("mark"); + assert_equals(entries.length, 2, "Two marks have been created for this test."); + + // clear all marks + self.performance.clearMarks(); + + // test that all marks were cleared + entries = self.performance.getEntriesByType("mark"); + + assert_equals(entries.length, 0, "All marks have been cleared."); + +}, "Clearing all marks remove all of them."); diff --git a/testing/web-platform/tests/user-timing/clear_all_measures.any.js b/testing/web-platform/tests/user-timing/clear_all_measures.any.js new file mode 100644 index 0000000000..32c993f282 --- /dev/null +++ b/testing/web-platform/tests/user-timing/clear_all_measures.any.js @@ -0,0 +1,21 @@ +test(function() +{ + self.performance.mark("mark1"); + self.performance.measure("measure1", "mark1"); + self.performance.mark("mark2"); + self.performance.measure("measure2", "mark2"); + + // test that two measures have been created + var entries = self.performance.getEntriesByType("measure"); + assert_equals(entries.length, 2, "Two measures have been created for this test."); + + // clear all measures + self.performance.clearMeasures(); + + // test that all measures were cleared + entries = self.performance.getEntriesByType("measure"); + assert_equals(entries.length, 0, + "After a call to self.performance.clearMeasures(), " + + "self.performance.getEntriesByType(\"measure\") returns an empty object."); + +}, "Clearing all marks remove all of them."); diff --git a/testing/web-platform/tests/user-timing/clear_non_existent_mark.any.js b/testing/web-platform/tests/user-timing/clear_non_existent_mark.any.js new file mode 100644 index 0000000000..c7d8b47861 --- /dev/null +++ b/testing/web-platform/tests/user-timing/clear_non_existent_mark.any.js @@ -0,0 +1,26 @@ +test(function() { + self.performance.mark("mark1"); + self.performance.mark("mark2"); + + // test that two marks have been created + var entries = self.performance.getEntriesByType("mark"); + assert_equals(entries.length, 2, "Two marks have been created for this test."); + + // clear non-existent mark + self.performance.clearMarks("mark3"); + + // test that "mark1" still exists + entries = self.performance.getEntriesByName("mark1"); + assert_equals(entries[0].name, "mark1", + "After a call to self.performance.clearMarks(\"mark3\"), where \"mark3" + + "\" is a non-existent mark, self.performance.getEntriesByName(\"mark1\") " + + "returns an object containing the \"mark1\" mark."); + + // test that "mark2" still exists + entries = self.performance.getEntriesByName("mark2"); + assert_equals(entries[0].name, "mark2", + "After a call to self.performance.clearMarks(\"mark3\"), where \"mark3" + + "\" is a non-existent mark, self.performance.getEntriesByName(\"mark2\") " + + "returns an object containing the \"mark2\" mark."); + +}, "Clearing a non-existent mark doesn't affect existing marks"); diff --git a/testing/web-platform/tests/user-timing/clear_non_existent_measure.any.js b/testing/web-platform/tests/user-timing/clear_non_existent_measure.any.js new file mode 100644 index 0000000000..9de0b5f266 --- /dev/null +++ b/testing/web-platform/tests/user-timing/clear_non_existent_measure.any.js @@ -0,0 +1,29 @@ +test(function() +{ + self.performance.mark("mark1"); + self.performance.measure("measure1", "mark1"); + self.performance.mark("mark2"); + self.performance.measure("measure2", "mark2"); + + // test that two measures have been created + var entries = self.performance.getEntriesByType("measure"); + assert_equals(entries.length, 2, "Two measures have been created for this test."); + + // clear non-existent measure + self.performance.clearMeasures("measure3"); + + // test that "measure1" still exists + entries = self.performance.getEntriesByName("measure1"); + assert_equals(entries[0].name, "measure1", + "After a call to self.performance.clearMeasures(\"measure3\"), where \"measure3" + + "\" is a non-existent measure, self.performance.getEntriesByName(\"measure1\") " + + "returns an object containing the \"measure1\" measure."); + + // test that "measure2" still exists + entries = self.performance.getEntriesByName("measure2"); + assert_equals(entries[0].name, "measure2", + "After a call to self.performance.clearMeasures(\"measure3\"), where \"measure3" + + "\" is a non-existent measure, self.performance.getEntriesByName(\"measure2\") " + + "returns an object containing the \"measure2\" measure."); + +}, "Clearing a non-existent measure doesn't affect existing measures"); diff --git a/testing/web-platform/tests/user-timing/clear_one_mark.any.js b/testing/web-platform/tests/user-timing/clear_one_mark.any.js new file mode 100644 index 0000000000..c180199d8c --- /dev/null +++ b/testing/web-platform/tests/user-timing/clear_one_mark.any.js @@ -0,0 +1,26 @@ +test(function() { + self.performance.mark("mark1"); + self.performance.mark("mark2"); + + // test that two marks have been created + var entries = self.performance.getEntriesByType("mark"); + assert_equals(entries.length, 2, "Two marks have been created for this test."); + + // clear existent mark + self.performance.clearMarks("mark1"); + + // test that "mark1" was cleared + entries = self.performance.getEntriesByName("mark1"); + + assert_equals(entries.length, 0, + "After a call to self.performance.clearMarks(\"mark1\"), " + + "window.performance.getEntriesByName(\"mark1\") returns an empty object."); + + // test that "mark2" still exists + entries = self.performance.getEntriesByName("mark2"); + assert_equals(entries[0].name, "mark2", + "After a call to self.performance.clearMarks(\"mark1\"), " + + "window.performance.getEntriesByName(\"mark2\") returns an object containing the " + + "\"mark2\" mark."); + +}, "Clearing an existent mark doesn't affect other existing marks"); diff --git a/testing/web-platform/tests/user-timing/clear_one_measure.any.js b/testing/web-platform/tests/user-timing/clear_one_measure.any.js new file mode 100644 index 0000000000..a5e663772c --- /dev/null +++ b/testing/web-platform/tests/user-timing/clear_one_measure.any.js @@ -0,0 +1,29 @@ +test(function() +{ + self.performance.mark("mark1"); + self.performance.measure("measure1", "mark1"); + self.performance.mark("mark2"); + self.performance.measure("measure2", "mark2"); + + // test that two measures have been created + var entries = self.performance.getEntriesByType("measure"); + assert_equals(entries.length, 2, "Two measures have been created for this test."); + + // clear existent measure + self.performance.clearMeasures("measure1"); + + // test that "measure1" was cleared + entries = self.performance.getEntriesByName("measure1"); + + assert_equals(entries.length, 0, + "After a call to self.performance.clearMeasures(\"measure1\"), " + + "self.performance.getEntriesByName(\"measure1\") returns an empty object."); + + // test that "measure2" still exists + entries = self.performance.getEntriesByName("measure2"); + assert_equals(entries[0].name, "measure2", + "After a call to self.performance.clearMeasures(\"measure1\"), " + + "self.performance.getEntriesByName(\"measure2\") returns an object containing the " + + "\"measure2\" measure."); + +}, "Clearing an existent measure doesn't affect other existing measures"); diff --git a/testing/web-platform/tests/user-timing/entry_type.any.js b/testing/web-platform/tests/user-timing/entry_type.any.js new file mode 100644 index 0000000000..1e37453d09 --- /dev/null +++ b/testing/web-platform/tests/user-timing/entry_type.any.js @@ -0,0 +1,13 @@ +test(function () { + self.performance.mark('mark'); + var mark_entry = self.performance.getEntriesByName('mark')[0]; + + assert_equals(Object.prototype.toString.call(mark_entry), '[object PerformanceMark]', 'Class name of mark entry should be PerformanceMark.'); +}, "Validate the user timing entry type PerformanceMark"); + +test(function () { + self.performance.measure('measure'); + var measure_entry = self.performance.getEntriesByName('measure')[0]; + + assert_equals(Object.prototype.toString.call(measure_entry), '[object PerformanceMeasure]', 'Class name of measure entry should be PerformanceMeasure.'); +}, "Validate the user timing entry type PerformanceMeasure"); diff --git a/testing/web-platform/tests/user-timing/idlharness-shadowrealm.window.js b/testing/web-platform/tests/user-timing/idlharness-shadowrealm.window.js new file mode 100644 index 0000000000..340da96f74 --- /dev/null +++ b/testing/web-platform/tests/user-timing/idlharness-shadowrealm.window.js @@ -0,0 +1,2 @@ +// META: script=/resources/idlharness-shadowrealm.js +idl_test_shadowrealm(["user-timing"], ["hr-time", "performance-timeline", "dom"]); diff --git a/testing/web-platform/tests/user-timing/idlharness.any.js b/testing/web-platform/tests/user-timing/idlharness.any.js new file mode 100644 index 0000000000..511f2d0455 --- /dev/null +++ b/testing/web-platform/tests/user-timing/idlharness.any.js @@ -0,0 +1,33 @@ +// META: global=window,worker +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js +// META: timeout=long + +// https://w3c.github.io/user-timing/ + +'use strict'; + +idl_test( + ['user-timing'], + ['hr-time', 'performance-timeline', 'dom'], + idl_array => { + try { + performance.mark('test'); + performance.measure('test'); + for (const m of performance.getEntriesByType('mark')) { + self.mark = m; + } + for (const m of performance.getEntriesByType('measure')) { + self.measure = m; + } + } catch (e) { + // Will be surfaced when mark is undefined below. + } + + idl_array.add_objects({ + Performance: ['performance'], + PerformanceMark: ['mark'], + PerformanceMeasure: ['measure'], + }); + } +); diff --git a/testing/web-platform/tests/user-timing/invoke_with_timing_attributes.html b/testing/web-platform/tests/user-timing/invoke_with_timing_attributes.html new file mode 100644 index 0000000000..1df94a3006 --- /dev/null +++ b/testing/web-platform/tests/user-timing/invoke_with_timing_attributes.html @@ -0,0 +1,35 @@ + + + + + exception test of performance.mark and performance.measure + + + + + + +

Description

+

This test validates exception scenarios of invoking mark() and measure() with timing attributes as value.

+
+ + + diff --git a/testing/web-platform/tests/user-timing/invoke_with_timing_attributes.worker.js b/testing/web-platform/tests/user-timing/invoke_with_timing_attributes.worker.js new file mode 100644 index 0000000000..32677c64d3 --- /dev/null +++ b/testing/web-platform/tests/user-timing/invoke_with_timing_attributes.worker.js @@ -0,0 +1,25 @@ +importScripts("/resources/testharness.js"); +importScripts("resources/webperftestharness.js"); + +function emit_test(attrName) { + test(function() { + performance.mark(attrName); + performance.clearMarks(attrName); + }, "performance.mark should not throw if used with timing attribute " + attrName + + " in workers"); +} +for (var i in timingAttributes) { + emit_test(timingAttributes[i]); +} + +function emit_test2(attrName) { + test(function() { + performance.measure(attrName); + performance.clearMeasures(attrName); + }, "performance.measure should not throw if used with timing attribute " + attrName + + " in workers"); +} +for (var i in timingAttributes) { + emit_test2(timingAttributes[i]); +} +done(); diff --git a/testing/web-platform/tests/user-timing/invoke_without_parameter.html b/testing/web-platform/tests/user-timing/invoke_without_parameter.html new file mode 100644 index 0000000000..114435e59b --- /dev/null +++ b/testing/web-platform/tests/user-timing/invoke_without_parameter.html @@ -0,0 +1,26 @@ + + + + + exception test of performance.mark and performance.measure + + + + + + + +

Description

+

This test validates exception scenarios of invoking mark() and measure() without parameter.

+
+ + + diff --git a/testing/web-platform/tests/user-timing/mark-entry-constructor.any.js b/testing/web-platform/tests/user-timing/mark-entry-constructor.any.js new file mode 100644 index 0000000000..ef9c403dda --- /dev/null +++ b/testing/web-platform/tests/user-timing/mark-entry-constructor.any.js @@ -0,0 +1,40 @@ +// META: script=resources/user-timing-helper.js + +test(()=>{ + const entry = new PerformanceMark("name"); + assert_true(entry instanceof PerformanceMark); + checkEntry(entry, {name: "name", entryType: "mark"}); +}, "Mark entry can be created by 'new PerformanceMark(string)'."); + +test(()=>{ + const entry = new PerformanceMark("name", {}); + assert_true(entry instanceof PerformanceMark); + checkEntry(entry, {name: "name", entryType: "mark"}); +}, "Mark entry can be created by 'new PerformanceMark(string, {})'."); + +test(()=>{ + const entry = new PerformanceMark("name", {startTime: 1}); + assert_true(entry instanceof PerformanceMark); + checkEntry(entry, {name: "name", entryType: "mark", startTime: 1}); +}, "Mark entry can be created by 'new PerformanceMark(string, {startTime})'."); + +test(()=>{ + const entry = new PerformanceMark("name", {detail: {info: "abc"}}); + assert_true(entry instanceof PerformanceMark); + checkEntry(entry, {name: "name", entryType: "mark", detail: {info: "abc"}}); +}, "Mark entry can be created by 'new PerformanceMark(string, {detail})'."); + +test(()=>{ + const entry = + new PerformanceMark("name", {startTime: 1, detail: {info: "abc"}}); + assert_true(entry instanceof PerformanceMark); + checkEntry(entry, {name: "name", entryType: "mark", startTime: 1, detail: {info: "abc"}}); +}, "Mark entry can be created by " + + "'new PerformanceMark(string, {startTime, detail})'."); + +test(()=>{ + const entry = new PerformanceMark("name"); + assert_true(entry instanceof PerformanceMark); + checkEntry(entry, {name: "name", entryType: "mark"}); + assert_equals(performance.getEntriesByName("name").length, 0); +}, "Using new PerformanceMark() shouldn't add the entry to performance timeline."); diff --git a/testing/web-platform/tests/user-timing/mark-errors.any.js b/testing/web-platform/tests/user-timing/mark-errors.any.js new file mode 100644 index 0000000000..39bafc045c --- /dev/null +++ b/testing/web-platform/tests/user-timing/mark-errors.any.js @@ -0,0 +1,50 @@ +// If you're testing an API that constructs a PerformanceMark, add your test here. +// See the for loop below for details. +const markConstructionTests = [ + { + testName: "Number should be rejected as the mark-options.", + testFunction: function(newMarkFunction) { + assert_throws_js(TypeError, function() { newMarkFunction("mark1", 123); }, "Number passed as a dict argument should cause type-error."); + }, + }, + + { + testName: "NaN should be rejected as the mark-options.", + testFunction: function(newMarkFunction) { + assert_throws_js(TypeError, function() { newMarkFunction("mark1", NaN); }, "NaN passed as a dict argument should cause type-error."); + }, + }, + + { + testName: "Infinity should be rejected as the mark-options.", + testFunction: function(newMarkFunction) { + assert_throws_js(TypeError, function() { newMarkFunction("mark1", Infinity); }, "Infinity passed as a dict argument should cause type-error."); + }, + }, + + { + testName: "String should be rejected as the mark-options.", + testFunction: function(newMarkFunction) { + assert_throws_js(TypeError, function() { newMarkFunction("mark1", "string"); }, "String passed as a dict argument should cause type-error.") + }, + }, + + { + testName: "Negative startTime in mark-options should be rejected", + testFunction: function(newMarkFunction) { + assert_throws_js(TypeError, function() { newMarkFunction("mark1", {startTime: -1}); }, "Negative startTime should cause type-error.") + }, + }, +]; + +// There are multiple function calls that can construct a mark using the same arguments so we run +// each test on each construction method here, avoiding duplication. +for (let testInfo of markConstructionTests) { + test(function() { + testInfo.testFunction(self.performance.mark); + }, `[performance.mark]: ${testInfo.testName}`); + + test(function() { + testInfo.testFunction((markName, obj) => new PerformanceMark(markName, obj)); + }, `[new PerformanceMark]: ${testInfo.testName}`); +} diff --git a/testing/web-platform/tests/user-timing/mark-l3.any.js b/testing/web-platform/tests/user-timing/mark-l3.any.js new file mode 100644 index 0000000000..407a5c8bba --- /dev/null +++ b/testing/web-platform/tests/user-timing/mark-l3.any.js @@ -0,0 +1,39 @@ +// META: script=resources/user-timing-helper.js + +async_test(function (t) { + let mark_entries = []; + const expected_entries = + [{ entryType: "mark", name: "mark1", detail: null}, + { entryType: "mark", name: "mark2", detail: null}, + { entryType: "mark", name: "mark3", detail: null}, + { entryType: "mark", name: "mark4", detail: null}, + { entryType: "mark", name: "mark5", detail: null}, + { entryType: "mark", name: "mark6", detail: {}}, + { entryType: "mark", name: "mark7", detail: {info: 'abc'}}, + { entryType: "mark", name: "mark8", detail: null, startTime: 234.56}, + { entryType: "mark", name: "mark9", detail: {count: 3}, startTime: 345.67}]; + const observer = new PerformanceObserver( + t.step_func(function (entryList, obs) { + mark_entries = + mark_entries.concat(entryList.getEntries()); + if (mark_entries.length >= expected_entries.length) { + checkEntries(mark_entries, expected_entries); + observer.disconnect(); + t.done(); + } + }) + ); + self.performance.clearMarks(); + observer.observe({entryTypes: ["mark"]}); + const returned_entries = []; + returned_entries.push(self.performance.mark("mark1")); + returned_entries.push(self.performance.mark("mark2", undefined)); + returned_entries.push(self.performance.mark("mark3", null)); + returned_entries.push(self.performance.mark("mark4", {})); + returned_entries.push(self.performance.mark("mark5", {detail: null})); + returned_entries.push(self.performance.mark("mark6", {detail: {}})); + returned_entries.push(self.performance.mark("mark7", {detail: {info: 'abc'}})); + returned_entries.push(self.performance.mark("mark8", {startTime: 234.56})); + returned_entries.push(self.performance.mark("mark9", {detail: {count: 3}, startTime: 345.67})); + checkEntries(returned_entries, expected_entries); +}, "mark entries' detail and startTime are customizable."); diff --git a/testing/web-platform/tests/user-timing/mark-measure-feature-detection.html b/testing/web-platform/tests/user-timing/mark-measure-feature-detection.html new file mode 100644 index 0000000000..6f1ad489e9 --- /dev/null +++ b/testing/web-platform/tests/user-timing/mark-measure-feature-detection.html @@ -0,0 +1,36 @@ + + +User Timing: L2 vs L3 feature detection + + + diff --git a/testing/web-platform/tests/user-timing/mark-measure-return-objects.any.js b/testing/web-platform/tests/user-timing/mark-measure-return-objects.any.js new file mode 100644 index 0000000000..bb15c58398 --- /dev/null +++ b/testing/web-platform/tests/user-timing/mark-measure-return-objects.any.js @@ -0,0 +1,37 @@ +async_test(function (t) { + self.performance.clearMeasures(); + const measure = self.performance.measure("measure1"); + assert_true(measure instanceof PerformanceMeasure); + t.done(); +}, "L3: performance.measure(name) should return an entry."); + +async_test(function (t) { + self.performance.clearMeasures(); + const measure = self.performance.measure("measure2", + { start: 12, end: 23 }); + assert_true(measure instanceof PerformanceMeasure); + t.done(); +}, "L3: performance.measure(name, param1) should return an entry."); + +async_test(function (t) { + self.performance.clearMeasures(); + self.performance.mark("1"); + self.performance.mark("2"); + const measure = self.performance.measure("measure3", "1", "2"); + assert_true(measure instanceof PerformanceMeasure); + t.done(); +}, "L3: performance.measure(name, param1, param2) should return an entry."); + +async_test(function (t) { + self.performance.clearMarks(); + const mark = self.performance.mark("mark1"); + assert_true(mark instanceof PerformanceMark); + t.done(); +}, "L3: performance.mark(name) should return an entry."); + +async_test(function (t) { + self.performance.clearMarks(); + const mark = self.performance.mark("mark2", { startTime: 34 }); + assert_true(mark instanceof PerformanceMark); + t.done(); +}, "L3: performance.mark(name, param) should return an entry."); diff --git a/testing/web-platform/tests/user-timing/mark.any.js b/testing/web-platform/tests/user-timing/mark.any.js new file mode 100644 index 0000000000..7e814d2074 --- /dev/null +++ b/testing/web-platform/tests/user-timing/mark.any.js @@ -0,0 +1,118 @@ +// test data +var testThreshold = 20; + +var expectedTimes = new Array(); + +function match_entries(entries, index) +{ + var entry = entries[index]; + var match = self.performance.getEntriesByName("mark")[index]; + assert_equals(entry.name, match.name, "entry.name"); + assert_equals(entry.startTime, match.startTime, "entry.startTime"); + assert_equals(entry.entryType, match.entryType, "entry.entryType"); + assert_equals(entry.duration, match.duration, "entry.duration"); +} + +function filter_entries_by_type(entryList, entryType) +{ + var testEntries = new Array(); + + // filter entryList + for (var i in entryList) + { + if (entryList[i].entryType == entryType) + { + testEntries.push(entryList[i]); + } + } + + return testEntries; +} + +test(function () { + // create first mark + self.performance.mark("mark"); + + expectedTimes[0] = self.performance.now(); + + const entries = self.performance.getEntriesByName("mark"); + assert_equals(entries.length, 1); +}, "Entry 0 is properly created"); + +test(function () { + // create second, duplicate mark + self.performance.mark("mark"); + + expectedTimes[1] = self.performance.now(); + + const entries = self.performance.getEntriesByName("mark"); + assert_equals(entries.length, 2); + +}, "Entry 1 is properly created"); + +function test_mark(index) { + test(function () { + const entries = self.performance.getEntriesByName("mark"); + assert_equals(entries[index].name, "mark", "Entry has the proper name"); + }, "Entry " + index + " has the proper name"); + + test(function () { + const entries = self.performance.getEntriesByName("mark"); + assert_approx_equals(entries[index].startTime, expectedTimes[index], testThreshold); + }, "Entry " + index + " startTime is approximately correct (up to " + testThreshold + + "ms difference allowed)"); + + test(function () { + const entries = self.performance.getEntriesByName("mark"); + assert_equals(entries[index].entryType, "mark"); + }, "Entry " + index + " has the proper entryType"); + + test(function () { + const entries = self.performance.getEntriesByName("mark"); + assert_equals(entries[index].duration, 0); + }, "Entry " + index + " duration == 0"); + + test(function () { + const entries = self.performance.getEntriesByName("mark", "mark"); + assert_equals(entries[index].name, "mark"); + }, "getEntriesByName(\"mark\", \"mark\")[" + index + "] returns an " + + "object containing a \"mark\" mark"); + + test(function () { + const entries = self.performance.getEntriesByName("mark", "mark"); + match_entries(entries, index); + }, "The mark returned by getEntriesByName(\"mark\", \"mark\")[" + index + + "] matches the mark returned by " + + "getEntriesByName(\"mark\")[" + index + "]"); + + test(function () { + const entries = filter_entries_by_type(self.performance.getEntries(), "mark"); + assert_equals(entries[index].name, "mark"); + }, "getEntries()[" + index + "] returns an " + + "object containing a \"mark\" mark"); + + test(function () { + const entries = filter_entries_by_type(self.performance.getEntries(), "mark"); + match_entries(entries, index); + }, "The mark returned by getEntries()[" + index + + "] matches the mark returned by " + + "getEntriesByName(\"mark\")[" + index + "]"); + + test(function () { + const entries = self.performance.getEntriesByType("mark"); + assert_equals(entries[index].name, "mark"); + }, "getEntriesByType(\"mark\")[" + index + "] returns an " + + "object containing a \"mark\" mark"); + + test(function () { + const entries = self.performance.getEntriesByType("mark"); + match_entries(entries, index); + }, "The mark returned by getEntriesByType(\"mark\")[" + index + + "] matches the mark returned by " + + "getEntriesByName(\"mark\")[" + index + "]"); + +} + +for (var i = 0; i < expectedTimes.length; i++) { + test_mark(i); +} diff --git a/testing/web-platform/tests/user-timing/mark.html b/testing/web-platform/tests/user-timing/mark.html new file mode 100644 index 0000000000..e03e9e6247 --- /dev/null +++ b/testing/web-platform/tests/user-timing/mark.html @@ -0,0 +1,58 @@ + + + + +functionality test of window.performance.mark + + + + + + + + + + +

Description

+

This test validates functionality of the interface window.performance.mark.

+
+ + diff --git a/testing/web-platform/tests/user-timing/mark_exceptions.html b/testing/web-platform/tests/user-timing/mark_exceptions.html new file mode 100644 index 0000000000..b445c6b877 --- /dev/null +++ b/testing/web-platform/tests/user-timing/mark_exceptions.html @@ -0,0 +1,41 @@ + + + + + window.performance User Timing mark() method is throwing the proper exceptions + + + + + + + + + +

Description

+

This test validates that the performance.mark() method throws a SYNTAX_ERR exception whenever a navigation + timing attribute is provided for the name parameter. +

+ +
+ + diff --git a/testing/web-platform/tests/user-timing/measure-exceptions.html b/testing/web-platform/tests/user-timing/measure-exceptions.html new file mode 100644 index 0000000000..2836eaee2a --- /dev/null +++ b/testing/web-platform/tests/user-timing/measure-exceptions.html @@ -0,0 +1,49 @@ + + + + This tests that 'performance.measure' throws exceptions with reasonable messages. + + + + + + + \ No newline at end of file diff --git a/testing/web-platform/tests/user-timing/measure-l3.any.js b/testing/web-platform/tests/user-timing/measure-l3.any.js new file mode 100644 index 0000000000..642b55ab63 --- /dev/null +++ b/testing/web-platform/tests/user-timing/measure-l3.any.js @@ -0,0 +1,35 @@ +// META: script=resources/user-timing-helper.js + +function endTime(entry) { + return entry.startTime + entry.duration; +} + +test(function() { + performance.clearMarks(); + performance.clearMeasures(); + const markEntry = performance.mark("mark", {startTime: 123}); + const measureEntry = performance.measure("A", undefined, "mark"); + assert_equals(measureEntry.startTime, 0); + assert_equals(endTime(measureEntry), markEntry.startTime); +}, "When the end mark is given and the start is unprovided, the end time of the measure entry should be the end mark's time, the start time should be 0."); + +test(function() { + performance.clearMarks(); + performance.clearMeasures(); + const markEntry = performance.mark("mark", {startTime: 123}); + const endMin = Number(performance.now().toFixed(2)); + const measureEntry = performance.measure("A", "mark", undefined); + const endMax = Number(performance.now().toFixed(2)); + assert_equals(measureEntry.startTime, markEntry.startTime); + assert_greater_than_equal(Number(endTime(measureEntry).toFixed(2)), endMin); + assert_greater_than_equal(endMax, Number(endTime(measureEntry).toFixed(2))); +}, "When the start mark is given and the end is unprovided, the start time of the measure entry should be the start mark's time, the end should be now."); + +test(function() { + performance.clearMarks(); + performance.clearMeasures(); + const markEntry = performance.mark("mark", {startTime: 123}); + const measureEntry = performance.measure("A", "mark", "mark"); + assert_equals(endTime(measureEntry), markEntry.startTime); + assert_equals(measureEntry.startTime, markEntry.startTime); +}, "When start and end mark are both given, the start time and end time of the measure entry should be the the marks' time, repectively"); diff --git a/testing/web-platform/tests/user-timing/measure-with-dict.any.js b/testing/web-platform/tests/user-timing/measure-with-dict.any.js new file mode 100644 index 0000000000..b452feb0de --- /dev/null +++ b/testing/web-platform/tests/user-timing/measure-with-dict.any.js @@ -0,0 +1,112 @@ +// META: script=resources/user-timing-helper.js + +function cleanupPerformanceTimeline() { + performance.clearMarks(); + performance.clearMeasures(); +} + +async_test(function (t) { + this.add_cleanup(cleanupPerformanceTimeline); + let measureEntries = []; + const timeStamp1 = 784.4; + const timeStamp2 = 1234.5; + const timeStamp3 = 66.6; + const timeStamp4 = 5566; + const expectedEntries = + [{ entryType: "measure", name: "measure1", detail: null, startTime: 0 }, + { entryType: "measure", name: "measure2", detail: null, startTime: 0 }, + { entryType: "measure", name: "measure3", detail: null, startTime: 0 }, + { entryType: "measure", name: "measure4", detail: null }, + { entryType: "measure", name: "measure5", detail: null, startTime: 0 }, + { entryType: "measure", name: "measure6", detail: null, startTime: timeStamp1 }, + { entryType: "measure", name: "measure7", detail: null, startTime: timeStamp1, duration: timeStamp2 - timeStamp1 }, + { entryType: "measure", name: "measure8", detail: null, startTime: 0 }, + { entryType: "measure", name: "measure9", detail: null, startTime: 0 }, + { entryType: "measure", name: "measure10", detail: null, startTime: timeStamp1 }, + { entryType: "measure", name: "measure11", detail: null, startTime: timeStamp3 }, + { entryType: "measure", name: "measure12", detail: null, startTime: 0 }, + { entryType: "measure", name: "measure13", detail: null, startTime: 0 }, + { entryType: "measure", name: "measure14", detail: null, startTime: timeStamp3, duration: timeStamp1 - timeStamp3 }, + { entryType: "measure", name: "measure15", detail: null, startTime: timeStamp1, duration: timeStamp2 - timeStamp1 }, + { entryType: "measure", name: "measure16", detail: null, startTime: timeStamp1 }, + { entryType: "measure", name: "measure17", detail: { customInfo: 159 }, startTime: timeStamp3, duration: timeStamp2 - timeStamp3 }, + { entryType: "measure", name: "measure18", detail: null, startTime: timeStamp1, duration: timeStamp2 - timeStamp1 }, + { entryType: "measure", name: "measure19", detail: null, startTime: timeStamp1, duration: timeStamp2 - timeStamp1 }, + { entryType: "measure", name: "measure20", detail: null, startTime: 0 }, + { entryType: "measure", name: "measure21", detail: null, startTime: 0 }, + { entryType: "measure", name: "measure22", detail: null, startTime: 0 }, + { entryType: "measure", name: "measure23", detail: null, startTime: 0 }]; + const observer = new PerformanceObserver( + t.step_func(function (entryList, obs) { + measureEntries = + measureEntries.concat(entryList.getEntries()); + if (measureEntries.length >= expectedEntries.length) { + checkEntries(measureEntries, expectedEntries); + observer.disconnect(); + t.done(); + } + }) + ); + observer.observe({ entryTypes: ["measure"] }); + self.performance.mark("mark1", { detail: { randomInfo: 3 }, startTime: timeStamp1 }); + self.performance.mark("mark2", { startTime: timeStamp2 }); + + const returnedEntries = []; + returnedEntries.push(self.performance.measure("measure1")); + returnedEntries.push(self.performance.measure("measure2", undefined)); + returnedEntries.push(self.performance.measure("measure3", null)); + returnedEntries.push(self.performance.measure("measure4", 'mark1')); + returnedEntries.push( + self.performance.measure("measure5", null, 'mark1')); + returnedEntries.push( + self.performance.measure("measure6", 'mark1', undefined)); + returnedEntries.push( + self.performance.measure("measure7", 'mark1', 'mark2')); + returnedEntries.push( + self.performance.measure("measure8", {})); + returnedEntries.push( + self.performance.measure("measure9", { start: undefined })); + returnedEntries.push( + self.performance.measure("measure10", { start: 'mark1' })); + returnedEntries.push( + self.performance.measure("measure11", { start: timeStamp3 })); + returnedEntries.push( + self.performance.measure("measure12", { end: undefined })); + returnedEntries.push( + self.performance.measure("measure13", { end: 'mark1' })); + returnedEntries.push( + self.performance.measure("measure14", { start: timeStamp3, end: 'mark1' })); + returnedEntries.push( + self.performance.measure("measure15", { start: timeStamp1, end: timeStamp2, detail: undefined })); + returnedEntries.push( + self.performance.measure("measure16", { start: 'mark1', end: undefined, detail: null })); + returnedEntries.push( + self.performance.measure("measure17", { start: timeStamp3, end: 'mark2', detail: { customInfo: 159 }})); + returnedEntries.push( + self.performance.measure("measure18", { start: timeStamp1, duration: timeStamp2 - timeStamp1 })); + returnedEntries.push( + self.performance.measure("measure19", { duration: timeStamp2 - timeStamp1, end: timeStamp2 })); + // {}, null, undefined, invalid-dict passed to startOrOptions are interpreted as start time being 0. + returnedEntries.push(self.performance.measure("measure20", {}, 'mark1')); + returnedEntries.push(self.performance.measure("measure21", null, 'mark1')); + returnedEntries.push(self.performance.measure("measure22", undefined, 'mark1')); + returnedEntries.push(self.performance.measure("measure23", { invalidDict:1 }, 'mark1')); + checkEntries(returnedEntries, expectedEntries); +}, "measure entries' detail and start/end are customizable"); + +test(function() { + this.add_cleanup(cleanupPerformanceTimeline); + assert_throws_js(TypeError, function() { + self.performance.measure("optionsAndNumberEnd", {'start': 2}, 12); + }, "measure should throw a TypeError when passed an options object and an end time"); + assert_throws_js(TypeError, function() { + self.performance.measure("optionsAndMarkEnd", {'start': 2}, 'mark1'); + }, "measure should throw a TypeError when passed an options object and an end mark"); + assert_throws_js(TypeError, function() { + self.performance.measure("negativeStartInOptions", {'start': -1}); + }, "measure cannot have a negative time stamp."); + assert_throws_js(TypeError, function() { + self.performance.measure("negativeEndInOptions", {'end': -1}); + }, "measure cannot have a negative time stamp for end."); +}, "measure should throw a TypeError when passed an invalid argument combination"); + diff --git a/testing/web-platform/tests/user-timing/measure.html b/testing/web-platform/tests/user-timing/measure.html new file mode 100644 index 0000000000..40f71a3362 --- /dev/null +++ b/testing/web-platform/tests/user-timing/measure.html @@ -0,0 +1,362 @@ + + + + + + window.performance User Timing measure() method is working properly + + + + + + + + + + +

Description

+

This test validates that the performance.measure() method is working properly. This test creates the + following measures to test this method: +

+ After creating each measure, the existence of these measures is validated by calling + performance.getEntriesByName() (both with and without the entryType parameter provided), + performance.getEntriesByType(), and performance.getEntries() +

+ +
+ + diff --git a/testing/web-platform/tests/user-timing/measure_associated_with_navigation_timing.html b/testing/web-platform/tests/user-timing/measure_associated_with_navigation_timing.html new file mode 100644 index 0000000000..a874ad9172 --- /dev/null +++ b/testing/web-platform/tests/user-timing/measure_associated_with_navigation_timing.html @@ -0,0 +1,66 @@ + + + + +functionality test of window.performance.measure + + + + + + + + + + +

Description

+

This test validates functionality of the interface window.performance.measure using keywords from the Navigation Timing spec.

+
+ + diff --git a/testing/web-platform/tests/user-timing/measure_exception.html b/testing/web-platform/tests/user-timing/measure_exception.html new file mode 100644 index 0000000000..5c1aa086c0 --- /dev/null +++ b/testing/web-platform/tests/user-timing/measure_exception.html @@ -0,0 +1,34 @@ + + + + +exception test of window.performance.measure + + + + + + + + + + +

Description

+

This test validates all exception scenarios of method window.performance.measure in User Timing API

+ +
+ + + diff --git a/testing/web-platform/tests/user-timing/measure_exceptions_navigation_timing.html b/testing/web-platform/tests/user-timing/measure_exceptions_navigation_timing.html new file mode 100644 index 0000000000..b1868b2cb6 --- /dev/null +++ b/testing/web-platform/tests/user-timing/measure_exceptions_navigation_timing.html @@ -0,0 +1,70 @@ + + + + + window.performance User Timing measure() method is throwing the proper exceptions + + + + + + + + + +

Description

+

window.performance.measure() method throws a InvalidAccessError + whenever a navigation timing attribute with a value of zero is provided as the startMark or endMark. +

+ +
+ + diff --git a/testing/web-platform/tests/user-timing/measure_navigation_timing.html b/testing/web-platform/tests/user-timing/measure_navigation_timing.html new file mode 100644 index 0000000000..d6480d27a2 --- /dev/null +++ b/testing/web-platform/tests/user-timing/measure_navigation_timing.html @@ -0,0 +1,205 @@ + + + + + + window.performance User Timing clearMeasures() method is working properly with navigation timing + attributes + + + + + + + + + + +

Description

+

This test validates that the performance.measure() method is working properly when navigation timing + attributes are used in place of mark names. This test creates the following measures to test this method: +

+ After creating each measure, the existence of these measures is validated by calling + performance.getEntriesByName() with each measure name +

+ +
+ + diff --git a/testing/web-platform/tests/user-timing/measure_syntax_err.any.js b/testing/web-platform/tests/user-timing/measure_syntax_err.any.js new file mode 100644 index 0000000000..9b762a4090 --- /dev/null +++ b/testing/web-platform/tests/user-timing/measure_syntax_err.any.js @@ -0,0 +1,33 @@ +test(function () { + self.performance.mark("existing_mark"); + var entries = self.performance.getEntriesByName("existing_mark"); + assert_equals(entries.length, 1); + self.performance.measure("measure", "existing_mark"); +}, "Create a mark \"existing_mark\""); +test(function () { + assert_throws_dom("SyntaxError", function () { + self.performance.measure("measure", "mark"); + }); +}, "self.performance.measure(\"measure\", \"mark\"), where \"mark\" is a non-existent mark, " + + "throws a SyntaxError exception."); + +test(function () { + assert_throws_dom("SyntaxError", function () { + self.performance.measure("measure", "mark", "existing_mark"); + }); +}, "self.performance.measure(\"measure\", \"mark\", \"existing_mark\"), where \"mark\" is a " + + "non-existent mark, throws a SyntaxError exception."); + +test(function () { + assert_throws_dom("SyntaxError", function () { + self.performance.measure("measure", "existing_mark", "mark"); + }); +}, "self.performance.measure(\"measure\", \"existing_mark\", \"mark\"), where \"mark\" " + + "is a non-existent mark, throws a SyntaxError exception."); + +test(function () { + assert_throws_dom("SyntaxError", function () { + self.performance.measure("measure", "mark", "mark"); + }); +}, "self.performance.measure(\"measure\", \"mark\", \"mark\"), where \"mark\" is a " + + "non-existent mark, throws a SyntaxError exception."); diff --git a/testing/web-platform/tests/user-timing/measures.html b/testing/web-platform/tests/user-timing/measures.html new file mode 100644 index 0000000000..0de68965dd --- /dev/null +++ b/testing/web-platform/tests/user-timing/measures.html @@ -0,0 +1,66 @@ + + + + +functionality test of window.performance.measure + + + + + + + + + + +

Description

+

This test validates functionality of the interface window.performance.measure.

+
+ + diff --git a/testing/web-platform/tests/user-timing/performance-measure-invalid.worker.js b/testing/web-platform/tests/user-timing/performance-measure-invalid.worker.js new file mode 100644 index 0000000000..bab3c35dcb --- /dev/null +++ b/testing/web-platform/tests/user-timing/performance-measure-invalid.worker.js @@ -0,0 +1,16 @@ +importScripts("/resources/testharness.js"); + +test(() => { + assert_throws_js(TypeError, () => { + performance.measure('name', 'navigationStart', 'navigationStart'); + }); +}, "When converting 'navigationStart' to a timestamp, the global object has to be a Window object."); + +test(() => { + assert_throws_js(TypeError, () => { + performance.mark('navigationStart'); + performance.measure('name', 'navigationStart', 'navigationStart'); + }); +}, "When converting 'navigationStart' to a timestamp and a mark named 'navigationStart' exists, the global object has to be a Window object."); + +done(); diff --git a/testing/web-platform/tests/user-timing/resources/user-timing-helper.js b/testing/web-platform/tests/user-timing/resources/user-timing-helper.js new file mode 100644 index 0000000000..8d43768ec2 --- /dev/null +++ b/testing/web-platform/tests/user-timing/resources/user-timing-helper.js @@ -0,0 +1,30 @@ +// Compares a list of performance entries to a predefined one. +// actualEntries is an array of performance entries from the user agent, +// and expectedEntries is an array of performance entries minted by the test. +// The comparison doesn't assert the order of the entries. +function checkEntries(actualEntries, expectedEntries) { + assert_equals(actualEntries.length, expectedEntries.length, + `The length of actual and expected entries should match. + actual: ${JSON.stringify(actualEntries)}, + expected: ${JSON.stringify(expectedEntries)}`); + const actualEntrySet = new Set(actualEntries.map(ae=>ae.name)); + assert_equals(actualEntrySet.size, actualEntries.length, `Actual entry names are not unique: ${JSON.stringify(actualEntries)}`); + const expectedEntrySet = new Set(expectedEntries.map(ee=>ee.name)); + assert_equals(expectedEntrySet.size, expectedEntries.length, `Expected entry names are not unique: ${JSON.stringify(expectedEntries)}`); + actualEntries.forEach(ae=>{ + const expectedEntry = expectedEntries.find(e=>e.name === ae.name); + assert_true(!!expectedEntry, `Entry name '${ae.name}' was not found.`); + checkEntry(ae, expectedEntry); + }); +} + +function checkEntry(entry, {name, entryType, startTime, detail, duration}) { + assert_equals(entry.name, name); + assert_equals(entry.entryType, entryType); + if (startTime !== undefined) + assert_equals(entry.startTime, startTime); + if (detail !== undefined) + assert_equals(JSON.stringify(entry.detail), JSON.stringify(detail)); + if (duration !== undefined) + assert_equals(entry.duration, duration); +} diff --git a/testing/web-platform/tests/user-timing/resources/webperftestharness.js b/testing/web-platform/tests/user-timing/resources/webperftestharness.js new file mode 100644 index 0000000000..9627e18a03 --- /dev/null +++ b/testing/web-platform/tests/user-timing/resources/webperftestharness.js @@ -0,0 +1,124 @@ +// +// Helper functions for User Timing tests +// + +var timingAttributes = [ + "navigationStart", + "unloadEventStart", + "unloadEventEnd", + "redirectStart", + "redirectEnd", + "fetchStart", + "domainLookupStart", + "domainLookupEnd", + "connectStart", + "connectEnd", + "secureConnectionStart", + "requestStart", + "responseStart", + "responseEnd", + "domLoading", + "domInteractive", + "domContentLoadedEventStart", + "domContentLoadedEventEnd", + "domComplete", + "loadEventStart", + "loadEventEnd" +]; + +function has_required_interfaces() +{ + if (window.performance.mark == undefined || + window.performance.clearMarks == undefined || + window.performance.measure == undefined || + window.performance.clearMeasures == undefined || + window.performance.getEntriesByName == undefined || + window.performance.getEntriesByType == undefined || + window.performance.getEntries == undefined) { + return false; + } + + return true; +} + +function test_namespace(child_name, skip_root) +{ + if (skip_root === undefined) { + var msg = 'window.performance is defined'; + wp_test(function () { assert_not_equals(performanceNamespace, undefined, msg); }, msg); + } + + if (child_name !== undefined) { + var msg2 = 'window.performance.' + child_name + ' is defined'; + wp_test(function() { assert_not_equals(performanceNamespace[child_name], undefined, msg2); }, msg2); + } +} + +function test_attribute_exists(parent_name, attribute_name, properties) +{ + var msg = 'window.performance.' + parent_name + '.' + attribute_name + ' is defined.'; + wp_test(function() { assert_not_equals(performanceNamespace[parent_name][attribute_name], undefined, msg); }, msg, properties); +} + +function test_enum(parent_name, enum_name, value, properties) +{ + var msg = 'window.performance.' + parent_name + '.' + enum_name + ' is defined.'; + wp_test(function() { assert_not_equals(performanceNamespace[parent_name][enum_name], undefined, msg); }, msg, properties); + + msg = 'window.performance.' + parent_name + '.' + enum_name + ' = ' + value; + wp_test(function() { assert_equals(performanceNamespace[parent_name][enum_name], value, msg); }, msg, properties); +} + +function test_timing_order(attribute_name, greater_than_attribute, properties) +{ + // ensure it's not 0 first + var msg = "window.performance.timing." + attribute_name + " > 0"; + wp_test(function() { assert_true(performanceNamespace.timing[attribute_name] > 0, msg); }, msg, properties); + + // ensure it's in the right order + msg = "window.performance.timing." + attribute_name + " >= window.performance.timing." + greater_than_attribute; + wp_test(function() { assert_true(performanceNamespace.timing[attribute_name] >= performanceNamespace.timing[greater_than_attribute], msg); }, msg, properties); +} + +function test_timing_greater_than(attribute_name, greater_than, properties) +{ + var msg = "window.performance.timing." + attribute_name + " > " + greater_than; + test_greater_than(performanceNamespace.timing[attribute_name], greater_than, msg, properties); +} + +function test_timing_equals(attribute_name, equals, msg, properties) +{ + var test_msg = msg || "window.performance.timing." + attribute_name + " == " + equals; + test_equals(performanceNamespace.timing[attribute_name], equals, test_msg, properties); +} + +// +// Non-test related helper functions +// + +function sleep_milliseconds(n) +{ + var start = new Date().getTime(); + while (true) { + if ((new Date().getTime() - start) >= n) break; + } +} + +// +// Common helper functions +// + +function test_greater_than(value, greater_than, msg, properties) +{ + wp_test(function () { assert_greater_than(value, greater_than, msg); }, msg, properties); +} + +function test_greater_or_equals(value, greater_than, msg, properties) +{ + wp_test(function () { assert_greater_than_equal(value, greater_than, msg); }, msg, properties); +} + +function test_not_equals(value, notequals, msg, properties) +{ + wp_test(function() { assert_not_equals(value, notequals, msg); }, msg, properties); +} diff --git a/testing/web-platform/tests/user-timing/resources/webperftestharnessextension.js b/testing/web-platform/tests/user-timing/resources/webperftestharnessextension.js new file mode 100644 index 0000000000..8640918d4f --- /dev/null +++ b/testing/web-platform/tests/user-timing/resources/webperftestharnessextension.js @@ -0,0 +1,202 @@ +// +// Helper functions for User Timing tests +// + +var mark_names = [ + '', + '1', + 'abc', +]; + +var measures = [ + [''], + ['2', 1], + ['aaa', 'navigationStart', ''], +]; + +function test_method_exists(method, method_name, properties) +{ + var msg; + if (typeof method === 'function') + msg = 'performance.' + method.name + ' is supported!'; + else + msg = 'performance.' + method_name + ' is supported!'; + wp_test(function() { assert_equals(typeof method, 'function', msg); }, msg, properties); +} + +function test_method_throw_exception(func_str, exception, msg) +{ + let exception_name; + let test_func; + if (typeof exception == "function") { + exception_name = exception.name; + test_func = assert_throws_js; + } else { + exception_name = exception; + test_func = assert_throws_dom; + } + var msg = 'Invocation of ' + func_str + ' should throw ' + exception_name + ' Exception.'; + wp_test(function() { test_func(exception, function() {eval(func_str)}, msg); }, msg); +} + +function test_noless_than(value, greater_than, msg, properties) +{ + wp_test(function () { assert_true(value >= greater_than, msg); }, msg, properties); +} + +function test_fail(msg, properties) +{ + wp_test(function() { assert_unreached(); }, msg, properties); +} + +function test_resource_entries(entries, expected_entries) +{ + // This is slightly convoluted so that we can sort the output. + var actual_entries = {}; + var origin = window.location.protocol + "//" + window.location.host; + + for (var i = 0; i < entries.length; ++i) { + var entry = entries[i]; + var found = false; + for (var expected_entry in expected_entries) { + if (entry.name == origin + expected_entry) { + found = true; + if (expected_entry in actual_entries) { + test_fail(expected_entry + ' is not expected to have duplicate entries'); + } + actual_entries[expected_entry] = entry; + break; + } + } + if (!found) { + test_fail(entries[i].name + ' is not expected to be in the Resource Timing buffer'); + } + } + + sorted_urls = []; + for (var i in actual_entries) { + sorted_urls.push(i); + } + sorted_urls.sort(); + for (var i in sorted_urls) { + var url = sorted_urls[i]; + test_equals(actual_entries[url].initiatorType, + expected_entries[url], + origin + url + ' is expected to have initiatorType ' + expected_entries[url]); + } + for (var j in expected_entries) { + if (!(j in actual_entries)) { + test_fail(origin + j + ' is expected to be in the Resource Timing buffer'); + } + } +} + +function performance_entrylist_checker(type) +{ + const entryType = type; + + function entry_check(entry, expectedNames, testDescription = '') + { + const msg = testDescription + 'Entry \"' + entry.name + '\" should be one that we have set.'; + wp_test(function() { assert_in_array(entry.name, expectedNames, msg); }, msg); + test_equals(entry.entryType, entryType, testDescription + 'entryType should be \"' + entryType + '\".'); + if (type === "measure") { + test_true(isFinite(entry.startTime), testDescription + 'startTime should be a number.'); + test_true(isFinite(entry.duration), testDescription + 'duration should be a number.'); + } else if (type === "mark") { + test_greater_than(entry.startTime, 0, testDescription + 'startTime should greater than 0.'); + test_equals(entry.duration, 0, testDescription + 'duration of mark should be 0.'); + } + } + + function entrylist_order_check(entryList) + { + let inOrder = true; + for (let i = 0; i < entryList.length - 1; ++i) + { + if (entryList[i + 1].startTime < entryList[i].startTime) { + inOrder = false; + break; + } + } + return inOrder; + } + + function entrylist_check(entryList, expectedLength, expectedNames, testDescription = '') + { + test_equals(entryList.length, expectedLength, testDescription + 'There should be ' + expectedLength + ' entries.'); + test_true(entrylist_order_check(entryList), testDescription + 'Entries in entrylist should be in order.'); + for (let i = 0; i < entryList.length; ++i) + { + entry_check(entryList[i], expectedNames, testDescription + 'Entry_list ' + i + '. '); + } + } + + return{"entrylist_check":entrylist_check}; +} + +function PerformanceContext(context) +{ + this.performanceContext = context; +} + +PerformanceContext.prototype = +{ + + initialMeasures: function(item, index, array) + { + this.performanceContext.measure.apply(this.performanceContext, item); + }, + + mark: function() + { + this.performanceContext.mark.apply(this.performanceContext, arguments); + }, + + measure: function() + { + this.performanceContext.measure.apply(this.performanceContext, arguments); + }, + + clearMarks: function() + { + this.performanceContext.clearMarks.apply(this.performanceContext, arguments); + }, + + clearMeasures: function() + { + this.performanceContext.clearMeasures.apply(this.performanceContext, arguments); + + }, + + getEntries: function() + { + return this.performanceContext.getEntries.apply(this.performanceContext, arguments); + }, + + getEntriesByType: function() + { + return this.performanceContext.getEntriesByType.apply(this.performanceContext, arguments); + }, + + getEntriesByName: function() + { + return this.performanceContext.getEntriesByName.apply(this.performanceContext, arguments); + }, + + setResourceTimingBufferSize: function() + { + return this.performanceContext.setResourceTimingBufferSize.apply(this.performanceContext, arguments); + }, + + registerResourceTimingBufferFullCallback: function(func) + { + this.performanceContext.onresourcetimingbufferfull = func; + }, + + clearResourceTimings: function() + { + this.performanceContext.clearResourceTimings.apply(this.performanceContext, arguments); + } + +}; diff --git a/testing/web-platform/tests/user-timing/structured-serialize-detail.any.js b/testing/web-platform/tests/user-timing/structured-serialize-detail.any.js new file mode 100644 index 0000000000..dcceffde27 --- /dev/null +++ b/testing/web-platform/tests/user-timing/structured-serialize-detail.any.js @@ -0,0 +1,66 @@ +test(function() { + performance.clearMarks(); + const detail = { randomInfo: 123 } + const markEntry = new PerformanceMark("A", { detail }); + assert_equals(markEntry.detail.randomInfo, detail.randomInfo); + assert_not_equals(markEntry.detail, detail); +}, "The detail property in the mark constructor should be structured-clone."); + +test(function() { + performance.clearMarks(); + const detail = { randomInfo: 123 } + const markEntry = performance.mark("A", { detail }); + assert_equals(markEntry.detail.randomInfo, detail.randomInfo); + assert_not_equals(markEntry.detail, detail); +}, "The detail property in the mark method should be structured-clone."); + +test(function() { + performance.clearMarks(); + const markEntry = performance.mark("A"); + assert_equals(markEntry.detail, null); +}, "When accessing detail from a mark entry and the detail is not provided, just return a null value."); + +test(function() { + performance.clearMarks(); + const detail = { unserializable: Symbol() }; + assert_throws_dom("DataCloneError", ()=>{ + new PerformanceMark("A", { detail }); + }, "Trying to structured-serialize a Symbol."); +}, "Mark: Throw an exception when the detail property cannot be structured-serialized."); + +test(function() { + performance.clearMeasures(); + const detail = { randomInfo: 123 } + const measureEntry = performance.measure("A", { start: 0, detail }); + assert_equals(measureEntry.detail.randomInfo, detail.randomInfo); + assert_not_equals(measureEntry.detail, detail); +}, "The detail property in the measure method should be structured-clone."); + +test(function() { + performance.clearMeasures(); + const detail = { randomInfo: 123 } + const measureEntry = performance.measure("A", { start: 0, detail }); + assert_equals(measureEntry.detail, measureEntry.detail); +}, "The detail property in the measure method should be the same reference."); + +test(function() { + performance.clearMeasures(); + const measureEntry = performance.measure("A"); + assert_equals(measureEntry.detail, null); +}, "When accessing detail from a measure entry and the detail is not provided, just return a null value."); + +test(function() { + performance.clearMeasures(); + const detail = { unserializable: Symbol() }; + assert_throws_dom("DataCloneError", ()=>{ + performance.measure("A", { start: 0, detail }); + }, "Trying to structured-serialize a Symbol."); +}, "Measure: Throw an exception when the detail property cannot be structured-serialized."); + +test(function() { + const bar = { 1: 2 }; + const detail = { foo: 1, bar }; + const mark = performance.mark("m", { detail }); + detail.foo = 2; + assert_equals(mark.detail.foo, 1); +}, "The detail object is cloned when passed to mark API."); diff --git a/testing/web-platform/tests/user-timing/supported-usertiming-types.any.js b/testing/web-platform/tests/user-timing/supported-usertiming-types.any.js new file mode 100644 index 0000000000..ea3b2fe9dc --- /dev/null +++ b/testing/web-platform/tests/user-timing/supported-usertiming-types.any.js @@ -0,0 +1,37 @@ +test(() => { + if (typeof PerformanceObserver.supportedEntryTypes === "undefined") + assert_unreached("supportedEntryTypes is not supported."); + const types = PerformanceObserver.supportedEntryTypes; + assert_true(types.includes("mark"), + "There should be 'mark' in PerformanceObserver.supportedEntryTypes"); + assert_true(types.includes("measure"), + "There should be 'measure' in PerformanceObserver.supportedEntryTypes"); + assert_greater_than(types.indexOf("measure"), types.indexOf('mark'), + "The 'measure' entry should appear after the 'mark' entry"); +}, "supportedEntryTypes contains 'mark' and 'measure'."); + +if (typeof PerformanceObserver.supportedEntryTypes !== "undefined") { + const entryTypes = { + "mark": () => { + performance.mark('foo'); + }, + "measure": () => { + performance.measure('bar'); + } + } + for (let entryType in entryTypes) { + if (PerformanceObserver.supportedEntryTypes.includes(entryType)) { + promise_test(async() => { + await new Promise((resolve) => { + new PerformanceObserver(function (list, observer) { + observer.disconnect(); + resolve(); + }).observe({entryTypes: [entryType]}); + + // Force the PerformanceEntry. + entryTypes[entryType](); + }) + }, `'${entryType}' entries should be observable.`) + } + } +} diff --git a/testing/web-platform/tests/user-timing/user-timing-tojson.html b/testing/web-platform/tests/user-timing/user-timing-tojson.html new file mode 100644 index 0000000000..6aef7fa904 --- /dev/null +++ b/testing/web-platform/tests/user-timing/user-timing-tojson.html @@ -0,0 +1,44 @@ + + + + + + + + + + diff --git a/testing/web-platform/tests/user-timing/user_timing_exists.any.js b/testing/web-platform/tests/user-timing/user_timing_exists.any.js new file mode 100644 index 0000000000..adf9052ebd --- /dev/null +++ b/testing/web-platform/tests/user-timing/user_timing_exists.any.js @@ -0,0 +1,12 @@ +test(function() { + assert_not_equals(self.performance.mark, undefined); +}, "self.performance.mark is defined."); +test(function() { + assert_not_equals(self.performance.clearMarks, undefined); +}, "self.performance.clearMarks is defined."); +test(function() { + assert_not_equals(self.performance.measure, undefined); +}, "self.performance.measure is defined."); +test(function() { + assert_not_equals(self.performance.clearMeasures, undefined); +}, "self.performance.clearMeasures is defined."); -- cgit v1.2.3