Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toJSON tests for some perf APIs #18436

Merged
merged 1 commit into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions element-timing/toJSON.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Element Timing: toJSON</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/element-timing-helpers.js"></script>
<img elementtiming='img' src="resources/square100.png"/>
<script>
async_test(function (t) {
if (!window.PerformanceElementTiming) {
assert_unreached("PerformanceElementTiming is not implemented");
}
const observer = new PerformanceObserver(
t.step_func_done(function(entryList) {
assert_equals(entryList.getEntries().length, 1);
const entry = entryList.getEntries()[0];
assert_equals(typeof(entry.toJSON), 'function');
const json = entry.toJSON();
assert_equals(typeof(json), 'object');
const keys = [
// PerformanceEntry
'name',
'entryType',
'startTime',
'duration',
// PerformanceElementTiming
'renderTime',
'loadTime',
'intersectionRect',
'identifier',
'naturalWidth',
'naturalHeight',
'id',
'element',
'url',
];
for (const key of keys) {
assert_equals(json[key], entry[key],
'PerformanceElementTiming ${key} entry does not match its toJSON value');
}
})
);
observer.observe({type: 'element', buffered: true});
}, 'Test toJSON() in PerformanceElementTiming.');
</script>
</body>
43 changes: 43 additions & 0 deletions event-timing/toJSON.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Event Timing: toJSON</title>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
<script src=/resources/testdriver-vendor.js></script>
<script src=resources/event-timing-test-utils.js></script>
<button id='button'>Generate a 'click' event</button>
<script>
async_test(function (t) {
if (!window.PerformanceEventTiming) {
assert_unreached("PerformanceEventTiming is not implemented");
}
const observer = new PerformanceObserver(
t.step_func_done(function(entryList) {
const entry = entryList.getEntries()[0];
assert_equals(typeof(entry.toJSON), 'function');
const json = entry.toJSON();
assert_equals(typeof(json), 'object');
const keys = [
// PerformanceEntry
'name',
'entryType',
'startTime',
'duration',
// PerformanceEventTiming
'processingStart',
'processingEnd',
'cancelable',
];
for (const key of keys) {
assert_equals(json[key], entry[key],
'PerformanceEventTiming ${key} entry does not match its toJSON value');
}
})
);
observer.observe({type: 'event'});
clickAndBlockMain('button');
}, 'Test toJSON() in PerformanceEventTiming.');
</script>
</body>
42 changes: 42 additions & 0 deletions largest-contentful-paint/toJSON.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Largest Contentful Paint: toJSON</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<p>Text!</p>
<script>
async_test(function (t) {
if (!window.LargestContentfulPaint) {
assert_unreached("LargestContentfulPaint is not implemented");
}
const observer = new PerformanceObserver(
t.step_func_done(function(entryList) {
const entry = entryList.getEntries()[0];
assert_equals(typeof(entry.toJSON), 'function');
const json = entry.toJSON();
assert_equals(typeof(json), 'object');
const keys = [
// PerformanceEntry
'name',
'entryType',
'startTime',
'duration',
// LargestContentfulPaint
'renderTime',
'loadTime',
'size',
'id',
'url',
'element',
];
for (const key of keys) {
assert_equals(json[key], entry[key],
'LargestContentfulPaint ${key} entry does not match its toJSON value');
}
})
);
observer.observe({type: 'largest-contentful-paint', buffered: true});
}, 'Test toJSON() in LargestContentfulPaint.');
</script>
</body>
42 changes: 42 additions & 0 deletions layout-instability/toJSON.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Layout Instability: toJSON</title>
<body>
<style>
#myDiv { position: relative; width: 300px; height: 100px; }
</style>
<div id='myDiv'></div>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function (t) {
if (!window.LayoutShift)
assert_unreached('LayoutShift entries are not supported');
const observer = new PerformanceObserver(
t.step_func_done(function(entryList) {
const entry = entryList.getEntries()[0];
assert_equals(typeof(entry.toJSON), 'function');
const json = entry.toJSON();
assert_equals(typeof(json), 'object');
const keys = [
// PerformanceEntry
'name',
'entryType',
'startTime',
'duration',
// LayoutShift
'value',
'hadRecentInput',
'lastInputTime',
];
for (const key of keys) {
assert_equals(json[key], entry[key],
'LayoutShift ${key} entry does not match its toJSON value');
}
})
);
observer.observe({type: 'layout-shift'});
document.getElementById('myDiv').style = "top: 60px";
}, 'Test toJSON() in LayoutShift.');
</script>
</body>