| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 1 | <!DOCTYPE HTML> |
| 2 | <meta charset=utf-8> |
| 3 | <title>LongTask Timing: validate long task attributes</title> |
| 4 | <body> |
| 5 | |
| 6 | <script src="/resources/testharness.js"></script> |
| 7 | <script src="/resources/testharnessreport.js"></script> |
| 8 | |
| 9 | <h1>Long Task Attributes</h1> |
| 10 | <div id="log"></div> |
| 11 | <script> |
| 12 | async_test(function (t) { |
| Nicolas Pena | cd75119 | 2018-07-10 21:05:27 | [diff] [blame] | 13 | if (typeof PerformanceLongTaskTiming === 'undefined') { |
| 14 | assert_unreached("Longtasks are not supported."); |
| 15 | t.done(); |
| 16 | } |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 17 | const observer = new PerformanceObserver( |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 18 | t.step_func(function (entryList) { |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 19 | const entries = entryList.getEntries(); |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 20 | assert_equals(entries.length, 1, |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 21 | 'Exactly one entry is expected.'); |
| 22 | const longtask = entries[0]; |
| 23 | assert_equals(longtask.entryType, 'longtask'); |
| 24 | assert_equals(longtask.name, 'self'); |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 25 | assert_greater_than(longtask.duration, 50); |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 26 | assert_greater_than_equal(longtask.startTime, 0); |
| 27 | const currentTime = performance.now(); |
| 28 | assert_less_than_equal(longtask.startTime, currentTime); |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 29 | |
| 30 | // Assert the TaskAttributionTiming entry in attribution. |
| 31 | assert_equals(longtask.attribution.length, 1, |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 32 | 'Exactly one attribution entry is expected'); |
| 33 | const attribution = longtask.attribution[0]; |
| 34 | assert_equals(attribution.entryType, 'taskattribution'); |
| Nicolas Pena | 4309ceb | 2018-11-15 20:00:44 | [diff] [blame] | 35 | assert_equals(attribution.name, 'unknown'); |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 36 | assert_equals(attribution.duration, 0); |
| 37 | assert_equals(attribution.startTime, 0); |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 38 | assert_equals(attribution.containerId, ''); |
| 39 | assert_equals(attribution.containerName, ''); |
| 40 | assert_equals(attribution.containerSrc, ''); |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 41 | observer.disconnect(); |
| 42 | t.done(); |
| 43 | }) |
| 44 | ); |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 45 | observer.observe({entryTypes: ['longtask']}); |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 46 | |
| Nicolas Pena | 930d2ef | 2018-07-16 20:18:13 | [diff] [blame] | 47 | window.onload = () => { |
| 48 | /* Generate a slow task */ |
| 49 | const begin = window.performance.now(); |
| 50 | while (window.performance.now() < begin + 60); |
| 51 | }; |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 52 | }, 'Performance longtask entries are observable.'); |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 53 | </script> |
| 54 | |
| Nicolas Pena | 4309ceb | 2018-11-15 20:00:44 | [diff] [blame] | 55 | </body> |