| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 1 | <!DOCTYPE HTML> |
| 2 | <meta charset=utf-8> |
| 3 | <title>LongTask Timing: long task in external script</title> |
| 4 | <body> |
| 5 | |
| 6 | <script src="/resources/testharness.js"></script> |
| 7 | <script src="/resources/testharnessreport.js"></script> |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 8 | |
| 9 | <h1>Long Task: External Script</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); |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 26 | |
| 27 | // Assert the TaskAttributionTiming entry in attribution. |
| 28 | assert_equals(longtask.attribution.length, 1, |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 29 | 'Exactly one attribution entry is expected'); |
| 30 | const attribution = longtask.attribution[0]; |
| 31 | assert_equals(attribution.entryType, 'taskattribution'); |
| 32 | assert_equals(attribution.name, 'script'); |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 33 | assert_equals(attribution.duration, 0); |
| 34 | assert_equals(attribution.startTime, 0); |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 35 | assert_equals(attribution.containerId, ''); |
| 36 | assert_equals(attribution.containerName, ''); |
| 37 | assert_equals(attribution.containerSrc, ''); |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 38 | observer.disconnect(); |
| 39 | t.done(); |
| 40 | }) |
| 41 | ); |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 42 | observer.observe({entryTypes: ['longtask']}); |
| Nicolas Pena | 930d2ef | 2018-07-16 20:18:13 | [diff] [blame^] | 43 | window.onload = () => { |
| 44 | const script = document.createElement('script'); |
| 45 | script.src = 'resources/makelongtask.js'; |
| 46 | document.body.appendChild(script); |
| 47 | } |
| npm@chromium.org | 71ff888 | 2017-08-15 17:22:01 | [diff] [blame] | 48 | }, 'Performance longtask entries are observable.'); |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 49 | </script> |
| spanicker | a5b95cb | 2017-03-10 22:42:55 | [diff] [blame] | 50 | </body> |