Commit 11e9b068 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[UserTiming] Add tests to cover edge use-cases for measure API

Before we introduce CustomUserTiming, we need to ensure the edge cases behave
the same between the old and the new API while the feature flag of the new API
is off.

Hereby, we identify the following use cases. As the start/end marks are in
String type, when passing the following args, they are converted to respective
Strings:

{} -> '[object Object]'
null -> 'null'
51.15 -> '51.15'

This CL introduces some test cases to cover these behaviors.

Bug: 758385
Change-Id: I4ad60f907f3d794309bee1d8e3ce4268e2e5f49f
Reviewed-on: https://chromium-review.googlesource.com/883943
Commit-Queue: Liquan Gu <maxlg@chromium.org>
Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531683}
parent ee78a8ec
...@@ -15,6 +15,9 @@ PASS window.performance.measure("measuring", 'domContentLoadedEventEnd', "mark") ...@@ -15,6 +15,9 @@ PASS window.performance.measure("measuring", 'domContentLoadedEventEnd', "mark")
PASS window.performance.measure("measuring", 'domComplete', "mark") threw exception InvalidAccessError: Failed to execute 'measure' on 'Performance': 'domComplete' is empty: either the event hasn't happened yet, or it would provide cross-origin timing information.. PASS window.performance.measure("measuring", 'domComplete', "mark") threw exception InvalidAccessError: Failed to execute 'measure' on 'Performance': 'domComplete' is empty: either the event hasn't happened yet, or it would provide cross-origin timing information..
PASS window.performance.measure("measuring", 'loadEventStart', "mark") threw exception InvalidAccessError: Failed to execute 'measure' on 'Performance': 'loadEventStart' is empty: either the event hasn't happened yet, or it would provide cross-origin timing information.. PASS window.performance.measure("measuring", 'loadEventStart', "mark") threw exception InvalidAccessError: Failed to execute 'measure' on 'Performance': 'loadEventStart' is empty: either the event hasn't happened yet, or it would provide cross-origin timing information..
PASS window.performance.measure("measuring", 'loadEventEnd', "mark") threw exception InvalidAccessError: Failed to execute 'measure' on 'Performance': 'loadEventEnd' is empty: either the event hasn't happened yet, or it would provide cross-origin timing information.. PASS window.performance.measure("measuring", 'loadEventEnd', "mark") threw exception InvalidAccessError: Failed to execute 'measure' on 'Performance': 'loadEventEnd' is empty: either the event hasn't happened yet, or it would provide cross-origin timing information..
PASS window.performance.measure("measuring", 51.15, "mark") threw exception SyntaxError: Failed to execute 'measure' on 'Performance': The mark '51.15' does not exist..
PASS window.performance.measure("measuring", null, "mark") threw exception SyntaxError: Failed to execute 'measure' on 'Performance': The mark 'null' does not exist..
PASS window.performance.measure("measuring", {}, "mark") threw exception SyntaxError: Failed to execute 'measure' on 'Performance': The mark '[object Object]' does not exist..
PASS successfullyParsed is true PASS successfullyParsed is true
TEST COMPLETE TEST COMPLETE
......
...@@ -7,11 +7,13 @@ ...@@ -7,11 +7,13 @@
<script> <script>
description("This tests that 'performance.measure' throws exceptions with reasonable messages."); description("This tests that 'performance.measure' throws exceptions with reasonable messages.");
window.performance.clearMarks();
window.performance.clearMeasures();
shouldThrow('window.performance.measure("DoesNotExist", "AlsoDoesNotExist")', '"SyntaxError: Failed to execute \'measure\' on \'Performance\': The mark \'AlsoDoesNotExist\' does not exist."'); shouldThrow('window.performance.measure("DoesNotExist", "AlsoDoesNotExist")', '"SyntaxError: Failed to execute \'measure\' on \'Performance\': The mark \'AlsoDoesNotExist\' does not exist."');
window.performance.mark('mark'); window.performance.mark('mark');
var allTheExceptionalThings = [ const eventMarks = [
'unloadEventStart', 'unloadEventStart',
'unloadEventEnd', 'unloadEventEnd',
'redirectStart', 'redirectStart',
...@@ -24,9 +26,18 @@ ...@@ -24,9 +26,18 @@
'loadEventStart', 'loadEventStart',
'loadEventEnd', 'loadEventEnd',
]; ];
allTheExceptionalThings.forEach(function(name) { eventMarks.forEach(function(name) {
shouldThrow('window.performance.measure("measuring", \'' + name + '\', "mark")', '"InvalidAccessError: Failed to execute \'measure\' on \'Performance\': \'' + name + '\' is empty: either the event hasn\'t happened yet, or it would provide cross-origin timing information."'); shouldThrow('window.performance.measure("measuring", \'' + name + '\', "mark")', '"InvalidAccessError: Failed to execute \'measure\' on \'Performance\': \'' + name + '\' is empty: either the event hasn\'t happened yet, or it would provide cross-origin timing information."');
}); });
const argAndConvertedArgs = {
"51.15": "51.15",
"null": "null",
"{}": "[object Object]",
};
Object.entries(argAndConvertedArgs).forEach(function(pair) {
shouldThrow('window.performance.measure("measuring", ' + pair[0] + ', "mark")', '"SyntaxError: Failed to execute \'measure\' on \'Performance\': The mark \'' + pair[1]+ '\' does not exist."');
});
</script> </script>
</body> </body>
</html> </html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment