Bug 1610669 [wpt PR 21326] - Use assert_precondition in ElementTiming/LargestContentf...
[gecko.git] / testing / web-platform / tests / element-timing / toJSON.html
blobba13a0fa90797c0bc6fb104857d5ab86a0790b3d
1 <!DOCTYPE HTML>
2 <meta charset=utf-8>
3 <title>Element Timing: toJSON</title>
4 <body>
5 <script src="/resources/testharness.js"></script>
6 <script src="/resources/testharnessreport.js"></script>
7 <script src="resources/element-timing-helpers.js"></script>
8 <img elementtiming='img' src="resources/square100.png"/>
9 <script>
10 async_test(function (t) {
11 assert_precondition(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented");
12 const observer = new PerformanceObserver(
13 t.step_func_done(function(entryList) {
14 assert_equals(entryList.getEntries().length, 1);
15 const entry = entryList.getEntries()[0];
16 assert_equals(typeof(entry.toJSON), 'function');
17 const json = entry.toJSON();
18 assert_equals(typeof(json), 'object');
19 const keys = [
20 // PerformanceEntry
21 'name',
22 'entryType',
23 'startTime',
24 'duration',
25 // PerformanceElementTiming
26 'renderTime',
27 'loadTime',
28 'intersectionRect',
29 'identifier',
30 'naturalWidth',
31 'naturalHeight',
32 'id',
33 'element',
34 'url',
36 for (const key of keys) {
37 assert_equals(json[key], entry[key],
38 'PerformanceElementTiming ${key} entry does not match its toJSON value');
42 observer.observe({type: 'element', buffered: true});
43 }, 'Test toJSON() in PerformanceElementTiming.');
44 </script>
45 </body>